implemented task editing right from the project list
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -216,7 +216,14 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
if (taskId == null) throw new UmbrellaException("Failed to save task {0}",task.name());
|
||||
return new Task(taskId,task.projectId(),task.parentTaskId(),task.name(),task.description(),task.status(),task.estimatedTime(),task.start(),task.dueDate(),task.showClosed(),task.noIndex(),task.members());
|
||||
}
|
||||
throw new UmbrellaException(HTTP_NOT_IMPLEMENTED,"updating task in SqliteDb.save(task) not implemented");
|
||||
if (task.isDirty()) {
|
||||
update(TABLE_TASKS).set(PROJECT_ID,PARENT_TASK_ID,NAME,DESCRIPTION,STATUS,EST_TIME,START_DATE,DUE_DATE,SHOW_CLOSED,NO_INDEX)
|
||||
.where(ID,equal(task.id())).prepare(db)
|
||||
.apply(task.projectId(),task.parentTaskId(),task.name(),task.description(),task.status().code(),task.estimatedTime(),task.start(),task.dueDate(),task.showClosed(),task.noIndex())
|
||||
.close();
|
||||
task.clean();
|
||||
}
|
||||
return task;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to save task {0}",task.name());
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ import static de.srsoftware.umbrella.core.Paths.*;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_NOT_IMPLEMENTED;
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.core.model.Permission.READ_ONLY;
|
||||
import static de.srsoftware.umbrella.project.Constants.PERMISSIONS;
|
||||
import static de.srsoftware.umbrella.task.Constants.*;
|
||||
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
||||
import static java.net.HttpURLConnection.HTTP_OK;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
@@ -75,6 +77,33 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
return sendEmptyResponse(HTTP_OK,ex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPatch(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) {
|
||||
case null -> super.doGet(path,ex);
|
||||
default -> {
|
||||
var taskId = Long.parseLong(head);
|
||||
head = path.pop();
|
||||
yield head == null ? patchTask(ex,taskId,user.get()) : super.doGet(path,ex);
|
||||
}
|
||||
};
|
||||
} catch (UmbrellaException e){
|
||||
return send(ex,e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPost(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
@@ -173,6 +202,15 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
return mappedTask;
|
||||
}
|
||||
|
||||
private boolean patchTask(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.permission() == READ_ONLY ) throw forbidden("You are not a allowed to edit {0}!",task.name());
|
||||
taskDb.save(task.patch(json(ex)));
|
||||
|
||||
return sendContent(ex,task);
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -181,7 +219,7 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
var project = projects.load(projectId);
|
||||
projects.loadMembers(List.of(project));
|
||||
var member = project.members().get(user.id());
|
||||
if (member == null || member.permission() == Permission.READ_ONLY) throw forbidden("You are not allowed to create new tasks in this project");
|
||||
if (member == null || member.permission() == READ_ONLY) throw forbidden("You are not allowed to create new tasks in this project");
|
||||
Task task = Task.of(json);
|
||||
task = taskDb.save(task);
|
||||
for (var key : memberData.keySet()){
|
||||
|
||||
Reference in New Issue
Block a user