Update the API to prevent the user from leaving a group if they are the only member and have a quest active. (#10091)

* Update the API to prevent the user from leaving a group if they are the only member and have a quest active.

fixes #10068

* fixing api doc
This commit is contained in:
Travis
2018-03-17 14:26:07 -07:00
committed by Matteo Pagliazzi
parent 3ad0ffcaec
commit 45eb19e992
4 changed files with 44 additions and 8 deletions

View File

@@ -518,6 +518,18 @@ api.joinGroup = {
if (inviterParty) {
inviter = inviterParty.inviter;
// If user was in a different party (when partying solo you can be invited to a new party)
// make them leave that party before doing anything
if (user.party._id) {
let userPreviousParty = await Group.getGroup({user, groupId: user.party._id});
if (userPreviousParty.memberCount === 1 && user.party.quest.key) {
throw new NotAuthorized(res.t('messageCannotLeaveWhileQuesting'));
}
if (userPreviousParty) await userPreviousParty.leave(user);
}
// Clear all invitations of new user
user.invitations.parties = [];
user.invitations.party = {};
@@ -530,13 +542,6 @@ api.joinGroup = {
group.markModified('quest.members');
}
// If user was in a different party (when partying solo you can be invited to a new party)
// make them leave that party before doing anything
if (user.party._id) {
let userPreviousParty = await Group.getGroup({user, groupId: user.party._id});
if (userPreviousParty) await userPreviousParty.leave(user);
}
user.party._id = group._id; // Set group as user's party
isUserInvited = true;