mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 13:17:24 +01:00
Group category update issue (#14186)
* Overwrite arrays instead of merging * Test removing a category * Fix previous duplicated categories on group edit
This commit is contained in:
@@ -492,7 +492,17 @@ api.updateGroup = {
|
||||
|
||||
if (req.body.leader !== user._id && group.hasNotCancelled()) throw new NotAuthorized(res.t('cannotChangeLeaderWithActiveGroupPlan'));
|
||||
|
||||
_.assign(group, _.merge(group.toObject(), Group.sanitizeUpdate(req.body)));
|
||||
const handleArrays = (currentValue, updatedValue) => {
|
||||
if (!_.isArray(currentValue)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Previously, categories could get duplicated. By making the updated category list unique,
|
||||
// the duplication issue is fixed on every group edit
|
||||
return _.uniqBy(updatedValue, 'slug');
|
||||
};
|
||||
|
||||
_.assign(group, _.mergeWith(group.toObject(), Group.sanitizeUpdate(req.body), handleArrays));
|
||||
|
||||
const savedGroup = await group.save();
|
||||
const response = await Group.toJSONCleanChat(savedGroup, user);
|
||||
|
||||
Reference in New Issue
Block a user