summaryrefslogtreecommitdiff
path: root/makima/src/server/handlers/mesh.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/server/handlers/mesh.rs')
-rw-r--r--makima/src/server/handlers/mesh.rs34
1 files changed, 32 insertions, 2 deletions
diff --git a/makima/src/server/handlers/mesh.rs b/makima/src/server/handlers/mesh.rs
index ac5652a..63b1827 100644
--- a/makima/src/server/handlers/mesh.rs
+++ b/makima/src/server/handlers/mesh.rs
@@ -122,7 +122,11 @@ pub async fn list_tasks(
};
let result = if query.orphan {
- repository::list_orphan_tasks_for_owner(pool, auth.owner_id).await
+ // Backed by the per-owner tmp directive going forward — see
+ // `list_tmp_tasks_for_owner` for the semantics. The query parameter
+ // name (`?orphan=true`) is preserved for backwards compatibility
+ // with existing frontend callers.
+ repository::list_tmp_tasks_for_owner(pool, auth.owner_id).await
} else {
repository::list_tasks_for_owner(pool, auth.owner_id).await
};
@@ -228,7 +232,7 @@ pub async fn get_task(
pub async fn create_task(
State(state): State<SharedState>,
Authenticated(auth): Authenticated,
- Json(req): Json<CreateTaskRequest>,
+ Json(mut req): Json<CreateTaskRequest>,
) -> impl IntoResponse {
let Some(ref pool) = state.db_pool else {
return (
@@ -238,6 +242,32 @@ pub async fn create_task(
.into_response();
};
+ // Every top-level task must live under SOME directive going forward —
+ // the unified directive surface is the only way users see tasks. If a
+ // caller doesn't supply directive_id, attach to the owner's tmp
+ // (scratchpad) directive, auto-creating it if needed. Subtasks
+ // (parent_task_id set) inherit their parent's directive linkage and
+ // are fine without an explicit directive_id.
+ if req.directive_id.is_none() && req.parent_task_id.is_none() {
+ match repository::get_or_create_tmp_directive(pool, auth.owner_id).await {
+ Ok(tmp) => {
+ req.directive_id = Some(tmp.id);
+ }
+ Err(e) => {
+ tracing::error!(
+ owner_id = %auth.owner_id,
+ error = %e,
+ "Failed to provision tmp directive for orphan task"
+ );
+ return (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(ApiError::new("TMP_PROVISION_FAILED", &e.to_string())),
+ )
+ .into_response();
+ }
+ }
+ }
+
match repository::create_task_for_owner(pool, auth.owner_id, req).await {
Ok(task) => {
// Record history event for task creation