Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(github): split canView / canManage in settings tab for read-only members (MUL-2413) (#2898)
Jiayuan Zhang4a487adfeb68
diff --git a/packages/core/types/github.ts b/packages/core/types/github.tsindex 4a67fd2393..b77351f693 100644--- a/packages/core/types/github.ts+++ b/packages/core/types/github.ts@@ -22,6 +22,10 @@ export interface GitHubInstallation {account_type: "User" | "Organization";account_avatar_url: string | null;created_at: string;+ /** Display name of the workspace member who connected this installation.+ * Optional because older backends and minimum-visibility deployments may+ * omit it; the UI renders the "connected by" line only when present. */+ connected_by?: string;}export interface GitHubPullRequest {diff --git a/packages/views/locales/en/settings.json b/packages/views/locales/en/settings.jsonindex fa7e766fc2..30719e7cc6 100644--- a/packages/views/locales/en/settings.json+++ b/packages/views/locales/en/settings.json@@ -191,7 +191,9 @@"disconnect_confirm_action": "Disconnect","not_configured": "GitHub integration is not configured for this deployment. Operators must set","not_configured_and": "and",- "manage_hint": "Only admins and owners can manage the GitHub connection.",+ "read_only_hint": "Read-only view. Only workspace admins and owners can connect or disconnect GitHub.",+ "contact_admin_to_connect": "GitHub is not connected for this workspace. Ask an admin or owner to set up the GitHub App.",+ "connected_by": "Connected by {{name}}","toast_not_configured": "GitHub integration is not configured for this deployment","toast_open_failed": "Failed to open GitHub install","toast_disconnect_failed": "Failed to disconnect GitHub App",diff --git a/packages/views/locales/zh-Hans/settings.json b/packages/views/locales/zh-Hans/settings.jsonindex 1309973ab6..1da6142ec9 100644--- a/packages/views/locales/zh-Hans/settings.json+++ b/packages/views/locales/zh-Hans/settings.json@@ -191,7 +191,9 @@"disconnect_confirm_action": "断开","not_configured": "当前部署没有配置 GitHub 集成。运维需要设置","not_configured_and": "和",- "manage_hint": "只有管理员和所有者可以管理 GitHub 连接。",+ "read_only_hint": "只读视图。只有管理员和所有者可以连接或断开 GitHub。",+ "contact_admin_to_connect": "当前工作区尚未连接 GitHub。请让管理员或所有者完成 GitHub App 的配置。",+ "connected_by": "由 {{name}} 连接","toast_not_configured": "当前部署未配置 GitHub 集成","toast_open_failed": "打开 GitHub 安装页失败","toast_disconnect_failed": "断开 GitHub App 失败",diff --git a/packages/views/settings/components/github-tab.test.tsx b/packages/views/settings/components/github-tab.test.tsxindex 17560aa266..d57c9e5427 100644--- a/packages/views/settings/components/github-tab.test.tsx+++ b/packages/views/settings/components/github-tab.test.tsx@@ -22,11 +22,21 @@ const workspaceRef = vi.hoisted(() => ({repos: [{ url: "https://github.com/acme/api" }] as { url: string }[],},}));+type MemberRole = "owner" | "admin" | "member" | "guest";const membersRef = vi.hoisted(() => ({- current: [{ user_id: "user-1", role: "owner" as const }],+ current: [{ user_id: "user-1", role: "owner" as MemberRole }],}));const installationsRef = vi.hoisted(() => ({- current: { installations: [] as { id: string; account_login: string }[], configured: true },+ current: {+ installations: [] as {+ id: string;+ account_login: string;+ installation_id?: number;+ connected_by?: string;+ }[],+ configured: true,+ can_manage: true as boolean,+ },}));vi.mock("@tanstack/react-query", () => ({@@ -124,7 +134,7 @@ function resetFixtures() {repos: [{ url: "https://github.com/acme/api" }],};membersRef.current = [{ user_id: "user-1", role: "owner" }];- installationsRef.current = { installations: [], configured: true };+ installationsRef.current = { installations: [], configured: true, can_manage: true };}describe("GitHubTab", () => {@@ -184,7 +194,8 @@ describe("GitHubTab", () => {const user = userEvent.setup();installationsRef.current = {configured: true,- installations: [{ id: "inst-42", account_login: "acme" }],+ can_manage: true,+ installations: [{ id: "inst-42", account_login: "acme", installation_id: 42 }],};mockDeleteInstallation.mockResolvedValue(undefined);@@ -208,12 +219,58 @@ describe("GitHubTab", () => {workspaceRef.current.settings = { github_enabled: false };installationsRef.current = {configured: true,- installations: [{ id: "inst-1", account_login: "acme" }],+ can_manage: true,+ installations: [{ id: "inst-1", account_login: "acme", installation_id: 1 }],};render(<GitHubTab />, { wrapper: I18nWrapper });expect(screen.getByRole("button", { name: /^Disconnect$/ })).toBeTruthy();});+ it("non-admin sees the existing connection but no Connect/Disconnect controls", () => {+ membersRef.current = [{ user_id: "user-1", role: "member" }];+ installationsRef.current = {+ configured: true,+ can_manage: false,+ installations: [{ id: "inst-1", account_login: "acme" }],+ };+ render(<GitHubTab />, { wrapper: I18nWrapper });++ expect(screen.getByText(/Connected to acme/i)).toBeTruthy();+ expect(screen.getByText(/Read-only view\./i)).toBeTruthy();+ expect(screen.queryByRole("button", { name: /^Connect GitHub$/ })).toBeNull();+ expect(screen.queryByRole("button", { name: /^Disconnect$/ })).toBeNull();+ });++ it("non-admin with no connection sees the contact-admin hint", () => {+ membersRef.current = [{ user_id: "user-1", role: "member" }];+ installationsRef.current = {+ configured: true,+ can_manage: false,+ installations: [],+ };+ render(<GitHubTab />, { wrapper: I18nWrapper });++ expect(screen.getByText(/Ask an admin or owner/i)).toBeTruthy();+ expect(screen.queryByRole("button", { name: /^Connect GitHub$/ })).toBeNull();+ });++ it("renders the connected_by line when the backend provides it", () => {+ installationsRef.current = {+ configured: true,+ can_manage: true,+ installations: [+ {+ id: "inst-7",+ account_login: "acme",+ installation_id: 7,+ connected_by: "Jiayuan",+ },+ ],+ };+ render(<GitHubTab />, { wrapper: I18nWrapper });+ expect(screen.getByText(/Connected by Jiayuan/)).toBeTruthy();+ });+it("repositories shortcut navigates to the repositories tab", async () => {const user = userEvent.setup();render(<GitHubTab />, { wrapper: I18nWrapper });diff --git a/packages/views/settings/components/github-tab.tsx b/packages/views/settings/components/github-tab.tsxindex f1b0dd1843..78a56a54f9 100644--- a/packages/views/settings/components/github-tab.tsx+++ b/packages/views/settings/components/github-tab.tsx@@ -48,15 +48,21 @@ export function GitHubTab() {const { data: members = [] } = useQuery(memberListOptions(wsId));const currentMember = members.find((m) => m.user_id === user?.id) ?? null;- const canManage = currentMember?.role === "owner" || currentMember?.role === "admin";+ // `canView` gates the read-only installation list (every workspace member+ // sees it after MUL-2413); `canManage` gates the Connect / Disconnect+ // actions and comes from the backend response (`can_manage`) so the+ // frontend never claims management rights the server would reject.+ const canView = !!currentMember;const { data: installationData } = useQuery({...githubInstallationsOptions(wsId),- enabled: !!wsId && canManage,+ enabled: !!wsId && canView,});const installations = installationData?.installations ?? [];const configured = installationData?.configured ?? false;+ const canManage = installationData?.can_manage === true;const connected = installations.length > 0;+ const primaryInstallation = installations[0] ?? null;const flags = deriveGitHubSettings(workspace);const [savingKey, setSavingKey] = useState<SettingsKey | null>(null);@@ -169,12 +175,21 @@ export function GitHubTab() {<div className="space-y-1"><p className="text-sm font-medium">{t(($) => $.github.connection_title)}</p>{connected ? (- <p className="text-xs text-muted-foreground">- {t(($) => $.github.connected_to, {- login: installations.map((i) => i.account_login).join(", "),- })}- </p>- ) : (+ <>+ <p className="text-xs text-muted-foreground">+ {t(($) => $.github.connected_to, {+ login: installations.map((i) => i.account_login).join(", "),+ })}+ </p>+ {primaryInstallation?.connected_by && (+ <p className="text-xs text-muted-foreground">+ {t(($) => $.github.connected_by, {+ name: primaryInstallation.connected_by!,+ })}+ </p>+ )}+ </>+ ) : canManage ? (<p className="text-xs text-muted-foreground">{t(($) => $.github.connection_description_prefix)}{" "}<code className="rounded bg-muted px-1 py-0.5 text-[10px]">@@ -183,19 +198,23 @@ export function GitHubTab() {{t(($) => $.github.connection_description_suffix)}{" "}<strong>{t(($) => $.github.connection_description_done)}</strong>.</p>+ ) : (+ <p className="text-xs text-muted-foreground">+ {t(($) => $.github.contact_admin_to_connect)}+ </p>)}</div></div>{canManage && (<div className="flex items-center gap-2">- {connected && installations[0] ? (+ {connected && primaryInstallation ? (// Disconnect must stay reachable even when the master switch// is off — disconnect is a separate intent (revoke the App// grant) from hiding the feature.<Buttonvariant="outline"size="sm"- onClick={() => setDisconnectTarget(installations[0]!.id)}+ onClick={() => setDisconnectTarget(primaryInstallation.id)}>{t(($) => $.github.disconnect)}</Button>@@ -228,9 +247,9 @@ export function GitHubTab() {</p>)}- {!canManage && (+ {!canManage && connected && (<p className="text-xs text-muted-foreground">- {t(($) => $.github.manage_hint)}+ {t(($) => $.github.read_only_hint)}</p>)}</CardContent>