mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FIX: Category group moderators can read flagged post meta_topics (#14014)
When a post is flagged with the reason of 'Something Else' a brief message can be added by the user which subsequently creates a `meta_topic` private message. The group `moderators` is automatically added to this topic. If category group moderation is enabled, and the post belongs to a category with a reviewable group, that group should also be added to the meta_topic. Note: This extends the `notify_moderators` logic, and will add the reviewable group to the meta_topic, regardless of the settings of that group.
This commit is contained in:
parent
630d485f0f
commit
20a6bad87e
|
@ -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?)
|
||||
end
|
||||
|
|
|
@ -306,7 +306,11 @@ private
|
|||
|
||||
if [: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
|
||||
end
|
||||
else
|
||||
create_args[:subtype] = TopicSubtype.notify_user
|
||||
|
||||
|
|
|
@ -91,6 +91,28 @@ describe PostAction do
|
|||
expect(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
|
||||
|
||||
end
|
||||
|
||||
describe "update_counters" do
|
||||
|
@ -831,16 +853,11 @@ describe PostAction do
|
|||
end
|
||||
|
||||
it "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_failed
|
||||
end
|
||||
|
||||
it "should succeed even with low max title length" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user