implemented deletion of tasks
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -8,6 +8,7 @@ public class Constants {
|
||||
|
||||
|
||||
private Constants(){}
|
||||
|
||||
public static final String ADDRESS = "address";
|
||||
public static final String ATTACHMENTS = "attachments";
|
||||
public static final String AUTHORIZATION = "Authorization";
|
||||
@@ -23,6 +24,7 @@ public class Constants {
|
||||
public static final String DATE = "date";
|
||||
public static final String DEFAULT_LANGUAGE = "en";
|
||||
public static final String DEFAULT_THEME = "winter";
|
||||
public static final String DELETED = "deleted";
|
||||
public static final String DESCRIPTION = "description";
|
||||
public static final String DOMAIN = "domain";
|
||||
public static final String DROP_MEMBER = "drop_member";
|
||||
|
||||
@@ -31,7 +31,7 @@ public class UmbrellaException extends RuntimeException{
|
||||
|
||||
public static UmbrellaException databaseException(String message, Object... fills) {
|
||||
System.getLogger("Configuration").log(WARNING,message,fills);
|
||||
return new UmbrellaException(HTTP_SERVER_ERROR,message,fills);
|
||||
return new UmbrellaException(message,fills);
|
||||
}
|
||||
|
||||
public static UmbrellaException forbidden(String message, Object... fills) {
|
||||
@@ -45,7 +45,7 @@ public class UmbrellaException extends RuntimeException{
|
||||
|
||||
public static UmbrellaException missingConfigException(String field){
|
||||
System.getLogger("Configuration").log(ERROR,ERROR_MISSING_CONFIG, field);
|
||||
return new UmbrellaException(HTTP_SERVER_ERROR, ERROR_MISSING_CONFIG, field);
|
||||
return new UmbrellaException(ERROR_MISSING_CONFIG, field);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,4 +12,8 @@ public record Member(UmbrellaUser user, Permission permission) implements Mappab
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(USER,user.toMap(),PERMISSION,permission.toMap());
|
||||
}
|
||||
|
||||
public boolean mayWrite() {
|
||||
return permission.mayWrite();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,17 @@ import java.security.InvalidParameterException;
|
||||
import java.util.Map;
|
||||
|
||||
public enum Permission implements Mappable {
|
||||
OWNER(1),
|
||||
EDIT(2),
|
||||
ASSIGNEE(3),
|
||||
READ_ONLY(4);
|
||||
OWNER(1,true),
|
||||
EDIT(2,true),
|
||||
ASSIGNEE(3,true),
|
||||
READ_ONLY(4,false);
|
||||
|
||||
private final int code;
|
||||
private final boolean mayWrite;
|
||||
|
||||
Permission(int code){
|
||||
Permission(int code, boolean mayWrite){
|
||||
this.code = code;
|
||||
this.mayWrite = mayWrite;
|
||||
}
|
||||
|
||||
public int code(){
|
||||
@@ -36,4 +38,8 @@ public enum Permission implements Mappable {
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(NAME,name(),CODE,code);
|
||||
}
|
||||
|
||||
public boolean mayWrite() {
|
||||
return mayWrite;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
.execute(db);
|
||||
return settings;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to update customer settings");
|
||||
throw new UmbrellaException("Failed to update customer settings");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,11 @@
|
||||
});
|
||||
if (resp.ok){
|
||||
delete tasks[task.assignee][task.status.code][task.id]
|
||||
if (!tasks[user]) tasks[user] = {}
|
||||
if (!tasks[user][state]) tasks[user][state] = {}
|
||||
tasks[user][state][task.id] = task;
|
||||
task.assignee = user;
|
||||
task.status = {code:state,name:states[state]};
|
||||
error = null;
|
||||
} else {
|
||||
error = await resp.text();
|
||||
|
||||
@@ -13,11 +13,27 @@
|
||||
let children = $state(null);
|
||||
let error = $state(null);
|
||||
let start = 0;
|
||||
let deleted = $state(false);
|
||||
|
||||
function addSubtask(){
|
||||
router.navigate(`/task/${task.id}/add_subtask`);
|
||||
}
|
||||
|
||||
async function deleteTask(){
|
||||
if (confirm(t('confirm_delete',{element:task.name}))){
|
||||
const url = api(`task/${task.id}`);
|
||||
const resp = await fetch(url,{
|
||||
credentials:'include',
|
||||
method:'DELETE'
|
||||
});
|
||||
if (resp.ok){
|
||||
deleted = true;
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function loadChildren(){
|
||||
const url = api('task/list');
|
||||
var data = {
|
||||
@@ -70,6 +86,7 @@
|
||||
onMount(loadChildren);
|
||||
</script>
|
||||
|
||||
{#if !deleted}
|
||||
<li class="task {task.status.name.toLowerCase()}">
|
||||
<LineEditor bind:value={task.name} onclick={openTask} editable={true} onSet={setName} type="span" />
|
||||
{#if task.estimated_time}
|
||||
@@ -90,7 +107,7 @@
|
||||
{#if task.status.name != 'CANCELLED'}
|
||||
<button class="symbol" title={t('abort')} onclick={() => patchTask({status:'CANCELLED'})} ></button>
|
||||
{/if}
|
||||
|
||||
<button class="symbol" title={t('delete_task')} onclick={deleteTask} ></button>
|
||||
<button class="symbol" title={t('add_subtask')} onclick={addSubtask}></button>
|
||||
{#if error}
|
||||
<span class="error">{error}</span>
|
||||
@@ -99,3 +116,4 @@
|
||||
<TaskList tasks={children} {estimated_time} {show_closed} />
|
||||
{/if}
|
||||
</li>
|
||||
{/if}
|
||||
@@ -7,7 +7,7 @@ export async function loadTranslation(lang){
|
||||
translations.values = await fetch(url).then(resp => resp.json());
|
||||
}
|
||||
|
||||
export function t(key,...args){
|
||||
export function t(key,args = {}){
|
||||
if (key === undefined) return "";
|
||||
if (key instanceof Response) key = 'status.'+key.status;
|
||||
let set = translations.values;
|
||||
@@ -19,6 +19,6 @@ export function t(key,...args){
|
||||
}
|
||||
set = set[token];
|
||||
}
|
||||
for (var i in args) set = set.replace(`{${i}}`,args[i]);
|
||||
for (var key of Object.keys(args)) set = set.replace(`{${key}}`,args[key]);
|
||||
return set;
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class SqliteDb implements ItemDb{
|
||||
rs.close();
|
||||
return items;
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load items from database");
|
||||
throw new UmbrellaException("Failed to load items from database");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
rs.close();
|
||||
return result;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Faailed to load project members");
|
||||
throw new UmbrellaException("Faailed to load project members");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
if (result == null) throw UmbrellaException.notFound("No project found for id {0}",projectId);
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load project from database");
|
||||
throw new UmbrellaException("Failed to load project from database");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
rs.close();
|
||||
return projects;
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load items from database");
|
||||
throw new UmbrellaException("Failed to load items from database");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
rs.close();
|
||||
return projects;
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to load items from database");
|
||||
throw new UmbrellaException("Failed to load items from database");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
return new Project(id, prj.name(), prj.description(),prj.status(),prj.companyId().orElse(null),prj.showClosed(),prj.members());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to insert project into database");
|
||||
throw new UmbrellaException("Failed to insert project into database");
|
||||
}
|
||||
} else { // Update
|
||||
try {
|
||||
@@ -232,7 +232,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
}
|
||||
return prj;
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to update project in database");
|
||||
throw new UmbrellaException("Failed to update project in database");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"code": "Code",
|
||||
"connect_service": "mit Service verbinden",
|
||||
"connected_services": "verbundene Login-Services",
|
||||
"confirm_deletion": "Soll '{pos}' wirklich gelöscht werden?",
|
||||
"confirm_delete": "Soll '{element}' wirklich gelöscht werden?",
|
||||
"company": "Firma",
|
||||
"company_optional": "Firma (optional)",
|
||||
"confirmation": "Bestätigung",
|
||||
|
||||
@@ -512,7 +512,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
rs.close();
|
||||
return users;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException(HTTP_SERVER_ERROR,"Failed to search for user by key = {0}",key);
|
||||
throw new UmbrellaException("Failed to search for user by key = {0}",key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user