diff --git a/test/api/v3/integration/chat/POST-groups_id_chat_id_clear_flags.test.js b/test/api/v3/integration/chat/POST-groups_id_chat_id_clear_flags.test.js index 87cad5d6f0..615a296b85 100644 --- a/test/api/v3/integration/chat/POST-groups_id_chat_id_clear_flags.test.js +++ b/test/api/v3/integration/chat/POST-groups_id_chat_id_clear_flags.test.js @@ -54,6 +54,25 @@ describe('POST /groups/:id/chat/:id/clearflags', () => { expect(messages[0].flagCount).to.eql(0); expect(messages[0].flags).to.have.property(admin._id, true); }); + + it('clears flags in a private group', async () => { + let { group, members } = await createAndPopulateGroup({ + groupDetails: { + type: 'party', + privacy: 'private', + }, + members: 1, + }); + + let privateMessage = await members[0].post(`/groups/${group._id}/chat`, { message: 'Some message' }); + privateMessage = privateMessage.message; + + await admin.post(`/groups/${group._id}/chat/${privateMessage.id}/flag`); + await admin.post(`/groups/${group._id}/chat/${privateMessage.id}/clearflags`); + + let messages = await members[0].get(`/groups/${group._id}/chat`); + expect(messages[0].flagCount).to.eql(0); + }); }); context('admin user, group with multiple messages', () => { diff --git a/website/server/controllers/api-v3/chat.js b/website/server/controllers/api-v3/chat.js index d1179b0ee2..ea74d4238e 100644 --- a/website/server/controllers/api-v3/chat.js +++ b/website/server/controllers/api-v3/chat.js @@ -270,16 +270,20 @@ api.flagChat = { }; /** - * @api {post} /api/v3/groups/:groupId/chat/:chatId/clearflags Clear a group chat message's flags - * @apiDescription Admin-only - * @apiVersion 3.0.0 + * @api {post} /api/v3/groups/:groupId/chat/:chatId/clearflags Clear flags + * @apiDescription Resets the flag count on a chat message. Retains the id of the user's that have flagged the message. (Only visible to moderators) + * @apiPermission Moderators * @apiName ClearFlags * @apiGroup Chat * - * @apiParam {UUID} groupId The group _id ('party' for the user party and 'habitrpg' for tavern are accepted) + * @apiParam {UUID} groupId The group id ('party' for the user party and 'habitrpg' for tavern are accepted) * @apiParam {UUID} chatId The chat message id * * @apiSuccess {Object} data An empty object + * + * @apiError MustBeAdmin Must be a moderator to use this route + * @apiError GroupNotFound Group could not be found or you don't have access + * @apiError ChatNotFound Chat message with specified id could not be found */ api.clearChatFlags = { method: 'Post', @@ -300,7 +304,11 @@ api.clearChatFlags = { throw new NotAuthorized(res.t('messageGroupChatAdminClearFlagCount')); } - let group = await Group.getGroup({user, groupId}); + let group = await Group.getGroup({ + user, + groupId, + optionalMembership: user.contributor.admin, + }); if (!group) throw new NotFound(res.t('groupNotFound')); let message = _.find(group.chat, {id: chatId});