You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ya...@apache.org on 2026/10/18 03:04:29 UTC
(airavata-custos) 10/12: pick role members from real users
This is an automated email from the ASF dual-hosted git repository.
yasithdev pushed a commit to branch stack-bugfixes
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit a73d2d085e1484fdff55beaa24c08f16667d4c4f
Author: Yasith Jayawardana <ya...@icloud.com>
AuthorDate: Sat Oct 17 22:52:57 2026 -0400
pick role members from real users
---
web/src/app/(portal)/admin/users/layout.tsx | 25 ++--
.../(portal)/admin/users/roles/RoleFormDialog.tsx | 9 +-
web/src/shared/users-admin/UsersAdminContext.tsx | 129 ---------------------
web/src/shared/users-admin/roles-catalog.ts | 86 --------------
web/src/shared/users-admin/seed-users.ts | 106 -----------------
web/src/shared/users-admin/types.ts | 31 -----
6 files changed, 16 insertions(+), 370 deletions(-)
diff --git a/web/src/app/(portal)/admin/users/layout.tsx b/web/src/app/(portal)/admin/users/layout.tsx
index 0e7e087b3..cdd42015b 100644
--- a/web/src/app/(portal)/admin/users/layout.tsx
+++ b/web/src/app/(portal)/admin/users/layout.tsx
@@ -16,22 +16,19 @@
// under the License.
import type { ReactNode } from "react";
-import { UsersAdminProvider } from "@/shared/users-admin/UsersAdminContext";
export default function AdminUsersLayout({ children }: { children: ReactNode }) {
return (
- <UsersAdminProvider>
- <div className="space-y-4">
- <header className="space-y-1 pb-4">
- <h1 className="font-display text-[28px] font-bold leading-tight">
- Users & Permissions
- </h1>
- <p className="text-sm text-muted-foreground">
- Manage user accounts, roles, and the permissions each role grants.
- </p>
- </header>
- {children}
- </div>
- </UsersAdminProvider>
+ <div className="space-y-4">
+ <header className="space-y-1 pb-4">
+ <h1 className="font-display text-[28px] font-bold leading-tight">
+ Users & Permissions
+ </h1>
+ <p className="text-sm text-muted-foreground">
+ Manage user accounts, roles, and the permissions each role grants.
+ </p>
+ </header>
+ {children}
+ </div>
);
}
diff --git a/web/src/app/(portal)/admin/users/roles/RoleFormDialog.tsx b/web/src/app/(portal)/admin/users/roles/RoleFormDialog.tsx
index 2ac222df5..8ee77a04c 100644
--- a/web/src/app/(portal)/admin/users/roles/RoleFormDialog.tsx
+++ b/web/src/app/(portal)/admin/users/roles/RoleFormDialog.tsx
@@ -21,6 +21,8 @@ import * as React from "react";
import { toast } from "sonner";
import { useCreateRole, usePrivilegeCatalog, useUpdateRole } from "@/features/core/roles/queries";
import type { RoleRow } from "@/features/core/roles/schemas";
+import { useUsers } from "@/features/core/users/queries";
+import type { User } from "@/generated/core/zod.gen";
import { Button } from "@/shared/ui/button";
import {
Dialog,
@@ -35,11 +37,9 @@ import { Input } from "@/shared/ui/input";
import { Label } from "@/shared/ui/label";
import { togglePermission } from "@/shared/users-admin/permissions";
import type { PermissionKey } from "@/shared/users-admin/permissions";
-import { useUsersAdmin } from "@/shared/users-admin/UsersAdminContext";
-import type { UserRow } from "@/shared/users-admin/types";
import { PermissionMatrixEditor } from "./PermissionMatrixEditor";
-function fullNameFor(user: UserRow): string {
+function fullNameFor(user: User): string {
const name = [user.first_name, user.last_name].filter(Boolean).join(" ");
return name || user.email || "Unknown user";
}
@@ -58,7 +58,7 @@ export function RoleFormDialog({
const catalogQuery = usePrivilegeCatalog();
const createRole = useCreateRole();
const updateRole = useUpdateRole();
- const { users } = useUsersAdmin();
+ const usersQuery = useUsers({ limit: 200 });
const [open, setOpen] = React.useState(false);
const [name, setName] = React.useState("");
const [description, setDescription] = React.useState("");
@@ -106,6 +106,7 @@ export function RoleFormDialog({
const saving = createRole.isPending || updateRole.isPending;
const catalog = catalogQuery.data ?? [];
+ const users = usersQuery.data?.items ?? [];
const needle = userSearch.trim().toLowerCase();
const matchingUsers = needle
? users.filter((u) => `${fullNameFor(u)} ${u.email}`.toLowerCase().includes(needle))
diff --git a/web/src/shared/users-admin/UsersAdminContext.tsx b/web/src/shared/users-admin/UsersAdminContext.tsx
deleted file mode 100644
index 15ab99cc6..000000000
--- a/web/src/shared/users-admin/UsersAdminContext.tsx
+++ /dev/null
@@ -1,129 +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 type { PermissionKey } from "./permissions";
-import { INITIAL_ROLES } from "./roles-catalog";
-import { INITIAL_USERS } from "./seed-users";
-import type { RoleRow, UserRow } from "./types";
-
-export type RoleInput = {
- name: string;
- description: string;
- permissions: PermissionKey[];
-};
-
-type UsersAdminContextValue = {
- users: UserRow[];
- roles: RoleRow[];
- toggleUserRole: (userId: string, roleId: string) => void;
- addRole: (input: RoleInput, memberUserIds: string[]) => void;
- updateRole: (roleId: string, input: RoleInput, memberUserIds: string[]) => void;
-};
-
-const UsersAdminContext = React.createContext<UsersAdminContextValue | null>(null);
-
-let nextRoleSuffix = 1;
-
-export function UsersAdminProvider({ children }: { children: React.ReactNode }) {
- const [users, setUsers] = React.useState<UserRow[]>(INITIAL_USERS);
- const [roles, setRoles] = React.useState<RoleRow[]>(INITIAL_ROLES);
-
- function toggleUserRole(userId: string, roleId: string) {
- const role = roles.find((r) => r.id === roleId);
- if (!role) return;
- setUsers((prev) =>
- prev.map((user) => {
- if (user.id !== userId) return user;
- const hasRole = user.roles.some((r) => r.id === roleId);
- const nextRoles = hasRole
- ? user.roles.filter((r) => r.id !== roleId)
- : [...user.roles, role];
- return { ...user, roles: nextRoles };
- }),
- );
- }
-
- function addRole(input: RoleInput, memberUserIds: string[]) {
- const role: RoleRow = {
- id: `role-custom-${nextRoleSuffix++}`,
- name: input.name,
- description: input.description,
- is_system: false,
- created_at: new Date().toISOString(),
- permissions: input.permissions,
- };
- setRoles((prev) => [...prev, role]);
- if (memberUserIds.length > 0) {
- const memberSet = new Set(memberUserIds);
- setUsers((prev) =>
- prev.map((user) =>
- user.id && memberSet.has(user.id) ? { ...user, roles: [...user.roles, role] } : user,
- ),
- );
- }
- }
-
- // Role objects are embedded (by value) into each user's `roles` array
- // rather than referenced by id, mirroring how the table/drawer render
- // them — so updating a role here must also refresh the copy held by every
- // member, add it to newly-assigned members, and drop it from anyone
- // deselected.
- function updateRole(roleId: string, input: RoleInput, memberUserIds: string[]) {
- const existing = roles.find((r) => r.id === roleId);
- const updated: RoleRow = {
- id: roleId,
- name: input.name,
- description: input.description,
- is_system: existing?.is_system ?? false,
- created_at: existing?.created_at ?? new Date().toISOString(),
- permissions: input.permissions,
- };
- setRoles((prev) => prev.map((r) => (r.id === roleId ? updated : r)));
- const memberSet = new Set(memberUserIds);
- setUsers((prev) =>
- prev.map((user) => {
- const hasRole = user.roles.some((r) => r.id === roleId);
- const shouldHaveRole = Boolean(user.id) && memberSet.has(user.id);
- if (shouldHaveRole) {
- const nextRoles = hasRole
- ? user.roles.map((r) => (r.id === roleId ? updated : r))
- : [...user.roles, updated];
- return { ...user, roles: nextRoles };
- }
- if (hasRole) {
- return { ...user, roles: user.roles.filter((r) => r.id !== roleId) };
- }
- return user;
- }),
- );
- }
-
- return (
- <UsersAdminContext.Provider value={{ users, roles, toggleUserRole, addRole, updateRole }}>
- {children}
- </UsersAdminContext.Provider>
- );
-}
-
-export function useUsersAdmin(): UsersAdminContextValue {
- const ctx = React.useContext(UsersAdminContext);
- if (!ctx) throw new Error("useUsersAdmin must be used within UsersAdminProvider");
- return ctx;
-}
diff --git a/web/src/shared/users-admin/roles-catalog.ts b/web/src/shared/users-admin/roles-catalog.ts
deleted file mode 100644
index 798f705d8..000000000
--- a/web/src/shared/users-admin/roles-catalog.ts
+++ /dev/null
@@ -1,86 +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 { RoleRow } from "./types";
-
-// Seed roles for the mock portal. Permissions are granted per left-nav
-// section (see permissions.ts) — source once a real "list roles" call backs
-// this page: GET /roles + GET /roles/{id}.
-export const ROLE_SUPER_ADMIN: RoleRow = {
- id: "role-super-admin",
- name: "Super Admin",
- description: "Full administrative access across the portal.",
- is_system: true,
- created_at: "2026-01-15T09:00:00Z",
- permissions: [
- "amie:packets:read",
- "amie:packets:write",
- "amie:replies:read",
- "amie:replies:write",
- "amie:unmapped:read",
- "amie:unmapped:write",
- "core:allocations:read",
- "core:allocations:write",
- "core:clusters:read",
- "core:clusters:write",
- "core:organizations:read",
- "core:organizations:write",
- "core:projects:read",
- "core:projects:write",
- "core:traces:read",
- "core:users:read",
- "core:users:write",
- "temp-account:accounts:read",
- "temp-account:accounts:write",
- ],
-};
-export const ROLE_OPERATOR: RoleRow = {
- id: "role-operator",
- name: "Operator",
- description: "Day-to-day allocation, project, and AMIE operations (read + write).",
- is_system: false,
- created_at: "2026-01-15T09:00:00Z",
- permissions: [
- "amie:packets:read",
- "amie:packets:write",
- "amie:replies:read",
- "amie:replies:write",
- "amie:unmapped:read",
- "amie:unmapped:write",
- "core:allocations:read",
- "core:allocations:write",
- "core:projects:read",
- "core:projects:write",
- ],
-};
-export const ROLE_AUDITOR: RoleRow = {
- id: "role-auditor",
- name: "Auditor",
- description: "Read-only access across allocations, projects, tracing, and AMIE.",
- is_system: false,
- created_at: "2026-01-15T09:00:00Z",
- permissions: [
- "core:allocations:read",
- "core:projects:read",
- "core:traces:read",
- "amie:packets:read",
- "amie:replies:read",
- "amie:unmapped:read",
- ],
-};
-
-export const INITIAL_ROLES: RoleRow[] = [ROLE_SUPER_ADMIN, ROLE_OPERATOR, ROLE_AUDITOR];
diff --git a/web/src/shared/users-admin/seed-users.ts b/web/src/shared/users-admin/seed-users.ts
deleted file mode 100644
index 47545645f..000000000
--- a/web/src/shared/users-admin/seed-users.ts
+++ /dev/null
@@ -1,106 +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 { UserIdentity } from "@/generated/core/types.gen";
-import { ROLE_AUDITOR, ROLE_OPERATOR, ROLE_SUPER_ADMIN } from "./roles-catalog";
-import type { UserRow } from "./types";
-
-function identity(
- user_id: string,
- source: string,
- external_id: string,
- email?: string,
-): UserIdentity {
- return {
- id: `${user_id}-${source}`,
- user_id,
- source,
- external_id,
- ...(email === undefined ? {} : { email }),
- created_at: "2026-01-15T09:00:00Z",
- };
-}
-
-export const INITIAL_USERS: UserRow[] = [
- {
- id: "u1",
- first_name: "Dev",
- last_name: "Admin",
- email: "admin@custos.local",
- organization_id: "msw-org",
- type: "CLUSTER_LOCAL",
- status: "ACTIVE",
- roles: [ROLE_SUPER_ADMIN, ROLE_OPERATOR, ROLE_AUDITOR],
- identities: [
- identity("u1", "access", "dev-admin-access-001", "admin@access-ci.org"),
- identity("u1", "cilogon", "cilogon-uid-1001", "admin@cilogon.org"),
- identity("u1", "orcid", "0000-0001-1111-0001"),
- identity("u1", "nairr", "nairr-uid-1001"),
- ],
- },
- {
- id: "u2",
- first_name: "Rachel",
- last_name: "Gao",
- email: "rgao@access-ci.org",
- organization_id: "msw-org",
- type: "CLUSTER_LOCAL",
- status: "ACTIVE",
- roles: [ROLE_OPERATOR],
- identities: [
- identity("u2", "access", "rgao-access-001", "rgao@access-ci.org"),
- identity("u2", "orcid", "0000-0002-1825-0097"),
- ],
- },
- {
- id: "u3",
- first_name: "James",
- last_name: "Okonkwo",
- email: "jokonkwo@university.edu",
- organization_id: "msw-org",
- type: "CLUSTER_LOCAL",
- status: "ACTIVE",
- roles: [ROLE_AUDITOR],
- identities: [identity("u3", "cilogon", "cilogon-uid-3003", "jokonkwo@cilogon.org")],
- },
- {
- id: "u4",
- first_name: "Priya",
- last_name: "Sharma",
- email: "psharma@hpc-lab.org",
- organization_id: "msw-org",
- type: "CLUSTER_LOCAL",
- status: "SUSPENDED",
- roles: [ROLE_OPERATOR, ROLE_AUDITOR],
- identities: [
- identity("u4", "access", "psharma-access-004", "psharma@hpc-lab.org"),
- identity("u4", "cilogon", "cilogon-uid-4004"),
- identity("u4", "nairr", "nairr-uid-4004"),
- ],
- },
- {
- id: "u5",
- first_name: "Daniel",
- last_name: "Wu",
- email: "dwu@custos-hpc.io",
- organization_id: "msw-org",
- type: "CLUSTER_LOCAL",
- status: "INACTIVE",
- identities: [],
- roles: [],
- },
-];
diff --git a/web/src/shared/users-admin/types.ts b/web/src/shared/users-admin/types.ts
deleted file mode 100644
index 64b484c3b..000000000
--- a/web/src/shared/users-admin/types.ts
+++ /dev/null
@@ -1,31 +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 { Role, User, UserIdentity } from "@/generated/core/types.gen";
-import type { PermissionKey } from "./permissions";
-
-export type RoleRow = Role & { permissions: PermissionKey[] };
-
-// Shaped to match GET /users/{id} (User), joined with the roles resolved
-// from GET /users/{id}/roles + GET /roles, and the linked accounts from
-// GET /users/{id}/user-identities — a stand-in for a future "list users"
-// endpoint that returns this view directly. Effective permissions are
-// derived from the union of the user's roles rather than tracked per-user.
-export type UserRow = User & {
- roles: RoleRow[];
- identities: UserIdentity[];
-};