implemented deletion of tasks
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -112,10 +112,20 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Task task) throws UmbrellaException {
|
||||
try {
|
||||
Query.delete().from(TABLE_TASKS).where(ID,equal(task.id())).execute(db);
|
||||
Query.delete().from(TABLE_TASKS_USERS).where(TASK_ID,equal(task.id())).execute(db);
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException("Failed to delete task");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropMember(long projectId, long userId) {
|
||||
try {
|
||||
delete().from(TABLE_TASKS_USERS)
|
||||
Query.delete().from(TABLE_TASKS_USERS)
|
||||
.where(TASK_ID,equal(projectId))
|
||||
.where(USER_ID,equal(userId))
|
||||
.execute(db);
|
||||
@@ -133,7 +143,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
rs.close();
|
||||
return result;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Faailed to load task members");
|
||||
throw new UmbrellaException("Faailed to load task members");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +165,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
rs.close();
|
||||
return tasks;
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load tasks for project ids");
|
||||
throw new UmbrellaException("Failed to load tasks for project ids");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +186,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
return tasks;
|
||||
} catch (SQLException e){
|
||||
LOG.log(WARNING,"Failed to load tasks for project (pid: {0}, user_id: {1}",projectId,user.id(),e);
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load tasks for project id");
|
||||
throw new UmbrellaException("Failed to load tasks for project id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +206,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
return tasks;
|
||||
} catch (SQLException e){
|
||||
LOG.log(WARNING,"Failed to load child tasks (parentTaskId: {0}, user_id: {1}",parentTaskId,user.id(),e);
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load tasks for project id");
|
||||
throw new UmbrellaException("Failed to load tasks for project id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +224,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
rs.close();
|
||||
return tasks;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load tasks for project {0}",projectId);
|
||||
throw new UmbrellaException("Failed to load tasks for project {0}",projectId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +238,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
if (result == null) throw UmbrellaException.notFound("No task found for id {0}",taskId);
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load task from database");
|
||||
throw new UmbrellaException("Failed to load task from database");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +271,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
}
|
||||
return task;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to save task {0}",task.name());
|
||||
throw new UmbrellaException("Failed to save task {0}",task.name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +280,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
try {
|
||||
replaceInto(TABLE_TASKS_USERS,TASK_ID,USER_ID,PERMISSIONS).values(taskId,userId,permission.code()).execute(db).close();
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to store permissions");
|
||||
throw new UmbrellaException("Failed to store permissions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ import java.util.Map;
|
||||
|
||||
public interface TaskDb {
|
||||
|
||||
void delete(Task task) throws UmbrellaException;
|
||||
void dropMember(long projectId, long userId);
|
||||
Map<Long, Permission> getMembers(Task task);
|
||||
HashMap<Long, Task> listChildrenOf(Long parentTaskId, UmbrellaUser user, boolean showClosed);
|
||||
HashMap<Long, Task> listProjectTasks(Long projectId, Long parentTaskId) throws UmbrellaException;
|
||||
HashMap<Long, Task> listRootTasks(Long projectId, UmbrellaUser user, boolean showClosed);
|
||||
|
||||
HashMap<Long, Task> listTasks(Collection<Long> projectIds) throws UmbrellaException;
|
||||
|
||||
Task load(long taskId) throws UmbrellaException;
|
||||
|
||||
@@ -62,6 +62,34 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
return companies;
|
||||
}
|
||||
|
||||
private boolean deleteTask(HttpExchange ex, long taskId, UmbrellaUser user) throws IOException {
|
||||
var task = loadMembers(taskDb.load(taskId));
|
||||
var member = task.members().get(user.id());
|
||||
if (member == null || !member.mayWrite()) throw forbidden("You are not allowed to delete {0}",task.name());
|
||||
taskDb.delete(task);
|
||||
return sendContent(ex,Map.of(DELETED,taskId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
try {
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
var user = users.loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var head = path.pop();
|
||||
return switch (head) {
|
||||
default -> {
|
||||
var taskId = Long.parseLong(head);
|
||||
head = path.pop();
|
||||
yield head == null ? deleteTask(ex,taskId,user.get()) : super.doDelete(path,ex);
|
||||
}
|
||||
};
|
||||
} catch (UmbrellaException e){
|
||||
return send(ex,e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
@@ -103,7 +131,7 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
default -> {
|
||||
var taskId = Long.parseLong(head);
|
||||
head = path.pop();
|
||||
yield head == null ? patchTask(ex,taskId,user.get()) : super.doGet(path,ex);
|
||||
yield head == null ? patchTask(ex,taskId,user.get()) : super.doPatch(path,ex);
|
||||
}
|
||||
};
|
||||
} catch (UmbrellaException e){
|
||||
@@ -123,7 +151,7 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
case ADD -> postNewTask(user.get(),ex);
|
||||
case ESTIMATED_TIMES -> estimatedTimes(user.get(),ex);
|
||||
case LIST -> postTaskList(user.get(),ex);
|
||||
default -> super.doGet(path,ex);
|
||||
default -> super.doPost(path,ex);
|
||||
};
|
||||
} catch (UmbrellaException e){
|
||||
return send(ex,e);
|
||||
|
||||
Reference in New Issue
Block a user