mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Merge branch 'develop' into release
This commit is contained in:
@@ -7,7 +7,10 @@ import {
|
||||
import _ from 'lodash';
|
||||
import apiError from '../../libs/apiError';
|
||||
import validator from 'validator';
|
||||
import { validateItemPath } from '../../libs/items/utils';
|
||||
import {
|
||||
validateItemPath,
|
||||
castItemVal,
|
||||
} from '../../libs/items/utils';
|
||||
|
||||
|
||||
let api = {};
|
||||
@@ -271,7 +274,7 @@ api.updateHero = {
|
||||
hero.markModified('items.pets');
|
||||
}
|
||||
if (updateData.itemPath && updateData.itemVal && validateItemPath(updateData.itemPath)) {
|
||||
_.set(hero, updateData.itemPath, updateData.itemVal); // Sanitization at 5c30944 (deemed unnecessary)
|
||||
_.set(hero, updateData.itemPath, castItemVal(updateData.itemPath, updateData.itemVal)); // Sanitization at 5c30944 (deemed unnecessary)
|
||||
}
|
||||
|
||||
if (updateData.auth && updateData.auth.blocked === true) {
|
||||
|
||||
@@ -12,6 +12,7 @@ let api = {};
|
||||
* @apiDescription Get inbox messages for a user
|
||||
*
|
||||
* @apiParam (Query) {Number} page Load the messages of the selected Page - 10 Messages per Page
|
||||
* @apiParam (Query) {GUID} conversation Loads only the messages of a conversation
|
||||
*
|
||||
* @apiSuccess {Array} data An array of inbox messages
|
||||
*/
|
||||
@@ -22,9 +23,10 @@ api.getInboxMessages = {
|
||||
async handler (req, res) {
|
||||
const user = res.locals.user;
|
||||
const page = req.query.page;
|
||||
const conversation = req.query.conversation;
|
||||
|
||||
const userInbox = await inboxLib.getUserInbox(user, {
|
||||
page,
|
||||
page, conversation,
|
||||
});
|
||||
|
||||
res.respond(200, userInbox);
|
||||
|
||||
@@ -206,6 +206,14 @@ api.assignTask = {
|
||||
let message = res.t('userIsClamingTask', {username: user.profile.name, task: task.text});
|
||||
const newMessage = group.sendChat(message);
|
||||
promises.push(newMessage.save());
|
||||
} else {
|
||||
const taskText = task.text;
|
||||
const managerName = user.profile.name;
|
||||
|
||||
assignedUser.addNotification('GROUP_TASK_ASSIGNED', {
|
||||
message: res.t('youHaveBeenAssignedTask', {managerName, taskText}),
|
||||
taskId: task._id,
|
||||
});
|
||||
}
|
||||
|
||||
promises.push(group.syncTask(task, assignedUser));
|
||||
@@ -261,6 +269,15 @@ api.unassignTask = {
|
||||
|
||||
await group.unlinkTask(task, assignedUser);
|
||||
|
||||
let notificationIndex = assignedUser.notifications.findIndex(function findNotification (notification) {
|
||||
return notification && notification.data && notification.type === 'GROUP_TASK_ASSIGNED' && notification.data.taskId === task._id;
|
||||
});
|
||||
|
||||
if (notificationIndex !== -1) {
|
||||
assignedUser.notifications.splice(notificationIndex, 1);
|
||||
await assignedUser.save();
|
||||
}
|
||||
|
||||
res.respond(200, task);
|
||||
},
|
||||
};
|
||||
@@ -308,6 +325,9 @@ api.approveTask = {
|
||||
|
||||
if (canNotEditTasks(group, user)) throw new NotAuthorized(res.t('onlyGroupLeaderCanEditTasks'));
|
||||
if (task.group.approval.approved === true) throw new NotAuthorized(res.t('canOnlyApproveTaskOnce'));
|
||||
if (!task.group.approval.requested) {
|
||||
throw new NotAuthorized(res.t('taskApprovalWasNotRequested'));
|
||||
}
|
||||
|
||||
task.group.approval.dateApproved = new Date();
|
||||
task.group.approval.approvingUser = user._id;
|
||||
|
||||
Reference in New Issue
Block a user