A platform for community discussion. Free, open, simple.
FIX: Category group moderators can read flagged post meta_topics (#14014)
jbrw20a6bad87ee4
diff --git a/lib/guardian.rb b/lib/guardian.rbindex 54822b95b92..9312442f414 100644--- a/lib/guardian.rb+++ b/lib/guardian.rb@@ -445,7 +445,7 @@ class Guardian# Can't send PMs to suspended users(is_staff? || is_group || !target.suspended?) &&# Check group messageable level- (is_staff? || is_user || Group.messageable(@user).where(id: target.id).exists?) &&+ (is_staff? || is_user || Group.messageable(@user).where(id: target.id).exists? || notify_moderators) &&# Silenced users can only send PM to staff(!is_silenced? || target.staff?)enddiff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rbindex 559aaaf23ec..e1f42eef74c 100644--- a/lib/post_action_creator.rb+++ b/lib/post_action_creator.rb@@ -306,7 +306,11 @@ privateif [:notify_moderators, :spam].include?(@post_action_name)create_args[:subtype] = TopicSubtype.notify_moderators- create_args[:target_group_names] = Group[:moderators].name+ create_args[:target_group_names] = [Group[:moderators].name]++ if SiteSetting.enable_category_group_moderation? && @post.topic&.category&.reviewable_by_group_id?+ create_args[:target_group_names] << @post.topic.category.reviewable_by_group.name+ endelsecreate_args[:subtype] = TopicSubtype.notify_userdiff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rbindex b81b73504b2..45bf725fdb2 100644--- a/spec/models/post_action_spec.rb+++ b/spec/models/post_action_spec.rb@@ -91,6 +91,28 @@ describe PostAction doexpect(topic.message_archived?(mod)).to eq(true)end+ context "category group moderators" do+ fab!(:group_user) { Fabricate(:group_user) }+ let(:group) { group_user.group }++ before do+ SiteSetting.enable_category_group_moderation = true+ group.update!(messageable_level: Group::ALIAS_LEVELS[:nobody])+ post.topic.category.update!(reviewable_by_group_id: group.id)+ end++ it "notifies via pm" do+ result = PostActionCreator.notify_moderators(+ codinghorror,+ post,+ "this is my special long message"+ )++ readable_by_groups = result.reviewable_score.meta_topic.topic_allowed_groups.map(&:group_id)+ expect(readable_by_groups).to include(group.id)+ end+ end+enddescribe "update_counters" do@@ -831,16 +853,11 @@ describe PostAction doendit "should raise the right errors when it fails to create a post" do- begin- group = Group[:moderators]- messageable_level = group.messageable_level- group.update!(messageable_level: Group::ALIAS_LEVELS[:nobody])+ user = Fabricate(:user)+ UserSilencer.new(user, Discourse.system_user).silence- result = PostActionCreator.notify_moderators(Fabricate(:user), post, 'testing')- expect(result).to be_failed- ensure- group.update!(messageable_level: messageable_level)- end+ result = PostActionCreator.notify_moderators(user, post, 'testing')+ expect(result).to be_failedendit "should succeed even with low max title length" do