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

* FEATURE: allow category group moderators to edit posts

If the `enable_category_group_moderation` SiteSetting is enabled, posts should be editable by those belonging to the appropraite groups.
This commit is contained in:
jbrw 2020-10-23 12:37:44 -04:00 committed by GitHub
parent 8a3a6face5
commit ce76553010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 17 deletions

View File

@ -131,7 +131,8 @@ module PostGuardian
( (
SiteSetting.trusted_users_can_edit_others? && SiteSetting.trusted_users_can_edit_others? &&
@user.has_trust_level?(TrustLevel[4]) @user.has_trust_level?(TrustLevel[4])
) ) ||
is_category_group_moderator?(post.topic.category)
) )
if post.topic&.archived? || post.user_deleted || post.deleted_at if post.topic&.archived? || post.user_deleted || post.deleted_at

View File

@ -1388,7 +1388,7 @@ describe Guardian do
expect(Guardian.new(trust_level_4).can_edit?(post)).to be_truthy expect(Guardian.new(trust_level_4).can_edit?(post)).to be_truthy
end 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 SiteSetting.trusted_users_can_edit_others = false
expect(Guardian.new(trust_level_4).can_edit?(post)).to eq(false) expect(Guardian.new(trust_level_4).can_edit?(post)).to eq(false)
end end
@ -1438,6 +1438,24 @@ describe Guardian do
expect(Guardian.new(post.user).can_edit?(post)).to be_truthy expect(Guardian.new(post.user).can_edit?(post)).to be_truthy
end 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 describe 'post edit time limits' do
context 'post is older than post_edit_time_limit' 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) } let(:old_post) { build(:post, topic: topic, user: topic.user, created_at: 6.minutes.ago) }

View File

@ -448,21 +448,6 @@ describe PostsController do
expect(UserHistory.where(action: UserHistory.actions[:post_edit]).count).to eq(1) expect(UserHistory.where(action: UserHistory.actions[:post_edit]).count).to eq(1)
end 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 it "can not update category descriptions in other categories" do
second_category = Fabricate(:category) second_category = Fabricate(:category)
topic.update!(category: second_category) topic.update!(category: second_category)