FEATURE: Allow Category Group Moderators to edit topic titles (#11340)

* FEATURE: Allow Category Group Moderators to edit topic titles

Adds category group moderators to the topic guardian’s `can_edit` method.

The value of `can_edit` is returned by the topic view serializer, and this value determines whether the current user can edit the title/category/tags of the topic directly (which category group moderators could already do by editing the first post of a topic).

Note that the value of `can_edit` is now always returned by the topic view serializer (ie, for both true and false values) to cover the case where a topic is moved out of a category that a category group moderator has permissions on, so that when the topic is reloaded the UI picks up that `can_edit` is now false, and thus the edit icon should no longer be displayed.

* DEV: Add a comment explaining why `can_edit` is always returned
This commit is contained in:
jbrw
2020-12-02 17:21:59 -05:00
committed by GitHub
parent 2b66a4364d
commit 1c87038255
3 changed files with 32 additions and 5 deletions

View File

@@ -365,6 +365,27 @@ describe TopicViewSerializer do
expect(json[:details][:can_edit_tags]).to eq(true)
end
end
context "can_edit" do
fab!(:group_user) { Fabricate(:group_user) }
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
fab!(:topic) { Fabricate(:topic, category: category) }
let(:user) { group_user.user }
before do
SiteSetting.enable_category_group_moderation = true
end
it 'explicitly returns can_edit' do
json = serialize_topic(topic, user)
expect(json[:details][:can_edit]).to eq(true)
topic.update!(category: nil)
json = serialize_topic(topic, user)
expect(json[:details][:can_edit]).to eq(false)
end
end
end
context "published_page" do