Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: allow category group moderators to edit posts (#11005)

jbrwce765530105d
diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb
index 7126e669122..31a198142e5 100644
--- a/lib/guardian/post_guardian.rb
+++ b/lib/guardian/post_guardian.rb
@@ -131,7 +131,8 @@ module PostGuardian
(
SiteSetting.trusted_users_can_edit_others? &&
@user.has_trust_level?(TrustLevel[4])
- )
+ ) ||
+ is_category_group_moderator?(post.topic.category)
)
if post.topic&.archived? || post.user_deleted || post.deleted_at
diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb
index b438054bfbc..5bfa887a679 100644
--- a/spec/components/guardian_spec.rb
+++ b/spec/components/guardian_spec.rb
@@ -1388,7 +1388,7 @@ describe Guardian do
expect(Guardian.new(trust_level_4).can_edit?(post)).to be_truthy
end
- it 'returns false as a TL4 user if trusted_users_can_edit_others is true' do
+ it 'returns false as a TL4 user if trusted_users_can_edit_others is false' do
SiteSetting.trusted_users_can_edit_others = false
expect(Guardian.new(trust_level_4).can_edit?(post)).to eq(false)
end
@@ -1438,6 +1438,24 @@ describe Guardian do
expect(Guardian.new(post.user).can_edit?(post)).to be_truthy
end
+ context 'category group moderation is enabled' do
+ fab!(:cat_mod_user) { Fabricate(:user) }
+
+ before do
+ SiteSetting.enable_category_group_moderation = true
+ GroupUser.create!(group_id: group.id, user_id: cat_mod_user.id)
+ post.topic.category.update!(reviewable_by_group_id: group.id)
+ end
+
+ it 'returns true as a category group moderator user' do
+ expect(Guardian.new(cat_mod_user).can_edit?(post)).to eq(true)
+ end
+
+ it 'returns false for a regular user' do
+ expect(Guardian.new(another_user).can_edit?(post)).to eq(false)
+ end
+ end
+
describe 'post edit time limits' do
context 'post is older than post_edit_time_limit' do
let(:old_post) { build(:post, topic: topic, user: topic.user, created_at: 6.minutes.ago) }
diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb
index 20b2488343d..5e230a3f9f5 100644
--- a/spec/requests/posts_controller_spec.rb
+++ b/spec/requests/posts_controller_spec.rb
@@ -448,21 +448,6 @@ describe PostsController do
expect(UserHistory.where(action: UserHistory.actions[:post_edit]).count).to eq(1)
end
- it "can not update other posts within the primary category topic" do
- second_post = Fabricate(:post, user: user, topic: topic)
-
- put "/posts/#{second_post.id}.json", params: update_params
- expect(response.status).to eq(403)
- end
-
- it "can not update other first posts of topics in the same category" do
- second_topic_in_category = Fabricate(:topic, category: category)
- post_in_second_topic = Fabricate(:post, user: user, topic: second_topic_in_category)
-
- put "/posts/#{post_in_second_topic.id}.json", params: update_params
- expect(response.status).to eq(403)
- end
-
it "can not update category descriptions in other categories" do
second_category = Fabricate(:category)
topic.update!(category: second_category)