fix(tasks): hide human assignee when auth is disabled (#3417)
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { Task } from "@/app/office/tasks/[id]/types";
|
||||
import { TaskProperties } from "./task-properties";
|
||||
|
||||
const mockAppState = vi.hoisted(() => ({
|
||||
auth: {
|
||||
mode: "enabled",
|
||||
authenticated: true,
|
||||
user: { id: "user-1" } as { id: string } | null,
|
||||
ssoProviders: [],
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/state-provider", () => ({
|
||||
useAppStore: (selector: (state: typeof mockAppState) => unknown) => selector(mockAppState),
|
||||
}));
|
||||
|
||||
vi.mock("./components/status-picker", () => ({ StatusPicker: () => null }));
|
||||
vi.mock("./components/priority-picker", () => ({ PriorityPicker: () => null }));
|
||||
vi.mock("./components/labels-picker", () => ({ LabelsPicker: () => null }));
|
||||
vi.mock("./components/assignee-picker", () => ({ AssigneePicker: () => null }));
|
||||
vi.mock("./components/human-assignee-picker", () => ({
|
||||
HumanAssigneePicker: () => <span data-testid="human-assignee-picker-trigger" />,
|
||||
}));
|
||||
vi.mock("./components/project-picker", () => ({ ProjectPicker: () => null }));
|
||||
vi.mock("./components/parent-picker", () => ({ ParentPicker: () => null }));
|
||||
vi.mock("./components/blockers-picker", () => ({ BlockersPicker: () => null }));
|
||||
vi.mock("./components/sub-issues-row", () => ({ SubIssuesRow: () => null }));
|
||||
vi.mock("./components/reviewers-picker", () => ({ ReviewersPicker: () => null }));
|
||||
vi.mock("./components/approvers-picker", () => ({ ApproversPicker: () => null }));
|
||||
vi.mock("./components/pending-approval-badge", () => ({ PendingApprovalBadge: () => null }));
|
||||
vi.mock("./components/quorum-status-badge", () => ({ QuorumStatusBadge: () => null }));
|
||||
|
||||
const TASK = {
|
||||
id: "task-1",
|
||||
workspaceId: "workspace-1",
|
||||
identifier: "TASK-1",
|
||||
title: "Auth gate task",
|
||||
status: "todo",
|
||||
priority: "medium",
|
||||
labels: [],
|
||||
blockedBy: [],
|
||||
blocking: [],
|
||||
children: [],
|
||||
reviewers: [],
|
||||
approvers: [],
|
||||
decisions: [],
|
||||
createdBy: "user-1",
|
||||
createdAt: "2026-09-05T12:00:00Z",
|
||||
updatedAt: "2026-09-05T12:00:00Z",
|
||||
} satisfies Task;
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
mockAppState.auth.mode = "enabled";
|
||||
mockAppState.auth.user = { id: "user-1" };
|
||||
});
|
||||
|
||||
describe("TaskProperties human assignee", () => {
|
||||
it.each(["disabled", "setup"] as const)("hides the row in %s auth mode", (mode) => {
|
||||
mockAppState.auth.mode = mode;
|
||||
mockAppState.auth.user = { id: "default-user" };
|
||||
|
||||
render(<TaskProperties task={TASK} />);
|
||||
|
||||
expect(screen.queryByText("Assigned to", { exact: true })).toBeNull();
|
||||
});
|
||||
|
||||
it("hides the row when enabled auth has no signed-in user", () => {
|
||||
mockAppState.auth.user = null;
|
||||
|
||||
render(<TaskProperties task={TASK} />);
|
||||
|
||||
expect(screen.queryByText("Assigned to", { exact: true })).toBeNull();
|
||||
});
|
||||
|
||||
it("shows the row when authentication is enabled for a signed-in user", () => {
|
||||
render(<TaskProperties task={TASK} />);
|
||||
|
||||
expect(screen.getByText("Assigned to", { exact: true })).toBeTruthy();
|
||||
expect(screen.getByTestId("human-assignee-picker-trigger")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -21,6 +21,7 @@ import { PendingApprovalBadge } from "./components/pending-approval-badge";
|
||||
import { QuorumStatusBadge } from "./components/quorum-status-badge";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useAppStore } from "@/components/state-provider";
|
||||
import { canShowHumanAssignee } from "@/lib/auth/human-assignee";
|
||||
|
||||
type TaskPropertiesProps = {
|
||||
task: Task;
|
||||
@@ -60,8 +61,8 @@ function NoneLabel() {
|
||||
// user, so the control would offer a choice that cannot mean anything.
|
||||
function HumanAssigneeRow({ task }: { task: Task }) {
|
||||
const { t } = useTranslation();
|
||||
const hasIdentity = useAppStore((s) => Boolean(s.auth.user));
|
||||
if (!hasIdentity) return null;
|
||||
const showHumanAssignee = useAppStore((s) => canShowHumanAssignee(s.auth));
|
||||
if (!showHumanAssignee) return null;
|
||||
return (
|
||||
<PropertyRow label={t("task:assignedTo")} valueClassName="ml-auto">
|
||||
<HumanAssigneePicker task={task} />
|
||||
|
||||
@@ -28,6 +28,7 @@ vi.mock("@/lib/api/domains/team-access-api", () => ({
|
||||
}));
|
||||
|
||||
import { updateTask } from "@/lib/api/domains/kanban-api";
|
||||
import { listDirectoryUsers, listWorkspaceMembers } from "@/lib/api/domains/team-access-api";
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
@@ -76,6 +77,23 @@ function renderControl(assigneeUserId?: string, authenticated = true) {
|
||||
);
|
||||
}
|
||||
|
||||
function renderControlWithDisabledSyntheticUser(assigneeUserId?: string) {
|
||||
const state = stateWith(assigneeUserId);
|
||||
state.auth.mode = "disabled";
|
||||
state.auth.user = {
|
||||
id: "default-user",
|
||||
email: "",
|
||||
display_name: "",
|
||||
role: "admin",
|
||||
status: "active",
|
||||
};
|
||||
return render(
|
||||
<StateProvider initialState={state}>
|
||||
<TaskAssigneeControl taskId="t-1" workspaceId="ws-1" />
|
||||
</StateProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("TaskAssigneeControl", () => {
|
||||
it("shows the assignee's name from the store, not a raw user id", async () => {
|
||||
renderControl("user-1");
|
||||
@@ -105,8 +123,10 @@ describe("TaskAssigneeControl", () => {
|
||||
await waitFor(() => expect(updateTask).toHaveBeenCalledWith("t-1", { assignee_user_id: "" }));
|
||||
});
|
||||
|
||||
it("renders nothing when authentication is disabled", () => {
|
||||
renderControl(undefined, false);
|
||||
it("renders nothing for the synthetic user when authentication is disabled", () => {
|
||||
renderControlWithDisabledSyntheticUser("default-user");
|
||||
expect(screen.queryByTestId(CONTROL)).toBeNull();
|
||||
expect(listDirectoryUsers).not.toHaveBeenCalled();
|
||||
expect(listWorkspaceMembers).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Combobox, type ComboboxOption } from "@/components/combobox";
|
||||
import { useAppStore } from "@/components/state-provider";
|
||||
import { useAssignablePeople } from "@/hooks/domains/users/use-assignable-people";
|
||||
import { updateTask } from "@/lib/api/domains/kanban-api";
|
||||
import { canShowHumanAssignee } from "@/lib/auth/human-assignee";
|
||||
import { initialsFor } from "@/lib/user-initials";
|
||||
|
||||
// i18n-exempt: sentinels compared with ===, never displayed.
|
||||
@@ -35,6 +36,7 @@ type Props = {
|
||||
*/
|
||||
export function TaskAssigneeControl({ taskId, workspaceId, isArchived }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const showHumanAssignee = useAppStore((s) => canShowHumanAssignee(s.auth));
|
||||
const currentUser = useAppStore((s) => s.auth.user);
|
||||
// Read from the store rather than through props: `task.updated` lands the
|
||||
// new assignee there, so another person taking the task over shows up here
|
||||
@@ -42,7 +44,7 @@ export function TaskAssigneeControl({ taskId, workspaceId, isArchived }: Props)
|
||||
const assigneeUserId = useAppStore(
|
||||
(s) => s.kanban.tasks.find((entry: { id: string }) => entry.id === taskId)?.assigneeUserId,
|
||||
);
|
||||
const enabled = Boolean(currentUser) && Boolean(taskId) && !isArchived;
|
||||
const enabled = showHumanAssignee && Boolean(taskId) && !isArchived;
|
||||
const { people, nameFor } = useAssignablePeople(workspaceId, { enabled });
|
||||
const [pending, setPending] = useState(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user