From 63376b918e994afa0fedc5a70b3eceea77b09e21 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 22 Aug 2023 12:25:17 -0500 Subject: [PATCH] Squashed commit of the following: commit b7fb903dcab2dbdc55ddd27e9cbd8054f0d5e2a8 Author: SabreCat Date: Sat Aug 19 19:44:42 2023 -0500 fix(invites): add missing param commit 30053cc8b86fc1992d872a068e60f3dd5a456a07 Author: SabreCat Date: Sat Aug 19 19:06:51 2023 -0500 fix(party): enforce size limit when using @-names commit 62dd314cda4165bedbc6b490a8e2f21de87deaf4 Author: SabreCat Date: Sat Aug 19 19:01:15 2023 -0500 Revert "Revert "fix(parties): actual 30 not 29"" This reverts commit 63414a80fe6066d28e448d9225af158e48181364. --- .../v3/integration/groups/POST-groups_invite.test.js | 4 ++-- website/common/script/constants.js | 2 +- website/server/models/group.js | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/api/v3/integration/groups/POST-groups_invite.test.js b/test/api/v3/integration/groups/POST-groups_invite.test.js index 0001e09e3a..aab4c50a27 100644 --- a/test/api/v3/integration/groups/POST-groups_invite.test.js +++ b/test/api/v3/integration/groups/POST-groups_invite.test.js @@ -7,7 +7,7 @@ import { } from '../../../../helpers/api-integration/v3'; const INVITES_LIMIT = 100; -const PARTY_LIMIT_MEMBERS = 29; +const PARTY_LIMIT_MEMBERS = 30; const MAX_EMAIL_INVITES_BY_USER = 200; describe('Post /groups/:groupId/invite', () => { @@ -571,7 +571,7 @@ describe('Post /groups/:groupId/invite', () => { .to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', - message: t('partyExceedsMembersLimit', { maxMembersParty: PARTY_LIMIT_MEMBERS + 1 }), + message: t('partyExceedsMembersLimit', { maxMembersParty: PARTY_LIMIT_MEMBERS }), }); }).timeout(10000); }); diff --git a/website/common/script/constants.js b/website/common/script/constants.js index b3510378e0..bc569da079 100644 --- a/website/common/script/constants.js +++ b/website/common/script/constants.js @@ -27,7 +27,7 @@ export const SUPPORTED_SOCIAL_NETWORKS = [ export const GUILDS_PER_PAGE = 30; // number of guilds to return per page when using pagination -export const PARTY_LIMIT_MEMBERS = 29; +export const PARTY_LIMIT_MEMBERS = 30; export const MINIMUM_PASSWORD_LENGTH = 8; export const MAXIMUM_PASSWORD_LENGTH = 64; diff --git a/website/server/models/group.js b/website/server/models/group.js index c41aa0320b..6ca51cc955 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -414,7 +414,7 @@ function getInviteError (uuids, emails, usernames) { return errorString; } -function getInviteCount (uuids, emails) { +function getInviteCount (uuids, emails, usernames) { let totalInvites = 0; if (uuids) { @@ -425,6 +425,10 @@ function getInviteCount (uuids, emails) { totalInvites += emails.length; } + if (usernames) { + totalInvites += usernames.length; + } + return totalInvites; } @@ -445,7 +449,7 @@ schema.statics.validateInvitations = async function getInvitationErr (invites, r const errorString = getInviteError(uuids, emails, usernames); if (errorString) throw new BadRequest(res.t(errorString)); - const totalInvites = getInviteCount(uuids, emails); + const totalInvites = getInviteCount(uuids, emails, usernames); if (totalInvites > INVITES_LIMIT) { throw new BadRequest(res.t('canOnlyInviteMaxInvites', { maxInvites: INVITES_LIMIT })); } @@ -471,7 +475,7 @@ schema.statics.validateInvitations = async function getInvitationErr (invites, r memberCount += totalInvites; if (memberCount > shared.constants.PARTY_LIMIT_MEMBERS) { - throw new BadRequest(res.t('partyExceedsMembersLimit', { maxMembersParty: shared.constants.PARTY_LIMIT_MEMBERS + 1 })); + throw new BadRequest(res.t('partyExceedsMembersLimit', { maxMembersParty: shared.constants.PARTY_LIMIT_MEMBERS })); } } };