mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:09:00 +08:00
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:
parent
8a3a6face5
commit
ce76553010
|
@ -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
|
||||||
|
|
|
@ -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) }
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user