BUGFIX: moderators can notify moderators

This commit is contained in:
Régis Hanol 2014-05-13 17:44:23 +02:00
parent d11d31acaa
commit 08dde3d881
2 changed files with 25 additions and 25 deletions

View File

@ -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={})

View File

@ -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")