FIX: NewPostManager should respect category_group_moderator settings (#12116)

NewPostManager’s `post_needs_approval_in_its_category` method should allow category group moderators to create topics/reply to topics that where they have appropraite permissions.

(ie, if a user has permission to moderate a post, any posts made by them shouldn’t be sent to moderation)
This commit is contained in:
jbrw 2021-02-18 13:00:06 -05:00 committed by GitHub
parent 916e1d85cf
commit 447ea3f888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View File

@ -120,9 +120,12 @@ class NewPostManager
if manager.args[:topic_id].present?
cat = Category.joins(:topics).find_by(topics: { id: manager.args[:topic_id] })
return false unless cat
cat.require_reply_approval?
topic = Topic.find(manager.args[:topic_id])
cat.require_reply_approval? && !manager.user.guardian.can_review_topic?(topic)
elsif manager.args[:category].present?
Category.find(manager.args[:category]).require_topic_approval?
cat = Category.find(manager.args[:category])
cat.require_topic_approval? && !manager.user.guardian.is_category_group_moderator?(cat)
else
false
end

View File

@ -451,7 +451,8 @@ describe NewPostManager do
context 'when posting in the category requires approval' do
fab!(:user) { Fabricate(:user) }
fab!(:category) { Fabricate(:category) }
fab!(:review_group) { Fabricate(:group) }
fab!(:category) { Fabricate(:category, reviewable_by_group_id: review_group.id) }
context 'when new topics require approval' do
before do
@ -471,6 +472,22 @@ describe NewPostManager do
expect(result.action).to eq(:enqueued)
expect(result.reason).to eq(:category)
end
it 'does not enqueue the topic when the poster is a category group moderator' do
SiteSetting.enable_category_group_moderation = true
review_group.users << user
manager = NewPostManager.new(
user,
raw: 'this is a new topic',
title: "Let's start a new topic!",
category: category.id
)
result = manager.perform
expect(result.action).to eq(:create_post)
expect(result).to be_success
end
end
context 'when new posts require approval' do
@ -499,6 +516,21 @@ describe NewPostManager do
expect(manager.perform.action).to eq(:create_post)
end.not_to raise_error
end
it 'does not enqueue the post when the poster is a category group moderator' do
SiteSetting.enable_category_group_moderation = true
review_group.users << user
manager = NewPostManager.new(
user,
raw: 'this is a new post',
topic_id: topic.id
)
result = manager.perform
expect(result.action).to eq(:create_post)
expect(result).to be_success
end
end
end