mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Added inital group task approval
This commit is contained in:
@@ -315,6 +315,10 @@ api.scoreTask = {
|
||||
|
||||
if (!task) throw new NotFound(res.t('taskNotFound'));
|
||||
|
||||
if (task.requiresApproval && !task.approved) {
|
||||
throw new NotAuthorized(res.t('taskRequiresApproval'));
|
||||
}
|
||||
|
||||
let wasCompleted = task.completed;
|
||||
|
||||
let [delta] = common.ops.scoreTask({task, user, direction}, req);
|
||||
|
||||
@@ -178,4 +178,54 @@ api.unassignTask = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {post} /api/v3/tasks/:taskId/approve/:userId Approve a user's task
|
||||
* @apiDescription Approves a user assigned to a group task
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName ApproveTask
|
||||
* @apiGroup Task
|
||||
*
|
||||
* @apiParam {UUID} taskId The id of the task that is the original group task
|
||||
* @apiParam {UUID} userId The id of the user that will be approved
|
||||
*
|
||||
* @apiSuccess task The approved task
|
||||
*/
|
||||
api.approveTask = {
|
||||
method: 'POST',
|
||||
url: '/tasks/:taskId/approve/:userId',
|
||||
middlewares: [ensureDevelpmentMode, authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
req.checkParams('taskId', res.t('taskIdRequired')).notEmpty().isUUID();
|
||||
req.checkParams('assignedUserId', res.t('userIdRequired')).notEmpty().isUUID();
|
||||
|
||||
let reqValidationErrors = req.validationErrors();
|
||||
if (reqValidationErrors) throw reqValidationErrors;
|
||||
|
||||
let user = res.locals.user;
|
||||
let assignedUserId = req.params.assignedUserId;
|
||||
let assignedUser = await User.findById(assignedUserId);
|
||||
|
||||
let taskId = req.params.taskId;
|
||||
let task = await Tasks.Task.findByIdOrAlias(taskId, user._id);
|
||||
|
||||
if (!task) {
|
||||
throw new NotFound(res.t('taskNotFound'));
|
||||
}
|
||||
|
||||
if (!task.group.id) {
|
||||
throw new NotAuthorized(res.t('onlyGroupTasksCanBeAssigned'));
|
||||
}
|
||||
|
||||
let group = await Group.getGroup({user, groupId: task.group.id, fields: requiredGroupFields});
|
||||
if (!group) throw new NotFound(res.t('groupNotFound'));
|
||||
|
||||
if (group.leader !== user._id) throw new NotAuthorized(res.t('onlyGroupLeaderCanEditTasks'));
|
||||
|
||||
await group.unlinkTask(task, assignedUser);
|
||||
|
||||
res.respond(200, task);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
module.exports = api;
|
||||
|
||||
Reference in New Issue
Block a user