From 50fce0998f18932fa395886dc444250cf24c6951 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 11 Apr 2016 18:07:28 +0530 Subject: [PATCH] FEATURE: allow moderators to see offical warnings --- app/models/topic.rb | 6 +++++- spec/models/topic_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index 7150e00ec..1f8c6eb57 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -254,9 +254,13 @@ class Topic < ActiveRecord::Base .exists? end + def is_official_warning? + subtype == TopicSubtype.moderator_warning + end + # all users (in groups or directly targetted) that are going to get the pm def all_allowed_users - moderators_sql = " UNION #{User.moderators.to_sql}" if private_message? && has_flags? + moderators_sql = " UNION #{User.moderators.to_sql}" if private_message? && (has_flags? || is_official_warning?) User.from("(#{allowed_users.to_sql} UNION #{allowed_group_users.to_sql}#{moderators_sql}) as users") end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 6c071fce2..4ae8009f3 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1367,6 +1367,12 @@ describe Topic do expect(topic.all_allowed_users).to include moderator end + it 'includes moderators if offical warning' do + topic.stubs(:subtype).returns(TopicSubtype.moderator_warning) + topic.stubs(:private_message?).returns(true) + expect(topic.all_allowed_users).to include moderator + end + it 'does not include moderators if pm without flags' do topic.stubs(:private_message?).returns(true) expect(topic.all_allowed_users).not_to include moderator