You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2026/07/22 06:51:43 UTC
(airavata-custos) 06/29: Add access request surface for unlinked users
This is an automated email from the ASF dual-hosted git repository.
lahirujayathilake pushed a commit to branch pearc26
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit c26f8c94dd66f3fd4a1a5ecf9f14c14b128a5cf5
Author: lahiruj <la...@gmail.com>
AuthorDate: Thu Jul 16 01:45:45 2026 -0400
Add access request surface for unlinked users
---
.../app/(portal)/admin/access-requests/page.tsx | 36 ++++
web/src/app/no-access/NoAccessBody.tsx | 216 +++++++++++++++++++--
.../app/no-access/__tests__/NoAccessBody.test.tsx | 158 +++++++++++++++
.../core/access-requests/PendingCountBadge.tsx | 33 ++++
web/src/features/core/access-requests/api.ts | 93 +++++++++
web/src/features/core/access-requests/queries.ts | 92 +++++++++
web/src/features/core/access-requests/schemas.ts | 60 ++++++
web/src/generated/core/index.ts | 4 +-
web/src/generated/core/sdk.gen.ts | 75 +++++--
web/src/generated/core/types.gen.ts | 208 +++++++++++++++++++-
web/src/generated/core/zod.gen.ts | 102 +++++++++-
web/src/mocks/handlers.ts | 2 +
web/src/mocks/handlers/access-requests.ts | 149 ++++++++++++++
web/src/shared/casl/abilities.ts | 2 +
web/src/shared/layout/Sidebar.tsx | 2 +
web/src/shared/layout/nav.ts | 12 ++
web/src/shared/users-admin/roles-catalog.ts | 4 +-
17 files changed, 1201 insertions(+), 47 deletions(-)
diff --git a/web/src/app/(portal)/admin/access-requests/page.tsx b/web/src/app/(portal)/admin/access-requests/page.tsx
new file mode 100644
index 000000000..4be4e6d63
--- /dev/null
+++ b/web/src/app/(portal)/admin/access-requests/page.tsx
@@ -0,0 +1,36 @@
+// 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 { EmptyState } from "@/shared/ui/EmptyState";
+
+export const metadata: Metadata = {
+ title: "Access Requests — Admin",
+};
+
+// Placeholder: the queue lands in the next phase on this branch.
+export default function AdminAccessRequestsPage() {
+ return (
+ <div className="flex flex-col gap-6">
+ <h1 className="font-display text-[28px] font-bold leading-tight">Access Requests</h1>
+ <EmptyState
+ heading="Review queue coming in this branch"
+ description="Pending trial-access requests will be listed here for approval."
+ />
+ </div>
+ );
+}
diff --git a/web/src/app/no-access/NoAccessBody.tsx b/web/src/app/no-access/NoAccessBody.tsx
index 495e21eaa..79f3b95ca 100644
--- a/web/src/app/no-access/NoAccessBody.tsx
+++ b/web/src/app/no-access/NoAccessBody.tsx
@@ -17,31 +17,79 @@
"use client";
+import { useQueryClient } from "@tanstack/react-query";
+import { useSession } from "next-auth/react";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
+import { useState } from "react";
+import {
+ accessRequestKeys,
+ useAccessEvent,
+ useCreateAccessRequest,
+ useMyAccessRequest,
+} from "@/features/core/access-requests/queries";
+import type { AccessRequest } from "@/features/core/access-requests/schemas";
+import { ApiError } from "@/shared/api/client";
+import { useDebounce } from "@/shared/hooks/useDebounce";
+import { Button } from "@/shared/ui/button";
+import { Input } from "@/shared/ui/input";
+import { Label } from "@/shared/ui/label";
-const COPY: Record<string, { heading: string; body: string }> = {
- identity_not_linked: {
- heading: "No portal access",
- body: "Your identity isn't linked to a portal user. Ask an administrator to link your account.",
- },
-};
-
-const DEFAULT_COPY = {
- heading: "No portal access",
- body: "Your account has no privileges yet. Ask an administrator to grant you a role.",
-};
+function formatDate(iso: string): string {
+ return new Date(iso).toLocaleDateString(undefined, {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ });
+}
+// Four requester states driven by GET /access-requests/me:
+// no request yet → entry, then the form; PENDING → received; DENIED →
+// declined with re-request. APPROVED shows a re-sign-in hint because the
+// session's privileges are minted at sign-in.
export function NoAccessBody() {
- const params = useSearchParams();
- const reason = params.get("reason");
- const { heading, body } = (reason && COPY[reason]) || DEFAULT_COPY;
+ const { data: request, isLoading, error } = useMyAccessRequest();
+ const [formOpen, setFormOpen] = useState(false);
+
+ let content: React.ReactNode;
+ if (isLoading) {
+ content = <p className="text-sm text-muted-foreground">Loading…</p>;
+ } else if (error) {
+ content = (
+ <Card heading="No portal access">
+ Your account has no privileges yet. Ask an administrator to grant you a role.
+ </Card>
+ );
+ } else if (request?.status === "PENDING") {
+ content = <PendingCard request={request} />;
+ } else if (request?.status === "APPROVED") {
+ content = (
+ <Card heading="Request approved">
+ Your trial access is ready. Sign out and sign back in to enter the portal.
+ </Card>
+ );
+ } else if (request?.status === "DENIED" && !formOpen) {
+ content = <DeclinedCard request={request} onReapply={() => setFormOpen(true)} />;
+ } else if (formOpen) {
+ content = <RequestForm />;
+ } else {
+ content = (
+ <Card heading="No portal access">
+ <span className="block">
+ Your identity isn't linked to a portal user yet. If you are attending a supported
+ event, you can request temporary trial access with your event code.
+ </span>
+ <Button variant="brand" className="mt-4" onClick={() => setFormOpen(true)}>
+ Request trial access
+ </Button>
+ </Card>
+ );
+ }
return (
<div className="flex min-h-screen items-center justify-center bg-muted px-6 py-12">
<div className="w-full max-w-md rounded-2xl border border-border bg-card p-8 shadow-sm">
- <h1 className="text-xl font-semibold tracking-tight">{heading}</h1>
- <p className="mt-2 text-sm text-muted-foreground">{body}</p>
+ {content}
<Link href="/sign-in" className="mt-6 inline-block text-sm font-medium text-brand">
Sign in as a different user
</Link>
@@ -49,3 +97,139 @@ export function NoAccessBody() {
</div>
);
}
+
+function Card({ heading, children }: { heading: string; children: React.ReactNode }) {
+ return (
+ <div>
+ <h1 className="text-xl font-semibold tracking-tight">{heading}</h1>
+ <div className="mt-2 text-sm text-muted-foreground">{children}</div>
+ </div>
+ );
+}
+
+function PendingCard({ request }: { request: AccessRequest }) {
+ const { data: event } = useAccessEvent(request.event_code);
+ return (
+ <Card heading="Request received">
+ Your request for {event?.name ?? request.event_code} is waiting for review. Submitted{" "}
+ {formatDate(request.timestamp)}.
+ </Card>
+ );
+}
+
+function DeclinedCard({ request, onReapply }: { request: AccessRequest; onReapply: () => void }) {
+ return (
+ <Card heading="Request declined">
+ <span className="block">Your access request was declined.</span>
+ {request.deny_reason ? (
+ <span className="mt-2 block rounded-md bg-muted px-3 py-2 text-foreground">
+ {request.deny_reason}
+ </span>
+ ) : null}
+ <Button variant="brand" className="mt-4" onClick={onReapply}>
+ Submit a new request
+ </Button>
+ </Card>
+ );
+}
+
+function RequestForm() {
+ const { data: session } = useSession();
+ const params = useSearchParams();
+ const queryClient = useQueryClient();
+ const create = useCreateAccessRequest();
+
+ const [institution, setInstitution] = useState("");
+ const [code, setCode] = useState(params.get("event") ?? "");
+ const [reason, setReason] = useState("");
+
+ const trimmedCode = code.trim();
+ const debouncedCode = useDebounce(trimmedCode, 400);
+ const eventQuery = useAccessEvent(debouncedCode);
+ const settled = debouncedCode === trimmedCode && trimmedCode.length > 0 && !eventQuery.isFetching;
+ const resolved = settled ? (eventQuery.data ?? null) : null;
+ const unknownCode = settled && eventQuery.data === null;
+
+ const canSubmit = institution.trim().length > 0 && Boolean(resolved) && !create.isPending;
+
+ function handleSubmit(e: React.FormEvent) {
+ e.preventDefault();
+ if (!canSubmit) return;
+ create.mutate(
+ {
+ institution: institution.trim(),
+ event_code: trimmedCode,
+ reason: reason.trim() || undefined,
+ },
+ {
+ onError: (err) => {
+ // A pending request already exists; refetch /me to show it.
+ if (err instanceof ApiError && err.status === 409) {
+ void queryClient.invalidateQueries({ queryKey: accessRequestKeys.mine() });
+ }
+ },
+ },
+ );
+ }
+
+ const submitError =
+ create.error && !(create.error instanceof ApiError && create.error.status === 409)
+ ? create.error.message
+ : null;
+
+ return (
+ <form onSubmit={handleSubmit} noValidate>
+ <h1 className="text-xl font-semibold tracking-tight">Request trial access</h1>
+ <div className="mt-4 flex flex-col gap-3">
+ <div className="flex flex-col gap-1.5">
+ <Label htmlFor="ar-name">Name</Label>
+ <Input id="ar-name" value={session?.user?.name ?? ""} readOnly disabled />
+ </div>
+ <div className="flex flex-col gap-1.5">
+ <Label htmlFor="ar-email">Email</Label>
+ <Input id="ar-email" value={session?.user?.email ?? ""} readOnly disabled />
+ </div>
+ <div className="flex flex-col gap-1.5">
+ <Label htmlFor="ar-institution">Institution</Label>
+ <Input
+ id="ar-institution"
+ required
+ value={institution}
+ onChange={(e) => setInstitution(e.target.value)}
+ placeholder="Your university or organization"
+ />
+ </div>
+ <div className="flex flex-col gap-1.5">
+ <Label htmlFor="ar-event">Event code</Label>
+ <Input
+ id="ar-event"
+ required
+ value={code}
+ onChange={(e) => setCode(e.target.value)}
+ placeholder="e.g. PEARC26"
+ aria-invalid={unknownCode || undefined}
+ />
+ {unknownCode ? (
+ <p className="text-xs text-destructive">Unknown event code.</p>
+ ) : resolved ? (
+ <p className="text-xs text-muted-foreground">Event: {resolved.name}</p>
+ ) : null}
+ </div>
+ <div className="flex flex-col gap-1.5">
+ <Label htmlFor="ar-reason">Reason (optional)</Label>
+ <textarea
+ id="ar-reason"
+ value={reason}
+ onChange={(e) => setReason(e.target.value)}
+ placeholder="What do you plan to use the trial access for?"
+ className="min-h-20 w-full rounded-lg border border-input bg-transparent px-2.5 py-1.5 text-sm outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50"
+ />
+ </div>
+ {submitError ? <p className="text-xs text-destructive">{submitError}</p> : null}
+ <Button type="submit" variant="brand" disabled={!canSubmit}>
+ {create.isPending ? "Submitting…" : "Submit request"}
+ </Button>
+ </div>
+ </form>
+ );
+}
diff --git a/web/src/app/no-access/__tests__/NoAccessBody.test.tsx b/web/src/app/no-access/__tests__/NoAccessBody.test.tsx
new file mode 100644
index 000000000..4b13dab59
--- /dev/null
+++ b/web/src/app/no-access/__tests__/NoAccessBody.test.tsx
@@ -0,0 +1,158 @@
+// 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 { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { fireEvent, render, screen } from "@testing-library/react";
+import { http, HttpResponse } from "msw";
+import { setupServer } from "msw/node";
+import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
+import type { AccessRequest } from "@/features/core/access-requests/schemas";
+import { accessRequestsHandlers, resetAccessRequests } from "@/mocks/handlers/access-requests";
+
+let searchParams = "";
+
+vi.mock("next-auth/react", () => ({
+ useSession: () => ({
+ data: { user: { name: "Jane Doe", email: "jane@example.edu" } },
+ status: "authenticated",
+ }),
+}));
+
+vi.mock("next/navigation", () => ({
+ useSearchParams: () => new URLSearchParams(searchParams),
+}));
+
+import { NoAccessBody } from "../NoAccessBody";
+
+const server = setupServer(...accessRequestsHandlers);
+
+beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
+afterAll(() => server.close());
+afterEach(() => {
+ server.resetHandlers();
+ resetAccessRequests();
+ searchParams = "";
+});
+
+const myRequest = (overrides: Partial<AccessRequest> = {}): AccessRequest => ({
+ id: "areq-me",
+ oidc_sub: "sub-mock-caller",
+ email: "jane@example.edu",
+ name: "Jane Doe",
+ institution: "Example University",
+ event_code: "PEARC26",
+ reason: "",
+ status: "PENDING",
+ approver_id: "",
+ deny_reason: "",
+ expires_at: null,
+ created_user_id: "",
+ timestamp: "2026-07-12T10:00:00Z",
+ ...overrides,
+});
+
+function renderBody() {
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ return render(
+ <QueryClientProvider client={client}>
+ <NoAccessBody />
+ </QueryClientProvider>,
+ );
+}
+
+async function openForm() {
+ renderBody();
+ fireEvent.click(await screen.findByRole("button", { name: /request trial access/i }));
+}
+
+describe("<NoAccessBody />", () => {
+ it("shows the entry state when the caller has no request yet", async () => {
+ renderBody();
+ expect(await screen.findByRole("button", { name: /request trial access/i })).toBeVisible();
+ expect(screen.getByText(/request temporary trial access/i)).toBeInTheDocument();
+ });
+
+ it("prefills the form from the token and the ?event= param, resolving the code", async () => {
+ searchParams = "event=PEARC26";
+ await openForm();
+ expect(screen.getByLabelText("Name")).toHaveValue("Jane Doe");
+ expect(screen.getByLabelText("Email")).toHaveValue("jane@example.edu");
+ expect(screen.getByLabelText("Event code")).toHaveValue("PEARC26");
+ await screen.findByText(/pearc26-tutorial/i, undefined, { timeout: 2000 });
+ // Institution is still empty, so submit stays blocked.
+ expect(screen.getByRole("button", { name: /submit request/i })).toBeDisabled();
+ });
+
+ it("blocks submit on an unknown event code with an inline error", async () => {
+ await openForm();
+ fireEvent.change(screen.getByLabelText("Institution"), { target: { value: "Example U" } });
+ fireEvent.change(screen.getByLabelText("Event code"), { target: { value: "NOPE" } });
+ await screen.findByText(/unknown event code/i, undefined, { timeout: 2000 });
+ expect(screen.getByRole("button", { name: /submit request/i })).toBeDisabled();
+ });
+
+ it("submits a valid request and flips to the pending state", async () => {
+ searchParams = "event=PEARC26";
+ await openForm();
+ fireEvent.change(screen.getByLabelText("Institution"), { target: { value: "Example U" } });
+ await screen.findByText(/pearc26-tutorial/i, undefined, { timeout: 2000 });
+ fireEvent.click(screen.getByRole("button", { name: /submit request/i }));
+ await screen.findByRole("heading", { name: /request received/i });
+ });
+
+ it("shows the pending state for an existing PENDING request", async () => {
+ server.use(http.get("*/api/v1/access-requests/me", () => HttpResponse.json(myRequest())));
+ renderBody();
+ await screen.findByRole("heading", { name: /request received/i });
+ expect(await screen.findByText(/pearc26-tutorial/i)).toBeInTheDocument();
+ expect(screen.getByText(/jul 12, 2026/i)).toBeInTheDocument();
+ });
+
+ it("shows the deny reason verbatim and allows a new request", async () => {
+ server.use(
+ http.get("*/api/v1/access-requests/me", () =>
+ HttpResponse.json(myRequest({ status: "DENIED", deny_reason: "Event is full." })),
+ ),
+ );
+ renderBody();
+ await screen.findByRole("heading", { name: /request declined/i });
+ expect(screen.getByText("Event is full.")).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: /submit a new request/i }));
+ expect(screen.getByLabelText("Institution")).toBeInTheDocument();
+ });
+
+ it("falls back to the pending state when the backend reports a pending conflict", async () => {
+ let posted = false;
+ server.use(
+ http.get("*/api/v1/access-requests/me", () =>
+ posted
+ ? HttpResponse.json(myRequest())
+ : HttpResponse.json({ error: "nf" }, { status: 404 }),
+ ),
+ http.post("*/api/v1/access-requests", () => {
+ posted = true;
+ return HttpResponse.json({ error: "a pending request already exists" }, { status: 409 });
+ }),
+ );
+ searchParams = "event=PEARC26";
+ await openForm();
+ fireEvent.change(screen.getByLabelText("Institution"), { target: { value: "Example U" } });
+ await screen.findByText(/pearc26-tutorial/i, undefined, { timeout: 2000 });
+ fireEvent.click(screen.getByRole("button", { name: /submit request/i }));
+ await screen.findByRole("heading", { name: /request received/i });
+ });
+});
diff --git a/web/src/features/core/access-requests/PendingCountBadge.tsx b/web/src/features/core/access-requests/PendingCountBadge.tsx
new file mode 100644
index 000000000..3932f59ff
--- /dev/null
+++ b/web/src/features/core/access-requests/PendingCountBadge.tsx
@@ -0,0 +1,33 @@
+// 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 { useAccessRequests } from "./queries";
+
+// Rendered only when the nav item is visible, i.e. the caller holds the
+// read privilege — no extra ability check needed here.
+export function PendingCountBadge() {
+ const { data } = useAccessRequests({ status: "PENDING" }, { refetchInterval: 20_000 });
+ const count = data?.length ?? 0;
+ if (count === 0) return null;
+ return (
+ <span className="ml-auto rounded-full bg-brand/10 px-2 py-0.5 text-xs font-semibold text-brand">
+ {count}
+ </span>
+ );
+}
diff --git a/web/src/features/core/access-requests/api.ts b/web/src/features/core/access-requests/api.ts
new file mode 100644
index 000000000..7ee64e31e
--- /dev/null
+++ b/web/src/features/core/access-requests/api.ts
@@ -0,0 +1,93 @@
+// 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 { ApiError, apiFetch } from "@/shared/api/client";
+import {
+ type AccessEventResolve,
+ type AccessRequest,
+ accessEventResolveSchema,
+ accessRequestSchema,
+ accessRequestsSchema,
+} from "./schemas";
+
+// 404 means "no request yet" / "unknown code" — a state, not a failure.
+async function orNullOn404<T>(fetchIt: () => Promise<T>): Promise<T | null> {
+ try {
+ return await fetchIt();
+ } catch (err) {
+ if (err instanceof ApiError && err.status === 404) return null;
+ throw err;
+ }
+}
+
+export async function getMyAccessRequest(): Promise<AccessRequest | null> {
+ return orNullOn404(async () => accessRequestSchema.parse(await apiFetch("/access-requests/me")));
+}
+
+export async function resolveAccessEvent(code: string): Promise<AccessEventResolve | null> {
+ return orNullOn404(async () =>
+ accessEventResolveSchema.parse(
+ await apiFetch(`/access-requests/events/${encodeURIComponent(code)}`),
+ ),
+ );
+}
+
+export type CreateAccessRequestBody = {
+ institution: string;
+ event_code: string;
+ reason?: string;
+};
+
+export async function createAccessRequest(body: CreateAccessRequestBody): Promise<AccessRequest> {
+ const raw = await apiFetch("/access-requests", { method: "POST", body });
+ return accessRequestSchema.parse(raw);
+}
+
+export type AccessRequestListFilter = {
+ status?: string;
+ event?: string;
+ limit?: number;
+};
+
+export async function listAccessRequests(
+ filter: AccessRequestListFilter = {},
+): Promise<AccessRequest[]> {
+ const search = new URLSearchParams();
+ if (filter.status) search.set("status", filter.status);
+ if (filter.event) search.set("event", filter.event);
+ if (typeof filter.limit === "number") search.set("limit", String(filter.limit));
+ const qs = search.toString();
+ const raw = await apiFetch(`/access-requests${qs ? `?${qs}` : ""}`);
+ return accessRequestsSchema.parse(raw);
+}
+
+export type DecideAccessRequestBody = {
+ status: "APPROVED" | "DENIED";
+ expires_at?: string;
+ deny_reason?: string;
+};
+
+export async function decideAccessRequest(
+ id: string,
+ body: DecideAccessRequestBody,
+): Promise<AccessRequest> {
+ const raw = await apiFetch(`/access-requests/${encodeURIComponent(id)}`, {
+ method: "PUT",
+ body,
+ });
+ return accessRequestSchema.parse(raw);
+}
diff --git a/web/src/features/core/access-requests/queries.ts b/web/src/features/core/access-requests/queries.ts
new file mode 100644
index 000000000..f2522c76d
--- /dev/null
+++ b/web/src/features/core/access-requests/queries.ts
@@ -0,0 +1,92 @@
+// 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 { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
+import { useSession } from "next-auth/react";
+import {
+ type AccessRequestListFilter,
+ createAccessRequest,
+ decideAccessRequest,
+ type DecideAccessRequestBody,
+ getMyAccessRequest,
+ listAccessRequests,
+ resolveAccessEvent,
+} from "./api";
+
+export const accessRequestKeys = {
+ all: ["access-requests"] as const,
+ mine: () => [...accessRequestKeys.all, "me"] as const,
+ event: (code: string) => [...accessRequestKeys.all, "event", code] as const,
+ list: (filter: AccessRequestListFilter) => [...accessRequestKeys.all, "list", filter] as const,
+};
+
+export function useMyAccessRequest() {
+ const { status } = useSession();
+ return useQuery({
+ queryKey: accessRequestKeys.mine(),
+ queryFn: getMyAccessRequest,
+ enabled: status === "authenticated",
+ retry: false,
+ refetchOnWindowFocus: false,
+ });
+}
+
+export function useAccessEvent(code: string) {
+ return useQuery({
+ queryKey: accessRequestKeys.event(code),
+ queryFn: () => resolveAccessEvent(code),
+ enabled: code.length > 0,
+ retry: false,
+ staleTime: 60_000,
+ refetchOnWindowFocus: false,
+ });
+}
+
+export function useCreateAccessRequest() {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: createAccessRequest,
+ onSuccess: (created) => {
+ queryClient.setQueryData(accessRequestKeys.mine(), created);
+ },
+ });
+}
+
+export function useAccessRequests(
+ filter: AccessRequestListFilter = {},
+ options: { refetchInterval?: number } = {},
+) {
+ return useQuery({
+ queryKey: accessRequestKeys.list(filter),
+ queryFn: () => listAccessRequests(filter),
+ refetchOnWindowFocus: false,
+ ...options,
+ });
+}
+
+export function useDecideAccessRequest() {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: ({ id, body }: { id: string; body: DecideAccessRequestBody }) =>
+ decideAccessRequest(id, body),
+ onSuccess: () => {
+ void queryClient.invalidateQueries({ queryKey: accessRequestKeys.all });
+ },
+ });
+}
diff --git a/web/src/features/core/access-requests/schemas.ts b/web/src/features/core/access-requests/schemas.ts
new file mode 100644
index 000000000..5fee017fb
--- /dev/null
+++ b/web/src/features/core/access-requests/schemas.ts
@@ -0,0 +1,60 @@
+// 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 { z } from "zod";
+
+export const accessRequestStatusSchema = z.enum(["PENDING", "APPROVED", "DENIED"]);
+export type AccessRequestStatus = z.infer<typeof accessRequestStatusSchema>;
+
+export const accessRequestSchema = z.object({
+ id: z.string(),
+ oidc_sub: z.string(),
+ email: z.string(),
+ name: z.string(),
+ institution: z.string(),
+ event_code: z.string(),
+ reason: z
+ .string()
+ .nullish()
+ .transform((v) => v ?? ""),
+ status: accessRequestStatusSchema,
+ approver_id: z
+ .string()
+ .nullish()
+ .transform((v) => v ?? ""),
+ deny_reason: z
+ .string()
+ .nullish()
+ .transform((v) => v ?? ""),
+ expires_at: z.string().nullish(),
+ created_user_id: z
+ .string()
+ .nullish()
+ .transform((v) => v ?? ""),
+ timestamp: z.string(),
+});
+export type AccessRequest = z.infer<typeof accessRequestSchema>;
+
+export const accessRequestsSchema = z.array(accessRequestSchema);
+
+// The resolve endpoint deliberately returns only the code and the
+// allocation's display name — the caller is not a user yet.
+export const accessEventResolveSchema = z.object({
+ code: z.string(),
+ name: z.string(),
+});
+export type AccessEventResolve = z.infer<typeof accessEventResolveSchema>;
diff --git a/web/src/generated/core/index.ts b/web/src/generated/core/index.ts
index 379e6c28b..b822b7435 100644
--- a/web/src/generated/core/index.ts
+++ b/web/src/generated/core/index.ts
@@ -1,4 +1,4 @@
// This file is auto-generated by @hey-api/openapi-ts
-export { deleteComputeAllocationChangeRequestEventsById, deleteComputeAllocationChangeRequestsById, deleteComputeAllocationDiffsById, deleteComputeAllocationMembershipResourceOverridesById, deleteComputeAllocationMembershipsById, deleteComputeAllocationsByIdResourcesByResourceId, deleteComputeAllocationUsagesById, deleteComputeClusterUsersById, deleteRolesById, deleteRolesByIdPrivilegesByKey, deleteUserIdentitiesById, deleteUsersByIdPrivilegesByKey, deleteUsersByIdRolesByRoleId, getAudit [...]
-export type { AllocationMembershipResponse, AllocationStatus, AllocationSuTotalResponse, AttachResourceRequest, CallerProfileResponse, CallerRoleGrant, ClientOptions, ComputeAllocation, ComputeAllocationChangeRequest, ComputeAllocationChangeRequestEvent, ComputeAllocationDiff, ComputeAllocationListResponse, ComputeAllocationMembership, ComputeAllocationMembershipResourceOverride, ComputeAllocationResource, ComputeAllocationResourceMapping, ComputeAllocationResourceRate, ComputeAllocation [...]
+export { deleteComputeAllocationChangeRequestEventsById, deleteComputeAllocationChangeRequestsById, deleteComputeAllocationDiffsById, deleteComputeAllocationMembershipResourceOverridesById, deleteComputeAllocationMembershipsById, deleteComputeAllocationsByIdResourcesByResourceId, deleteComputeAllocationUsagesById, deleteComputeClusterUsersById, deleteRolesById, deleteRolesByIdPrivilegesByKey, deleteUserIdentitiesById, deleteUsersByIdPrivilegesByKey, deleteUsersByIdRolesByRoleId, getAcces [...]
+export type { AccessRequest, AccessRequestStatus, AllocationMembershipResponse, AllocationStatus, AllocationSuTotalResponse, AttachResourceRequest, CallerProfileResponse, CallerRoleGrant, ClientOptions, ComputeAllocation, ComputeAllocationChangeRequest, ComputeAllocationChangeRequestEvent, ComputeAllocationDiff, ComputeAllocationListResponse, ComputeAllocationMembership, ComputeAllocationMembershipResourceOverride, ComputeAllocationResource, ComputeAllocationResourceMapping, ComputeAlloc [...]
diff --git a/web/src/generated/core/sdk.gen.ts b/web/src/generated/core/sdk.gen.ts
index 149b028f8..767eb29d9 100644
--- a/web/src/generated/core/sdk.gen.ts
+++ b/web/src/generated/core/sdk.gen.ts
@@ -2,7 +2,7 @@
import type { Client, ClientMeta, Options as Options2, RequestResult, TDataShape } from './client';
import { client } from './client.gen';
-import type { DeleteComputeAllocationChangeRequestEventsByIdData, DeleteComputeAllocationChangeRequestEventsByIdErrors, DeleteComputeAllocationChangeRequestEventsByIdResponses, DeleteComputeAllocationChangeRequestsByIdData, DeleteComputeAllocationChangeRequestsByIdErrors, DeleteComputeAllocationChangeRequestsByIdResponses, DeleteComputeAllocationDiffsByIdData, DeleteComputeAllocationDiffsByIdErrors, DeleteComputeAllocationDiffsByIdResponses, DeleteComputeAllocationMembershipResourceOverr [...]
+import type { DeleteComputeAllocationChangeRequestEventsByIdData, DeleteComputeAllocationChangeRequestEventsByIdErrors, DeleteComputeAllocationChangeRequestEventsByIdResponses, DeleteComputeAllocationChangeRequestsByIdData, DeleteComputeAllocationChangeRequestsByIdErrors, DeleteComputeAllocationChangeRequestsByIdResponses, DeleteComputeAllocationDiffsByIdData, DeleteComputeAllocationDiffsByIdErrors, DeleteComputeAllocationDiffsByIdResponses, DeleteComputeAllocationMembershipResourceOverr [...]
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = Options2<TData, ThrowOnError, TResponse> & {
/**
@@ -18,6 +18,59 @@ export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends
meta?: keyof ClientMeta extends never ? Record<string, unknown> : ClientMeta;
};
+/**
+ * List access requests
+ */
+export const getAccessRequests = <ThrowOnError extends boolean = false>(options?: Options<GetAccessRequestsData, ThrowOnError>): RequestResult<GetAccessRequestsResponses, unknown, ThrowOnError> => (options?.client ?? client).get<GetAccessRequestsResponses, unknown, ThrowOnError>({
+ security: [{ name: 'Authorization', type: 'apiKey' }],
+ url: '/access-requests',
+ ...options
+});
+
+/**
+ * Submit an access request
+ */
+export const postAccessRequests = <ThrowOnError extends boolean = false>(options: Options<PostAccessRequestsData, ThrowOnError>): RequestResult<PostAccessRequestsResponses, PostAccessRequestsErrors, ThrowOnError> => (options.client ?? client).post<PostAccessRequestsResponses, PostAccessRequestsErrors, ThrowOnError>({
+ security: [{ name: 'Authorization', type: 'apiKey' }],
+ url: '/access-requests',
+ ...options,
+ headers: {
+ 'Content-Type': 'application/json',
+ ...options.headers
+ }
+});
+
+/**
+ * Approve or deny an access request
+ */
+export const putAccessRequestsById = <ThrowOnError extends boolean = false>(options: Options<PutAccessRequestsByIdData, ThrowOnError>): RequestResult<PutAccessRequestsByIdResponses, PutAccessRequestsByIdErrors, ThrowOnError> => (options.client ?? client).put<PutAccessRequestsByIdResponses, PutAccessRequestsByIdErrors, ThrowOnError>({
+ security: [{ name: 'Authorization', type: 'apiKey' }],
+ url: '/access-requests/{id}',
+ ...options,
+ headers: {
+ 'Content-Type': 'application/json',
+ ...options.headers
+ }
+});
+
+/**
+ * Resolve an access event code
+ */
+export const getAccessRequestsEventsByCode = <ThrowOnError extends boolean = false>(options: Options<GetAccessRequestsEventsByCodeData, ThrowOnError>): RequestResult<GetAccessRequestsEventsByCodeResponses, GetAccessRequestsEventsByCodeErrors, ThrowOnError> => (options.client ?? client).get<GetAccessRequestsEventsByCodeResponses, GetAccessRequestsEventsByCodeErrors, ThrowOnError>({
+ security: [{ name: 'Authorization', type: 'apiKey' }],
+ url: '/access-requests/events/{code}',
+ ...options
+});
+
+/**
+ * Get the caller's latest access request
+ */
+export const getAccessRequestsMe = <ThrowOnError extends boolean = false>(options?: Options<GetAccessRequestsMeData, ThrowOnError>): RequestResult<GetAccessRequestsMeResponses, GetAccessRequestsMeErrors, ThrowOnError> => (options?.client ?? client).get<GetAccessRequestsMeResponses, GetAccessRequestsMeErrors, ThrowOnError>({
+ security: [{ name: 'Authorization', type: 'apiKey' }],
+ url: '/access-requests/me',
+ ...options
+});
+
/**
* List audit events for a trace (optionally one span)
*/
@@ -431,10 +484,8 @@ export const getComputeAllocationUsagesById = <ThrowOnError extends boolean = fa
/**
* List compute allocations (filtered + paginated)
- *
- * Callers without the allocations read privilege get only allocations where they hold a membership or a governance role on the parent project; filters and pagination apply to privileged callers only.
*/
-export const getComputeAllocations = <ThrowOnError extends boolean = false>(options?: Options<GetComputeAllocationsData, ThrowOnError>): RequestResult<GetComputeAllocationsResponses, GetComputeAllocationsErrors, ThrowOnError> => (options?.client ?? client).get<GetComputeAllocationsResponses, GetComputeAllocationsErrors, ThrowOnError>({
+export const getComputeAllocations = <ThrowOnError extends boolean = false>(options?: Options<GetComputeAllocationsData, ThrowOnError>): RequestResult<GetComputeAllocationsResponses, unknown, ThrowOnError> => (options?.client ?? client).get<GetComputeAllocationsResponses, unknown, ThrowOnError>({
security: [{ name: 'Authorization', type: 'apiKey' }],
url: '/compute-allocations',
...options
@@ -455,8 +506,6 @@ export const postComputeAllocations = <ThrowOnError extends boolean = false>(opt
/**
* Get a compute allocation by ID
- *
- * Callers without the allocations read privilege must hold a membership on the allocation or a governance role on its project; others return 404.
*/
export const getComputeAllocationsById = <ThrowOnError extends boolean = false>(options: Options<GetComputeAllocationsByIdData, ThrowOnError>): RequestResult<GetComputeAllocationsByIdResponses, GetComputeAllocationsByIdErrors, ThrowOnError> => (options.client ?? client).get<GetComputeAllocationsByIdResponses, GetComputeAllocationsByIdErrors, ThrowOnError>({
security: [{ name: 'Authorization', type: 'apiKey' }],
@@ -493,8 +542,6 @@ export const getComputeAllocationsByIdDiffsLatest = <ThrowOnError extends boolea
/**
* List members of a compute allocation
- *
- * Callers without the allocations read privilege must hold a membership on the allocation or a governance role on its project; others return 404.
*/
export const getComputeAllocationsByIdMemberships = <ThrowOnError extends boolean = false>(options: Options<GetComputeAllocationsByIdMembershipsData, ThrowOnError>): RequestResult<GetComputeAllocationsByIdMembershipsResponses, GetComputeAllocationsByIdMembershipsErrors, ThrowOnError> => (options.client ?? client).get<GetComputeAllocationsByIdMembershipsResponses, GetComputeAllocationsByIdMembershipsErrors, ThrowOnError>({
security: [{ name: 'Authorization', type: 'apiKey' }],
@@ -504,8 +551,6 @@ export const getComputeAllocationsByIdMemberships = <ThrowOnError extends boolea
/**
* List resources attached to a compute allocation
- *
- * Callers without the allocations read privilege must hold a membership on the allocation or a governance role on its project; others return 404.
*/
export const getComputeAllocationsByIdResources = <ThrowOnError extends boolean = false>(options: Options<GetComputeAllocationsByIdResourcesData, ThrowOnError>): RequestResult<GetComputeAllocationsByIdResourcesResponses, GetComputeAllocationsByIdResourcesErrors, ThrowOnError> => (options.client ?? client).get<GetComputeAllocationsByIdResourcesResponses, GetComputeAllocationsByIdResourcesErrors, ThrowOnError>({
security: [{ name: 'Authorization', type: 'apiKey' }],
@@ -552,8 +597,6 @@ export const putComputeAllocationsByIdResourcesByResourceId = <ThrowOnError exte
/**
* List usages for a compute allocation
- *
- * Callers without the allocations read privilege must hold a membership on the allocation or a governance role on its project; others return 404.
*/
export const getComputeAllocationsByIdUsages = <ThrowOnError extends boolean = false>(options: Options<GetComputeAllocationsByIdUsagesData, ThrowOnError>): RequestResult<GetComputeAllocationsByIdUsagesResponses, GetComputeAllocationsByIdUsagesErrors, ThrowOnError> => (options.client ?? client).get<GetComputeAllocationsByIdUsagesResponses, GetComputeAllocationsByIdUsagesErrors, ThrowOnError>({
security: [{ name: 'Authorization', type: 'apiKey' }],
@@ -563,8 +606,6 @@ export const getComputeAllocationsByIdUsages = <ThrowOnError extends boolean = f
/**
* Get total SU usage for a compute allocation
- *
- * Callers without the allocations read privilege must hold a membership on the allocation or a governance role on its project; others return 404.
*/
export const getComputeAllocationsByIdUsagesTotal = <ThrowOnError extends boolean = false>(options: Options<GetComputeAllocationsByIdUsagesTotalData, ThrowOnError>): RequestResult<GetComputeAllocationsByIdUsagesTotalResponses, GetComputeAllocationsByIdUsagesTotalErrors, ThrowOnError> => (options.client ?? client).get<GetComputeAllocationsByIdUsagesTotalResponses, GetComputeAllocationsByIdUsagesTotalErrors, ThrowOnError>({
security: [{ name: 'Authorization', type: 'apiKey' }],
@@ -738,10 +779,8 @@ export const getPrivilegesCatalog = <ThrowOnError extends boolean = false>(optio
/**
* List projects (filtered + paginated, PI joined)
- *
- * Callers without the projects read privilege get only the projects they participate in; filters and pagination apply to privileged callers only.
*/
-export const getProjects = <ThrowOnError extends boolean = false>(options?: Options<GetProjectsData, ThrowOnError>): RequestResult<GetProjectsResponses, GetProjectsErrors, ThrowOnError> => (options?.client ?? client).get<GetProjectsResponses, GetProjectsErrors, ThrowOnError>({
+export const getProjects = <ThrowOnError extends boolean = false>(options?: Options<GetProjectsData, ThrowOnError>): RequestResult<GetProjectsResponses, unknown, ThrowOnError> => (options?.client ?? client).get<GetProjectsResponses, unknown, ThrowOnError>({
security: [{ name: 'Authorization', type: 'apiKey' }],
url: '/projects',
...options
@@ -762,8 +801,6 @@ export const postProjects = <ThrowOnError extends boolean = false>(options: Opti
/**
* Get a project by ID
- *
- * Callers without the projects read privilege only see projects they participate in; others return 404.
*/
export const getProjectsById = <ThrowOnError extends boolean = false>(options: Options<GetProjectsByIdData, ThrowOnError>): RequestResult<GetProjectsByIdResponses, GetProjectsByIdErrors, ThrowOnError> => (options.client ?? client).get<GetProjectsByIdResponses, GetProjectsByIdErrors, ThrowOnError>({
security: [{ name: 'Authorization', type: 'apiKey' }],
diff --git a/web/src/generated/core/types.gen.ts b/web/src/generated/core/types.gen.ts
index 58c9f2310..6ce0b376a 100644
--- a/web/src/generated/core/types.gen.ts
+++ b/web/src/generated/core/types.gen.ts
@@ -4,6 +4,24 @@ export type ClientOptions = {
baseUrl: 'localhost:8080/' | (string & {});
};
+export type AccessRequest = {
+ approver_id?: string;
+ created_user_id?: string;
+ deny_reason?: string;
+ email?: string;
+ event_code?: string;
+ expires_at?: string;
+ id?: string;
+ institution?: string;
+ name?: string;
+ oidc_sub?: string;
+ reason?: string;
+ status?: AccessRequestStatus;
+ timestamp?: string;
+};
+
+export type AccessRequestStatus = 'PENDING' | 'APPROVED' | 'DENIED';
+
export type AllocationMembershipResponse = {
compute_allocation_id?: string;
display_name?: string;
@@ -300,7 +318,7 @@ export type OrganizationListResponse = {
total?: number;
};
-export type PrivilegeKey = 'core:clusters:read' | 'core:clusters:write' | 'core:allocations:read' | 'core:allocations:write' | 'core:projects:read' | 'core:projects:write' | 'core:users:read' | 'core:users:write' | 'core:organizations:read' | 'core:organizations:write' | 'core:traces:read' | 'core:privileges:grant' | 'core:roles:manage';
+export type PrivilegeKey = 'core:clusters:read' | 'core:clusters:write' | 'core:allocations:read' | 'core:allocations:write' | 'core:projects:read' | 'core:projects:write' | 'core:users:read' | 'core:users:write' | 'core:organizations:read' | 'core:organizations:write' | 'core:traces:read' | 'core:privileges:grant' | 'core:roles:manage' | 'core:access-requests:read' | 'core:access-requests:write';
export type Project = {
created_time?: string;
@@ -527,6 +545,188 @@ export type UserNameUpdateRequest = {
middle_name?: string;
};
+export type GetAccessRequestsData = {
+ body?: never;
+ path?: never;
+ query?: {
+ /**
+ * Filter by status
+ */
+ status?: string;
+ /**
+ * Filter by event code
+ */
+ event?: string;
+ /**
+ * Maximum rows (default 50)
+ */
+ limit?: number;
+ };
+ url: '/access-requests';
+};
+
+export type GetAccessRequestsResponses = {
+ /**
+ * OK
+ */
+ 200: Array<AccessRequest>;
+};
+
+export type GetAccessRequestsResponse = GetAccessRequestsResponses[keyof GetAccessRequestsResponses];
+
+export type PostAccessRequestsData = {
+ /**
+ * Access request payload
+ */
+ body: {
+ event_code?: string;
+ institution?: string;
+ reason?: string;
+ };
+ path?: never;
+ query?: never;
+ url: '/access-requests';
+};
+
+export type PostAccessRequestsErrors = {
+ /**
+ * Bad Request
+ */
+ 400: {
+ error?: string;
+ };
+ /**
+ * Not Found
+ */
+ 404: {
+ error?: string;
+ };
+ /**
+ * Conflict
+ */
+ 409: {
+ error?: string;
+ };
+};
+
+export type PostAccessRequestsError = PostAccessRequestsErrors[keyof PostAccessRequestsErrors];
+
+export type PostAccessRequestsResponses = {
+ /**
+ * Created
+ */
+ 201: AccessRequest;
+};
+
+export type PostAccessRequestsResponse = PostAccessRequestsResponses[keyof PostAccessRequestsResponses];
+
+export type PutAccessRequestsByIdData = {
+ /**
+ * Decision payload
+ */
+ body: {
+ deny_reason?: string;
+ expires_at?: string;
+ status?: string;
+ };
+ path: {
+ /**
+ * Access request ID
+ */
+ id: string;
+ };
+ query?: never;
+ url: '/access-requests/{id}';
+};
+
+export type PutAccessRequestsByIdErrors = {
+ /**
+ * Bad Request
+ */
+ 400: {
+ error?: string;
+ };
+ /**
+ * Not Found
+ */
+ 404: {
+ error?: string;
+ };
+};
+
+export type PutAccessRequestsByIdError = PutAccessRequestsByIdErrors[keyof PutAccessRequestsByIdErrors];
+
+export type PutAccessRequestsByIdResponses = {
+ /**
+ * OK
+ */
+ 200: AccessRequest;
+};
+
+export type PutAccessRequestsByIdResponse = PutAccessRequestsByIdResponses[keyof PutAccessRequestsByIdResponses];
+
+export type GetAccessRequestsEventsByCodeData = {
+ body?: never;
+ path: {
+ /**
+ * Event code
+ */
+ code: string;
+ };
+ query?: never;
+ url: '/access-requests/events/{code}';
+};
+
+export type GetAccessRequestsEventsByCodeErrors = {
+ /**
+ * Not Found
+ */
+ 404: {
+ error?: string;
+ };
+};
+
+export type GetAccessRequestsEventsByCodeError = GetAccessRequestsEventsByCodeErrors[keyof GetAccessRequestsEventsByCodeErrors];
+
+export type GetAccessRequestsEventsByCodeResponses = {
+ /**
+ * OK
+ */
+ 200: {
+ code?: string;
+ name?: string;
+ };
+};
+
+export type GetAccessRequestsEventsByCodeResponse = GetAccessRequestsEventsByCodeResponses[keyof GetAccessRequestsEventsByCodeResponses];
+
+export type GetAccessRequestsMeData = {
+ body?: never;
+ path?: never;
+ query?: never;
+ url: '/access-requests/me';
+};
+
+export type GetAccessRequestsMeErrors = {
+ /**
+ * Not Found
+ */
+ 404: {
+ error?: string;
+ };
+};
+
+export type GetAccessRequestsMeError = GetAccessRequestsMeErrors[keyof GetAccessRequestsMeErrors];
+
+export type GetAccessRequestsMeResponses = {
+ /**
+ * OK
+ */
+ 200: AccessRequest;
+};
+
+export type GetAccessRequestsMeResponse = GetAccessRequestsMeResponses[keyof GetAccessRequestsMeResponses];
+
export type GetAuditEventsData = {
body?: never;
path?: never;
@@ -2794,7 +2994,7 @@ export type GetPrivilegesByKeyHoldersData = {
/**
* Privilege key
*/
- key: 'core:clusters:read' | 'core:clusters:write' | 'core:allocations:read' | 'core:allocations:write' | 'core:projects:read' | 'core:projects:write' | 'core:users:read' | 'core:users:write' | 'core:organizations:read' | 'core:organizations:write' | 'core:traces:read' | 'core:privileges:grant' | 'core:roles:manage';
+ key: 'core:clusters:read' | 'core:clusters:write' | 'core:allocations:read' | 'core:allocations:write' | 'core:projects:read' | 'core:projects:write' | 'core:users:read' | 'core:users:write' | 'core:organizations:read' | 'core:organizations:write' | 'core:traces:read' | 'core:privileges:grant' | 'core:roles:manage' | 'core:access-requests:read' | 'core:access-requests:write';
};
query?: never;
url: '/privileges/{key}/holders';
@@ -3324,7 +3524,7 @@ export type DeleteRolesByIdPrivilegesByKeyData = {
/**
* Privilege key
*/
- key: 'core:clusters:read' | 'core:clusters:write' | 'core:allocations:read' | 'core:allocations:write' | 'core:projects:read' | 'core:projects:write' | 'core:users:read' | 'core:users:write' | 'core:organizations:read' | 'core:organizations:write' | 'core:traces:read' | 'core:privileges:grant' | 'core:roles:manage';
+ key: 'core:clusters:read' | 'core:clusters:write' | 'core:allocations:read' | 'core:allocations:write' | 'core:projects:read' | 'core:projects:write' | 'core:users:read' | 'core:users:write' | 'core:organizations:read' | 'core:organizations:write' | 'core:traces:read' | 'core:privileges:grant' | 'core:roles:manage' | 'core:access-requests:read' | 'core:access-requests:write';
};
query?: never;
url: '/roles/{id}/privileges/{key}';
@@ -3950,7 +4150,7 @@ export type DeleteUsersByIdPrivilegesByKeyData = {
/**
* Privilege key
*/
- key: 'core:clusters:read' | 'core:clusters:write' | 'core:allocations:read' | 'core:allocations:write' | 'core:projects:read' | 'core:projects:write' | 'core:users:read' | 'core:users:write' | 'core:organizations:read' | 'core:organizations:write' | 'core:traces:read' | 'core:privileges:grant' | 'core:roles:manage';
+ key: 'core:clusters:read' | 'core:clusters:write' | 'core:allocations:read' | 'core:allocations:write' | 'core:projects:read' | 'core:projects:write' | 'core:users:read' | 'core:users:write' | 'core:organizations:read' | 'core:organizations:write' | 'core:traces:read' | 'core:privileges:grant' | 'core:roles:manage' | 'core:access-requests:read' | 'core:access-requests:write';
};
query?: never;
url: '/users/{id}/privileges/{key}';
diff --git a/web/src/generated/core/zod.gen.ts b/web/src/generated/core/zod.gen.ts
index 959dbf89d..db615bb6d 100644
--- a/web/src/generated/core/zod.gen.ts
+++ b/web/src/generated/core/zod.gen.ts
@@ -2,6 +2,32 @@
import * as z from 'zod';
+export const zAccessRequestStatus = z.enum([
+ 'PENDING',
+ 'APPROVED',
+ 'DENIED'
+]);
+
+export type accessRequestStatusZodType = z.infer<typeof zAccessRequestStatus>;
+
+export const zAccessRequest = z.object({
+ approver_id: z.string().optional(),
+ created_user_id: z.string().optional(),
+ deny_reason: z.string().optional(),
+ email: z.string().optional(),
+ event_code: z.string().optional(),
+ expires_at: z.string().optional(),
+ id: z.string().optional(),
+ institution: z.string().optional(),
+ name: z.string().optional(),
+ oidc_sub: z.string().optional(),
+ reason: z.string().optional(),
+ status: zAccessRequestStatus.optional(),
+ timestamp: z.string().optional()
+});
+
+export type accessRequestZodType = z.infer<typeof zAccessRequest>;
+
export const zAllocationSuTotalResponse = z.object({
compute_allocation_id: z.string().optional(),
total_su_amount: z.int().optional()
@@ -209,7 +235,9 @@ export const zPrivilegeKey = z.enum([
'core:organizations:write',
'core:traces:read',
'core:privileges:grant',
- 'core:roles:manage'
+ 'core:roles:manage',
+ 'core:access-requests:read',
+ 'core:access-requests:write'
]);
export type privilegeKeyZodType = z.infer<typeof zPrivilegeKey>;
@@ -500,6 +528,66 @@ export const zUserNameUpdateRequest = z.object({
export type userNameUpdateRequestZodType = z.infer<typeof zUserNameUpdateRequest>;
+export const zGetAccessRequestsQuery = z.object({
+ status: z.string().optional(),
+ event: z.string().optional(),
+ limit: z.int().optional()
+});
+
+/**
+ * OK
+ */
+export const zGetAccessRequestsResponse = z.array(zAccessRequest);
+
+/**
+ * Access request payload
+ */
+export const zPostAccessRequestsBody = z.object({
+ event_code: z.string().optional(),
+ institution: z.string().optional(),
+ reason: z.string().optional()
+});
+
+/**
+ * Created
+ */
+export const zPostAccessRequestsResponse = zAccessRequest;
+
+/**
+ * Decision payload
+ */
+export const zPutAccessRequestsByIdBody = z.object({
+ deny_reason: z.string().optional(),
+ expires_at: z.string().optional(),
+ status: z.string().optional()
+});
+
+export const zPutAccessRequestsByIdPath = z.object({
+ id: z.string()
+});
+
+/**
+ * OK
+ */
+export const zPutAccessRequestsByIdResponse = zAccessRequest;
+
+export const zGetAccessRequestsEventsByCodePath = z.object({
+ code: z.string()
+});
+
+/**
+ * OK
+ */
+export const zGetAccessRequestsEventsByCodeResponse = z.object({
+ code: z.string().optional(),
+ name: z.string().optional()
+});
+
+/**
+ * OK
+ */
+export const zGetAccessRequestsMeResponse = zAccessRequest;
+
export const zGetAuditEventsQuery = z.object({
trace_id: z.string(),
span_id: z.string().optional()
@@ -1130,7 +1218,9 @@ export const zGetPrivilegesByKeyHoldersPath = z.object({
'core:organizations:write',
'core:traces:read',
'core:privileges:grant',
- 'core:roles:manage'
+ 'core:roles:manage',
+ 'core:access-requests:read',
+ 'core:access-requests:write'
])
});
@@ -1279,7 +1369,9 @@ export const zDeleteRolesByIdPrivilegesByKeyPath = z.object({
'core:organizations:write',
'core:traces:read',
'core:privileges:grant',
- 'core:roles:manage'
+ 'core:roles:manage',
+ 'core:access-requests:read',
+ 'core:access-requests:write'
])
});
@@ -1468,7 +1560,9 @@ export const zDeleteUsersByIdPrivilegesByKeyPath = z.object({
'core:organizations:write',
'core:traces:read',
'core:privileges:grant',
- 'core:roles:manage'
+ 'core:roles:manage',
+ 'core:access-requests:read',
+ 'core:access-requests:write'
])
});
diff --git a/web/src/mocks/handlers.ts b/web/src/mocks/handlers.ts
index 113dd2c11..a9760e32f 100644
--- a/web/src/mocks/handlers.ts
+++ b/web/src/mocks/handlers.ts
@@ -16,6 +16,7 @@
// under the License.
import type { RequestHandler } from "msw";
+import { accessRequestsHandlers } from "./handlers/access-requests";
import { allocationsHandlers } from "./handlers/allocations";
import { amieHandlers } from "./handlers/amie";
import { analyticsHandlers } from "./handlers/analytics";
@@ -44,4 +45,5 @@ export const handlers: RequestHandler[] = [
...amieHandlers,
...clustersHandlers,
...resourcesHandlers,
+ ...accessRequestsHandlers,
];
diff --git a/web/src/mocks/handlers/access-requests.ts b/web/src/mocks/handlers/access-requests.ts
new file mode 100644
index 000000000..158b1f69c
--- /dev/null
+++ b/web/src/mocks/handlers/access-requests.ts
@@ -0,0 +1,149 @@
+// 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 { http, HttpResponse } from "msw";
+import type { AccessRequest } from "@/features/core/access-requests/schemas";
+
+const EVENT_NAMES: Record<string, string> = {
+ PEARC26: "pearc26-tutorial",
+};
+
+function seedRequests(): AccessRequest[] {
+ return [
+ {
+ id: "areq-001",
+ oidc_sub: "sub-queue-001",
+ email: "amara.osei@example.edu",
+ name: "Amara Osei",
+ institution: "Example University",
+ event_code: "PEARC26",
+ reason: "Hands-on tutorial attendee.",
+ status: "PENDING",
+ approver_id: "",
+ deny_reason: "",
+ expires_at: null,
+ created_user_id: "",
+ timestamp: "2026-07-10T14:05:00Z",
+ },
+ {
+ id: "areq-002",
+ oidc_sub: "sub-queue-002",
+ email: "li.wei@example.org",
+ name: "Li Wei",
+ institution: "Example Institute",
+ event_code: "PEARC26",
+ reason: "",
+ status: "PENDING",
+ approver_id: "",
+ deny_reason: "",
+ expires_at: null,
+ created_user_id: "",
+ timestamp: "2026-07-11T09:30:00Z",
+ },
+ ];
+}
+
+let requests = seedRequests();
+// The signed-in mock caller's own request; null = no request yet.
+let mine: AccessRequest | null = null;
+
+export function resetAccessRequests() {
+ requests = seedRequests();
+ mine = null;
+}
+
+const notFound = () => HttpResponse.json({ error: "not found" }, { status: 404 });
+
+export const accessRequestsHandlers = [
+ http.get("*/api/v1/access-requests/me", () => (mine ? HttpResponse.json(mine) : notFound())),
+
+ http.get("*/api/v1/access-requests/events/:code", ({ params }) => {
+ const code = String(params.code);
+ const name = EVENT_NAMES[code];
+ return name ? HttpResponse.json({ code, name }) : notFound();
+ }),
+
+ http.post("*/api/v1/access-requests", async ({ request }) => {
+ if (mine?.status === "PENDING") {
+ return HttpResponse.json({ error: "a pending request already exists" }, { status: 409 });
+ }
+ const body = (await request.json()) as {
+ institution?: string;
+ event_code?: string;
+ reason?: string;
+ };
+ if (!body.institution || !body.event_code) {
+ return HttpResponse.json(
+ { error: "institution and event_code are required" },
+ { status: 400 },
+ );
+ }
+ if (!EVENT_NAMES[body.event_code]) return notFound();
+ mine = {
+ id: `areq-${String(requests.length + 1).padStart(3, "0")}`,
+ oidc_sub: "sub-mock-caller",
+ email: "caller@example.edu",
+ name: "Mock Caller",
+ institution: body.institution,
+ event_code: body.event_code,
+ reason: body.reason ?? "",
+ status: "PENDING",
+ approver_id: "",
+ deny_reason: "",
+ expires_at: null,
+ created_user_id: "",
+ timestamp: new Date().toISOString(),
+ };
+ requests = [mine, ...requests];
+ return HttpResponse.json(mine, { status: 201 });
+ }),
+
+ http.get("*/api/v1/access-requests", ({ request }) => {
+ const url = new URL(request.url);
+ const status = url.searchParams.get("status");
+ const event = url.searchParams.get("event");
+ let rows = requests;
+ if (status) rows = rows.filter((r) => r.status === status);
+ if (event) rows = rows.filter((r) => r.event_code === event);
+ return HttpResponse.json(rows);
+ }),
+
+ http.put("*/api/v1/access-requests/:id", async ({ params, request }) => {
+ const row = requests.find((r) => r.id === String(params.id));
+ if (!row) return notFound();
+ if (row.status !== "PENDING") {
+ return HttpResponse.json({ error: "request already decided" }, { status: 400 });
+ }
+ const body = (await request.json()) as {
+ status?: string;
+ expires_at?: string;
+ deny_reason?: string;
+ };
+ if (body.status !== "APPROVED" && body.status !== "DENIED") {
+ return HttpResponse.json({ error: "status must be APPROVED or DENIED" }, { status: 400 });
+ }
+ row.status = body.status;
+ row.approver_id = "user-admin-001";
+ if (body.status === "APPROVED") {
+ row.expires_at =
+ body.expires_at ?? new Date(Date.now() + 30 * 24 * 3600 * 1000).toISOString();
+ } else {
+ row.deny_reason = body.deny_reason ?? "";
+ }
+ return HttpResponse.json(row);
+ }),
+];
diff --git a/web/src/shared/casl/abilities.ts b/web/src/shared/casl/abilities.ts
index 4e63752a6..beb130844 100644
--- a/web/src/shared/casl/abilities.ts
+++ b/web/src/shared/casl/abilities.ts
@@ -26,6 +26,8 @@ export type PrivilegeRule = { action: string; subject: string };
// TODO(privileges): backend should declare (subject, action) pairs per key
// so clients can derive this map from /me instead of shipping it.
export const PRIVILEGE_ABILITY_MAP: Record<string, PrivilegeRule[]> = {
+ "core:access-requests:read": [{ action: "read", subject: "AccessRequest" }],
+ "core:access-requests:write": [{ action: "manage", subject: "AccessRequest" }],
"core:clusters:read": [{ action: "read", subject: "Cluster" }],
"core:clusters:write": [{ action: "manage", subject: "Cluster" }],
"core:allocations:read": [{ action: "read", subject: "Allocation" }],
diff --git a/web/src/shared/layout/Sidebar.tsx b/web/src/shared/layout/Sidebar.tsx
index 9a4ce3d4a..dfcd203a1 100644
--- a/web/src/shared/layout/Sidebar.tsx
+++ b/web/src/shared/layout/Sidebar.tsx
@@ -72,6 +72,7 @@ function isActive(pathname: string, href: string): boolean {
function SidebarLink({ item, active }: { item: NavItem; active: boolean }) {
const Icon = item.icon;
+ const Badge = item.badge;
return (
<Link
href={item.href}
@@ -85,6 +86,7 @@ function SidebarLink({ item, active }: { item: NavItem; active: boolean }) {
>
<Icon className="h-5 w-5 stroke-[1.75]" />
<span className="truncate">{item.label}</span>
+ {Badge ? <Badge /> : null}
{active && <span className="absolute top-2 right-0 bottom-2 w-1 rounded-l-full bg-brand" />}
</Link>
);
diff --git a/web/src/shared/layout/nav.ts b/web/src/shared/layout/nav.ts
index bd8617df9..645ab499a 100644
--- a/web/src/shared/layout/nav.ts
+++ b/web/src/shared/layout/nav.ts
@@ -25,7 +25,10 @@ import {
type LucideIcon,
Server,
UserCog,
+ UserPlus,
} from "lucide-react";
+import type { ComponentType } from "react";
+import { PendingCountBadge } from "@/features/core/access-requests/PendingCountBadge";
export type AbilityCheck = { action: string; subject: string };
@@ -37,6 +40,7 @@ export type NavItem = {
icon: LucideIcon;
group: NavGroup;
ability?: AbilityCheck;
+ badge?: ComponentType;
};
export const NAV_GROUP_LABELS: Record<NavGroup, string> = {
@@ -65,6 +69,14 @@ export const portalNav: NavItem[] = [
icon: ChartColumn,
group: "allocations",
},
+ {
+ href: "/admin/access-requests",
+ label: "Access Requests",
+ icon: UserPlus,
+ group: "admin",
+ ability: { action: "read", subject: "AccessRequest" },
+ badge: PendingCountBadge,
+ },
{
href: "/admin/users",
label: "Users & Permissions",
diff --git a/web/src/shared/users-admin/roles-catalog.ts b/web/src/shared/users-admin/roles-catalog.ts
index ff09246ce..d61dbd639 100644
--- a/web/src/shared/users-admin/roles-catalog.ts
+++ b/web/src/shared/users-admin/roles-catalog.ts
@@ -32,6 +32,8 @@ export const ROLE_SUPER_ADMIN: RoleRow = {
"amie:replies:write",
"amie:unmapped:read",
"amie:unmapped:write",
+ "core:access-requests:read",
+ "core:access-requests:write",
"core:allocations:read",
"core:allocations:write",
"core:clusters:read",
@@ -43,8 +45,6 @@ export const ROLE_SUPER_ADMIN: RoleRow = {
"core:traces:read",
"core:users:read",
"core:users:write",
- "temp-account:accounts:read",
- "temp-account:accounts:write",
],
};
export const ROLE_OPERATOR: RoleRow = {