diff --git a/lib/guardian/topic_guardian.rb b/lib/guardian/topic_guardian.rb index 1cd93e4a838..263163babd1 100644 --- a/lib/guardian/topic_guardian.rb +++ b/lib/guardian/topic_guardian.rb @@ -65,7 +65,7 @@ module TopicGuardian return false if topic.trashed? return true if is_admin? - trusted = (authenticated? && user.has_trust_level?(TrustLevel[4])) || is_moderator? + trusted = (authenticated? && user.has_trust_level?(TrustLevel[4])) || is_moderator? || can_perform_action_available_to_group_moderators?(topic) (!(topic.closed? || topic.archived?) || trusted) && can_create_post?(topic) end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 3f59df457df..6b93acbc026 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -879,15 +879,45 @@ RSpec.describe TopicsController do expect(response.status).to eq(200) expect(topic.reload.closed).to eq(true) + expect(topic.posts.last.action_code).to eq('closed.enabled') + end + + it 'should allow a group moderator to open a closed topic' do + topic.update!(closed: true) + + expect do + put "/t/#{topic.id}/status.json", params: { + status: 'closed', enabled: 'false' + } + end.to change { topic.reload.posts.count }.by(1) + + expect(response.status).to eq(200) + expect(topic.reload.closed).to eq(false) + expect(topic.posts.last.action_code).to eq('closed.disabled') end it 'should allow a group moderator to archive a topic' do - put "/t/#{topic.id}/status.json", params: { - status: 'archived', enabled: 'true' - } + expect do + put "/t/#{topic.id}/status.json", params: { + status: 'archived', enabled: 'true' + } + end.to change { topic.reload.posts.count }.by(1) expect(response.status).to eq(200) expect(topic.reload.archived).to eq(true) + expect(topic.posts.last.action_code).to eq('archived.enabled') + end + + it 'should allow a group moderator to unarchive an archived topic' do + topic.update!(archived: true) + + put "/t/#{topic.id}/status.json", params: { + status: 'archived', enabled: 'false' + } + + expect(response.status).to eq(200) + expect(topic.reload.archived).to eq(false) + expect(topic.posts.last.action_code).to eq('archived.disabled') end it 'should not allow a group moderator to pin a topic' do