fix(tasks): recover deleted captures without reviving tombstones
This commit is contained in:
1 parent
43a2d8c5a1
commit
4049acf76e
10 files changed
+594
-28
No files matched your search
@@ -0,0 +1,226 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func TestTaskCaptureDeletedRecreation(t *testing.T) {
|
||||
for _, wiki := range []bool{false, true} {
|
||||
t.Run(fmt.Sprint(wiki), func(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
id := uuid.NewString()
|
||||
input := map[string]any{"request_id": id, "title": "Original"}
|
||||
if wiki {
|
||||
input["wiki_body"], input["wiki_prefix"] = "Original private body", "/mail"
|
||||
}
|
||||
w := taskRequest(s, token, "POST", "capture", input, "")
|
||||
if w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
var result struct {
|
||||
Item store.TaskRecord `json:"item"`
|
||||
Path string `json:"page_path"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
page, path := result.Item.PageUUID, result.Path
|
||||
var revision string
|
||||
if wiki {
|
||||
r, err := s.store.GetLatestRevision(page)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
revision = r.UUID
|
||||
}
|
||||
if w = taskRequest(s, token, "DELETE", "items/"+id, nil, `"1"`); w.Code != 204 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w = taskRequest(s, token, "GET", "items/"+id, nil, ""); w.Code != 404 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
for _, title := range []string{"Original", "Changed"} {
|
||||
input["title"] = title
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 410 || !strings.Contains(w.Body.String(), `"deleted"`) {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
input["replaces_deleted"], input["request_id"] = id, store.TaskRecreationID(id)
|
||||
if wiki {
|
||||
input["wiki_body"] = "Must not overwrite the retained page"
|
||||
for _, invalidBody := range []string{"bad\x00body", strings.Repeat("x", 256<<10+1)} {
|
||||
input["wiki_body"] = invalidBody
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 422 {
|
||||
t.Fatal("reused page bypassed body validation", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
input["wiki_body"] = "Must not overwrite the retained page"
|
||||
}
|
||||
// A lost successful response, including concurrent retries, creates one
|
||||
// successor. It neither revives the original nor revises the Wiki.
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 4; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
v := taskRequest(s, token, "POST", "capture", input, "")
|
||||
if v.Code != 201 {
|
||||
t.Errorf("concurrent recreation: %d %s", v.Code, v.Body)
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
w = taskRequest(s, token, "POST", "capture", input, "")
|
||||
if w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Item.UUID != store.TaskRecreationID(id) || result.Item.UUID == id || result.Item.Title != "Changed" || result.Item.Version != 1 || result.Item.PageUUID != page || result.Path != path {
|
||||
t.Fatal(result)
|
||||
}
|
||||
if wiki {
|
||||
r, err := s.store.GetLatestRevision(page)
|
||||
if err != nil || r.UUID != revision || !strings.Contains(r.Body, "Original private body") {
|
||||
t.Fatal("Wiki changed", r, err)
|
||||
}
|
||||
}
|
||||
for table, expected := range map[string]int{"organizer_items": 1, "organizer_capture_receipts": 2, "organizer_task_deletions": 1, "organizer_revisions": 1} {
|
||||
var count int
|
||||
if err := s.store.DB.QueryRow("SELECT count(*) FROM " + table).Scan(&count); err != nil || count != expected {
|
||||
t.Fatal(table, count, err)
|
||||
}
|
||||
}
|
||||
if _, err := s.store.SaveTask(ctx, domain, actor, store.TaskRecord{UUID: id, Kind: "task", Title: "Offline resurrection", Status: "todo", Bucket: "inbox", Priority: 1}, 0); err != store.ErrTaskDeleted {
|
||||
t.Fatal("old UUID revived", err)
|
||||
}
|
||||
input["title"] = "Different committed recovery"
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 412 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
// Deleting the successor cannot be undone by replaying the recovery.
|
||||
if w = taskRequest(s, token, "DELETE", "items/"+result.Item.UUID, nil, `"1"`); w.Code != 204 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 410 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskCaptureRecreationGuards(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
id := uuid.NewString()
|
||||
input := map[string]any{"request_id": id, "title": "Original"}
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
recreate := map[string]any{"request_id": store.TaskRecreationID(id), "replaces_deleted": id, "title": "New"}
|
||||
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 412 {
|
||||
t.Fatal("live capture replaced", w.Code, w.Body)
|
||||
}
|
||||
if w := taskRequest(s, token, "DELETE", "items/"+id, nil, `"1"`); w.Code != 204 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
other, err := s.store.CreatePasswordAccount(domain, "recreateother", "long fixture password", "Other", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
otherToken, err := s.store.CreateAuthSession(domain, other.UUID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, otherToken, "POST", "capture", recreate, ""); w.Code != 404 {
|
||||
t.Fatal("other owner", w.Code, w.Body)
|
||||
}
|
||||
if _, err := s.store.RecreateCapturedTask(context.Background(), "other-domain", actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Wrong domain"), "", "", id); err != store.ErrAccessDenied {
|
||||
t.Fatal("wrong domain", err)
|
||||
}
|
||||
if err := s.store.SetPrincipalState(domain, actor, "readonly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.RecreateCapturedTask(context.Background(), domain, actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Readonly"), "", "", id); err != store.ErrAccessDenied {
|
||||
t.Fatal("readonly", err)
|
||||
}
|
||||
if err := s.store.SetPrincipalState(domain, actor, "active"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, err = s.store.CreateAuthSession(domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":false}`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.RecreateCapturedTask(context.Background(), domain, actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Disabled"), "", "", id); err != store.ErrAccessDenied {
|
||||
t.Fatal("extension disabled", err)
|
||||
}
|
||||
if err := s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":true}`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, invalid := range []string{uuid.NewString(), id, "not-an-id"} {
|
||||
recreate["request_id"] = invalid
|
||||
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 422 {
|
||||
t.Fatal("arbitrary recovery ID", w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
recreate["request_id"] = store.TaskRecreationID(id)
|
||||
// Failure during receipt insertion rolls back the task, page and journals.
|
||||
if _, err := s.store.DB.Exec(`CREATE TRIGGER reject_recreation BEFORE INSERT ON organizer_capture_receipts BEGIN SELECT RAISE(ABORT,'fixture rejection'); END`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
recreate["wiki_body"], recreate["wiki_prefix"] = "New body", "/recreated"
|
||||
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 500 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
var count int
|
||||
if err := s.store.DB.QueryRow(`SELECT count(*) FROM organizer_items`).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatal("orphan task", count, err)
|
||||
}
|
||||
if err := s.store.DB.QueryRow(`SELECT count(*) FROM paths WHERE path LIKE '/recreated/%'`).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatal("orphan page", count, err)
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`DROP TRIGGER reject_recreation`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if _, err := s.store.GetTask(context.Background(), domain, actor, store.TaskRecreationID(id)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskCaptureOrphanReceipt(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
id := uuid.NewString()
|
||||
input := map[string]any{"request_id": id, "title": "Original"}
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
// Simulate preexisting corruption, not a supported user deletion operation.
|
||||
if _, err := s.store.DB.Exec(`DELETE FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=?`, domain, actor, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, title := range []string{"Original", "Changed"} {
|
||||
input["title"] = title
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 409 || !strings.Contains(w.Body.String(), "capture_missing") {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
input["request_id"], input["replaces_deleted"] = store.TaskRecreationID(id), id
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 409 || !strings.Contains(w.Body.String(), "capture_missing") {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
@@ -56,20 +56,21 @@ func applyTaskReminderDefaults(item *store.TaskRecord, p store.TaskPreferences)
|
||||
}
|
||||
|
||||
type taskCaptureInput struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Title string `json:"title"`
|
||||
Notes string `json:"notes"`
|
||||
ProjectUUID *string `json:"project_uuid"`
|
||||
AssigneeUUID *string `json:"assignee_uuid"`
|
||||
DueOn *string `json:"due_on"`
|
||||
StartOn *string `json:"start_on"`
|
||||
PlannedOn *string `json:"planned_on"`
|
||||
ReviewOn *string `json:"review_on"`
|
||||
Estimate *int `json:"estimate_minutes"`
|
||||
Complexity *int `json:"complexity"`
|
||||
WikiBody *string `json:"wiki_body,omitempty"`
|
||||
WikiPrefix *string `json:"wiki_prefix,omitempty"`
|
||||
WikiSuffix *string `json:"wiki_suffix,omitempty"`
|
||||
ReplacesDeleted string `json:"replaces_deleted,omitempty"`
|
||||
RequestID string `json:"request_id"`
|
||||
Title string `json:"title"`
|
||||
Notes string `json:"notes"`
|
||||
ProjectUUID *string `json:"project_uuid"`
|
||||
AssigneeUUID *string `json:"assignee_uuid"`
|
||||
DueOn *string `json:"due_on"`
|
||||
StartOn *string `json:"start_on"`
|
||||
PlannedOn *string `json:"planned_on"`
|
||||
ReviewOn *string `json:"review_on"`
|
||||
Estimate *int `json:"estimate_minutes"`
|
||||
Complexity *int `json:"complexity"`
|
||||
WikiBody *string `json:"wiki_body,omitempty"`
|
||||
WikiPrefix *string `json:"wiki_prefix,omitempty"`
|
||||
WikiSuffix *string `json:"wiki_suffix,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request, actor string, active bool, kind string) {
|
||||
@@ -197,6 +198,13 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
if input.ReplacesDeleted != "" {
|
||||
id, err := uuid.Parse(input.ReplacesDeleted)
|
||||
if err != nil || id.String() != input.ReplacesDeleted || input.RequestID != store.TaskRecreationID(input.ReplacesDeleted) {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
}
|
||||
raw, _ := json.Marshal(input)
|
||||
hash := sha256.Sum256(raw)
|
||||
requestHash := hex.EncodeToString(hash[:])
|
||||
@@ -261,7 +269,11 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
target = store.TaskCaptureWikiPath(prefix, item.Title, input.RequestID)
|
||||
pathID := input.RequestID
|
||||
if input.ReplacesDeleted != "" {
|
||||
pathID = input.ReplacesDeleted
|
||||
}
|
||||
target = store.TaskCaptureWikiPath(prefix, item.Title, pathID)
|
||||
if input.WikiSuffix != nil {
|
||||
if !store.ValidTaskMailSuffix(*input.WikiSuffix) {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
@@ -280,7 +292,11 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
item, err = s.store.CaptureTaskWithWiki(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body)
|
||||
if input.ReplacesDeleted != "" {
|
||||
item, err = s.store.RecreateCapturedTask(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body, input.ReplacesDeleted)
|
||||
} else {
|
||||
item, err = s.store.CaptureTaskWithWiki(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body)
|
||||
}
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
|
||||
@@ -62,6 +62,8 @@ func taskError(w http.ResponseWriter, err error) {
|
||||
status, code = 422, "invalid"
|
||||
case errors.Is(err, store.ErrTaskConflict):
|
||||
status, code = 412, "conflict"
|
||||
case errors.Is(err, store.ErrTaskCaptureMissing):
|
||||
status, code = 409, "capture_missing"
|
||||
case errors.Is(err, store.ErrTaskDeleted):
|
||||
status, code = 410, "deleted"
|
||||
case errors.Is(err, store.ErrTaskHasChildren):
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// A receipt without a live task or a deletion marker needs repair, not an
|
||||
// implicit create that could silently revive an inconsistent record.
|
||||
var ErrTaskCaptureMissing = errors.New("captured task is missing without a deletion record")
|
||||
|
||||
func TaskRecreationID(request string) string {
|
||||
return uuid.NewSHA1(uuid.NameSpaceURL, []byte("pages:task-recreate:"+request)).String()
|
||||
}
|
||||
|
||||
func deletedCapture(ctx context.Context, q interface {
|
||||
QueryRowContext(context.Context, string, ...any) *sql.Row
|
||||
}, domain, actor, request string) error {
|
||||
var id string
|
||||
if err := q.QueryRowContext(ctx, `SELECT item_uuid FROM organizer_capture_receipts WHERE domain_uuid=? AND owner_uuid=? AND request_uuid=?`, domain, actor, request).Scan(&id); err != nil {
|
||||
return err
|
||||
}
|
||||
var live, deleted bool
|
||||
if err := q.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_items WHERE domain_uuid=? AND uuid=?), EXISTS(SELECT 1 FROM organizer_task_deletions WHERE domain_uuid=? AND owner_uuid=? AND item_uuid=?)`, domain, id, domain, actor, id).Scan(&live, &deleted); err != nil {
|
||||
return err
|
||||
}
|
||||
if live {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
if !deleted {
|
||||
return ErrTaskCaptureMissing
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecreateCapturedTask never removes old receipts, tombstones or DAV identity
|
||||
// reservations. A deterministic successor ID makes a lost response retry safe.
|
||||
// The caller authorizes read/create/write for target, including retained pages.
|
||||
func (s *Store) RecreateCapturedTask(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body, replaces string) (TaskRecord, error) {
|
||||
id, err := uuid.Parse(replaces)
|
||||
if err != nil || id.String() != replaces || request != TaskRecreationID(replaces) {
|
||||
return TaskRecord{}, ErrTaskInvalid
|
||||
}
|
||||
if err = taskActor(ctx, s.DB, domain, actor, true); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
if err = deletedCapture(ctx, s.DB, domain, actor, replaces); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
return s.captureTaskWithWiki(ctx, domain, actor, request, hash, item, target, body, replaces)
|
||||
}
|
||||
@@ -77,8 +77,12 @@ func ValidTaskMailSuffix(s string) bool {
|
||||
return mailListSuffix.MatchString(s) || (mailMonthSuffix.MatchString(s) && !strings.HasPrefix(s, "0000/"))
|
||||
}
|
||||
|
||||
func validCapturedTaskWiki(target, body string) bool {
|
||||
return target != "" && ValidTaskWikiPrefix(path.Dir(target)) && path.Clean(target) == target && len(body) <= 256<<10 && utf8.ValidString(body) && strings.IndexByte(body, 0) < 0
|
||||
}
|
||||
|
||||
func (s *Store) createCapturedTaskWiki(ctx context.Context, tx *sql.Tx, domain, actor string, item *TaskRecord, target, body string) error {
|
||||
if target == "" || !ValidTaskWikiPrefix(path.Dir(target)) || path.Clean(target) != target || item.PageUUID != "" || len(body) > 256<<10 || !utf8.ValidString(body) || strings.IndexByte(body, 0) >= 0 {
|
||||
if !validCapturedTaskWiki(target, body) || item.PageUUID != "" {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
var exists bool
|
||||
|
||||
@@ -227,10 +227,22 @@ func (s *Store) CapturedTask(ctx context.Context, domain, actor, request, hash s
|
||||
if err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
// Check lifecycle before payload equality. A retained receipt must not
|
||||
// disguise a deleted task as an editable version conflict.
|
||||
item, err := s.GetTask(ctx, domain, actor, id)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
if err = deletedCapture(ctx, s.DB, domain, actor, request); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
return TaskRecord{}, ErrTaskDeleted
|
||||
}
|
||||
if err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
if stored != hash {
|
||||
return TaskRecord{}, ErrTaskConflict
|
||||
}
|
||||
return s.GetTask(ctx, domain, actor, id)
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *Store) CaptureTask(ctx context.Context, domain, actor, request, hash string, item TaskRecord) (TaskRecord, error) {
|
||||
@@ -240,6 +252,10 @@ func (s *Store) CaptureTask(ctx context.Context, domain, actor, request, hash st
|
||||
// CaptureTaskWithWiki commits the task, receipt and optional Wiki page together.
|
||||
// The HTTP caller must authorize read/create/write for the exact target path.
|
||||
func (s *Store) CaptureTaskWithWiki(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body string) (TaskRecord, error) {
|
||||
return s.captureTaskWithWiki(ctx, domain, actor, request, hash, item, target, body, "")
|
||||
}
|
||||
|
||||
func (s *Store) captureTaskWithWiki(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body, replaces string) (TaskRecord, error) {
|
||||
if _, err := uuid.Parse(request); err != nil {
|
||||
return TaskRecord{}, ErrTaskInvalid
|
||||
}
|
||||
@@ -252,11 +268,31 @@ func (s *Store) CaptureTaskWithWiki(ctx context.Context, domain, actor, request,
|
||||
}
|
||||
item.UUID = request
|
||||
out, err := s.saveTask(ctx, domain, actor, item, 0, func(tx *sql.Tx, current *TaskRecord, _ TaskRecord) error {
|
||||
if target != "" {
|
||||
if e := s.createCapturedTaskWiki(ctx, tx, domain, actor, current, target, body); e != nil {
|
||||
if replaces != "" {
|
||||
if e := deletedCapture(ctx, tx, domain, actor, replaces); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
if target != "" {
|
||||
if !validCapturedTaskWiki(target, body) || current.PageUUID != "" {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
// Explicit recreation may reuse a surviving Wiki page. Its content
|
||||
// and revisions are independent of task deletion and never replaced.
|
||||
reused := false
|
||||
if replaces != "" {
|
||||
e := tx.QueryRowContext(ctx, `SELECT p.object_uuid FROM paths p JOIN objects o ON o.uuid=p.object_uuid WHERE p.domain_uuid=? AND p.path=? AND o.kind='page'`, domain, target).Scan(¤t.PageUUID)
|
||||
if e != nil && !errors.Is(e, sql.ErrNoRows) {
|
||||
return e
|
||||
}
|
||||
reused = e == nil
|
||||
}
|
||||
if !reused {
|
||||
if e := s.createCapturedTaskWiki(ctx, tx, domain, actor, current, target, body); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
}
|
||||
_, e := tx.ExecContext(ctx, `INSERT INTO organizer_capture_receipts VALUES(?,?,?,?,?)`, domain, actor, request, hash, item.UUID)
|
||||
return e
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user