feat(api): Admins can unflag private group messages

This commit is contained in:
Blade Barringer
2016-08-25 15:31:39 -05:00
parent 7f50532e8b
commit 33377263d9
2 changed files with 32 additions and 5 deletions

View File

@@ -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', () => {

View File

@@ -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});