Commit 06bb1b3d authored by Florian Hübsch's avatar Florian Hübsch
Browse files

Install delayed_jobs, create SharingNotificationMailer.

parent d08f8d6b
......@@ -48,7 +48,12 @@ gem 'chemrails', git: 'git://github.com/cominch/chemrails'
# Free font icons
gem "font-awesome-rails"
# Email notifications and so on
gem 'delayed_job_active_record'
group :development, :test do
gem 'mailcatcher'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
......
......@@ -78,9 +78,14 @@ GEM
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
columnize (0.9.0)
daemons (1.2.2)
daemons (1.2.3)
database_cleaner (1.3.0)
debug_inspector (0.0.2)
delayed_job (4.1.1)
activesupport (>= 3.0, < 5.0)
delayed_job_active_record (4.1.0)
activerecord (>= 3.0, < 5)
delayed_job (>= 3.0, < 5)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (3.5.1)
......@@ -93,7 +98,7 @@ GEM
diff-lcs (1.2.5)
equalizer (0.0.11)
erubis (2.7.0)
eventmachine (1.0.7)
eventmachine (1.0.5)
execjs (2.5.2)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
......@@ -125,7 +130,7 @@ GEM
grape-kaminari (0.1.8)
grape
kaminari
haml (4.0.6)
haml (4.0.7)
tilt
haml-rails (0.9.0)
actionpack (>= 4.0.1)
......@@ -166,7 +171,15 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.6.1)
mailcatcher (0.6.1)
activesupport (>= 4.0.0, < 5)
eventmachine (~> 1.0.0, <= 1.0.5)
mail (~> 2.3)
sinatra (~> 1.2)
skinny (~> 0.2.3)
sqlite3 (~> 1.3)
thin (~> 1.5.0)
mime-types (2.6.2)
mini_portile (0.6.2)
minitest (5.7.0)
multi_json (1.11.1)
......@@ -177,11 +190,13 @@ GEM
pg (0.18.2)
pundit (0.3.0)
activesupport (>= 3.0.0)
rack (1.6.2)
rack (1.6.4)
rack-accept (0.4.5)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.0)
......@@ -246,6 +261,13 @@ GEM
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
sexp_processor (4.6.0)
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
skinny (0.2.3)
eventmachine (~> 1.0.0)
thin (~> 1.5.0)
spring (1.3.6)
sprockets (3.2.0)
rack (~> 1.0)
......@@ -253,10 +275,11 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
thin (1.6.3)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0)
rack (~> 1.0)
sqlite3 (1.3.10)
thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
......@@ -291,6 +314,7 @@ DEPENDENCIES
byebug
chemrails!
database_cleaner
delayed_job_active_record
devise
factory_girl_rails
font-awesome-rails
......@@ -304,6 +328,7 @@ DEPENDENCIES
jbuilder (~> 2.0)
jquery-rails
kaminari
mailcatcher
openbabel (= 2.3.2.1)!
pg
pundit
......
......@@ -20,6 +20,10 @@
Currently 3 users are seeded with respective email `test@ninjaconcept.com`, `hattori@ninjaconcept.com`, `momochi@ninjaconcept.com`, and password `ninjaconcept` (for all 3 the same).
# Mailing in Development Environment
Run `rake jobs:work` for asynchronous handling of email notifications. Run `mailcatcher` in your console and go to `localhost:1080` to see all sent mails.
# API (v1)
## Collections
......
class SendSharingNotificationJob < ActiveJob::Base
queue_as :default
def perform(user, data)
SharingNotificationMailer.send_mail(user, data).deliver_now
end
end
class SharingNotificationMailer < ActionMailer::Base
default from: "tba"
def send_mail(user, data)
mail(to: user.email, subject: "A new collection has been shared with you")
end
end
......@@ -3,6 +3,7 @@ module Usecases
class ShareWithUser
def initialize(params)
@params = params
@user = User.find(@params[:collection_attributes][:user_id])
end
def execute!
......@@ -20,6 +21,8 @@ module Usecases
@params.fetch(:wellplate_ids, []).each do |wellplate_id|
CollectionsWellplate.create(collection_id: c.id, wellplate_id: wellplate_id)
end
SendSharingNotificationJob.perform_later(@user, '')
end
end
end
......
Dear Chemotion-User,
%p
A new collection has been shared with you.
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize
......@@ -22,6 +22,8 @@ module Chemotion
config.autoload_paths += Dir[Rails.root.join('app')]
config.autoload_paths += Dir[Rails.root.join('lib')]
config.active_job.queue_adapter = :delayed_job
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
......
......@@ -35,6 +35,7 @@ Rails.application.configure do
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
#config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
end
class CreateDelayedJobs < ActiveRecord::Migration
def self.up
create_table :delayed_jobs, force: true do |table|
table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
table.text :handler, null: false # YAML-encoded string of the object that will do work
table.text :last_error # reason for last failure (See Note below)
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
table.datetime :locked_at # Set when a client is working on this object
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
table.string :locked_by # Who is working on this object (if locked)
table.string :queue # The name of the queue this job is in
table.timestamps null: true
end
add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
end
def self.down
drop_table :delayed_jobs
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150928075813) do
ActiveRecord::Schema.define(version: 20150929123358) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -58,6 +58,22 @@ ActiveRecord::Schema.define(version: 20150928075813) do
add_index "collections_wellplates", ["collection_id"], name: "index_collections_wellplates_on_collection_id", using: :btree
add_index "collections_wellplates", ["wellplate_id"], name: "index_collections_wellplates_on_wellplate_id", using: :btree
create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false
t.integer "attempts", default: 0, null: false
t.text "handler", null: false
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.string "queue"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
create_table "literatures", force: :cascade do |t|
t.integer "reaction_id", null: false
t.string "title"
......
require 'rails_helper'
RSpec.describe Usecases::Sharing::ShareWithUser do
let(:user) { create(:user) }
let(:sample_1) { create(:sample) }
let(:sample_2) { create(:sample) }
let(:reaction_1) { create(:reaction) }
......@@ -12,7 +13,7 @@ RSpec.describe Usecases::Sharing::ShareWithUser do
{
# TODO parent of collection?
collection_attributes: {
user_id: 7,
user_id: user.id,
label: 'test',
shared_by_id: 10,
is_shared: true,
......@@ -36,7 +37,7 @@ RSpec.describe Usecases::Sharing::ShareWithUser do
c = Collection.find_by(label: 'test')
expect(c).to_not be_nil
expect(c.user_id).to eq(7)
expect(c.user_id).to eq(user.id)
expect(c.shared_by_id).to eq(10)
expect(c.is_shared).to eq(true)
expect(c.permission_level).to eq(1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment