You are viewing a plain text version of this content. The canonical link for it is here.
Posted to custos@airavata.apache.org by "jayvenn21 (via GitHub)" <gi...@apache.org> on 2026/07/13 18:11:21 UTC

[PR] Wire role management tab to RBAC APIs [airavata-custos]

jayvenn21 opened a new pull request, #524:
URL: https://github.com/apache/airavata-custos/pull/524

   ## Summary
   - add a Role Management data layer for Custos RBAC role endpoints
   - wire the admin Role Management tab to list roles, load privileges/member counts, create/update roles, and add/remove role privileges
   - add MSW handlers and an e2e test for the role-management flow
   - fix existing portal compile issues in the account menu/nav and Playwright auth fixture
   
   ## Testing
   - PATH=/opt/homebrew/opt/node@22/bin:$PATH corepack pnpm typecheck
   - PATH=/opt/homebrew/opt/node@22/bin:$PATH corepack pnpm lint
   - PATH=/opt/homebrew/opt/node@22/bin:$PATH corepack pnpm test
   - PATH=/tmp/codex-pnpm-bin:/opt/homebrew/opt/node@22/bin:$PATH corepack pnpm exec playwright test tests/role-management.e2e.ts --timeout=60000
   - go test ./...
   
   Built on top of merged PR #520 and current master (#523/#521 included).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: custos-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "jayvenn21 (via GitHub)" <gi...@apache.org>.
jayvenn21 commented on PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#issuecomment-4969553884

   @lahirujayathilake  thanks for the feedback, i've made some changes with a new commit addressing the review. please take a look if there are any further changes to be made


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "lahirujayathilake (via GitHub)" <gi...@apache.org>.
lahirujayathilake commented on code in PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#discussion_r3576984738


##########
web/src/app/(portal)/admin/users/roles/PermissionMatrixEditor.tsx:
##########
@@ -17,38 +17,70 @@
 
 "use client";
 
-import { PermissionRW } from "@/shared/users-admin/PermissionRW";
+import { cn } from "@/lib/utils";
 import type { PermissionKey } from "@/shared/users-admin/permissions";
-import { rwStateFor } from "@/shared/users-admin/permissions";
+import { DEFAULT_PERMISSION_KEYS, permissionRowsFor } from "@/shared/users-admin/permissions";
+
+const ACTION_CHIP_CLASSES: Record<string, string> = {
+  read: "bg-[color:var(--tone-info-bg)] text-[color:var(--tone-info-fg)]",
+  write: "bg-[color:var(--tone-ok-bg)] text-[color:var(--tone-ok-fg)]",
+};
+const ACTION_CHIP_FALLBACK =
+  "bg-[color:var(--tone-accent-bg)] text-[color:var(--tone-accent-fg)]";
+const INACTIVE_CHIP_CLASS = "bg-muted text-muted-foreground";

Review Comment:
   `bg-muted` is the same color as the card background in dark mode



