solved issues when moving tasks
This commit is contained in:
@@ -277,12 +277,22 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
if (json.has(DROP_MEMBER) && json.get(DROP_MEMBER) instanceof Number id) dropMember(task,id.longValue());
|
||||
if (json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject memberJson) patchMembers(task,memberJson);
|
||||
if (json.has(NEW_MEMBER) && json.get(NEW_MEMBER) instanceof Number num) addMember(task,num.longValue());
|
||||
|
||||
if (json.has(PARENT_TASK_ID) && json.get(PARENT_TASK_ID) instanceof Number ptid && newParentIsSubtask(task,ptid.longValue())) throw forbidden("Task must not be sub-task of itself.");
|
||||
taskDb.save(task.patch(json));
|
||||
|
||||
return sendContent(ex,task);
|
||||
}
|
||||
|
||||
private boolean newParentIsSubtask(Task task, long newParent) {
|
||||
var parent = taskDb.load(newParent);
|
||||
while (parent != null){
|
||||
if (task.id() == parent.id()) return true;
|
||||
if (parent.parentTaskId() == null) break;
|
||||
parent = taskDb.load(parent.parentTaskId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean postNewTask(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
var json = json(ex);
|
||||
if (!(json.has(PROJECT_ID) && json.get(PROJECT_ID) instanceof Number pid)) throw missingFieldException(PROJECT_ID);
|
||||
|
||||
Reference in New Issue
Block a user