fix: use role insted of key for roles identifier

This commit is contained in:
Diana Olarte
2025-10-02 11:56:25 +10:00
committed by Adolfo R. Brandes
parent 6316586cc0
commit b0eaa1b035
6 changed files with 14 additions and 11 deletions

View File

@@ -9,7 +9,7 @@ export interface GetTeamMembersResponse {
}
export type PermissionsByRole = {
key: string;
role: string;
permissions: string[];
userCount: number;
};

View File

@@ -127,8 +127,8 @@ describe('useLibrary', () => {
describe('usePermissionsByRole', () => {
it('fetches roles for a given scope', async () => {
const mockRoles = [
{ key: 'admin', permissions: ['perm1'], userCount: 1 },
{ key: 'user', permissions: ['perm2'], userCount: 2 },
{ role: 'admin', permissions: ['perm1'], userCount: 1 },
{ role: 'user', permissions: ['perm2'], userCount: 2 },
];
getAuthenticatedHttpClient.mockReturnValue({

View File

@@ -3,10 +3,10 @@ import { PermissionMetadata, ResourceMetadata, RoleMetadata } from 'types';
// Note: this information will eventually come from the backend API
// but for the MVP we decided to manage it in the frontend
export const libraryRolesMetadata: RoleMetadata[] = [
{ key: 'library_admin', name: 'Library Admin', description: 'The Library Admin has full control over the library, including managing users, modifying content, and handling publishing workflows. They ensure content is properly maintained and accessible as needed.' },
{ key: 'library_author', name: 'Library Author', description: 'The Library Author is responsible for creating, editing, and publishing content within a library. They can manage tags and collections but cannot delete libraries or manage users.' },
{ key: 'library_collaborator', name: 'Library Collaborator', description: 'The Library Collaborator can create and edit content within a library but cannot publish it. They support the authoring process while leaving final publishing to Authors or Admins.' },
{ key: 'library_user', name: 'Library User', description: 'The Library User can view and reuse content but cannot edit or delete any resource.' },
{ role: 'library_admin', name: 'Library Admin', description: 'The Library Admin has full control over the library, including managing users, modifying content, and handling publishing workflows. They ensure content is properly maintained and accessible as needed.' },
{ role: 'library_author', name: 'Library Author', description: 'The Library Author is responsible for creating, editing, and publishing content within a library. They can manage tags and collections but cannot delete libraries or manage users.' },
{ role: 'library_collaborator', name: 'Library Collaborator', description: 'The Library Collaborator can create and edit content within a library but cannot publish it. They support the authoring process while leaving final publishing to Authors or Admins.' },
{ role: 'library_user', name: 'Library User', description: 'The Library User can view and reuse content but cannot edit or delete any resource.' },
];
export const libraryResourceTypes: ResourceMetadata[] = [

View File

@@ -16,7 +16,7 @@ jest.mock('@src/authz-module/data/hooks', () => ({
usePermissionsByRole: jest.fn().mockReturnValue({
data: [
{
key: 'library_author',
role: 'library_author',
permissions: [
'view_library_team',
'edit_library',

View File

@@ -51,7 +51,10 @@ export const LibraryAuthZProvider: React.FC<AuthZProviderProps> = ({ children }:
}
const { data: libraryRoles } = usePermissionsByRole(LIBRARY_AUTHZ_SCOPE);
const roles = libraryRoles.map(role => ({ ...role, ...libraryRolesMetadata.find(r => r.key === role.key) } as Role));
const roles = libraryRoles.map(role => ({
...role,
...libraryRolesMetadata.find(r => r.role === role.role),
} as Role));
const value = useMemo((): LibraryAuthZContextType => ({
username: authenticatedUser.username,

View File

@@ -1,6 +1,5 @@
export interface PermissionValidationRequest {
action: string;
object?: string;
scope?: string;
}
@@ -11,6 +10,7 @@ export interface PermissionValidationResponse extends PermissionValidationReques
// Libraries AuthZ types
export interface TeamMember {
username: string;
fullName: string;
email: string;
roles: string[];
}
@@ -23,7 +23,7 @@ export interface LibraryMetadata {
}
export interface RoleMetadata {
key: string;
role: string;
name: string;
description: string;
}