mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
BUGFIX: moderators can notify moderators
This commit is contained in:
parent
d11d31acaa
commit
08dde3d881
@ -96,33 +96,30 @@ class PostAction < ActiveRecord::Base
|
||||
|
||||
return unless opts[:message] && [:notify_moderators, :notify_user].include?(post_action_type)
|
||||
|
||||
target_usernames = if post_action_type == :notify_user
|
||||
post.user.username
|
||||
elsif post_action_type == :notify_moderators
|
||||
User.moderators.pluck(:username)
|
||||
title = I18n.t("post_action_types.#{post_action_type}.email_title", title: post.topic.title)
|
||||
body = I18n.t("post_action_types.#{post_action_type}.email_body", message: opts[:message], link: "#{Discourse.base_url}#{post.url}")
|
||||
|
||||
opts = {
|
||||
archetype: Archetype.private_message,
|
||||
title: title,
|
||||
raw: body
|
||||
}
|
||||
|
||||
if post_action_type == :notify_moderators
|
||||
opts[:subtype] = TopicSubtype.notify_moderators
|
||||
opts[:target_group_names] = "moderators"
|
||||
else
|
||||
# this is a hack to allow a PM with no reciepients, we should think through
|
||||
# a cleaner technique, a PM with myself is valid for flagging
|
||||
'x'
|
||||
opts[:subtype] = TopicSubtype.notify_user
|
||||
opts[:target_usernames] = if post_action_type == :notify_user
|
||||
post.user.username
|
||||
elsif post_action_type != :notify_moderators
|
||||
# this is a hack to allow a PM with no reciepients, we should think through
|
||||
# a cleaner technique, a PM with myself is valid for flagging
|
||||
'x'
|
||||
end
|
||||
end
|
||||
|
||||
title = I18n.t("post_action_types.#{post_action_type}.email_title",
|
||||
title: post.topic.title)
|
||||
body = I18n.t("post_action_types.#{post_action_type}.email_body",
|
||||
message: opts[:message],
|
||||
link: "#{Discourse.base_url}#{post.url}")
|
||||
|
||||
subtype = post_action_type == :notify_moderators ? TopicSubtype.notify_moderators : TopicSubtype.notify_user
|
||||
|
||||
if target_usernames.present?
|
||||
PostCreator.new(user,
|
||||
target_usernames: target_usernames,
|
||||
archetype: Archetype.private_message,
|
||||
subtype: subtype,
|
||||
title: title,
|
||||
raw: body
|
||||
).create.id
|
||||
end
|
||||
PostCreator.new(user, opts).create.id
|
||||
end
|
||||
|
||||
def self.act(user, post, post_action_type_id, opts={})
|
||||
|
@ -32,7 +32,10 @@ describe PostAction do
|
||||
# Moderators should be invited to the private topic, otherwise they're not permitted to see it
|
||||
topic_user_ids = posts[0].topic.topic_users.map {|x| x.user_id}
|
||||
topic_user_ids.should include(codinghorror.id)
|
||||
topic_user_ids.should include(mod.id)
|
||||
topic_user_ids.should_not include(mod.id)
|
||||
|
||||
# invite the moderator
|
||||
posts[0].topic.allowed_users << mod
|
||||
|
||||
# reply to PM should clear flag
|
||||
p = PostCreator.new(mod, topic_id: posts[0].topic_id, raw: "This is my test reply to the user, it should clear flags")
|
||||
|
Loading…
Reference in New Issue
Block a user