Let the coordinator and workspace admins hand over tasks and routines
delegate_task takes a task_id to hand over a task already on a list: it moves to the worker (a workspace's task stays on its list), goes to doing, and the job is linked back so its end is noted on the task. hand_over_schedule moves a bot's own routine to another bot, keeping its workspace. Users get Hand over in the Tasks UI and both routine lists. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import handOverPlace from "./hand-over-place";
|
||||
|
||||
describe("handOverPlace", () => {
|
||||
test("work in a workspace stays there", () => {
|
||||
expect(handOverPlace({ workspace_id: 3, label: "Task #1" })).toBe(3);
|
||||
expect(handOverPlace({ workspace_id: 3, asked_workspace_id: 3, label: "Task #1" })).toBe(3);
|
||||
});
|
||||
|
||||
test("refuses to move work out of its workspace", () => {
|
||||
expect(() => handOverPlace({ workspace_id: 3, asked_workspace_id: 4, label: "Task #1" })).toThrow(
|
||||
/Task #1 belongs to workspace 3/,
|
||||
);
|
||||
});
|
||||
|
||||
test("a bot's own goes to the asked workspace, else the new bot's own chat", () => {
|
||||
expect(handOverPlace({ workspace_id: null, asked_workspace_id: 5, label: "Routine #2" })).toBe(5);
|
||||
expect(handOverPlace({ workspace_id: null, label: "Routine #2" })).toBeNull();
|
||||
expect(handOverPlace({ workspace_id: "", asked_workspace_id: null, label: "Routine #2" })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import AppError from "./app-error";
|
||||
|
||||
type Params = {
|
||||
/**
|
||||
* The workspace the task's list or the routine belongs to now; none
|
||||
* for a bot's own.
|
||||
*/
|
||||
workspace_id?: number | string | null;
|
||||
/**
|
||||
* The workspace asked for, if any.
|
||||
*/
|
||||
asked_workspace_id?: number | string | null;
|
||||
/**
|
||||
* What is handed over, for the refusal ("Task #4").
|
||||
*/
|
||||
label: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Where handed-over work runs from now: a task on a workspace's list or a
|
||||
* routine in a workspace stays in that workspace, and asking for another
|
||||
* is refused; a bot's own goes to the asked workspace, or the new bot's
|
||||
* own chat (null).
|
||||
*/
|
||||
export default function handOverPlace({ workspace_id, asked_workspace_id, label }: Params): number | null {
|
||||
if (workspace_id) {
|
||||
if (asked_workspace_id && Number(asked_workspace_id) != Number(workspace_id)) {
|
||||
throw new AppError(`${label} belongs to workspace ${workspace_id}, and stays there. Leave workspace_id out.`);
|
||||
}
|
||||
|
||||
return Number(workspace_id);
|
||||
}
|
||||
|
||||
return asked_workspace_id ? Number(asked_workspace_id) : null;
|
||||
}
|
||||
Reference in New Issue
Block a user