fix(api) Allow revoked chat ussers to post in private guilds

This commit is contained in:
Blade Barringer
2016-10-04 17:49:19 -05:00
parent acee4bad80
commit 6d33acccf4
2 changed files with 38 additions and 2 deletions

View File

@@ -43,7 +43,7 @@ describe('POST /chat', () => {
}); });
}); });
it('Returns an error when chat privileges are revoked', async () => { it('returns an error when chat privileges are revoked when sending a message to a public guild', async () => {
await expect(userWithChatRevoked.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage})).to.eventually.be.rejected.and.eql({ await expect(userWithChatRevoked.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage})).to.eventually.be.rejected.and.eql({
code: 404, code: 404,
error: 'NotFound', error: 'NotFound',
@@ -51,6 +51,42 @@ describe('POST /chat', () => {
}); });
}); });
it('does not error when sending a message to a private guild with a user with revoked chat', async () => {
let { group, members } = await createAndPopulateGroup({
groupDetails: {
name: 'Private Guild',
type: 'guild',
privacy: 'private',
},
members: 1,
});
let privateGuildMemberWithChatsRevoked = members[0];
await privateGuildMemberWithChatsRevoked.update({'flags.chatRevoked': true});
let message = await privateGuildMemberWithChatsRevoked.post(`/groups/${group._id}/chat`, { message: testMessage});
expect(message.message.id).to.exist;
});
it('does not error when sending a message to a party with a user with revoked chat', async () => {
let { group, members } = await createAndPopulateGroup({
groupDetails: {
name: 'Party',
type: 'party',
privacy: 'private',
},
members: 1,
});
let privatePartyMemberWithChatsRevoked = members[0];
await privatePartyMemberWithChatsRevoked.update({'flags.chatRevoked': true});
let message = await privatePartyMemberWithChatsRevoked.post(`/groups/${group._id}/chat`, { message: testMessage});
expect(message.message.id).to.exist;
});
it('creates a chat', async () => { it('creates a chat', async () => {
let message = await user.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage}); let message = await user.post(`/groups/${groupWithChat._id}/chat`, { message: testMessage});

View File

@@ -101,7 +101,7 @@ api.postChat = {
let group = await Group.getGroup({user, groupId}); let group = await Group.getGroup({user, groupId});
if (!group) throw new NotFound(res.t('groupNotFound')); if (!group) throw new NotFound(res.t('groupNotFound'));
if (group.type !== 'party' && user.flags.chatRevoked) { if (group.privacy !== 'private' && user.flags.chatRevoked) {
throw new NotFound('Your chat privileges have been revoked.'); throw new NotFound('Your chat privileges have been revoked.');
} }