diff --git a/test/api/v3/integration/groups/POST-groups.test.js b/test/api/v3/integration/groups/POST-groups.test.js index b310e94627..0efbb71165 100644 --- a/test/api/v3/integration/groups/POST-groups.test.js +++ b/test/api/v3/integration/groups/POST-groups.test.js @@ -136,6 +136,21 @@ describe('POST /group', () => { }, }); }); + + it('returns an error when a user with no chat privileges attempts to create a public guild', async () => { + await user.update({ 'flags.chatRevoked': true }); + + await expect( + user.post('/groups', { + name: 'Test Public Guild', + type: 'guild', + }) + ).to.eventually.be.rejected.and.eql({ + code: 401, + error: 'NotAuthorized', + message: t('cannotCreatePublicGuildWhenMuted'), + }); + }); }); context('private guild', () => { @@ -163,6 +178,17 @@ describe('POST /group', () => { }); }); + it('creates a private guild when the user has no chat privileges', async () => { + await user.update({ 'flags.chatRevoked': true }); + let privateGuild = await user.post('/groups', { + name: groupName, + type: groupType, + privacy: groupPrivacy, + }); + + expect(privateGuild._id).to.exist; + }); + it('deducts gems from user and adds them to guild bank', async () => { let privateGuild = await user.post('/groups', { name: groupName, @@ -201,6 +227,16 @@ describe('POST /group', () => { }); }); + it('creates a party when the user has no chat privileges', async () => { + await user.update({ 'flags.chatRevoked': true }); + let party = await user.post('/groups', { + name: partyName, + type: partyType, + }); + + expect(party._id).to.exist; + }); + it('does not require gems to create a party', async () => { await user.update({ balance: 0 }); diff --git a/website/client/components/header/menu.vue b/website/client/components/header/menu.vue index 679a28997b..ee83dd2e8c 100644 --- a/website/client/components/header/menu.vue +++ b/website/client/components/header/menu.vue @@ -62,7 +62,7 @@ div span {{ userHourglasses }} .item-with-icon .top-menu-icon.svg-icon.gem(v-html="icons.gem", @click='showBuyGemsModal("gems")', v-b-tooltip.hover.bottom="$t('gems')") - span {{userGems | roundBigNumber}} + span {{userGems}} .item-with-icon.gold .top-menu-icon.svg-icon(v-html="icons.gold", v-b-tooltip.hover.bottom="$t('gold')") span {{Math.floor(user.stats.gp * 100) / 100}} diff --git a/website/common/locales/en/groups.json b/website/common/locales/en/groups.json index e28c3ca211..dd02a116d2 100644 --- a/website/common/locales/en/groups.json +++ b/website/common/locales/en/groups.json @@ -256,6 +256,7 @@ "userCountRequestsApproval": "<%= userCount %> request approval", "youAreRequestingApproval": "You are requesting approval", "chatPrivilegesRevoked": "Your chat privileges have been revoked.", + "cannotCreatePublicGuildWhenMuted": "You cannot create a public guild because your chat privileges have been revoked.", "cannotInviteWhenMuted": "You cannot invite anyone to a guild or party because your chat privileges have been revoked.", "newChatMessagePlainNotification": "New message in <%= groupName %> by <%= authorName %>. Click here to open the chat page!", "newChatMessageTitle": "New message in <%= groupName %>", diff --git a/website/server/controllers/api-v3/groups.js b/website/server/controllers/api-v3/groups.js index 79c1bafd96..11d61791d6 100644 --- a/website/server/controllers/api-v3/groups.js +++ b/website/server/controllers/api-v3/groups.js @@ -78,9 +78,10 @@ let api = {}; * "privacy": "private" * } * - * @apiError (400) {NotAuthorized} messageInsufficientGems User does not have enough gems (4) - * @apiError (400) {NotAuthorized} partyMustbePrivate Party must have privacy set to private - * @apiError (400) {NotAuthorized} messageGroupAlreadyInParty + * @apiError (401) {NotAuthorized} messageInsufficientGems User does not have enough gems (4) + * @apiError (401) {NotAuthorized} partyMustbePrivate Party must have privacy set to private + * @apiError (401) {NotAuthorized} messageGroupAlreadyInParty + * @apiError (401) {NotAuthorized} cannotCreatePublicGuildWhenMuted You cannot create a public guild because your chat privileges have been revoked. * * @apiSuccess (201) {Object} data The created group (See /website/server/models/group.js) * @@ -115,6 +116,7 @@ api.createGroup = { group.leader = user._id; if (group.type === 'guild') { + if (group.privacy === 'public' && user.flags.chatRevoked) throw new NotAuthorized(res.t('cannotCreatePublicGuildWhenMuted')); if (user.balance < 1) throw new NotAuthorized(res.t('messageInsufficientGems')); group.balance = 1;