mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
Client Tasks v3 (#8926)
* tasks hover state * hide column background if task too close * wip edit tasks * wip: replace tags * upgrade bootstrap-vue and fix creare btn for tasks * difficulty options colors and active label fixes * fix tags
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
} from '../../libs/email';
|
||||
import nconf from 'nconf';
|
||||
import get from 'lodash/get';
|
||||
import { model as Tag } from '../../models/tag';
|
||||
|
||||
const TECH_ASSISTANCE_EMAIL = nconf.get('EMAILS:TECH_ASSISTANCE_EMAIL');
|
||||
const DELETE_CONFIRMATION = 'DELETE';
|
||||
@@ -157,6 +158,7 @@ let updatablePaths = [
|
||||
'profile',
|
||||
'stats',
|
||||
'inbox.optOut',
|
||||
'tags',
|
||||
];
|
||||
|
||||
// This tells us for which paths users can call `PUT /user`.
|
||||
@@ -247,8 +249,43 @@ api.updateUser = {
|
||||
throw new NotAuthorized(res.t('mustPurchaseToSet', { val, key }));
|
||||
}
|
||||
|
||||
if (acceptablePUTPaths[key]) {
|
||||
if (acceptablePUTPaths[key] && key !== 'tags') {
|
||||
_.set(user, key, val);
|
||||
} else if (key === 'tags') {
|
||||
if (!Array.isArray(val)) throw new BadRequest('mustBeArray');
|
||||
|
||||
const removedTagsIds = [];
|
||||
|
||||
const oldTags = [];
|
||||
|
||||
// Keep challenge and group tags
|
||||
user.tags.forEach(t => {
|
||||
if (t.group || t.challenge) {
|
||||
oldTags.push(t);
|
||||
} else {
|
||||
removedTagsIds.push(t.id);
|
||||
}
|
||||
});
|
||||
|
||||
user.tags = oldTags;
|
||||
|
||||
val.forEach(t => {
|
||||
let oldI = removedTagsIds.findIndex(id => id === t.id);
|
||||
if (oldI > -1) {
|
||||
removedTagsIds.splice(oldI, 1);
|
||||
}
|
||||
|
||||
user.tags.push(Tag.sanitize(t));
|
||||
});
|
||||
|
||||
// Remove from all the tasks TODO test
|
||||
Tasks.Task.update({
|
||||
userId: user._id,
|
||||
}, {
|
||||
$pull: {
|
||||
tags: {$in: [removedTagsIds]},
|
||||
},
|
||||
}, {multi: true}).exec();
|
||||
} else {
|
||||
throw new NotAuthorized(res.t('messageUserOperationProtected', { operation: key }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user