From 2bdb53261be5d910b7496881539dcd7955393f54 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 15 Apr 2013 13:09:52 +1000 Subject: [PATCH] don't treat notify user as a flag --- .../discourse/models/action_summary.js | 7 +++++- app/controllers/admin/flags_controller.rb | 4 ++-- app/models/post_action.rb | 24 +++++++++---------- app/models/post_action_type.rb | 5 ++++ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/models/action_summary.js b/app/assets/javascripts/discourse/models/action_summary.js index d945ab433..66ae696d4 100644 --- a/app/assets/javascripts/discourse/models/action_summary.js +++ b/app/assets/javascripts/discourse/models/action_summary.js @@ -43,7 +43,12 @@ Discourse.ActionSummary = Discourse.Model.extend({ this.set('acted', true); this.set('count', this.get('count') + 1); this.set('can_act', false); - this.set('can_undo', action !== 'notify_moderators' && action !== 'notify_user'); + this.set('can_undo', true); + + if(action === 'notify_moderators' || action=='notify_user') { + this.set('can_undo',false); + this.set('can_clear_flags',false); + } // Add ourselves to the users who liked it if present if (this.present('users')) { diff --git a/app/controllers/admin/flags_controller.rb b/app/controllers/admin/flags_controller.rb index af2cd1107..eb0cbe71e 100644 --- a/app/controllers/admin/flags_controller.rb +++ b/app/controllers/admin/flags_controller.rb @@ -21,7 +21,7 @@ join ( limit 100 " - sql.where2 "post_action_type_id in (:flag_types)", flag_types: PostActionType.flag_types.values + sql.where2 "post_action_type_id in (:flag_types)", flag_types: PostActionType.notify_flag_types.values # it may make sense to add a view that shows flags on deleted posts, @@ -62,7 +62,7 @@ limit 100 from post_actions a /*where*/ " - sql.where("post_action_type_id in (:flag_types)", flag_types: PostActionType.flag_types.values) + sql.where("post_action_type_id in (:flag_types)", flag_types: PostActionType.notify_flag_types.values) sql.where("post_id in (:posts)", posts: posts.map{|p| p["id"].to_i}) if params[:filter] == 'old' diff --git a/app/models/post_action.rb b/app/models/post_action.rb index b870ebdbe..a06f5d802 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -20,7 +20,7 @@ class PostAction < ActiveRecord::Base def self.update_flagged_posts_count posts_flagged_count = PostAction.joins(post: :topic) - .where('post_actions.post_action_type_id' => PostActionType.flag_types.values, + .where('post_actions.post_action_type_id' => PostActionType.notify_flag_types.values, 'posts.deleted_at' => nil, 'topics.deleted_at' => nil).count('DISTINCT posts.id') @@ -74,23 +74,23 @@ class PostAction < ActiveRecord::Base def self.act(user, post, post_action_type_id, message = nil) begin title, target_usernames,body = nil - + if message [:notify_moderators, :notify_user].each do |k| if post_action_type_id == PostActionType.types[k] - target_usernames = k == :notify_moderators ? target_moderators(user) : post.user.username - title = I18n.t("post_action_types.#{k}.email_title", - title: post.topic.title) - body = I18n.t("post_action_types.#{k}.email_body", - message: message, + target_usernames = k == :notify_moderators ? target_moderators(user) : post.user.username + title = I18n.t("post_action_types.#{k}.email_title", + title: post.topic.title) + body = I18n.t("post_action_types.#{k}.email_body", + message: message, link: "#{Discourse.base_url}#{post.url}") end end end if target_usernames.present? - PostCreator.new(user, - target_usernames: target_usernames, + PostCreator.new(user, + target_usernames: target_usernames, archetype: Archetype.private_message, title: title, raw: body @@ -169,11 +169,11 @@ class PostAction < ActiveRecord::Base Topic.update_all ["#{column} = #{column} + ?", delta], id: post.topic_id - if PostActionType.flag_types.values.include?(post_action_type_id) + if PostActionType.notify_flag_types.values.include?(post_action_type_id) PostAction.update_flagged_posts_count end - if SiteSetting.flags_required_to_hide_post > 0 + if PostActionType.auto_action_flag_types.include?(post_action_type) && SiteSetting.flags_required_to_hide_post > 0 # automatic hiding of posts flag_counts = exec_sql("SELECT SUM(CASE WHEN deleted_at IS NULL THEN 1 ELSE 0 END) AS new_flags, SUM(CASE WHEN deleted_at IS NOT NULL THEN 1 ELSE 0 END) AS old_flags @@ -197,7 +197,7 @@ class PostAction < ActiveRecord::Base end end - protected + protected def self.target_moderators(me) User diff --git a/app/models/post_action_type.rb b/app/models/post_action_type.rb index 96c97b347..8eba6a8e4 100644 --- a/app/models/post_action_type.rb +++ b/app/models/post_action_type.rb @@ -21,6 +21,11 @@ class PostActionType < ActiveRecord::Base @flag_types ||= types.only(:off_topic, :spam, :inappropriate, :notify_user, :notify_moderators) end + # flags resulting in mod notifications + def notify_flag_types + @notify_flag_types ||= types.only(:off_topic, :spam, :inappropriate, :notify_moderators) + end + def is_flag?(sym) flag_types.valid?(sym) end