Squashed commit of the following:
commit d03bdee783deff98ee24cc211f1498525bf36c70 Merge:b31ba9323370f5aa1f55Author: SabreCat <sabe@habitica.com> Date: Mon Dec 18 15:47:29 2023 -0600 Merge branch 'release' into sabrecat/group-task-fixes commitb31ba93233Author: 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 commit8012f0294dAuthor: SabreCat <sabe@habitica.com> Date: Tue Oct 10 11:47:59 2023 -0500 fix(groups): use assigned keys as source of truth commit616b1e1486Author: 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:
@@ -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) {
|
||||
|
||||
@@ -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()];
|
||||
|
||||
Reference in New Issue
Block a user