FIX: Only send reminders to moderators and admins.

approved
#1

FIX: Only send reminders to moderators and admins.

diff --git a/app/models/remind_assigns_frequency_site_settings.rb b/app/models/remind_assigns_frequency_site_settings.rb
index 38a40bd..de65e61 100644
--- a/app/models/remind_assigns_frequency_site_settings.rb
+++ b/app/models/remind_assigns_frequency_site_settings.rb
@@ -7,12 +7,27 @@ class RemindAssignsFrequencySiteSettings < EnumSiteSetting
     values.any? { |v| v[:value] == val.to_i }
   end
 
+  DAILY_MINUTES = 24 * 60 * 1
+  MONTHLY_MINUTES = DAILY_MINUTES * 30
+  QUARTERLY_MINUTES = DAILY_MINUTES * 90
+
   def self.values
     @values ||= [
-      { name: 'discourse_assign.reminders_frequency.never', value: 0 },
-      { name: 'discourse_assign.reminders_frequency.daily', value: 1440 },
-      { name: 'discourse_assign.reminders_frequency.monthly', value: 43200 },
-      { name: 'discourse_assign.reminders_frequency.quarterly', value: 131400 }
+      {
+        name: 'discourse_assign.reminders_frequency.never', value: 0
+      },
+      {
+        name: 'discourse_assign.reminders_frequency.daily',
+        value: DAILY_MINUTES
+      },
+      {
+        name: 'discourse_assign.reminders_frequency.monthly',
+        value: MONTHLY_MINUTES
+      },
+      {
+        name: 'discourse_assign.reminders_frequency.quarterly',
+        value: QUARTERLY_MINUTES
+      }
     ]
   end
 
diff --git a/jobs/scheduled/enqueue_reminders.rb b/jobs/scheduled/enqueue_reminders.rb
index dada73a..ed96517 100644
--- a/jobs/scheduled/enqueue_reminders.rb
+++ b/jobs/scheduled/enqueue_reminders.rb
@@ -21,7 +21,9 @@ module Jobs
           LEFT OUTER JOIN user_custom_fields ON topic_custom_fields.value::INT = user_custom_fields.user_id
           AND user_custom_fields.name = '#{PendingAssignsReminder::REMINDED_AT}'
         SQL
-        ).where(<<~SQL
+        ).joins("INNER JOIN users ON topic_custom_fields.value::INT = users.id")
+        .where("users.moderator OR users.admin")
+        .where(<<~SQL
           user_custom_fields.value IS NULL OR
           user_custom_fields.value::TIMESTAMP <= CURRENT_TIMESTAMP - ('1 MINUTE'::INTERVAL * #{interval})
         SQL
diff --git a/spec/jobs/scheduled/enqueue_reminders_spec.rb b/spec/jobs/scheduled/enqueue_reminders_spec.rb
index f5e50d0..8ff7abb 100644
--- a/spec/jobs/scheduled/enqueue_reminders_spec.rb
+++ b/spec/jobs/scheduled/enqueue_reminders_spec.rb
@@ -1,7 +1,11 @@
 require 'rails_helper'
 
 RSpec.describe Jobs::EnqueueReminders do
-  let(:user) { Fabricate(:user) }
+  let(:user) { Fabricate(:user, admin: true) }
+
+  before do
+    SiteSetting.remind_assigns_frequency = RemindAssignsFrequencySiteSettings::MONTHLY_MINUTES
+  end
 
   describe '#execute' do
     it 'does not enqueue reminders when there are no assigned tasks' do

GitHub sha: 8b06b7cb

1 Like
Approved #2