Skip to content

Commit

Permalink
FEATURE: Add pending assign reminder threshold setting (#571)
Browse files Browse the repository at this point in the history
* FEATURE: Add pending assign reminder threshold setting

User can define a threshold for the pending assign reminder.

* DEV: rename REMINDER_THRESHOLD with SiteSetting
  • Loading branch information
Grubba27 committed May 8, 2024
1 parent 6c22928 commit e3c24ba
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ en:
assign_mailer: "When to send notification email for assignments"
remind_assigns: "Remind users about pending assigns."
remind_assigns_frequency: "Frequency for reminding users about assigned topics."
pending_assign_reminder_threshold: "Number of pending assignments that triggers a reminder notification."
max_assigned_topics: "Maximum number of topics that can be assigned to a user."
assign_allowed_on_groups: "Users in these groups are allowed to assign topics and can be assigned topics."
enable_assign_status: "Add a customizable status field to every assignment."
Expand Down
4 changes: 4 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ discourse_assign:
client: true
enum: "RemindAssignsFrequencySiteSettings"
default: 0
pending_assign_reminder_threshold:
client: true
default: 2
min: 1
max_assigned_topics:
client: true
default: 10
Expand Down
3 changes: 1 addition & 2 deletions lib/pending_assigns_reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ class PendingAssignsReminder
REMINDED_AT = "last_reminded_at"
REMINDERS_FREQUENCY = "remind_assigns_frequency"
CUSTOM_FIELD_NAME = "assigns_reminder"
REMINDER_THRESHOLD = 2

def remind(user)
newest_topics = assigned_topics(user, order: :desc)
return if newest_topics.size < REMINDER_THRESHOLD
return if newest_topics.size < SiteSetting.pending_assign_reminder_threshold

delete_previous_reminders(user)

Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/scheduled/enqueue_reminders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
it "doesn't count assigns from deleted topics" do
deleted_post = Fabricate(:post)
assign_one_task_to(user, post: deleted_post)
(PendingAssignsReminder::REMINDER_THRESHOLD - 1).times { assign_one_task_to(user) }
(SiteSetting.pending_assign_reminder_threshold - 1).times { assign_one_task_to(user) }

deleted_post.topic.trash!

Expand Down Expand Up @@ -115,7 +115,7 @@ def assign_one_task_to(user, assigned_on: 3.months.ago, post: Fabricate(:post))
end

def assign_multiple_tasks_to(user, assigned_on: 3.months.ago)
PendingAssignsReminder::REMINDER_THRESHOLD.times do
SiteSetting.pending_assign_reminder_threshold.times do
assign_one_task_to(user, assigned_on: assigned_on)
end
end
Expand Down

0 comments on commit e3c24ba

Please sign in to comment.