Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(task): let workspace batch delete remove teammates' tasks, with an explicit warning (#22089)

Rdmclin26d596e08b146
diff --git a/apps/server/src/services/task/batch.integration.test.ts b/apps/server/src/services/task/batch.integration.test.ts
index 35ec9429d60..d121624515f 100644
--- a/apps/server/src/services/task/batch.integration.test.ts
+++ b/apps/server/src/services/task/batch.integration.test.ts
@@ -12,7 +12,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { GoalModel } from '@/database/models/goal';
import { TaskModel } from '@/database/models/task';
import { TaskTopicModel } from '@/database/models/taskTopic';
-import { agents, taskActivities, tasks, users } from '@/database/schemas';
+import { agents, taskActivities, tasks, users, workspaces } from '@/database/schemas';
import { TaskRunnerService } from '@/server/services/taskRunner';
import { TaskBatchService } from './batch';
@@ -344,6 +344,38 @@ describe('TaskBatchService (real PostgreSQL)', () => {
});
describe('delete', () => {
+ it("deletes other members' visible workspace tasks, like the single-task delete", async () => {
+ const workspaceId = 'task-batch-delete-ws';
+ await db.insert(workspaces).values({
+ id: workspaceId,
+ name: 'Workspace',
+ primaryOwnerId: otherUserId,
+ slug: workspaceId,
+ });
+ const teammate = new TaskModel(db, otherUserId, workspaceId);
+ const shared = await teammate.create({ instruction: 'Teammate task', visibility: 'public' });
+ const hidden = await teammate.create({
+ instruction: 'Teammate private',
+ visibility: 'private',
+ });
+ const own = await new TaskModel(db, userId, workspaceId).create({
+ instruction: 'My task',
+ visibility: 'public',
+ });
+
+ const result = await new TaskBatchService(db, userId, workspaceId).delete([
+ shared.id,
+ own.id,
+ hidden.id,
+ ]);
+
+ expect(result.updated.sort()).toEqual([shared.id, own.id].sort());
+ // A teammate's private task is not visible, so it is reported, not touched.
+ expect(result.skipped).toEqual([{ id: hidden.id, reason: 'notFound' }]);
+ expect(await teammate.findById(shared.id)).toBeNull();
+ expect(await teammate.findById(hidden.id)).not.toBeNull();
+ });
+
it('deletes idle tasks in one pass and reports missing ones', async () => {
const [a, b] = await createTasks(2);
const keep = (await createTasks(1))[0];
diff --git a/apps/server/src/services/task/batch.ts b/apps/server/src/services/task/batch.ts
index e0da99df92a..61ae8046a95 100644
--- a/apps/server/src/services/task/batch.ts
+++ b/apps/server/src/services/task/batch.ts
@@ -28,8 +28,6 @@ const BATCH_SIDE_EFFECT_CONCURRENCY = 5;
const BATCH_CHECK_CONCURRENCY = 20;
export type TaskBatchSkipReason =
- /** A workspace bulk delete only removes tasks the caller created. */
- | 'forbidden'
/** The task is part of an open goal and cannot be archived. */
| 'inGoal'
/** Another member is editing the task. */
@@ -542,15 +540,10 @@ export class TaskBatchService {
* path, which interrupts the run before removing the row.
*/
async delete(ids: string[]): Promise<TaskBatchResult> {
- const { result, tasks: visible } = await this.loadSelection(ids);
- // Workspace bulk actions only affect caller-created content (the
- // `clearAll` rule, docs/usage/workspace-permissions): deleting a teammate's
- // task stays a deliberate one-at-a-time action.
- const tasks = visible.filter((task) => {
- if (!this.workspaceId || task.createdByUserId === this.userId) return true;
- result.skipped.push({ id: task.id, reason: 'forbidden' });
- return false;
- });
+ // Same scope as the single-task delete: any member who can edit tasks may
+ // delete a task they can see, whoever created it. The client confirms
+ // explicitly when the selection includes other members' tasks.
+ const { result, tasks } = await this.loadSelection(ids);
const taskTopicModel = new TaskTopicModel(this.db, this.userId, this.workspaceId);
const running = await taskTopicModel.findRunningByTaskIds(tasks.map((task) => task.id));
const busy = new Set([
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index bb715b671a2..54d255abb05 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -2622,6 +2622,8 @@
"taskList.bulk.delete": "Delete…",
"taskList.bulk.deleteConfirm.content": "Deleted tasks and their comments and runs cannot be recovered; their subtasks stay as top-level tasks. Running tasks are stopped first.",
"taskList.bulk.deleteConfirm.ok": "Delete",
+ "taskList.bulk.deleteConfirm.othersWarning_one": "{{count}} of these tasks was created by another workspace member. Deleting it removes it for everyone.",
+ "taskList.bulk.deleteConfirm.othersWarning_other": "{{count}} of these tasks were created by other workspace members. Deleting them removes them for everyone.",
"taskList.bulk.deleteConfirm.title_one": "Delete {{count}} task?",
"taskList.bulk.deleteConfirm.title_other": "Delete {{count}} tasks?",
"taskList.bulk.followUpFailed.desc": "The tasks were completed, but checkpoint pauses and dependent tasks could not be processed. Check the affected parent and dependent tasks.",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 9e9105d9f84..e0384e5b381 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -2622,6 +2622,8 @@
"taskList.bulk.delete": "删除…",
"taskList.bulk.deleteConfirm.content": "删除后,任务及其评论和运行记录无法恢复,子任务会保留为顶层任务。运行中的任务会先被停止。",
"taskList.bulk.deleteConfirm.ok": "删除",
+ "taskList.bulk.deleteConfirm.othersWarning_one": "其中 {{count}} 个任务由其他成员创建,删除后所有成员都将无法再看到。",
+ "taskList.bulk.deleteConfirm.othersWarning_other": "其中 {{count}} 个任务由其他成员创建,删除后所有成员都将无法再看到。",
"taskList.bulk.deleteConfirm.title_one": "删除 {{count}} 个任务?",
"taskList.bulk.deleteConfirm.title_other": "删除 {{count}} 个任务?",
"taskList.bulk.followUpFailed.desc": "任务已标记完成,但检查点暂停和依赖任务没有处理成功,请检查相关的父任务和依赖任务。",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index 148088c03f0..2ec1035f2d4 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -3088,6 +3088,10 @@ export default {
'taskList.bulk.deleteConfirm.content':
'Deleted tasks and their comments and runs cannot be recovered; their subtasks stay as top-level tasks. Running tasks are stopped first.',
'taskList.bulk.deleteConfirm.ok': 'Delete',
+ 'taskList.bulk.deleteConfirm.othersWarning_one':
+ '{{count}} of these tasks was created by another workspace member. Deleting it removes it for everyone.',
+ 'taskList.bulk.deleteConfirm.othersWarning_other':
+ '{{count}} of these tasks were created by other workspace members. Deleting them removes them for everyone.',
'taskList.bulk.deleteConfirm.title_one': 'Delete {{count}} task?',
'taskList.bulk.deleteConfirm.title_other': 'Delete {{count}} tasks?',
'taskList.bulk.followUpFailed.desc':
diff --git a/src/features/AgentTasks/AgentTaskList/selection/BulkDeleteConfirmContent.test.tsx b/src/features/AgentTasks/AgentTaskList/selection/BulkDeleteConfirmContent.test.tsx
new file mode 100644
index 00000000000..00245c49ea1
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskList/selection/BulkDeleteConfirmContent.test.tsx
@@ -0,0 +1,25 @@
+import { render, screen } from '@testing-library/react';
+import { describe, expect, it, vi } from 'vitest';
+
+import BulkDeleteConfirmContent from './BulkDeleteConfirmContent';
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({
+ t: (key: string, options?: { count?: number }) => `${key}:${options?.count}`,
+ }),
+}));
+
+describe('BulkDeleteConfirmContent', () => {
+ it("warns with the count when the selection includes other members' tasks", () => {
+ render(<BulkDeleteConfirmContent count={5} othersCount={2} />);
+
+ expect(screen.getByText('taskList.bulk.deleteConfirm.content:5')).toBeTruthy();
+ expect(screen.getByText('taskList.bulk.deleteConfirm.othersWarning:2')).toBeTruthy();
+ });
+
+ it('shows no warning when every selected task is the caller’s own', () => {
+ render(<BulkDeleteConfirmContent count={5} othersCount={0} />);
+
+ expect(screen.queryByText(/othersWarning/)).toBeNull();
+ });
+});
diff --git a/src/features/AgentTasks/AgentTaskList/selection/BulkDeleteConfirmContent.tsx b/src/features/AgentTasks/AgentTaskList/selection/BulkDeleteConfirmContent.tsx
new file mode 100644
index 00000000000..cac23f0a2e0
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskList/selection/BulkDeleteConfirmContent.tsx
@@ -0,0 +1,36 @@
+import { Alert } from '@lobehub/ui';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+interface BulkDeleteConfirmContentProps {
+ /** Selected tasks. */
+ count: number;
+ /** How many of them another workspace member created. */
+ othersCount: number;
+}
+
+/**
+ * Body of the batch delete confirmation. Deleting a teammate's task is allowed
+ * (as for a single task), but in a batch it is easy to miss, so a selection
+ * that includes any gets an explicit warning with the count.
+ */
+const BulkDeleteConfirmContent = memo<BulkDeleteConfirmContentProps>(({ count, othersCount }) => {
+ const { t } = useTranslation('chat');
+ return (
+ <>
+ <div>{t('taskList.bulk.deleteConfirm.content', { count })}</div>
+ {othersCount > 0 && (
+ <Alert
+ data-testid={'task-bulk-delete-others-warning'}
+ style={{ marginTop: 12 }}
+ title={t('taskList.bulk.deleteConfirm.othersWarning', { count: othersCount })}
+ type={'warning'}
+ />
+ )}
+ </>
+ );
+});
+
+BulkDeleteConfirmContent.displayName = 'BulkDeleteConfirmContent';
+
+export default BulkDeleteConfirmContent;
diff --git a/src/features/AgentTasks/AgentTaskList/selection/TaskBulkActionsPanel.tsx b/src/features/AgentTasks/AgentTaskList/selection/TaskBulkActionsPanel.tsx
index 3851a8d8fed..db3df2024d9 100644
--- a/src/features/AgentTasks/AgentTaskList/selection/TaskBulkActionsPanel.tsx
+++ b/src/features/AgentTasks/AgentTaskList/selection/TaskBulkActionsPanel.tsx
@@ -42,7 +42,9 @@ import { userProfileSelectors } from '@/store/user/selectors';
import { PRIORITY_META } from '../../features/TaskPriorityTag';
import { STATUS_META } from '../../features/taskStatusMeta';
import { hasWorkspaceMemberDirectory } from '../../shared/memberAssigneeMode';
+import BulkDeleteConfirmContent from './BulkDeleteConfirmContent';
import { useTaskSelectionStore } from './store';
+import { countTasksCreatedByOthers } from './taskSelectionModel';
import { type TaskBatchStatus, useTaskBatchActions } from './useTaskBatchActions';
const BATCH_STATUSES: TaskBatchStatus[] = ['backlog', 'paused', 'completed', 'canceled'];
@@ -126,8 +128,11 @@ const TaskBulkActionsPanel = memo<TaskBulkActionsPanelProps>(({ onClose, tasks }
const confirmDelete = () => {
onClose();
+ // Any member who can edit tasks may delete a teammate's task, as with a
+ // single task; in a batch it is easy to miss, so say how many are theirs.
+ const othersCount = activeWorkspaceId ? countTasksCreatedByOthers(selectedTasks, userId) : 0;
confirmModal({
- content: t('taskList.bulk.deleteConfirm.content', { count: selectedIds.length }),
+ content: <BulkDeleteConfirmContent count={selectedIds.length} othersCount={othersCount} />,
okButtonProps: { danger: true },
okText: t('taskList.bulk.deleteConfirm.ok'),
onOk: () => run({ kind: 'delete' }),
diff --git a/src/features/AgentTasks/AgentTaskList/selection/taskSelectionModel.test.ts b/src/features/AgentTasks/AgentTaskList/selection/taskSelectionModel.test.ts
index 549534e61ec..8c0512b18db 100644
--- a/src/features/AgentTasks/AgentTaskList/selection/taskSelectionModel.test.ts
+++ b/src/features/AgentTasks/AgentTaskList/selection/taskSelectionModel.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
import {
chunkIds,
+ countTasksCreatedByOthers,
isEditableTarget,
mergeOutcomes,
pruneSelection,
@@ -64,4 +65,16 @@ describe('taskSelectionModel', () => {
expect(isEditableTarget(div)).toBe(false);
expect(isEditableTarget(null)).toBe(false);
});
+
+ it('counts the selected tasks another member created', () => {
+ const tasks = [
+ { createdByUserId: 'me' },
+ { createdByUserId: 'teammate' },
+ { createdByUserId: 'other-teammate' },
+ { createdByUserId: null },
+ ];
+ expect(countTasksCreatedByOthers(tasks, 'me')).toBe(2);
+ expect(countTasksCreatedByOthers(tasks, undefined)).toBe(0);
+ expect(countTasksCreatedByOthers([], 'me')).toBe(0);
+ });
});
diff --git a/src/features/AgentTasks/AgentTaskList/selection/taskSelectionModel.ts b/src/features/AgentTasks/AgentTaskList/selection/taskSelectionModel.ts
index a766ff599e2..d50e6045a18 100644
--- a/src/features/AgentTasks/AgentTaskList/selection/taskSelectionModel.ts
+++ b/src/features/AgentTasks/AgentTaskList/selection/taskSelectionModel.ts
@@ -70,3 +70,16 @@ export const isEditableTarget = (target: EventTarget | null): boolean => {
if (element.isContentEditable) return true;
return !!element.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]');
};
+
+/**
+ * How many of `tasks` another member created. A workspace batch delete may
+ * remove them (same scope as deleting one task), so the confirmation has to
+ * say so explicitly. Tasks without a recorded creator are not counted.
+ */
+export const countTasksCreatedByOthers = (
+ tasks: readonly { createdByUserId?: string | null }[],
+ userId: string | null | undefined,
+): number => {
+ if (!userId) return 0;
+ return tasks.filter((task) => !!task.createdByUserId && task.createdByUserId !== userId).length;
+};