From b0b2e8d3a936b9ee4dfe0bf847446d0b0103be25 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 17 Jun 2019 10:01:59 +0200 Subject: [PATCH] use an async worker to notify users about policy update --- app/models/setting.rb | 4 +--- app/workers/notify_privacy_update_worker.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 app/workers/notify_privacy_update_worker.rb diff --git a/app/models/setting.rb b/app/models/setting.rb index 8e07e6535..517c2b912 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -51,9 +51,7 @@ class Setting < ActiveRecord::Base def notify_privacy_policy_changed return unless name == 'privacy_body' - NotificationCenter.call type: :notify_privacy_policy_changed, - receiver: User.all, - attached_object: self + NotifyPrivacyUpdateWorker.perform_async(id) end def value diff --git a/app/workers/notify_privacy_update_worker.rb b/app/workers/notify_privacy_update_worker.rb new file mode 100644 index 000000000..7e1266309 --- /dev/null +++ b/app/workers/notify_privacy_update_worker.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Send an email to all users (with role member) in the database to alert them about a privacy policy change +class NotifyPrivacyUpdateWorker + include Sidekiq::Worker + + def perform(setting_id) + setting = Setting.find(setting_id) + + # notify all users + NotificationCenter.call type: :notify_privacy_policy_changed, + receiver: User.with_role(:member).all, + attached_object: setting + end + +end