FIX: don't send repeated notifications that there are pending users who need to be approved to moderators who haven't read the previous notification
This commit is contained in:
parent
d9c2b316b6
commit
4c867c5796
|
@ -9,7 +9,24 @@ module Jobs
|
|||
if SiteSetting.must_approve_users
|
||||
count = AdminUserIndexQuery.new({query: 'pending'}).find_users_query.count
|
||||
if count > 0
|
||||
GroupMessage.create(Group[:moderators].name, :pending_users_reminder, {limit_once_per: false, message_params: {count: count}})
|
||||
target_usernames = Group[:moderators].users.map do |u|
|
||||
u.id > 0 && u.notifications.joins(:topic)
|
||||
.where("notifications.id > ?", u.seen_notification_id)
|
||||
.where("notifications.read = false")
|
||||
.where("topics.subtype = '#{TopicSubtype.pending_users_reminder}'")
|
||||
.count == 0 ? u.username : nil
|
||||
end.compact
|
||||
|
||||
unless target_usernames.empty?
|
||||
PostCreator.create(
|
||||
Discourse.system_user,
|
||||
target_usernames: target_usernames,
|
||||
archetype: Archetype.private_message,
|
||||
subtype: TopicSubtype.pending_users_reminder,
|
||||
title: I18n.t("system_messages.pending_users_reminder.subject_template", {count: count}),
|
||||
raw: I18n.t("system_messages.pending_users_reminder.text_body_template", {count: count, base_url: Discourse.base_url})
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,6 +37,10 @@ class TopicSubtype
|
|||
'notify_user'
|
||||
end
|
||||
|
||||
def self.pending_users_reminder
|
||||
'pending_users'
|
||||
end
|
||||
|
||||
def self.register(name, options={})
|
||||
@subtypes ||= {}
|
||||
@subtypes[name] = TopicSubtype.new(name, options)
|
||||
|
|
|
@ -9,13 +9,15 @@ describe Jobs::PendingUsersReminder do
|
|||
|
||||
it "doesn't send a message to anyone when there are no pending users" do
|
||||
AdminUserIndexQuery.any_instance.stubs(:find_users_query).returns(stub_everything(count: 0))
|
||||
GroupMessage.any_instance.expects(:create).never
|
||||
PostCreator.expects(:create).never
|
||||
Jobs::PendingUsersReminder.new.execute({})
|
||||
end
|
||||
|
||||
it "sends a message to moderators when there are pending users" do
|
||||
it "sends a message when there are pending users" do
|
||||
Fabricate(:moderator)
|
||||
Group.refresh_automatic_group!(:moderators)
|
||||
AdminUserIndexQuery.any_instance.stubs(:find_users_query).returns(stub_everything(count: 1))
|
||||
GroupMessage.expects(:create).with(Group[:moderators].name, :pending_users_reminder, anything)
|
||||
PostCreator.expects(:create).once
|
||||
Jobs::PendingUsersReminder.new.execute({})
|
||||
end
|
||||
end
|
||||
|
@ -27,7 +29,7 @@ describe Jobs::PendingUsersReminder do
|
|||
|
||||
it "doesn't send a message to anyone when there are pending users" do
|
||||
AdminUserIndexQuery.any_instance.stubs(:find_users_query).returns(stub_everything(count: 1))
|
||||
GroupMessage.any_instance.expects(:create).never
|
||||
PostCreator.expects(:create).never
|
||||
Jobs::PendingUsersReminder.new.execute({})
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue