Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ export function BoardColumn({
childrenByParent,
onOpenTask,
projectKey,
canEdit = false,
}: {
status: TaskStatus;
tasks: TaskRow[];
childrenByParent?: Map<string, TaskRow[]>;
onOpenTask?: (task: TaskRow) => void;
projectKey?: string | null;
/** Caller may write to the project — gates drag-reorder and inline pickers. */
canEdit?: boolean;
}) {
const { t } = useT('tasks');
// Column is itself a drop target so cards can be dropped into an empty lane.
Expand Down Expand Up @@ -65,6 +68,7 @@ export function BoardColumn({
subtasks={childrenByParent?.get(task._id)}
onOpen={onOpenTask}
projectKey={projectKey}
canEdit={canEdit}
/>
))}
</SortableContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ export function KanbanBoard({
tasks,
onOpenTask,
projectKey,
canEdit = false,
}: {
tasks: TaskRow[];
onOpenTask?: (task: TaskRow) => void;
projectKey?: string | null;
/** Caller may write to the project — gates drag-reorder and inline pickers. */
canEdit?: boolean;
}) {
const dnd = useTaskBoardDnd(tasks);
// The board keeps every task as a card (grouped by status); this map only
Expand Down Expand Up @@ -55,6 +58,7 @@ export function KanbanBoard({
childrenByParent={childrenByParent}
onOpenTask={onOpenTask}
projectKey={projectKey}
canEdit={canEdit}
/>
))}
</Row>
Expand All @@ -65,6 +69,7 @@ export function KanbanBoard({
subtasks={childrenByParent.get(dnd.activeTask._id)}
dragging
projectKey={projectKey}
canEdit={canEdit}
/>
) : null}
</DragOverlay>
Expand Down
21 changes: 19 additions & 2 deletions services/platform/app/features/tasks/components/task-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function TaskCard({
onOpen,
dragging,
projectKey,
canEdit = false,
}: {
task: TaskRow;
/** This task's subtasks, when known — drives the progress ring. */
Expand All @@ -42,6 +43,8 @@ export function TaskCard({
/** True when rendered inside the DragOverlay (floating clone). */
dragging?: boolean;
projectKey?: string | null;
/** Caller may write to the project — gates drag and the inline pickers. */
canEdit?: boolean;
}) {
const { t } = useT('tasks');
const identifier = formatTaskIdentifier(projectKey, task.number);
Expand All @@ -63,7 +66,13 @@ export function TaskCard({
: parent
? t('detail.partOf', { task: parent.title })
: t('detail.subtask');
const sortable = useSortable({ id: task._id, data: { status: task.status } });
// Read-only viewers can't reorder: disabling the sortable drops the drag
// listeners (the server rejects the move anyway).
const sortable = useSortable({
id: task._id,
data: { status: task.status },
disabled: !canEdit,
});
const style = {
transform: CSS.Translate.toString(sortable.transform),
transition: sortable.transition,
Expand Down Expand Up @@ -92,10 +101,16 @@ export function TaskCard({
{...sortable.listeners}
onClick={() => onOpen?.(task)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
// Enter always opens the task. Space starts a keyboard drag via
// dnd-kit's KeyboardSensor activator (kept in `sortable.listeners`),
// so we must forward to it rather than shadow it — but only when the
// card is draggable. For read-only cards Space opens instead.
if (e.key === 'Enter' || (e.key === ' ' && !canEdit)) {
e.preventDefault();
onOpen?.(task);
return;
}
sortable.listeners?.onKeyDown?.(e);
}}
>
{identifier && (
Expand Down Expand Up @@ -129,6 +144,7 @@ export function TaskCard({
<div className="flex items-center gap-1.5">
<PriorityPicker
priority={task.priority ?? null}
disabled={!canEdit}
onChange={(priority) =>
updateTask.mutate({ taskId: task._id, priority })
}
Expand All @@ -155,6 +171,7 @@ export function TaskCard({
projectId={task.projectId}
assigneeType={task.assigneeType}
assigneeId={task.assigneeId}
disabled={!canEdit}
onAssign={(assigneeType, assigneeId) =>
assignTask.mutate({ taskId: task._id, assigneeType, assigneeId })
}
Expand Down
31 changes: 29 additions & 2 deletions services/platform/app/features/tasks/components/tasks-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ export function TasksList({
tasks,
onOpenTask,
projectKey,
canEdit = false,
}: {
tasks: TaskRow[];
onOpenTask?: (task: TaskRow) => void;
projectKey?: string | null;
/** Caller may write to the project — gates drag-reorder and inline pickers. */
canEdit?: boolean;
}) {
const { topLevel, childrenByParent } = useMemo(
() => partitionSubtasks(tasks),
Expand Down Expand Up @@ -112,6 +115,7 @@ export function TasksList({
onToggleCollapsed={toggleCollapsed}
onOpenTask={onOpenTask}
projectKey={projectKey}
canEdit={canEdit}
/>
);
})}
Expand All @@ -123,6 +127,7 @@ export function TasksList({
subtasks={childrenByParent.get(dnd.activeTask._id)}
projectKey={projectKey}
dragging
canEdit={canEdit}
/>
) : null}
</DragOverlay>
Expand All @@ -140,6 +145,7 @@ function ListSwimlane({
onToggleCollapsed,
onOpenTask,
projectKey,
canEdit,
}: {
status: TaskStatus;
rows: TaskRow[];
Expand All @@ -150,6 +156,7 @@ function ListSwimlane({
onToggleCollapsed: (status: TaskStatus) => void;
onOpenTask?: (task: TaskRow) => void;
projectKey?: string | null;
canEdit: boolean;
}) {
const { t } = useT('tasks');
const { setNodeRef, isOver } = useDroppable({
Expand Down Expand Up @@ -199,6 +206,7 @@ function ListSwimlane({
onToggleExpanded={onToggleExpanded}
onOpen={onOpenTask}
projectKey={projectKey}
canEdit={canEdit}
/>
{isExpanded &&
children?.map((child) => (
Expand All @@ -208,6 +216,7 @@ function ListSwimlane({
nested
onOpen={onOpenTask}
projectKey={projectKey}
canEdit={canEdit}
/>
))}
</div>
Expand All @@ -234,6 +243,7 @@ function TaskListRow({
dragging,
nested,
projectKey,
canEdit = false,
}: {
task: TaskRow;
subtasks?: TaskRow[];
Expand All @@ -244,6 +254,8 @@ function TaskListRow({
/** Rendered as a nested subtask row (indented, non-draggable). */
nested?: boolean;
projectKey?: string | null;
/** Caller may write to the project — gates drag-reorder and inline pickers. */
canEdit?: boolean;
}) {
const { t } = useT('tasks');
const identifier = formatTaskIdentifier(projectKey, task.number);
Expand All @@ -256,7 +268,14 @@ function TaskListRow({
// Subtask rows are not draggable; only top-level rows participate in the DnD
// sortable context. `useSortable` is still called unconditionally to respect
// the rules of hooks, but its wiring is ignored for nested rows.
const sortable = useSortable({ id: task._id, data: { status: task.status } });
// Nested rows never drag; top-level rows drag only when the caller can write
// (disabling the sortable drops its drag listeners — the server rejects the
// move anyway).
const sortable = useSortable({
id: task._id,
data: { status: task.status },
disabled: nested || !canEdit,
});
const style = nested
? undefined
: {
Expand All @@ -281,10 +300,16 @@ function TaskListRow({
tabIndex={nested ? 0 : undefined}
onClick={() => onOpen?.(task)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
// Enter always opens the task. Space starts a keyboard drag via
// dnd-kit's KeyboardSensor activator (kept in `sortable.listeners`) for
// draggable rows; nested and read-only rows have no drag, so Space opens.
const draggable = !nested && canEdit;
if (e.key === 'Enter' || (e.key === ' ' && !draggable)) {
e.preventDefault();
onOpen?.(task);
return;
}
sortable.listeners?.onKeyDown?.(e);
}}
className={cn(
'group focus-visible:ring-ring/50 flex w-full cursor-pointer items-center gap-2.5 py-1.5 pr-3 text-left transition-colors focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset',
Expand Down Expand Up @@ -325,6 +350,7 @@ function TaskListRow({
<PriorityPicker
priority={task.priority ?? null}
align="start"
disabled={!canEdit}
onChange={(priority) =>
updateTask.mutate({ taskId: task._id, priority })
}
Expand Down Expand Up @@ -377,6 +403,7 @@ function TaskListRow({
assigneeType={task.assigneeType}
assigneeId={task.assigneeId}
align="end"
disabled={!canEdit}
onAssign={(assigneeType, assigneeId) =>
assignTask.mutate({ taskId: task._id, assigneeType, assigneeId })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function TasksWorkspace({
}) {
const { t } = useT('tasks');
const typedProjectId = asProjectId(projectId);
const { tasks, isLoading } = useTasksByProject(typedProjectId);
const { tasks, canEdit, isLoading } = useTasksByProject(typedProjectId);
const { edges } = useProjectDependencies(typedProjectId);
const { runningTaskIds, reviewTaskIds } =
useTaskOpsIndicators(typedProjectId);
Expand Down Expand Up @@ -105,9 +105,13 @@ export function TasksWorkspace({
>
{t('metrics.link')}
</LinkButton>
<Button size="sm" icon={Plus} onClick={() => setCreateOpen(true)}>
{t('actions.create')}
</Button>
{/* Read-only viewers can't create tasks (the server rejects the
write); hide the action rather than surface a doomed button. */}
{canEdit && (
<Button size="sm" icon={Plus} onClick={() => setCreateOpen(true)}>
{t('actions.create')}
</Button>
)}
</Row>
</Row>

Expand All @@ -128,6 +132,7 @@ export function TasksWorkspace({
tasks={tasks}
onOpenTask={handleOpenTask}
projectKey={projectKey}
canEdit={canEdit}
/>
</div>
) : (
Expand All @@ -136,6 +141,7 @@ export function TasksWorkspace({
tasks={tasks}
onOpenTask={handleOpenTask}
projectKey={projectKey}
canEdit={canEdit}
/>
</div>
)}
Expand Down
3 changes: 3 additions & 0 deletions services/platform/app/features/tasks/hooks/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export function useTasksByProject(
return {
tasks: data?.tasks ?? [],
truncated: data?.truncated ?? false,
// Defaults to false until the read resolves, so write controls stay hidden
// (rather than flashing) for a viewer who turns out to be read-only.
canEdit: data?.canEdit ?? false,
isLoading,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ export function useTaskBoardDnd(tasks: TaskRow[]): TaskBoardDnd {
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
// Space picks up / drops a card and arrow keys move it; Escape cancels.
// Enter is deliberately NOT a drag key so the card/row keydown handler can
// use it to OPEN the task — without this, dnd-kit's default (Space+Enter
// start a drag) would collide with opening.
keyboardCodes: {
start: ['Space'],
cancel: ['Escape'],
end: ['Space'],
},
}),
);

Expand Down
48 changes: 48 additions & 0 deletions services/platform/convex/tasks/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ for (const [key, loader] of Object.entries(rawModules)) {
const ORG = 'org_external_keys';
type T = TestConvex<typeof schema>;

// Seed the local member mirror so the org-membership gate resolves without the
// (test-unavailable) Better Auth component — mirrors apps/config.test.ts.
async function seedMember(t: T, userId: string, role: string): Promise<void> {
await t.run(async (ctx) => {
await ctx.db.insert('memberMirror', {
memberId: `m_${userId}`,
userId,
organizationId: ORG,
role,
createdAt: 0,
});
});
}

async function seedProject(t: T, name: string): Promise<Id<'projects'>> {
return await t.run((ctx) =>
ctx.db.insert('projects', {
Expand Down Expand Up @@ -134,6 +148,40 @@ describe('listExternalKeysByProject', () => {
});
});

// The board/list hide write controls (Create, the priority/assignee pickers,
// drag-reorder) for read-only viewers off this flag — the server still rejects
// any unauthorized write, so it's a UX/consistency affordance (#2069[57]).
describe('listTasksByProject canEdit', () => {
it('reports canEdit true for an editor on an org-wide project', async () => {
const t = convexTest(schema, modules);
const projectId = await seedProject(t, 'A'); // org-wide (no teamId)
await seedMember(t, 'user_editor', 'editor');

const result = await t
.withIdentity({ subject: 'user_editor' })
.query(api.tasks.queries.listTasksByProject, {
projectId,
organizationId: ORG,
});
expect(result.canEdit).toBe(true);
});

it('reports canEdit false for a read-only member who can still read', async () => {
const t = convexTest(schema, modules);
const projectId = await seedProject(t, 'A'); // org-wide → readable by all
await seedMember(t, 'user_member', 'member');

const result = await t
.withIdentity({ subject: 'user_member' })
.query(api.tasks.queries.listTasksByProject, {
projectId,
organizationId: ORG,
});
// Reads succeed (no throw) but writes are gated off.
expect(result.canEdit).toBe(false);
});
});

// The tasks domain derives access from the parent project via
// `loadAccessibleProject`, which now enforces active-org coherence: a task or
// project carried over from another org (a stale URL after an org switch) is
Expand Down
Loading
Loading