mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Leaving a group (#8517)
* Leaving a group or a guild no longer removes the user from the challenges of that group or guild. * Updating api docs for leaving group to take into account the default path no longer leaving challenges when leaving a group. * Updating api docs for leaving group to take into account the default path no longer leaving challenges when leaving a group. * refactored according to blade's comments to not be a breaking change. The api now accepts a body parameter to specify wether the user should remain in the groups challenges or leave them. The change also adds more tests around this behavior to confirm that it works as expected.
This commit is contained in:
@@ -900,7 +900,7 @@ schema.statics.tavernBoss = async function tavernBoss (user, progress) {
|
||||
}
|
||||
};
|
||||
|
||||
schema.methods.leave = async function leaveGroup (user, keep = 'keep-all') {
|
||||
schema.methods.leave = async function leaveGroup (user, keep = 'keep-all', keepChallenges = 'leave-challenges') {
|
||||
let group = this;
|
||||
let update = {};
|
||||
|
||||
@@ -908,16 +908,18 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all') {
|
||||
throw new NotAuthorized(shared.i18n.t('cannotDeleteActiveGroup'));
|
||||
}
|
||||
|
||||
// Unlink user challenge tasks
|
||||
let challenges = await Challenge.find({
|
||||
_id: {$in: user.challenges},
|
||||
group: group._id,
|
||||
}).exec();
|
||||
// only remove user from challenges if it's set to leave-challenges
|
||||
if (keepChallenges === 'leave-challenges') {
|
||||
let challenges = await Challenge.find({
|
||||
_id: {$in: user.challenges},
|
||||
group: group._id,
|
||||
}).exec();
|
||||
|
||||
let challengesToRemoveUserFrom = challenges.map(chal => {
|
||||
return chal.unlinkTasks(user, keep);
|
||||
});
|
||||
await Bluebird.all(challengesToRemoveUserFrom);
|
||||
let challengesToRemoveUserFrom = challenges.map(chal => {
|
||||
return chal.unlinkTasks(user, keep);
|
||||
});
|
||||
await Bluebird.all(challengesToRemoveUserFrom);
|
||||
}
|
||||
|
||||
// Unlink group tasks)
|
||||
let assignedTasks = await Tasks.Task.find({
|
||||
|
||||
Reference in New Issue
Block a user