FIX: query for cakeday candidates

FIX: query for cakeday candidates

Cakeday candidates must be activated, not silenced and not suspended.

diff --git a/jobs/scheduled/check_cakeday.rb b/jobs/scheduled/check_cakeday.rb
index b1fed34..ac8d7c6 100644
--- a/jobs/scheduled/check_cakeday.rb
+++ b/jobs/scheduled/check_cakeday.rb
@@ -19,8 +19,7 @@ module Jobs
 
     def assign_reminder_pm(user)
       manager_name = user.custom_fields[DevAdditions::MANAGER_CUSTOM_FIELD] || 'sam'
-      manager = User.find_by(username: manager_name)
-      manager ||= User.find_by(username: 'sam')
+      manager = User.find_by(username: manager_name) || User.find_by(username: 'sam')
 
       body = <<~STR
         It is time for a yearly review for #{user.username}.
@@ -57,20 +56,14 @@ module Jobs
 
       User
         .real
+        .activated
+        .not_silenced
+        .not_suspended
         .where(staged: false)
-        .joins("LEFT JOIN user_custom_fields f1 ON f1.user_id = users.id AND f1.name = 'cakeday_notice'")
+        .joins("LEFT JOIN user_custom_fields f1 ON f1.user_id = users.id AND f1.name = ?", DevAdditions::CAKEDAY_NOTICE_CUSTOM_FIELD)
         .joins('LEFT JOIN topics t ON f1.value IS NOT NULL AND f1.value::int = t.id')
-        .where(
-          'extract(DOY from users.created_at) between :from AND :to',
-          from: yday - 1,
-          to: yday + 1,
-          custom_field: DevAdditions::CAKEDAY_NOTICE_CUSTOM_FIELD
-        )
-        .where(
-          't.id IS NULL OR (t.created_at < :old)',
-          old: 10.days.ago
-        )
-
+        .where('EXTRACT(DOY FROM users.created_at) BETWEEN ? AND ?', yday - 1, yday + 1)
+        .where('t.id IS NULL OR (t.created_at < ?)', 10.days.ago)
     end
   end
 end

GitHub sha: 2cce071d