diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb index 008f1113b7d..9b72719232b 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -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 diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rb index b0ec1514e7b..0540b3207d8 100644 --- a/spec/components/new_post_manager_spec.rb +++ b/spec/components/new_post_manager_spec.rb @@ -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