From 2c5d87134de65db464f0fe7684144a8071ad78c1 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sat, 3 Apr 2021 14:21:39 +0200 Subject: [PATCH] allow changing item on tasks with logs. --- api/task.go | 18 ------------------ database/postgres/tasks.go | 5 +++++ svelte-ui/src/forms/TaskForm.svelte | 2 +- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/api/task.go b/api/task.go index fbf263e..67c0245 100644 --- a/api/task.go +++ b/api/task.go @@ -86,24 +86,6 @@ func Task(g *gin.RouterGroup, db database.Database) { return nil, err } - if update.ItemID != nil && *update.ItemID != task.ItemID { - _, err := l.FindItem(c.Request.Context(), *update.ItemID) - if err != nil { - return nil, err - } - - logs, err := l.ListLogs(c.Request.Context(), models.LogFilter{ - TaskIDs: []string{task.ID}, - }) - if err != nil { - return nil, err - } - - if len(logs) > 0 { - return nil, slerrors.Forbidden("You cannot change the item if the task has logs.") - } - } - if update.ProjectID != nil && *update.ProjectID != task.ProjectID { project, err := l.FindProject(c.Request.Context(), *update.ProjectID) if err != nil { diff --git a/database/postgres/tasks.go b/database/postgres/tasks.go index e7f2e49..71b9e2d 100644 --- a/database/postgres/tasks.go +++ b/database/postgres/tasks.go @@ -101,6 +101,11 @@ func (r *taskRepository) Update(ctx context.Context, task models.Task) error { if err != nil { return err } + + _, err = r.db.NamedExecContext(ctx, `UPDATE log SET item_id = :item_id WHERE task_id=:task_id`, &task) + if err != nil { + return err + } return nil } diff --git a/svelte-ui/src/forms/TaskForm.svelte b/svelte-ui/src/forms/TaskForm.svelte index b60c029..62e7473 100644 --- a/svelte-ui/src/forms/TaskForm.svelte +++ b/svelte-ui/src/forms/TaskForm.svelte @@ -117,7 +117,7 @@ import ProjectSelect from "../components/ProjectSelect.svelte";