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/13 23:44:37 UTC
(airavata-custos) branch me-roles updated: Show the roles in the user's settings page
This is an automated email from the ASF dual-hosted git repository.
lahirujayathilake pushed a commit to branch me-roles
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
The following commit(s) were added to refs/heads/me-roles by this push:
new f3eafbd91 Show the roles in the user's settings page
f3eafbd91 is described below
commit f3eafbd91cd530559d9eeb51d1d15b4607908036
Author: lahiruj <la...@gmail.com>
AuthorDate: Mon Jul 13 19:44:29 2026 -0400
Show the roles in the user's settings page
---
web/src/features/core/identity/api.ts | 5 +--
.../core/identity/components/AccessCard.tsx | 17 +++-------
.../core/identity/components/SettingsPage.tsx | 2 +-
.../components/__tests__/AccessCard.test.tsx | 26 ++++++++++++++-
web/src/features/core/identity/queries.ts | 37 +++++++++++++++++-----
web/src/features/core/identity/schemas.ts | 16 +++++++++-
web/src/generated/core/index.ts | 2 +-
web/src/generated/core/sdk.gen.ts | 4 ++-
web/src/generated/core/types.gen.ts | 7 ++++
web/src/generated/core/zod.gen.ts | 9 ++++++
web/src/mocks/handlers/identity.ts | 13 +++++++-
11 files changed, 110 insertions(+), 28 deletions(-)
diff --git a/web/src/features/core/identity/api.ts b/web/src/features/core/identity/api.ts
index 13933f09f..118df395c 100644
--- a/web/src/features/core/identity/api.ts
+++ b/web/src/features/core/identity/api.ts
@@ -26,6 +26,7 @@ import {
userSchema,
} from "./schemas";
import type {
+ CallerRoleGrant,
RoleWithPrivileges,
UserIdentity,
UserNameUpdate,
@@ -39,11 +40,11 @@ export async function getPrivileges(): Promise<Privilege[]> {
return privilegesResponseSchema.parse(raw);
}
-export type Me = { user: UserProfile; privileges: Privilege[] };
+export type Me = { user: UserProfile; privileges: Privilege[]; roles: CallerRoleGrant[] };
export async function getMe(): Promise<Me> {
const parsed = meResponseSchema.parse(await apiFetch("/me"));
- return { user: parsed.user, privileges: parsed.privileges ?? [] };
+ return { user: parsed.user, privileges: parsed.privileges ?? [], roles: parsed.roles };
}
export async function getMyIdentities(userId: string): Promise<UserIdentity[]> {
diff --git a/web/src/features/core/identity/components/AccessCard.tsx b/web/src/features/core/identity/components/AccessCard.tsx
index 424ac9ec3..87cd1ed37 100644
--- a/web/src/features/core/identity/components/AccessCard.tsx
+++ b/web/src/features/core/identity/components/AccessCard.tsx
@@ -68,18 +68,11 @@ export function AccessCard({ access }: { access: MyAccess }) {
<div className="grid grid-cols-1 border-t border-border md:grid-cols-2">
<section className="px-6 py-5 md:border-r md:border-border">
<h4 className={columnHeading}>Roles</h4>
- {access.provenance ? (
- <RolesColumn
- roles={access.roles}
- activeRole={activeRole}
- onHover={setActiveRole}
- />
- ) : (
- <p className="text-sm text-muted-foreground">
- Role details are not visible with your current access. Your effective
- privileges are listed on the right.
- </p>
- )}
+ <RolesColumn
+ roles={access.roles}
+ activeRole={activeRole}
+ onHover={setActiveRole}
+ />
</section>
<section className="border-t border-border px-6 py-5 md:border-t-0">
diff --git a/web/src/features/core/identity/components/SettingsPage.tsx b/web/src/features/core/identity/components/SettingsPage.tsx
index 77d86d77d..83cb12dc6 100644
--- a/web/src/features/core/identity/components/SettingsPage.tsx
+++ b/web/src/features/core/identity/components/SettingsPage.tsx
@@ -31,7 +31,7 @@ export function SettingsPage() {
// session.user.id may be an email fallback.
const userId = me.data?.user.id;
const identities = useMyIdentities(userId);
- const access = useMyAccess(userId, me.data?.privileges ?? []);
+ const access = useMyAccess(userId, me.data?.privileges ?? [], me.data?.roles ?? []);
return (
<div className="mx-auto w-full max-w-[1080px] px-6 py-8">
diff --git a/web/src/features/core/identity/components/__tests__/AccessCard.test.tsx b/web/src/features/core/identity/components/__tests__/AccessCard.test.tsx
index b1c0c9449..7235fc4a4 100644
--- a/web/src/features/core/identity/components/__tests__/AccessCard.test.tsx
+++ b/web/src/features/core/identity/components/__tests__/AccessCard.test.tsx
@@ -105,10 +105,34 @@ describe("AccessCard", () => {
}}
/>,
);
- expect(screen.getByText(/role details are not visible/i)).toBeInTheDocument();
+ expect(screen.getByText(/no roles assigned/i)).toBeInTheDocument();
expect(screen.getByText("core:users")).toBeInTheDocument();
expect(screen.getByText("amie:packets")).toBeInTheDocument();
// Never claim "Direct grant" without the provenance data.
expect(screen.queryByText("Direct grant")).not.toBeInTheDocument();
});
+
+ it("lists held roles with attribution even without provenance", () => {
+ render(
+ <AccessCard
+ access={{
+ provenance: false,
+ roles: [
+ {
+ role: { id: "role-reviewer", name: "Reviewer", description: "Reads reports." },
+ privileges: ["core:users:read"],
+ grant: { role_id: "role-reviewer", granted_at: "2026-07-01T09:00:00Z" },
+ },
+ ],
+ direct: [],
+ privileges: ["core:users:read", "core:traces:read"],
+ }}
+ />,
+ );
+ expect(roleCard("role-reviewer")).toHaveTextContent("Reviewer");
+ expect(roleCard("role-reviewer")).toHaveTextContent("Granted");
+ expect(rowFor("core:users")).toHaveTextContent("Reviewer");
+ // A key not carried by any visible role must not claim "Direct grant".
+ expect(rowFor("core:traces")).not.toHaveTextContent("Direct grant");
+ });
});
diff --git a/web/src/features/core/identity/queries.ts b/web/src/features/core/identity/queries.ts
index 4e2d3e58f..adb0d451c 100644
--- a/web/src/features/core/identity/queries.ts
+++ b/web/src/features/core/identity/queries.ts
@@ -28,7 +28,12 @@ import {
updateMyName,
} from "./api";
import { privilegesResponseSchema } from "./schemas";
-import type { RoleWithPrivileges, UserNameUpdate, UserPrivilege } from "./schemas";
+import type {
+ CallerRoleGrant,
+ RoleWithPrivileges,
+ UserNameUpdate,
+ UserPrivilege,
+} from "./schemas";
import type { CurrentUser, Privilege } from "./types";
export const identityKeys = {
@@ -95,22 +100,38 @@ export type MyAccess = {
roles: RoleWithPrivileges[];
direct: UserPrivilege[];
privileges: Privilege[];
- // False when the caller lacks the role/privilege read gates; the card then
- // shows effective privileges without provenance.
+ // False when the caller lacks the admin read gates; the card then never
+ // labels a privilege row "Direct grant".
provenance: boolean;
};
-// The roles and grants reads are admin-gated; run them only when the caller's
-// own privileges imply access. Everyone still gets the effective set from /me.
-export function useMyAccess(userId: string | undefined, effective: Privilege[]) {
+// Direct-grant reads are admin-gated; without them roles come from /me and
+// unattributed keys stay unlabeled instead of claiming "Direct grant".
+export function useMyAccess(
+ userId: string | undefined,
+ effective: Privilege[],
+ heldRoles: CallerRoleGrant[],
+) {
const provenance =
effective.includes("core:roles:manage") && effective.includes("core:privileges:grant");
+ const heldKey = heldRoles.map((g) => g.role.id ?? "").join(",");
return useQuery({
queryKey: userId
- ? [...identityKeys.access(userId), provenance]
+ ? [...identityKeys.access(userId), provenance, heldKey]
: [...identityKeys.all, "access", "none"],
queryFn: async (): Promise<MyAccess> => {
- if (!provenance) return { roles: [], direct: [], privileges: effective, provenance };
+ if (!provenance) {
+ const roles = heldRoles.map((g) => ({
+ role: g.role,
+ privileges: g.privileges,
+ grant: {
+ user_id: userId as string,
+ role_id: g.role.id ?? "",
+ granted_at: g.granted_at,
+ },
+ }));
+ return { roles, direct: [], privileges: effective, provenance };
+ }
const [roles, direct] = await Promise.all([
getMyRolesWithPrivileges(userId as string),
getMyDirectPrivileges(userId as string),
diff --git a/web/src/features/core/identity/schemas.ts b/web/src/features/core/identity/schemas.ts
index 05cbf9b5b..31e2f147f 100644
--- a/web/src/features/core/identity/schemas.ts
+++ b/web/src/features/core/identity/schemas.ts
@@ -54,10 +54,23 @@ export const privilegesResponseSchema = callerPrivilegesSchema.transform(
(value) => value.privileges ?? [],
);
-// GET /me — profile plus effective privilege keys.
+export const callerRoleGrantSchema = z.object({
+ role: zRole,
+ privileges: z
+ .array(privilegeKeySchema)
+ .nullish()
+ .transform((value) => value ?? []),
+ granted_at: z.string(),
+});
+
+// GET /me: profile plus effective privilege keys and held roles.
export const meResponseSchema = z.object({
user: zUser,
privileges: z.array(privilegeKeySchema).optional(),
+ roles: z
+ .array(callerRoleGrantSchema)
+ .nullish()
+ .transform((value) => value ?? []),
});
// Backend may send null instead of [] for empty lists; tolerate it.
@@ -94,4 +107,5 @@ export type UserIdentity = z.infer<typeof zUserIdentity>;
export type UserRole = z.infer<typeof userRoleSchema>;
export type UserPrivilege = z.infer<typeof userPrivilegeSchema>;
export type RoleWithPrivileges = z.infer<typeof roleWithPrivilegesSchema>;
+export type CallerRoleGrant = z.infer<typeof callerRoleGrantSchema>;
export type UserNameUpdate = z.infer<typeof userNameUpdateSchema>;
diff --git a/web/src/generated/core/index.ts b/web/src/generated/core/index.ts
index 609051d12..d5a9089f4 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, ClientOptions, ComputeAllocation, ComputeAllocationChangeRequest, ComputeAllocationChangeRequestEvent, ComputeAllocationDiff, ComputeAllocationListResponse, ComputeAllocationMembership, ComputeAllocationMembershipResourceOverride, ComputeAllocationResource, ComputeAllocationResourceMapping, ComputeAllocationResourceRate, ComputeAllocationResourceSummary, [...]
+export type { AllocationMembershipResponse, AllocationStatus, AllocationSuTotalResponse, AttachResourceRequest, CallerProfileResponse, CallerRoleGrant, ClientOptions, ComputeAllocation, ComputeAllocationChangeRequest, ComputeAllocationChangeRequestEvent, ComputeAllocationDiff, ComputeAllocationListResponse, ComputeAllocationMembership, ComputeAllocationMembershipResourceOverride, ComputeAllocationResource, ComputeAllocationResourceMapping, ComputeAllocationResourceRate, ComputeAllocation [...]
diff --git a/web/src/generated/core/sdk.gen.ts b/web/src/generated/core/sdk.gen.ts
index 5c476e63f..d1f0baef9 100644
--- a/web/src/generated/core/sdk.gen.ts
+++ b/web/src/generated/core/sdk.gen.ts
@@ -663,7 +663,9 @@ export const getComputeClustersByIdUsersByUserId = <ThrowOnError extends boolean
});
/**
- * Get the caller's user record and effective privileges
+ * Get the caller's user record, effective privileges, and roles
+ *
+ * Roles are the caller's own grants; unlike /users/{id}/roles this needs no admin privilege.
*/
export const getMe = <ThrowOnError extends boolean = false>(options?: Options<GetMeData, ThrowOnError>): RequestResult<GetMeResponses, GetMeErrors, ThrowOnError> => (options?.client ?? client).get<GetMeResponses, GetMeErrors, 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 8ac6d5f35..4c23caf38 100644
--- a/web/src/generated/core/types.gen.ts
+++ b/web/src/generated/core/types.gen.ts
@@ -28,9 +28,16 @@ export type AllocationStatus = 'ACTIVE' | 'INACTIVE' | 'DELETED';
export type CallerProfileResponse = {
privileges?: Array<PrivilegeKey>;
+ roles?: Array<CallerRoleGrant>;
user?: User;
};
+export type CallerRoleGrant = {
+ granted_at?: string;
+ privileges?: Array<PrivilegeKey>;
+ role?: Role;
+};
+
export type ComputeAllocation = {
/**
* The ID of the compute cluster where the allocation is provisioned.
diff --git a/web/src/generated/core/zod.gen.ts b/web/src/generated/core/zod.gen.ts
index 898f0518c..959dbf89d 100644
--- a/web/src/generated/core/zod.gen.ts
+++ b/web/src/generated/core/zod.gen.ts
@@ -287,6 +287,14 @@ export const zRole = z.object({
export type roleZodType = z.infer<typeof zRole>;
+export const zCallerRoleGrant = z.object({
+ granted_at: z.string().optional(),
+ privileges: z.array(zPrivilegeKey).optional(),
+ role: zRole.optional()
+});
+
+export type callerRoleGrantZodType = z.infer<typeof zCallerRoleGrant>;
+
export const zTraceEvent = z.object({
created_at: z.string().optional(),
description: z.string().optional(),
@@ -403,6 +411,7 @@ export type userZodType = z.infer<typeof zUser>;
export const zCallerProfileResponse = z.object({
privileges: z.array(zPrivilegeKey).optional(),
+ roles: z.array(zCallerRoleGrant).optional(),
user: zUser.optional()
});
diff --git a/web/src/mocks/handlers/identity.ts b/web/src/mocks/handlers/identity.ts
index 0fd9d2c73..9ad87ec55 100644
--- a/web/src/mocks/handlers/identity.ts
+++ b/web/src/mocks/handlers/identity.ts
@@ -27,7 +27,18 @@ let user = { ...fixture.user };
export const identityHandlers = [
http.get("*/api/v1/me", () =>
- HttpResponse.json({ user, privileges: effectivePrivileges() }),
+ HttpResponse.json({
+ user,
+ privileges: effectivePrivileges(),
+ roles: fixture.roles.flatMap((grant) => {
+ const detail = (fixture.roleDetails as Record<string, RoleDetail | undefined>)[
+ grant.role_id
+ ];
+ return detail?.role
+ ? [{ role: detail.role, privileges: detail.privileges, granted_at: grant.granted_at }]
+ : [];
+ }),
+ }),
),
http.get("*/api/v1/users/:id/user-identities", () =>
HttpResponse.json(fixture.identities),