mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user