implemented deleting of notes
This commit is contained in:
@@ -70,7 +70,7 @@ public class Application {
|
|||||||
var tagModule = new TagModule(config,userModule);
|
var tagModule = new TagModule(config,userModule);
|
||||||
var notesModule = new NoteModule(config,userModule);
|
var notesModule = new NoteModule(config,userModule);
|
||||||
var projectModule = new ProjectModule(config,companyModule,tagModule);
|
var projectModule = new ProjectModule(config,companyModule,tagModule);
|
||||||
var taskModule = new TaskModule(config,projectModule,tagModule);
|
var taskModule = new TaskModule(config,projectModule,tagModule,notesModule);
|
||||||
var timeModule = new TimeModule(config,taskModule);
|
var timeModule = new TimeModule(config,taskModule);
|
||||||
var webHandler = new WebHandler();
|
var webHandler = new WebHandler();
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,21 @@
|
|||||||
entity_id = null
|
entity_id = null
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
|
async function drop(nid){
|
||||||
|
if (!confirm(t('confirm_delete',{element:t('note')}))) return;
|
||||||
|
const url = api(`notes/${nid}`);
|
||||||
|
const resp = await fetch(url,{
|
||||||
|
credentials : 'include',
|
||||||
|
method : 'DELETE'
|
||||||
|
});
|
||||||
|
if (resp.ok) {
|
||||||
|
error = false;
|
||||||
|
delete notes[nid];
|
||||||
|
} else {
|
||||||
|
error = await resp.text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function load(){
|
async function load(){
|
||||||
const url = api(`notes/${module}/${entity_id}`);
|
const url = api(`notes/${module}/${entity_id}`);
|
||||||
const resp = await fetch(url,{credentials:'include'});
|
const resp = await fetch(url,{credentials:'include'});
|
||||||
@@ -85,7 +100,12 @@
|
|||||||
{#each Object.entries(notes) as [nid,note]}
|
{#each Object.entries(notes) as [nid,note]}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend class="author">{authors[note.user_id].name}</legend>
|
<legend class="author">{authors[note.user_id].name}</legend>
|
||||||
<legend class="time">{note.timestamp.replace('T',' ')}</legend>
|
<legend class="time">
|
||||||
|
{note.timestamp.replace('T',' ')}
|
||||||
|
{#if user.id == note.user_id}
|
||||||
|
<button class="symbol" onclick={() => drop(nid)}></button>
|
||||||
|
{/if}
|
||||||
|
</legend>
|
||||||
<Editor value={note.text} onSet={(newVal) => update(nid,newVal)} editable={user.id == note.user_id} />
|
<Editor value={note.text} onSet={(newVal) => update(nid,newVal)} editable={user.id == note.user_id} />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ package de.srsoftware.umbrella.notes;
|
|||||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
|
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
|
||||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable;
|
|
||||||
import static de.srsoftware.umbrella.notes.Constants.CONFIG_DATABASE;
|
import static de.srsoftware.umbrella.notes.Constants.CONFIG_DATABASE;
|
||||||
import static java.net.HttpURLConnection.HTTP_OK;
|
import static java.net.HttpURLConnection.HTTP_OK;
|
||||||
|
|
||||||
@@ -50,12 +49,20 @@ public class NoteModule extends BaseHandler implements NoteService {
|
|||||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||||
var user = users.loadUser(token);
|
var user = users.loadUser(token);
|
||||||
if (user.isEmpty()) return unauthorized(ex);
|
if (user.isEmpty()) return unauthorized(ex);
|
||||||
var module = path.pop();
|
|
||||||
if (module == null) throw unprocessable("Module missing in path.");
|
|
||||||
var head = path.pop();
|
var head = path.pop();
|
||||||
long noteId = Long.parseLong(head);
|
if (head == null) throw unprocessable("Module missing in path.");
|
||||||
noteId = notesDb.delete(noteId,user.get().id());
|
// try {
|
||||||
return sendContent(ex, noteId);
|
var noteId = Long.parseLong(head);
|
||||||
|
var note = notesDb.load(noteId);
|
||||||
|
if (note.authorId() != user.get().id()) throw forbidden("You are not allowed to delete notes of another user");
|
||||||
|
return sendContent(ex, notesDb.delete(noteId));
|
||||||
|
/* } catch (NumberFormatException ignored) {
|
||||||
|
var module = head;
|
||||||
|
head = path.pop();
|
||||||
|
long entityId = Long.parseLong(head);
|
||||||
|
notesDb.deleteEntity(module,entityId);
|
||||||
|
return sendContent(ex, entityId);
|
||||||
|
}*/
|
||||||
} catch (NumberFormatException e){
|
} catch (NumberFormatException e){
|
||||||
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path.");
|
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path.");
|
||||||
} catch (UmbrellaException e){
|
} catch (UmbrellaException e){
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import de.srsoftware.umbrella.core.model.Note;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface NotesDb {
|
public interface NotesDb {
|
||||||
long delete(long noteId, long userId);
|
long delete(long noteId);
|
||||||
|
|
||||||
void deleteEntity(String module, long entityId);
|
void deleteEntity(String module, long entityId);
|
||||||
|
|
||||||
|
|||||||
@@ -85,8 +85,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long delete(long noteId, long userId) {
|
public long delete(long noteId) {
|
||||||
LOG.log(WARNING,"Not checking whether deleted not belongs to user!");
|
|
||||||
try {
|
try {
|
||||||
Query.delete().from(TABLE_NOTES)
|
Query.delete().from(TABLE_NOTES)
|
||||||
.where(ID,equal(noteId))
|
.where(ID,equal(noteId))
|
||||||
|
|||||||
@@ -39,12 +39,14 @@ public class TaskModule extends BaseHandler implements TaskService {
|
|||||||
private final UserService users;
|
private final UserService users;
|
||||||
private final CompanyService companies;
|
private final CompanyService companies;
|
||||||
private final TagService tags;
|
private final TagService tags;
|
||||||
|
private final NoteService notes;
|
||||||
|
|
||||||
public TaskModule(Configuration config, ProjectService projectService, TagService tagService) throws UmbrellaException {
|
public TaskModule(Configuration config, ProjectService projectService, TagService tagService, NoteService noteService) throws UmbrellaException {
|
||||||
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
||||||
taskDb = new SqliteDb(connect(dbFile));
|
taskDb = new SqliteDb(connect(dbFile));
|
||||||
projects = projectService;
|
projects = projectService;
|
||||||
companies = projectService.companyService();
|
companies = projectService.companyService();
|
||||||
|
notes = noteService;
|
||||||
tags = tagService;
|
tags = tagService;
|
||||||
users = companies.userService();
|
users = companies.userService();
|
||||||
}
|
}
|
||||||
@@ -66,6 +68,7 @@ public class TaskModule extends BaseHandler implements TaskService {
|
|||||||
var member = task.members().get(user.id());
|
var member = task.members().get(user.id());
|
||||||
if (member == null || !member.mayWrite()) throw forbidden("You are not allowed to delete {0}",task.name());
|
if (member == null || !member.mayWrite()) throw forbidden("You are not allowed to delete {0}",task.name());
|
||||||
taskDb.delete(task);
|
taskDb.delete(task);
|
||||||
|
notes.deleteEntity(TASK,taskId);
|
||||||
tags.deleteEntity(TASK,taskId);
|
tags.deleteEntity(TASK,taskId);
|
||||||
return sendContent(ex,Map.of(DELETED,taskId));
|
return sendContent(ex,Map.of(DELETED,taskId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,7 @@
|
|||||||
"new_password": "neues Passwort",
|
"new_password": "neues Passwort",
|
||||||
"new_document_from": "{2} / neues {0}s-Dokument von {1}",
|
"new_document_from": "{2} / neues {0}s-Dokument von {1}",
|
||||||
"no_company": "keine Firma",
|
"no_company": "keine Firma",
|
||||||
|
"note": "Notiz",
|
||||||
"notes": "Notizen",
|
"notes": "Notizen",
|
||||||
"number": "Nummer",
|
"number": "Nummer",
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user