##########
web/src/app/(portal)/admin/users/roles/RoleCard.tsx:
##########
@@ -45,30 +43,19 @@ export function RoleCard({ role, memberCount }: { role: RoleRow; memberCount: nu
             <p className="mt-1 text-sm text-muted-foreground">{role.description}</p>
           </div>
           <Badge variant="secondary" className="shrink-0">
-            {memberCount} {memberCount === 1 ? "member" : "members"}
+            {role.memberCount} {role.memberCount === 1 ? "member" : "members"}
           </Badge>
         </div>
       </CardHeader>
       <CardContent className="space-y-4">
         <div className="border-t border-border" />
 
-        <div>
-          <h4 className="mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
-            Effective Privileges
-          </h4>
-          {rwPermissions.length === 0 ? (
-            <p className="text-sm text-muted-foreground">No privileges granted.</p>
-          ) : (
-            <ul className="space-y-2">
-              {rwPermissions.map((p) => (
-                <li key={p.section} className="flex items-center justify-between text-sm">
-                  <span className="font-mono text-foreground">{p.section}</span>
-                  <PermissionRW read={p.read} write={p.write} />
-                </li>
-              ))}
-            </ul>
-          )}
-        </div>
+        <PermissionMatrixEditor
+          permissions={role.privileges}
+          catalog={catalog}
+          onTogglePermission={() => undefined}
+          editable={false}
+        />

Review Comment:
   This card should only list the privileges the role grants not the entire catalog



##########
web/src/shared/users-admin/permissions.ts:
##########
@@ -15,38 +15,85 @@
 // specific language governing permissions and limitations
 // under the License.
 
-// Permission sections mirror the backend's privilege scopes (domain:resource,
-// e.g. "core:allocations"), so each section can be granted read/write
-// independently. Displayed verbatim as the effective-privilege key.
-export const PERMISSION_SECTIONS = [
-  "amie:packets",
-  "amie:replies",
-  "amie:unmapped",
-  "core:allocations",
-  "core:clusters",
-  "core:organizations",
-  "core:projects",
-  "core:traces",
-  "core:users",
-  "temp-account:accounts",
+export const DEFAULT_PERMISSION_KEYS = [

Review Comment:
   better to remove the hardcoded list instead of keeping it as a fallback. Make  GET /privileges/catalog is the only source 



##########
web/src/shared/layout/UserPill.tsx:
##########
@@ -81,7 +81,7 @@ export function UserPill() {
             onClick={() => void signOut()}
           >
             <LogOut className="mr-2 h-4 w-4" />
-            {isPending ? "Signing out…" : "Sign out"}
+            Sign out

Review Comment:
   please revert this change, this was added on purpose



##########
web/src/shared/layout/nav.ts:
##########
@@ -21,8 +21,8 @@ import {
   ClipboardList,
   FolderKanban,
   HardDrive,
-  type LucideIcon,
   Server,
+  type LucideIcon,

Review Comment:
   revert this change



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "lahirujayathilake (via GitHub)" <gi...@apache.org>.
lahirujayathilake commented on code in PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#discussion_r3591138799


##########
web/src/features/core/roles/queries.ts:
##########
@@ -0,0 +1,81 @@
+// 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 {
+  createRole,
+  listPrivilegeCatalog,
+  listRoleRows,
+  reconcileRolePrivileges,
+  updateRole,
+} from "./api";
+import type { RoleInput, RoleRow } from "./schemas";
+
+export const roleKeys = {
+  all: ["roles"] as const,
+  rows: () => [...roleKeys.all, "rows"] as const,
+  privileges: () => [...roleKeys.all, "privileges"] as const,
+};
+
+const DEFAULTS = {
+  staleTime: 30_000,
+  gcTime: 300_000,
+  refetchOnWindowFocus: false,
+} as const;
+
+export function useRoleRows() {
+  return useQuery({
+    queryKey: roleKeys.rows(),
+    queryFn: listRoleRows,
+    ...DEFAULTS,
+  });
+}
+
+export function usePrivilegeCatalog() {
+  return useQuery({
+    queryKey: roleKeys.privileges(),
+    queryFn: listPrivilegeCatalog,
+    ...DEFAULTS,
+  });
+}
+
+export function useCreateRole() {
+  const client = useQueryClient();
+  return useMutation({
+    mutationFn: async (input: RoleInput) => {
+      const role = await createRole(input);
+      if (role.id) await reconcileRolePrivileges(role.id, [], input.privileges);
+      return role;
+    },
+    onSuccess: () => client.invalidateQueries({ queryKey: roleKeys.all }),

Review Comment:
   Use `onSettled` instead. `reconcileRolePrivileges` is not atomic. Partial failures leave cache stale. 
   Valid for line 79 as well 



##########
web/src/features/core/roles/schemas.ts:
##########


Review Comment:
   Lines - 21,23,29,37
   These four already exist in features/core/identity/schemas.ts, import them instead



##########
web/src/app/(portal)/admin/users/roles/RoleCard.tsx:
##########
@@ -45,30 +42,19 @@ export function RoleCard({ role, memberCount }: { role: RoleRow; memberCount: nu
             <p className="mt-1 text-sm text-muted-foreground">{role.description}</p>
           </div>
           <Badge variant="secondary" className="shrink-0">
-            {memberCount} {memberCount === 1 ? "member" : "members"}
+            {role.memberCount} {role.memberCount === 1 ? "member" : "members"}
           </Badge>
         </div>
       </CardHeader>
       <CardContent className="space-y-4">
         <div className="border-t border-border" />
 
-        <div>
-          <h4 className="mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
-            Effective Privileges
-          </h4>
-          {rwPermissions.length === 0 ? (
-            <p className="text-sm text-muted-foreground">No privileges granted.</p>
-          ) : (
-            <ul className="space-y-2">
-              {rwPermissions.map((p) => (
-                <li key={p.section} className="flex items-center justify-between text-sm">
-                  <span className="font-mono text-foreground">{p.section}</span>
-                  <PermissionRW read={p.read} write={p.write} />
-                </li>
-              ))}
-            </ul>
-          )}
-        </div>
+        <PermissionMatrixEditor
+          permissions={role.privileges}
+          catalog={role.privileges}
+          onTogglePermission={() => undefined}
+          editable={false}

Review Comment:
   catalog is redundant here (defaults to permissions).
   Make the `onTogglePermission` optional in the `PermissionMatrixEditor` and drop it from here because read only card doesn't need a click handler
   



##########
web/tests/fixtures/auth.ts:
##########
@@ -79,6 +78,7 @@ export async function signInAs(page: Page, persona: Persona = "admin") {
     throw new Error("NEXTAUTH_SECRET must be set for the cookie-injection fixture");
   }
 
+  const { encode } = await import("next-auth/jwt");

Review Comment:
   Why dynamic import here?



##########
web/src/app/(portal)/admin/users/roles/RoleFormDialog.tsx:
##########
@@ -140,57 +125,17 @@ export function RoleFormDialog({
 
           <PermissionMatrixEditor
             permissions={permissions}
+            catalog={catalog}
             onTogglePermission={(key) => setPermissions((prev) => togglePermission(prev, key))}
           />
-
-          <div className="border-t border-border" />
-
-          <div className="space-y-2">
-            <Label htmlFor="role-user-search">Assign to users (optional)</Label>
-            <Input
-              id="role-user-search"
-              type="search"
-              value={userSearch}
-              onChange={(e) => setUserSearch(e.target.value)}
-              placeholder="Search by username or email"
-            />
-            <ul className="max-h-40 space-y-1 overflow-y-auto rounded-md border p-2">
-              {matchingUsers.length === 0 ? (
-                <li className="px-1 py-1 text-sm text-muted-foreground">No users match.</li>
-              ) : (
-                matchingUsers.map((u) => {
-                  const id = u.id ?? u.email ?? "";
-                  return (
-                    <li key={id}>
-                      <label className="flex cursor-pointer items-center gap-2 rounded-sm px-1 py-1 text-sm hover:bg-muted">
-                        <input
-                          type="checkbox"
-                          checked={selectedUserIds.has(id)}
-                          onChange={() => toggleUserSelected(id)}
-                          className="size-4 rounded border-input"
-                        />
-                        <span className="font-medium text-foreground">{fullNameFor(u)}</span>
-                        <span className="text-xs text-muted-foreground">{u.email}</span>
-                      </label>
-                    </li>
-                  );
-                })
-              )}
-            </ul>

Review Comment:
   Was dropping "Assign to users" intentional?



##########
web/src/shared/users-admin/permissions.ts:
##########
@@ -15,38 +15,69 @@
 // specific language governing permissions and limitations
 // under the License.
 
-// Permission sections mirror the backend's privilege scopes (domain:resource,
-// e.g. "core:allocations"), so each section can be granted read/write
-// independently. Displayed verbatim as the effective-privilege key.
-export const PERMISSION_SECTIONS = [
-  "amie:packets",
-  "amie:replies",
-  "amie:unmapped",
-  "core:allocations",
-  "core:clusters",
-  "core:organizations",
-  "core:projects",
-  "core:traces",
-  "core:users",
-  "temp-account:accounts",
-] as const;
-export type PermissionSection = (typeof PERMISSION_SECTIONS)[number];
-export type PermissionKey = `${PermissionSection}:read` | `${PermissionSection}:write`;
+export type PermissionKey = string;
 
-export function rwStateFor(permissions: PermissionKey[]) {
+type PermissionParts = {
+  section: string;
+  action: string;
+};
+
+function splitPermission(key: PermissionKey): PermissionParts {
+  const parts = key.split(":");
+  const action = parts.pop() ?? key;
+  return { section: parts.join(":") || key, action };
+}
+
+export function permissionRowsFor(
+  permissions: PermissionKey[],
+  catalog: readonly PermissionKey[] = permissions,
+) {
   const held = new Set(permissions);
-  return PERMISSION_SECTIONS.map((section) => ({
-    section,
-    read: held.has(`${section}:read` as PermissionKey),
-    write: held.has(`${section}:write` as PermissionKey),
+  const keys = Array.from(new Set([...catalog, ...permissions])).sort();
+  const rows = new Map<
+    string,
+    {
+      section: string;
+      actions: Array<{ action: string; key: PermissionKey; active: boolean }>;
+    }
+  >();
+
+  for (const key of keys) {
+    const { section, action } = splitPermission(key);
+    const row = rows.get(section) ?? { section, actions: [] };
+    row.actions.push({ action, key, active: held.has(key) });
+    rows.set(section, row);
+  }
+
+  return Array.from(rows.values()).map((row) => ({
+    ...row,
+    actions: row.actions.sort((a, b) => {
+      const order = ["read", "write", "grant", "manage"];

Review Comment:
   Move `order` out of the comparator.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "lahirujayathilake (via GitHub)" <gi...@apache.org>.
lahirujayathilake commented on PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#issuecomment-4991157218

   @jayvenn21 LGTM 👍🏼


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "jayvenn21 (via GitHub)" <gi...@apache.org>.
jayvenn21 commented on code in PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#discussion_r3591414788


##########
web/tests/fixtures/auth.ts:
##########
@@ -79,6 +78,7 @@ export async function signInAs(page: Page, persona: Persona = "admin") {
     throw new Error("NEXTAUTH_SECRET must be set for the cookie-injection fixture");
   }
 
+  const { encode } = await import("next-auth/jwt");

Review Comment:
   i changed the import because the JWT encoder is only needed inside the test helper when we mint the session cookie. also, there wasn’t a runtime behavior reason beyond keeping it scoped to the helper call. i can switch it back to a normal static import if preferred



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "jayvenn21 (via GitHub)" <gi...@apache.org>.
jayvenn21 commented on PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#issuecomment-4987666905

   @lahirujayathilake I've addressed all the feedback in the latest commit, please let me know if there are any further changes to be made


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "jayvenn21 (via GitHub)" <gi...@apache.org>.
jayvenn21 commented on code in PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#discussion_r3591411020


##########
web/src/app/(portal)/admin/users/roles/RoleFormDialog.tsx:
##########
@@ -140,57 +125,17 @@ export function RoleFormDialog({
 
           <PermissionMatrixEditor
             permissions={permissions}
+            catalog={catalog}
             onTogglePermission={(key) => setPermissions((prev) => togglePermission(prev, key))}
           />
-
-          <div className="border-t border-border" />
-
-          <div className="space-y-2">
-            <Label htmlFor="role-user-search">Assign to users (optional)</Label>
-            <Input
-              id="role-user-search"
-              type="search"
-              value={userSearch}
-              onChange={(e) => setUserSearch(e.target.value)}
-              placeholder="Search by username or email"
-            />
-            <ul className="max-h-40 space-y-1 overflow-y-auto rounded-md border p-2">
-              {matchingUsers.length === 0 ? (
-                <li className="px-1 py-1 text-sm text-muted-foreground">No users match.</li>
-              ) : (
-                matchingUsers.map((u) => {
-                  const id = u.id ?? u.email ?? "";
-                  return (
-                    <li key={id}>
-                      <label className="flex cursor-pointer items-center gap-2 rounded-sm px-1 py-1 text-sm hover:bg-muted">
-                        <input
-                          type="checkbox"
-                          checked={selectedUserIds.has(id)}
-                          onChange={() => toggleUserSelected(id)}
-                          className="size-4 rounded border-input"
-                        />
-                        <span className="font-medium text-foreground">{fullNameFor(u)}</span>
-                        <span className="text-xs text-muted-foreground">{u.email}</span>
-                      </label>
-                    </li>
-                  );
-                })
-              )}
-            </ul>

Review Comment:
   yes, dropping that was intentional for this PR. i kept the role dialog focused on role create/update + privilege change as assigning users to roles goes through /users/{id}/roles and feels more tied to the user-management flow. i'm happy to add it back here too if you want the role dialog to support assignment as part of this pull request



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "lahirujayathilake (via GitHub)" <gi...@apache.org>.
lahirujayathilake commented on code in PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#discussion_r3591910320


##########
web/src/app/(portal)/admin/users/roles/RoleFormDialog.tsx:
##########
@@ -140,57 +125,17 @@ export function RoleFormDialog({
 
           <PermissionMatrixEditor
             permissions={permissions}
+            catalog={catalog}
             onTogglePermission={(key) => setPermissions((prev) => togglePermission(prev, key))}
           />
-
-          <div className="border-t border-border" />
-
-          <div className="space-y-2">
-            <Label htmlFor="role-user-search">Assign to users (optional)</Label>
-            <Input
-              id="role-user-search"
-              type="search"
-              value={userSearch}
-              onChange={(e) => setUserSearch(e.target.value)}
-              placeholder="Search by username or email"
-            />
-            <ul className="max-h-40 space-y-1 overflow-y-auto rounded-md border p-2">
-              {matchingUsers.length === 0 ? (
-                <li className="px-1 py-1 text-sm text-muted-foreground">No users match.</li>
-              ) : (
-                matchingUsers.map((u) => {
-                  const id = u.id ?? u.email ?? "";
-                  return (
-                    <li key={id}>
-                      <label className="flex cursor-pointer items-center gap-2 rounded-sm px-1 py-1 text-sm hover:bg-muted">
-                        <input
-                          type="checkbox"
-                          checked={selectedUserIds.has(id)}
-                          onChange={() => toggleUserSelected(id)}
-                          className="size-4 rounded border-input"
-                        />
-                        <span className="font-medium text-foreground">{fullNameFor(u)}</span>
-                        <span className="text-xs text-muted-foreground">{u.email}</span>
-                      </label>
-                    </li>
-                  );
-                })
-              )}
-            </ul>

Review Comment:
   This is to assign a role to many users at once. If user management has that, dropping it here is the right call. Today it only does the reverse (one user, many roles), so that feature is still needed, either back here or in user management.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "lahirujayathilake (via GitHub)" <gi...@apache.org>.
lahirujayathilake commented on code in PR #524:
URL: https://github.com/apache/airavata-custos/pull/524#discussion_r3591913137


##########
web/tests/fixtures/auth.ts:
##########
@@ -79,6 +78,7 @@ export async function signInAs(page: Page, persona: Persona = "admin") {
     throw new Error("NEXTAUTH_SECRET must be set for the cookie-injection fixture");
   }
 
+  const { encode } = await import("next-auth/jwt");

Review Comment:
   better to switch it back



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Wire role management tab to RBAC APIs [airavata-custos]

Posted by "lahirujayathilake (via GitHub)" <gi...@apache.org>.
lahirujayathilake merged PR #524:
URL: https://github.com/apache/airavata-custos/pull/524


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: custos-unsubscribe@airavata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org