mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
sanitize task when updating in v2
This commit is contained in:
@@ -867,7 +867,20 @@ api.updateTask = function(req, res, next) {
|
||||
if(!task) return res.status(404).json({err: 'Task not found.'})
|
||||
|
||||
try {
|
||||
_.assign(task, shared.ops.updateTask(task.toObject(), req)[0]);
|
||||
// we have to convert task to an object because otherwise things don't get merged correctly. Bad for performances?
|
||||
let [updatedTaskObj] = shared.ops.updateTask(task.toObject(), req);
|
||||
|
||||
// Sanitize differently user tasks linked to a challenge
|
||||
let sanitizedObj;
|
||||
|
||||
if (task.userId && task.challenge && task.challenge.id) {
|
||||
sanitizedObj = Tasks.Task.sanitizeUserChallengeTask(updatedTaskObj);
|
||||
} else {
|
||||
sanitizedObj = Tasks.Task.sanitize(updatedTaskObj);
|
||||
}
|
||||
|
||||
_.assign(task, sanitizedObj);
|
||||
|
||||
task.save(function(err, task){
|
||||
if(err) return next(err);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user