From 08dde3d8815e4f652dd336bf7e31596554c6d52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 13 May 2014 17:44:23 +0200 Subject: [PATCH] BUGFIX: moderators can notify moderators --- app/models/post_action.rb | 45 +++++++++++++++------------------ spec/models/post_action_spec.rb | 5 +++- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 0096a5df3c3..e95ec5e79be 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -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={}) diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 0697130f5a2..182963aa1aa 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -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")