This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch custos-apps in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 8a322dfdca143bc15870dc252f4a29cd04f053ba Author: lahiruj <[email protected]> AuthorDate: Thu Nov 12 14:06:28 2026 -0500 Remove delegated apps and its views --- web/src/app/(portal)/apps/page.tsx | 27 ----- web/src/features/core/apps/api.ts | 31 +---- web/src/features/core/apps/components/AppsView.tsx | 5 - .../core/apps/components/CreateAppDialog.tsx | 57 +--------- .../core/apps/components/DeleteAppDialog.tsx | 11 +- .../core/apps/components/EditAppDialog.tsx | 2 +- web/src/features/core/apps/components/MyApps.tsx | 125 --------------------- web/src/features/core/apps/queries.ts | 21 ---- .../core/signer/__fixtures__/certificates.json | 6 +- .../signer/__tests__/CertificateDetail.test.tsx | 4 +- .../features/core/signer/__tests__/status.test.ts | 10 -- web/src/features/core/signer/api.ts | 6 - .../core/signer/components/CertificateDetail.tsx | 10 +- .../core/signer/components/MyCertificateDetail.tsx | 11 +- .../core/signer/components/MyCertificates.tsx | 17 +-- web/src/features/core/signer/queries.ts | 6 - web/src/features/core/signer/status.ts | 22 ---- web/src/mocks/handlers/apps.ts | 45 -------- web/src/shared/layout/nav.ts | 6 - web/tests/fixtures/signer-api.ts | 5 - 20 files changed, 22 insertions(+), 405 deletions(-) diff --git a/web/src/app/(portal)/apps/page.tsx b/web/src/app/(portal)/apps/page.tsx deleted file mode 100644 index 32162c3e1..000000000 --- a/web/src/app/(portal)/apps/page.tsx +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import type { Metadata } from "next"; -import { MyApps } from "@/features/core/apps/components/MyApps"; - -export const metadata: Metadata = { - title: "Apps", -}; - -export default function AppsPage() { - return <MyApps />; -} diff --git a/web/src/features/core/apps/api.ts b/web/src/features/core/apps/api.ts index 6fa9574ed..6b14da7e7 100644 --- a/web/src/features/core/apps/api.ts +++ b/web/src/features/core/apps/api.ts @@ -17,29 +17,20 @@ import { z } from "zod"; import { privilegeKeySchema } from "@/features/core/identity/schemas"; -import { - type AppAuthorizationView, - type AppMode, - zApp, - zAppAuthorizationView, - zAppWithTokenView, -} from "@/generated/core/zod.gen"; +import { zApp, zAppWithTokenView } from "@/generated/core/zod.gen"; import { apiFetch } from "@/shared/api/client"; const privilegesSchema = z.array(privilegeKeySchema).nullable(); const appSchema = zApp.extend({ privileges: privilegesSchema }); const appWithTokenSchema = zAppWithTokenView.extend({ privileges: privilegesSchema }); -export type { AppMode }; export type App = z.infer<typeof appSchema>; export type AppWithToken = z.infer<typeof appWithTokenSchema>; -export type AppAuthorization = AppAuthorizationView; export type NewApp = { key: string; name: string; description: string; - mode: AppMode; privileges: string[]; }; @@ -76,12 +67,6 @@ export async function enableApp(id: string): Promise<App> { return appSchema.parse(await apiFetch(`${appPath(id)}/enable`, { method: "POST" })); } -// How many users would lose the app if it were deleted. -export async function countAppAuthorizations(id: string): Promise<number> { - const app = z.object({ authorized_users: z.number().int() }).parse(await apiFetch(appPath(id))); - return app.authorized_users; -} - export async function deleteApp(id: string): Promise<void> { await apiFetch(appPath(id), { method: "DELETE" }); } @@ -89,17 +74,3 @@ export async function deleteApp(id: string): Promise<void> { export async function issueAppSecret(id: string): Promise<AppWithToken> { return appWithTokenSchema.parse(await apiFetch(`${appPath(id)}/secret`, { method: "POST" })); } - -const authorizationPath = (appId: string) => `/me/app-authorizations/${encodeURIComponent(appId)}`; - -export async function listAppAuthorizations(): Promise<AppAuthorization[]> { - return z.array(zAppAuthorizationView).parse(await apiFetch("/me/app-authorizations")); -} - -export async function authorizeApp(appId: string): Promise<void> { - await apiFetch(authorizationPath(appId), { method: "POST" }); -} - -export async function removeAppAuthorization(appId: string): Promise<void> { - await apiFetch(authorizationPath(appId), { method: "DELETE" }); -} diff --git a/web/src/features/core/apps/components/AppsView.tsx b/web/src/features/core/apps/components/AppsView.tsx index 487ddb06e..b0906a12b 100644 --- a/web/src/features/core/apps/components/AppsView.tsx +++ b/web/src/features/core/apps/components/AppsView.tsx @@ -67,11 +67,6 @@ export function AppsView() { header: "App key", cell: (app) => <span className="font-mono text-xs">{app.key}</span>, }, - { - key: "mode", - header: "Mode", - cell: (app) => (app.mode === "DELEGATED" ? "Delegated" : "Service"), - }, { key: "privileges", header: "Privileges", diff --git a/web/src/features/core/apps/components/CreateAppDialog.tsx b/web/src/features/core/apps/components/CreateAppDialog.tsx index dc4ed2806..f29e1f840 100644 --- a/web/src/features/core/apps/components/CreateAppDialog.tsx +++ b/web/src/features/core/apps/components/CreateAppDialog.tsx @@ -18,7 +18,6 @@ "use client"; import * as React from "react"; -import { cn } from "@/lib/utils"; import { Button } from "@/shared/ui/button"; import { Dialog, @@ -30,27 +29,12 @@ import { } from "@/shared/ui/dialog"; import { Input } from "@/shared/ui/input"; import { Label } from "@/shared/ui/label"; -import type { AppMode } from "../api"; import { useAppPrivileges, useCreateApp } from "../queries"; import { TokenReveal } from "./TokenReveal"; const APP_KEY = /^[a-z0-9]+(-[a-z0-9]+)*$/; const APP_KEY_MAX_LENGTH = 50; -const MODES: Array<{ mode: AppMode; name: string; description: string }> = [ - { - mode: "SERVICE", - name: "Service", - description: "Acts as itself with the privileges below. It never acts for a person.", - }, - { - mode: "DELEGATED", - name: "Delegated", - description: - "Acts for a person who allowed it, with what that person can do. Privileges below apply only when the person has them too.", - }, -]; - export type CreateAppDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; @@ -63,7 +47,6 @@ export function CreateAppDialog({ open, onOpenChange }: CreateAppDialogProps) { const [key, setKey] = React.useState(""); const [name, setName] = React.useState(""); const [description, setDescription] = React.useState(""); - const [mode, setMode] = React.useState<AppMode | null>(null); const [privileges, setPrivileges] = React.useState<string[]>([]); React.useEffect(() => { @@ -71,16 +54,14 @@ export function CreateAppDialog({ open, onOpenChange }: CreateAppDialogProps) { setKey(""); setName(""); setDescription(""); - setMode(null); setPrivileges([]); reset(); } }, [open, reset]); const keyIsValid = APP_KEY.test(key) && key.length <= APP_KEY_MAX_LENGTH; - const needsPrivilege = mode === "SERVICE" && privileges.length === 0; const canSubmit = - keyIsValid && name.trim() !== "" && mode !== null && !needsPrivilege && !create.isPending; + keyIsValid && name.trim() !== "" && privileges.length > 0 && !create.isPending; const result = create.data; function togglePrivilege(privilege: string, checked: boolean) { @@ -116,8 +97,7 @@ export function CreateAppDialog({ open, onOpenChange }: CreateAppDialogProps) { className="space-y-4" onSubmit={(e) => { e.preventDefault(); - if (canSubmit && mode) - create.mutate({ key, name: name.trim(), description, mode, privileges }); + if (canSubmit) create.mutate({ key, name: name.trim(), description, privileges }); }} > <div className="space-y-2"> @@ -146,41 +126,10 @@ export function CreateAppDialog({ open, onOpenChange }: CreateAppDialogProps) { onChange={(e) => setDescription(e.target.value)} /> </div> - <fieldset className="space-y-2"> - <legend className="text-sm font-medium">Mode</legend> - <p className="text-xs text-muted-foreground">It cannot be changed later.</p> - <div className="grid gap-2 sm:grid-cols-2"> - {MODES.map((option) => ( - <label - key={option.mode} - className={cn( - "cursor-pointer rounded-md border p-3 transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring", - mode === option.mode - ? "border-[color:var(--brand)] bg-[color:var(--brand-tint)]/40" - : "hover:bg-muted", - )} - > - <input - type="radio" - name="app-mode" - checked={mode === option.mode} - onChange={() => setMode(option.mode)} - className="sr-only" - /> - <span className="block text-sm font-medium">{option.name}</span> - <span className="block text-xs text-muted-foreground"> - {option.description} - </span> - </label> - ))} - </div> - </fieldset> <fieldset className="space-y-2"> <legend className="text-sm font-medium">Privileges</legend> <p className="text-xs text-muted-foreground"> - {mode === "DELEGATED" - ? "Optional. The app can always use the person's own pages, like SSH access." - : "Only privileges allowed for apps are listed. A service app needs at least one."} + Only privileges allowed for apps are listed. An app needs at least one. </p> {allowedPrivileges.data?.length === 0 ? ( <p className="text-sm text-muted-foreground"> diff --git a/web/src/features/core/apps/components/DeleteAppDialog.tsx b/web/src/features/core/apps/components/DeleteAppDialog.tsx index 5cffca659..daf9c495d 100644 --- a/web/src/features/core/apps/components/DeleteAppDialog.tsx +++ b/web/src/features/core/apps/components/DeleteAppDialog.tsx @@ -19,7 +19,7 @@ import { ConfirmDialog } from "@/shared/ui/ConfirmDialog"; import type { App } from "../api"; -import { useAppAuthorizationCount, useDeleteApp } from "../queries"; +import { useDeleteApp } from "../queries"; export type DeleteAppDialogProps = { app: App; @@ -27,9 +27,7 @@ export type DeleteAppDialogProps = { }; export function DeleteAppDialog({ app, onClose }: DeleteAppDialogProps) { - const count = useAppAuthorizationCount(app.id); const remove = useDeleteApp(); - const people = count.data ?? 0; return ( <ConfirmDialog @@ -39,13 +37,10 @@ export function DeleteAppDialog({ app, onClose }: DeleteAppDialogProps) { }} title={`Delete ${app.name}?`} confirmLabel="Delete app" - pending={remove.isPending || count.isLoading} - error={remove.error ?? count.error} + pending={remove.isPending} + error={remove.error} onConfirm={() => remove.mutate(app.id, { onSuccess: onClose })} > - {people > 0 - ? `${people} ${people === 1 ? "person has" : "people have"} allowed this app. They all lose it, and the app can't act for them again. ` - : null} This can't be undone. The app key {app.key} can't be used again. </ConfirmDialog> ); diff --git a/web/src/features/core/apps/components/EditAppDialog.tsx b/web/src/features/core/apps/components/EditAppDialog.tsx index 0d774d3dc..24a886107 100644 --- a/web/src/features/core/apps/components/EditAppDialog.tsx +++ b/web/src/features/core/apps/components/EditAppDialog.tsx @@ -54,7 +54,7 @@ export function EditAppDialog({ app, onClose }: EditAppDialogProps) { <DialogHeader> <DialogTitle>Edit {app.name}</DialogTitle> <DialogDescription> - The app key, mode and privileges cannot be changed. The token keeps working. + The app key and privileges cannot be changed. The token keeps working. </DialogDescription> </DialogHeader> <form diff --git a/web/src/features/core/apps/components/MyApps.tsx b/web/src/features/core/apps/components/MyApps.tsx deleted file mode 100644 index 2a6773811..000000000 --- a/web/src/features/core/apps/components/MyApps.tsx +++ /dev/null @@ -1,125 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -"use client"; - -import * as React from "react"; -import { toast } from "sonner"; -import { Button } from "@/shared/ui/button"; -import { ConfirmDialog } from "@/shared/ui/ConfirmDialog"; -import { DataTable, type DataTableColumn } from "@/shared/ui/DataTable"; -import { EmptyState } from "@/shared/ui/EmptyState"; -import { ErrorState } from "@/shared/ui/ErrorState"; -import { CardSkeleton } from "@/shared/ui/Loading"; -import { StatusBadge } from "@/shared/ui/StatusBadge"; -import type { AppAuthorization } from "../api"; -import { useAppAuthorizations, useAuthorizeApp, useRemoveAppAuthorization } from "../queries"; - -export function MyApps() { - const apps = useAppAuthorizations(); - const authorize = useAuthorizeApp(); - const remove = useRemoveAppAuthorization(); - const [removing, setRemoving] = React.useState<AppAuthorization | null>(null); - - const columns: Array<DataTableColumn<AppAuthorization>> = [ - { - key: "name", - header: "App", - cell: (app) => ( - <div> - <div className="font-medium">{app.name}</div> - {app.description ? ( - <div className="text-xs text-muted-foreground">{app.description}</div> - ) : null} - </div> - ), - }, - { - key: "status", - header: "Status", - cell: (app) => - app.authorized ? ( - <StatusBadge variant="active" label="Allowed" /> - ) : ( - <StatusBadge variant="inactive" label="Not allowed" /> - ), - }, - { - key: "manage", - header: "", - cell: (app) => ( - <div className="flex justify-end"> - {app.authorized ? ( - <Button size="sm" variant="outline" onClick={() => setRemoving(app)}> - Remove - </Button> - ) : ( - <Button - size="sm" - disabled={authorize.isPending} - onClick={() => - authorize.mutate(app.id, { onError: (error) => toast.error(error.message) }) - } - > - Allow - </Button> - )} - </div> - ), - }, - ]; - - return ( - <div className="space-y-6"> - <div> - <h1 className="font-display text-[28px] font-bold leading-tight">Apps</h1> - <p className="mt-1 text-sm text-muted-foreground"> - Apps you allow can act as you in Custos, for example to get SSH certificates. - </p> - </div> - - {apps.isLoading ? ( - <CardSkeleton /> - ) : apps.error ? ( - <ErrorState message={apps.error.message} onRetry={() => apps.refetch()} /> - ) : apps.data?.length === 0 ? ( - <EmptyState - heading="No apps can act for you yet." - description="Apps that can appear here once an admin adds them." - /> - ) : ( - <DataTable columns={columns} rows={apps.data ?? []} rowKey={(app) => app.id} /> - )} - - <ConfirmDialog - open={removing !== null} - onOpenChange={(open) => { - if (!open) setRemoving(null); - }} - title={`Remove ${removing?.name ?? "app"}?`} - confirmLabel="Remove" - pending={remove.isPending} - error={remove.error} - onConfirm={() => { - if (removing) remove.mutate(removing.id, { onSuccess: () => setRemoving(null) }); - }} - > - It can no longer act for you. Certificates it already generated are not revoked. - </ConfirmDialog> - </div> - ); -} diff --git a/web/src/features/core/apps/queries.ts b/web/src/features/core/apps/queries.ts index 31c63bf2d..0035eee27 100644 --- a/web/src/features/core/apps/queries.ts +++ b/web/src/features/core/apps/queries.ts @@ -19,34 +19,21 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { - authorizeApp, - countAppAuthorizations, createApp, deleteApp, disableApp, enableApp, issueAppSecret, - listAppAuthorizations, listAppPrivileges, listApps, - removeAppAuthorization, updateApp, } from "./api"; const appKeys = { list: ["apps", "list"] as const, privileges: ["apps", "privileges"] as const, - authorizations: ["apps", "authorizations"] as const, }; -export function useAppAuthorizations() { - return useQuery({ queryKey: appKeys.authorizations, queryFn: listAppAuthorizations }); -} - -export const useAuthorizeApp = () => useAppMutation(authorizeApp, appKeys.authorizations); -export const useRemoveAppAuthorization = () => - useAppMutation(removeAppAuthorization, appKeys.authorizations); - export function useApps() { return useQuery({ queryKey: appKeys.list, queryFn: listApps }); } @@ -55,14 +42,6 @@ export function useAppPrivileges() { return useQuery({ queryKey: appKeys.privileges, queryFn: listAppPrivileges }); } -export function useAppAuthorizationCount(id: string | undefined) { - return useQuery({ - queryKey: ["apps", "authorization-count", id], - queryFn: () => countAppAuthorizations(id ?? ""), - enabled: id !== undefined, - }); -} - function useAppMutation<Input, Output>( mutationFn: (input: Input) => Promise<Output>, queryKey: readonly string[] = appKeys.list, diff --git a/web/src/features/core/signer/__fixtures__/certificates.json b/web/src/features/core/signer/__fixtures__/certificates.json index c674cb4fb..9c20db0c9 100644 --- a/web/src/features/core/signer/__fixtures__/certificates.json +++ b/web/src/features/core/signer/__fixtures__/certificates.json @@ -1,6 +1,6 @@ [ { - "requested_by": "app/airavata", + "requested_by": "user/researcher", "user_email": "[email protected]", "user_sub": "sub-researcher", "serial_number": 42, @@ -16,7 +16,7 @@ "revoked": false }, { - "requested_by": "app/airavata", + "requested_by": "user/researcher", "user_email": "[email protected]", "user_sub": "sub-researcher", "serial_number": 43, @@ -32,7 +32,7 @@ "revoked": false }, { - "requested_by": "app/airavata", + "requested_by": "user/researcher", "user_email": "[email protected]", "user_sub": "sub-researcher", "serial_number": 44, diff --git a/web/src/features/core/signer/__tests__/CertificateDetail.test.tsx b/web/src/features/core/signer/__tests__/CertificateDetail.test.tsx index 35b6fb420..ba4b56149 100644 --- a/web/src/features/core/signer/__tests__/CertificateDetail.test.tsx +++ b/web/src/features/core/signer/__tests__/CertificateDetail.test.tsx @@ -48,7 +48,6 @@ vi.mock("@/shared/casl/AbilityProvider", () => ({ vi.mock("sonner", () => ({ toast: { success: state.toastSuccess } })); vi.mock("../queries", () => ({ - useAppNames: () => ({}), useCertificate: () => state.query, useRevokeCertificate: () => ({ mutate: state.mutate, isPending: state.isPending }), useUserEmail: (id: string | null) => (id === "admin-id" ? "[email protected]" : undefined), @@ -85,11 +84,10 @@ describe("<CertificateDetail />", () => { "sub-admin", "permit-pty, permit-user-rc", "/usr/bin/id", + "[email protected]", ]) { expect(screen.getByText(value)).toBeInTheDocument(); } - // Generated by and User email both show the owner's email. - expect(screen.getAllByText("[email protected]")).toHaveLength(2); }); it("renders a loading skeleton", () => { diff --git a/web/src/features/core/signer/__tests__/status.test.ts b/web/src/features/core/signer/__tests__/status.test.ts index b3646e9b4..f438a99f6 100644 --- a/web/src/features/core/signer/__tests__/status.test.ts +++ b/web/src/features/core/signer/__tests__/status.test.ts @@ -19,7 +19,6 @@ import { describe, expect, it } from "vitest"; import type { Certificate } from "../schemas"; import { formatCertificateLifetime, - generatedBy, getCertificateStatus, statusBadgeVariantFromCertificateStatus, } from "../status"; @@ -41,15 +40,6 @@ const base: Certificate = { const now = new Date(1_700_043_200 * 1000); // midway through the validity window -describe("generatedBy", () => { - // Make sure a certificate shows the app's name, and the person's own label when they generated it. - it("names the app that asked for the certificate", () => { - const fromApp = { ...base, requested_by: "app/notebook-hub" }; - expect(generatedBy(fromApp, { "notebook-hub": "Notebook Hub" }, "You")).toBe("Notebook Hub"); - expect(generatedBy(base, { "notebook-hub": "Notebook Hub" }, "You")).toBe("You"); - }); -}); - describe("getCertificateStatus", () => { it("returns revoked when revoked, regardless of validity", () => { expect(getCertificateStatus({ ...base, revoked: true }, now)).toBe("revoked"); diff --git a/web/src/features/core/signer/api.ts b/web/src/features/core/signer/api.ts index 3b1d58b98..f3f608339 100644 --- a/web/src/features/core/signer/api.ts +++ b/web/src/features/core/signer/api.ts @@ -16,7 +16,6 @@ // under the License. import { z } from "zod"; -import { zAppNameView } from "@/generated/core/zod.gen"; import { apiFetch } from "@/shared/api/client"; import { type Certificate, @@ -30,11 +29,6 @@ import { } from "./schemas"; import type { CertificateListParams } from "./types"; -export async function listAppNames(): Promise<Record<string, string>> { - const apps = z.array(zAppNameView).parse(await apiFetch("/apps/names")); - return Object.fromEntries(apps.map((app) => [app.key, app.name])); -} - export async function getUserEmail(id: string): Promise<string> { const user = z .object({ email: z.string() }) diff --git a/web/src/features/core/signer/components/CertificateDetail.tsx b/web/src/features/core/signer/components/CertificateDetail.tsx index df4bb0a52..7645846f9 100644 --- a/web/src/features/core/signer/components/CertificateDetail.tsx +++ b/web/src/features/core/signer/components/CertificateDetail.tsx @@ -26,15 +26,13 @@ import { Button } from "@/shared/ui/button"; import { ErrorState } from "@/shared/ui/ErrorState"; import { CardSkeleton } from "@/shared/ui/Loading"; import { MetaItem, MetaRow } from "@/shared/ui/MetaRow"; -import { useAppNames, useCertificate, useRevokeCertificate, useUserEmail } from "../queries"; +import { useCertificate, useRevokeCertificate, useUserEmail } from "../queries"; import type { Certificate } from "../schemas"; import { - actorLabel, CERTIFICATE_STATUS_LABELS, type CertificateStatus, formatCertificateLifetime, formatUnixSeconds, - generatedBy, getCertificateStatus, userIdOf, } from "../status"; @@ -137,11 +135,9 @@ export function CertificateDetail({ serial }: CertificateDetailProps) { } function CertificateMetadata({ cert }: { cert: Certificate }) { - const appNames = useAppNames(); const revokerId = userIdOf(cert.revoked_by); const revokerEmail = useUserEmail(revokerId); const items: Array<{ label: string; value: React.ReactNode }> = [ - { label: "Generated by", value: generatedBy(cert, appNames, cert.user_email) }, { label: "User email", value: cert.user_email || "—" }, { label: "Subject", value: <span className="break-all font-mono text-xs">{cert.user_sub}</span> }, { label: "Serial number", value: <span className="font-mono">{cert.serial_number}</span> }, @@ -175,9 +171,7 @@ function CertificateMetadata({ cert }: { cert: Certificate }) { { label: "Revocation reason", value: cert.revocation_reason || "—" }, { label: "Revoked by", - value: cert.revoked_by - ? actorLabel(cert.revoked_by, appNames, (id) => revokerEmail ?? id) - : "—", + value: revokerEmail ?? cert.revoked_by ?? "—", }, ); } diff --git a/web/src/features/core/signer/components/MyCertificateDetail.tsx b/web/src/features/core/signer/components/MyCertificateDetail.tsx index f8b8ea56f..05278182a 100644 --- a/web/src/features/core/signer/components/MyCertificateDetail.tsx +++ b/web/src/features/core/signer/components/MyCertificateDetail.tsx @@ -25,15 +25,14 @@ import { Button } from "@/shared/ui/button"; import { ErrorState } from "@/shared/ui/ErrorState"; import { CardSkeleton } from "@/shared/ui/Loading"; import { StatusBadge } from "@/shared/ui/StatusBadge"; -import { useAppNames, useMyCertificate, useRevokeMyCertificate } from "../queries"; +import { useMyCertificate, useRevokeMyCertificate } from "../queries"; import { - actorLabel, CERTIFICATE_STATUS_LABELS, formatCertificateLifetime, formatUnixSeconds, - generatedBy, getCertificateStatus, statusBadgeVariantFromCertificateStatus, + userIdOf, } from "../status"; import { revokeErrorMessage } from "./CertificateDetail"; import { loadErrorMessage } from "./MyCertificates"; @@ -41,7 +40,6 @@ import { RevokeCertificateDialog } from "./RevokeCertificateDialog"; export function MyCertificateDetail({ serial }: { serial: string }) { const query = useMyCertificate(serial); - const appNames = useAppNames(); const { user } = useCurrentUser(); const revoke = useRevokeMyCertificate(); const [dialogOpen, setDialogOpen] = React.useState(false); @@ -61,7 +59,6 @@ export function MyCertificateDetail({ serial }: { serial: string }) { const items: Array<[string, React.ReactNode]> = [ ["Logs in as", <span key="principal" className="font-mono">{cert.principal}</span>], ["Issued to", cert.user_email], - ["Generated by", generatedBy(cert, appNames, "You")], ["Key ID", <span key="key-id" className="break-all font-mono text-xs">{cert.key_id}</span>], ["Key fingerprint", <span key="fingerprint" className="break-all font-mono text-xs">{cert.public_key_fingerprint}</span>], ["Issued", formatUnixSeconds(cert.issued_at)], @@ -101,9 +98,7 @@ export function MyCertificateDetail({ serial }: { serial: string }) { <div className="rounded-md border border-[color:var(--custos-red-700)] p-3 text-sm"> <p className="font-medium"> Revoked {cert.revoked_at != null ? formatUnixSeconds(cert.revoked_at) : ""} by{" "} - {actorLabel(cert.revoked_by ?? "", appNames, (id) => - id === user?.id ? "you" : "your site", - )} + {userIdOf(cert.revoked_by) === user?.id ? "you" : "your site"} </p> <p>{cert.revocation_reason ? `Reason: ${cert.revocation_reason}` : "No reason given."}</p> <p className="text-muted-foreground"> diff --git a/web/src/features/core/signer/components/MyCertificates.tsx b/web/src/features/core/signer/components/MyCertificates.tsx index 714944b42..e1b5f4e73 100644 --- a/web/src/features/core/signer/components/MyCertificates.tsx +++ b/web/src/features/core/signer/components/MyCertificates.tsx @@ -27,13 +27,12 @@ import { EmptyState } from "@/shared/ui/EmptyState"; import { ErrorState } from "@/shared/ui/ErrorState"; import { TableSkeleton } from "@/shared/ui/Loading"; import { StatusBadge } from "@/shared/ui/StatusBadge"; -import { useAppNames, useCursorPaging, useMyCertificates, useRevokeMyCertificate } from "../queries"; +import { useCursorPaging, useMyCertificates, useRevokeMyCertificate } from "../queries"; import type { Certificate } from "../schemas"; import { CERTIFICATE_STATUS_LABELS, type CertificateStatus, formatUnixSeconds, - generatedBy, getCertificateStatus, statusBadgeVariantFromCertificateStatus, } from "../status"; @@ -50,7 +49,6 @@ export function loadErrorMessage(error: unknown): string { export function MyCertificates() { const { params, paging } = useCursorPaging(); const query = useMyCertificates(params); - const appNames = useAppNames(); const revoke = useRevokeMyCertificate(); const [generateOpen, setGenerateOpen] = React.useState(false); const [statusFilter, setStatusFilter] = React.useState<CertificateStatus | "all">("all"); @@ -64,19 +62,14 @@ export function MyCertificates() { const columns: Array<DataTableColumn<Certificate>> = [ { - key: "generatedBy", - header: "Generated by", + key: "issued", + header: "Issued", cell: (row) => ( - <Link href={`/ssh-access/${row.serial_number}`} className="font-medium hover:underline"> - {generatedBy(row, appNames, "You")} + <Link href={`/ssh-access/${row.serial_number}`} className="text-sm font-medium hover:underline"> + {formatUnixSeconds(row.issued_at)} </Link> ), }, - { - key: "issued", - header: "Issued", - cell: (row) => <span className="text-sm">{formatUnixSeconds(row.issued_at)}</span>, - }, { key: "validBefore", header: "Valid until", diff --git a/web/src/features/core/signer/queries.ts b/web/src/features/core/signer/queries.ts index 4e2d909e2..e91306744 100644 --- a/web/src/features/core/signer/queries.ts +++ b/web/src/features/core/signer/queries.ts @@ -24,7 +24,6 @@ import { getCertificate, getMyCertificate, getUserEmail, - listAppNames, listCertificates, listMyCertificates, revokeCertificate, @@ -40,11 +39,6 @@ export const signerKeys = { myDetail: (serial: number | string) => [...signerKeys.all, "me", "detail", String(serial)] as const, }; -export function useAppNames(): Record<string, string> { - const query = useQuery({ queryKey: ["app-names"], queryFn: listAppNames, staleTime: 300_000 }); - return query.data ?? {}; -} - export function useUserEmail(id: string | null): string | undefined { const query = useQuery({ queryKey: ["user-email", id], diff --git a/web/src/features/core/signer/status.ts b/web/src/features/core/signer/status.ts index 988252436..3b9350103 100644 --- a/web/src/features/core/signer/status.ts +++ b/web/src/features/core/signer/status.ts @@ -20,32 +20,10 @@ import type { Certificate } from "./schemas"; export type CertificateStatus = "active" | "not-yet-valid" | "expired" | "revoked"; -// requested_by and revoked_by are "user/<id>" or "app/<key>". -export function actorLabel( - actor: string, - appNames: Record<string, string>, - userLabel: (userId: string) => string, -): string { - if (actor.startsWith("app/")) { - const key = actor.slice("app/".length); - return appNames[key] ?? key; - } - return userLabel(actor.replace(/^user\//, "")); -} - export function userIdOf(actor: string | undefined): string | null { return actor?.startsWith("user/") ? actor.slice("user/".length) : null; } -// Only the owner generates for themselves, so a user here is always the owner. -export function generatedBy( - cert: Certificate, - appNames: Record<string, string>, - ownerLabel: string, -): string { - return actorLabel(cert.requested_by, appNames, () => ownerLabel); -} - export const CERTIFICATE_STATUS_LABELS: Record<CertificateStatus, string> = { active: "Active", "not-yet-valid": "Not yet valid", diff --git a/web/src/mocks/handlers/apps.ts b/web/src/mocks/handlers/apps.ts index 2e8d5ec25..f90487c4d 100644 --- a/web/src/mocks/handlers/apps.ts +++ b/web/src/mocks/handlers/apps.ts @@ -26,7 +26,6 @@ const apps: App[] = [ key: "notebook-hub", name: "Notebook Hub", description: "Creates workshop accounts.", - mode: "SERVICE", privileges: ["temp-account:users:create"], status: "ACTIVE", secret_hint: "9F3A", @@ -34,19 +33,6 @@ const apps: App[] = [ created_at: "2026-11-01T12:00:00Z", updated_at: "2026-11-01T12:00:00Z", }, - { - id: "app-2", - key: "science-gateway", - name: "Science Gateway", - description: "Gets SSH certificates for its users.", - mode: "DELEGATED", - privileges: [], - status: "ACTIVE", - secret_hint: "7C21", - created_by: "user-admin", - created_at: "2026-11-02T12:00:00Z", - updated_at: "2026-11-02T12:00:00Z", - }, ]; function setStatus(id: unknown, status: App["status"]) { @@ -56,39 +42,9 @@ function setStatus(id: unknown, status: App["status"]) { return HttpResponse.json(app); } -const allowed = new Set<string>(); - export const appsHandlers = [ - http.get("*/api/v1/me/app-authorizations", () => - HttpResponse.json( - apps - .filter((a) => a.status === "ACTIVE" && a.mode === "DELEGATED") - .map(({ id, name, description }) => ({ - id, - name, - description, - authorized: allowed.has(id), - })), - ), - ), - http.post("*/api/v1/me/app-authorizations/:appId", ({ params: { appId } }) => { - allowed.add(String(appId)); - return new HttpResponse(null, { status: 204 }); - }), - http.delete("*/api/v1/me/app-authorizations/:appId", ({ params: { appId } }) => { - allowed.delete(String(appId)); - return new HttpResponse(null, { status: 204 }); - }), http.get("*/api/v1/apps", () => HttpResponse.json(apps.filter((a) => a.status !== "DELETED"))), http.get("*/api/v1/apps/privileges", () => HttpResponse.json(appPrivileges)), - http.get("*/api/v1/apps/names", () => - HttpResponse.json(apps.map(({ key, name }) => ({ key, name }))), - ), - http.get("*/api/v1/apps/:id", ({ params: { id } }) => { - const app = apps.find((a) => a.id === id && a.status !== "DELETED"); - if (!app) return HttpResponse.json({ error: "not found" }, { status: 404 }); - return HttpResponse.json({ ...app, authorized_users: allowed.has(app.id) ? 1 : 0 }); - }), http.delete("*/api/v1/apps/:id", ({ params: { id } }) => { const app = apps.find((a) => a.id === id && a.status !== "DELETED"); if (!app) return HttpResponse.json({ error: "not found" }, { status: 404 }); @@ -96,7 +52,6 @@ export const appsHandlers = [ return HttpResponse.json({ error: "disable the app before deleting it" }, { status: 409 }); } app.status = "DELETED"; - allowed.delete(app.id); return new HttpResponse(null, { status: 204 }); }), http.put("*/api/v1/apps/:id", async ({ params: { id }, request }) => { diff --git a/web/src/shared/layout/nav.ts b/web/src/shared/layout/nav.ts index 0a1a61a8c..d0782cc8e 100644 --- a/web/src/shared/layout/nav.ts +++ b/web/src/shared/layout/nav.ts @@ -88,12 +88,6 @@ export const portalNav: NavItem[] = [ icon: SquareTerminal, group: "access", }, - { - href: "/apps", - label: "Apps", - icon: Blocks, - group: "access", - }, { href: "/admin/users", label: "Users & Permissions", diff --git a/web/tests/fixtures/signer-api.ts b/web/tests/fixtures/signer-api.ts index 4dfe36d77..9d21bef29 100644 --- a/web/tests/fixtures/signer-api.ts +++ b/web/tests/fixtures/signer-api.ts @@ -80,11 +80,6 @@ async function installSignerRoutes(context: BrowserContext) { return; } - if (request.method() === "GET" && url.pathname === "/api/v1/apps/names") { - await json(route, []); - return; - } - if (url.pathname === "/api/v1/connectors/signer/me/certificates") { if (request.method() === "GET") { await json(route, { certificates, limit: certificates.length });
