mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-04 04:59:40 +00:00
Unlink group tags when a user leaves it
This commit is contained in:
parent
023173fada
commit
1c719a8dbb
1 changed files with 11 additions and 0 deletions
|
|
@ -1345,6 +1345,8 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all', keepC
|
|||
.map(task => this.unlinkTask(task, user, keep, false));
|
||||
await Promise.all(assignedTasksToRemoveUserFrom);
|
||||
|
||||
this.unlinkTags(user);
|
||||
|
||||
// the user could be modified by calls to `unlinkTask` for challenge and group tasks
|
||||
// it has not been saved before to avoid multiple saves in parallel
|
||||
const promises = user.isModified() ? [user.save()] : [];
|
||||
|
|
@ -1407,6 +1409,15 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all', keepC
|
|||
return Promise.all(promises);
|
||||
};
|
||||
|
||||
schema.methods.unlinkTags = function unlinkTags (user) {
|
||||
const group = this;
|
||||
user.tags.forEach(tag => {
|
||||
if (tag.group && tag.group === group._id) {
|
||||
tag.group = undefined;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates all linked tasks for a group task
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue