Squashed commit of the following:

commit d03bdee783deff98ee24cc211f1498525bf36c70
Merge: b31ba93233 70f5aa1f55
Author: SabreCat <sabe@habitica.com>
Date:   Mon Dec 18 15:47:29 2023 -0600

    Merge branch 'release' into sabrecat/group-task-fixes

commit b31ba93233
Author: SabreCat <sabe@habitica.com>
Date:   Tue Oct 10 12:02:41 2023 -0500

    fix(groups): missing dot path step
    Also sync assignments on unassign as well as assign

commit 8012f0294d
Author: SabreCat <sabe@habitica.com>
Date:   Tue Oct 10 11:47:59 2023 -0500

    fix(groups): use assigned keys as source of truth

commit 616b1e1486
Author: SabreCat <sabe@habitica.com>
Date:   Tue Oct 10 11:33:28 2023 -0500

    fix(groups): clean up groups to copy tasks
    Fixes #14916
This commit is contained in:
SabreCat
2023-12-18 15:50:58 -06:00
parent b97f85fa60
commit 0dbd597d0b
2 changed files with 12 additions and 12 deletions
+9 -5
View File
@@ -147,8 +147,10 @@ export async function update (req, res, { isV3 = false }) {
await checkNewInputForProfanity(user, res, newBlurb);
}
let groupsToMirror;
let matchingGroupsArray;
if (req.body['preferences.tasks.mirrorGroupTasks'] !== undefined) {
const groupsToMirror = req.body['preferences.tasks.mirrorGroupTasks'];
groupsToMirror = req.body['preferences.tasks.mirrorGroupTasks'];
if (!Array.isArray(groupsToMirror)) {
throw new BadRequest('Groups to copy tasks from must be an array.');
}
@@ -160,7 +162,7 @@ export async function update (req, res, { isV3 = false }) {
}
}
const matchingGroupsCount = await Groups.countDocuments({
const matchingGroups = await Groups.find({
_id: { $in: groupsToMirror },
'purchased.plan.customerId': { $exists: true },
$or: [
@@ -168,11 +170,11 @@ export async function update (req, res, { isV3 = false }) {
{ 'purchased.plan.dateTerminated': null },
{ 'purchased.plan.dateTerminated': { $gt: new Date() } },
],
}, {
_id: 1,
}).exec();
if (matchingGroupsCount !== groupsToMirror.length) {
throw new BadRequest('Groups to copy tasks from must have subscriptions.');
}
matchingGroupsArray = _.map(matchingGroups, groupRecord => groupRecord._id);
}
_.each(req.body, (val, key) => {
@@ -234,6 +236,8 @@ export async function update (req, res, { isV3 = false }) {
if (lastNewsPost) {
user.flags.lastNewStuffRead = lastNewsPost._id;
}
} else if (key === 'preferences.tasks.mirrorGroupTasks') {
user.preferences.tasks.mirrorGroupTasks = _.intersection(groupsToMirror, matchingGroupsArray);
} else if (acceptablePUTPaths[key]) {
let adjustedVal = val;
if (key === 'stats.lvl' && val > common.constants.MAX_LEVEL_HARD_CAP) {
+3 -7
View File
@@ -1432,11 +1432,6 @@ schema.methods.syncTask = async function groupSyncTask (taskToSync, users, assig
completed: false,
};
if (!taskToSync.group.assignedUsers) {
taskToSync.group.assignedUsers = [];
}
taskToSync.group.assignedUsers.push(user._id);
if (!taskToSync.group.assignedUsersDetail) {
taskToSync.group.assignedUsersDetail = {};
}
@@ -1445,6 +1440,8 @@ schema.methods.syncTask = async function groupSyncTask (taskToSync, users, assig
}
taskToSync.markModified('group.assignedUsersDetail');
taskToSync.group.assignedUsers = _.keys(taskToSync.group.assignedUsersDetail);
// Sync tags
const userTags = user.tags;
const i = _.findIndex(userTags, { id: group._id });
@@ -1478,8 +1475,7 @@ schema.methods.unlinkTask = async function groupUnlinkTask (
};
delete unlinkingTask.group.assignedUsersDetail[user._id];
const assignedUserIndex = unlinkingTask.group.assignedUsers.indexOf(user._id);
unlinkingTask.group.assignedUsers.splice(assignedUserIndex, 1);
unlinkingTask.group.assignedUsers = _.keys(unlinkingTask.group.assignedUsersDetail);
unlinkingTask.markModified('group');
const promises = [unlinkingTask.save()];