10282: Added code for blocking party and guild invitations from block… (#10454)

* 10282: Added code for blocking party and guild invitations from blocked players, added tests

* 10282: fixed test label

* Update POST-groups_invite.test.js

removed `it.only` which was used for testing
This commit is contained in:
Jerell Mendoza
2018-06-27 13:07:57 -04:00
committed by Matteo Pagliazzi
parent a362914f93
commit d549fea4ed
3 changed files with 24 additions and 3 deletions

View File

@@ -958,6 +958,11 @@ async function _inviteByUUID (uuid, group, inviter, req, res) {
throw new BadRequest(res.t('cannotInviteSelfToGroup'));
}
const objections = inviter.getObjectionsToInteraction('group-invitation', userToInvite);
if (objections.length > 0) {
throw new NotAuthorized(res.t(objections[0], { userId: uuid, username: userToInvite.profile.name}));
}
if (group.type === 'guild') {
if (_.includes(userToInvite.guilds, group._id)) {
throw new NotAuthorized(res.t('userAlreadyInGroup', { userId: uuid, username: userToInvite.profile.name}));
@@ -1160,6 +1165,7 @@ async function _inviteByEmail (invite, group, inviter, req, res) {
* @apiError (401) {NotAuthorized} UserAlreadyInvited The user has already been invited to the group.
* @apiError (401) {NotAuthorized} UserAlreadyInGroup The user is already a member of the group.
* @apiError (401) {NotAuthorized} CannotInviteWhenMuted You cannot invite anyone to a guild or party because your chat privileges have been revoked.
* @apiError (401) {NotAuthorized} NotAuthorizedToSendMessageToThisUser You can't send a message to this player because they have chosen to block messages.
*
* @apiUse GroupNotFound
* @apiUse UserNotFound
@@ -1168,9 +1174,7 @@ async function _inviteByEmail (invite, group, inviter, req, res) {
api.inviteToGroup = {
method: 'POST',
url: '/groups/:groupId/invite',
middlewares: [authWithHeaders({
userFieldsToExclude: ['inbox'],
})],
middlewares: [authWithHeaders({})],
async handler (req, res) {
let user = res.locals.user;