Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package workbench
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func lockResourceForDeletion(ctx context.Context, tx *gorm.DB, kind, id string) (*Resource, error) {
|
|
return lockResource(ctx, tx, kind, id)
|
|
}
|
|
|
|
// The caller holds both resource locks and has checked that the task is idle.
|
|
// Only references change; historical prose and import metadata are preserved.
|
|
func detachResourceForDeletion(ctx context.Context, tx *gorm.DB, parent, task *Resource) error {
|
|
tenant, actor, admin, err := identity(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if parent.TenantID != tenant || task.TenantID != tenant || task.Kind != "content-tasks" {
|
|
return ErrForbidden
|
|
}
|
|
if !admin && (parent.OwnerID != actor || task.OwnerID != actor) {
|
|
return ErrForbidden
|
|
}
|
|
d, err := decode[TaskData](task.Data)
|
|
if err != nil {
|
|
return ErrInvalid
|
|
}
|
|
if (parent.Kind != "flows" || d.FlowID != parent.ID) && (parent.Kind != "training-maps" || d.MapID != parent.ID) {
|
|
return ErrInvalid
|
|
}
|
|
if task.OwnerID != actor {
|
|
if err := archiveResource(ctx, tx, task); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if parent.Kind == "flows" {
|
|
task.Data["flow_id"] = ""
|
|
} else {
|
|
task.Data["map_id"] = ""
|
|
}
|
|
task.Status = "needs_configuration"
|
|
return persistResource(ctx, tx, task, task.Version)
|
|
}
|