fix(db): report write errors, multi-step changes all or nothing (FLAW-14)
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 1m4s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 1m4s
Store.execInTx runs related statements in one transaction and returns the first error. Used for deleting and moving folders (with the trash), shared folders, folder shares and mounts, deleting task lists and accounts, pinning, and the password reset (new password and the end of all other links together). Writes whose success the API reports now pass their error to the client (logout, new password, setup, sharing mode, new group, restore, unlinking a note block), follow-up tasks and alarm markers log failures. Remaining ignored writes are listed as intentional in flaws.md. Found on the way: DeleteTaskList unlinked all tasks before checking ownership, so a stranger with the list ID could empty it; viewers could unlink tasks from note blocks. Both fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
792ca946f8
commit
6b56a33500
19 files changed
+274
-112
No files matched your search
@@ -30,13 +30,15 @@ type TrashedDocument struct {
|
||||
|
||||
const trashScope = `is_archived = 1 AND (user_id = ? OR archived_by = ?)`
|
||||
|
||||
func (s *Store) trashDocument(userID, docID string) error {
|
||||
_, err := s.db.Exec(`UPDATE documents SET is_archived = 1, archived_at = ?, archived_by = ? WHERE id = ?`,
|
||||
domain.NowISO(), userID, docID)
|
||||
if err == nil {
|
||||
_, _ = s.db.Exec(`DELETE FROM doc_pins WHERE doc_id = ?`, docID)
|
||||
func trashStmts(userID, docID string) []sqlStmt {
|
||||
return []sqlStmt{
|
||||
stmt(`UPDATE documents SET is_archived = 1, archived_at = ?, archived_by = ? WHERE id = ?`, domain.NowISO(), userID, docID),
|
||||
stmt(`DELETE FROM doc_pins WHERE doc_id = ?`, docID),
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Store) trashDocument(userID, docID string) error {
|
||||
return s.execInTx(trashStmts(userID, docID)...)
|
||||
}
|
||||
|
||||
// GetTrash lists the notes in the user's trash, newest deletion first.
|
||||
@@ -90,10 +92,14 @@ func (s *Store) RestoreDocument(userID, docID string) error {
|
||||
var exists int
|
||||
_ = s.db.QueryRow(`SELECT COUNT(*) FROM workspace_shared_folders WHERE id = ?`, sharedFolderID).Scan(&exists)
|
||||
if exists == 0 {
|
||||
_, _ = s.db.Exec(`UPDATE documents SET shared_folder_id = '', sub_folder_path = '', folder_path = '' WHERE id = ?`, docID)
|
||||
if _, err := s.db.Exec(`UPDATE documents SET shared_folder_id = '', sub_folder_path = '', folder_path = '' WHERE id = ?`, docID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else if folderPath != "" {
|
||||
_, _ = s.CreateFolder(owner, folderPath)
|
||||
if _, err := s.CreateFolder(owner, folderPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = s.db.Exec(`UPDATE documents SET is_archived = 0, archived_at = '', archived_by = '' WHERE id = ?`, docID)
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user