diff --git a/src/authz-module/role-detail/RoleDetailPage.test.tsx b/src/authz-module/role-detail/RoleDetailPage.test.tsx
index 3af224a7..36ef7faf 100644
--- a/src/authz-module/role-detail/RoleDetailPage.test.tsx
+++ b/src/authz-module/role-detail/RoleDetailPage.test.tsx
@@ -306,10 +306,9 @@ describe('RoleDetailPage', () => {
expect(screen.getByRole('tab', { name: messages['authz.custom.role.tabs.comparison'].defaultMessage, selected: true })).toBeInTheDocument();
});
- it('opens Members for #comparison on a custom role, which has no Comparison tab', () => {
+ it('opens Comparison for #comparison on a custom role', () => {
renderRoleDetail('custom-role-123', '#comparison');
- expect(screen.queryByRole('tab', { name: messages['authz.custom.role.tabs.comparison'].defaultMessage })).not.toBeInTheDocument();
- expect(screen.getByRole('tab', { name: messages['authz.custom.role.tabs.members'].defaultMessage, selected: true })).toBeInTheDocument();
+ expect(screen.getByRole('tab', { name: messages['authz.custom.role.tabs.comparison'].defaultMessage, selected: true })).toBeInTheDocument();
});
it('opens Members for an unknown hash', () => {
@@ -318,6 +317,25 @@ describe('RoleDetailPage', () => {
});
});
+ it.each([
+ ['custom', 'user_defined' as const],
+ ['built-in', 'static' as const],
+ ])('renders the Comparison tab for %s roles', (_kind, definitionKind) => {
+ mockCatalogWithRoles({ ...mockRole, definitionKind });
+ renderRoleDetail();
+ expect(screen.getByRole('tab', { name: messages['authz.custom.role.tabs.comparison'].defaultMessage })).toBeInTheDocument();
+ });
+
+ it('shows the roles and permissions matrix of the role scope type in the Comparison tab', async () => {
+ const user = userEvent.setup();
+ mockCatalogWithRoles({ ...mockRole, scopeTypes: ['lib'] });
+ renderRoleDetail();
+ await user.click(screen.getByRole('tab', { name: messages['authz.custom.role.tabs.comparison'].defaultMessage }));
+ expect(await screen.findByRole('columnheader', { name: 'Library Roles' })).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Courses' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Libraries' })).not.toBeInTheDocument();
+ });
+
it('renders Permissions tab that can be navigated to', async () => {
const user = userEvent.setup();
renderRoleDetail();
diff --git a/src/authz-module/role-detail/RoleDetailPage.tsx b/src/authz-module/role-detail/RoleDetailPage.tsx
index 63f5bef5..b02b9e14 100644
--- a/src/authz-module/role-detail/RoleDetailPage.tsx
+++ b/src/authz-module/role-detail/RoleDetailPage.tsx
@@ -20,6 +20,8 @@ import AddRoleButton from '../components/AddRoleButton';
import DuplicateRoleButton from '../components/DuplicateRoleButton';
import { useCanManageRoles } from '../hooks/useCanManageRoles';
import RoleMembersTable from './members/RoleMembersTable';
+import RolesPermissions from './permissions/RolesPermissions';
+import RolePermissionEditor from './permissions/RolePermissionEditor';
// Tab keys, also used as the URL hash that opens each tab (e.g. `#comparison`).
const ROLE_DETAIL_TABS = {
@@ -28,14 +30,11 @@ const ROLE_DETAIL_TABS = {
COMPARISON: 'comparison',
} as const;
-/**
- * The tab the URL hash asks for. Comparison only exists for built-in roles, so a custom role
- * falls back to Members, as does any other hash.
- */
-const getTabFromHash = (hash: string, isCustom: boolean) => {
+/** The tab the URL hash asks for; any other hash, or none, opens Members. */
+const getTabFromHash = (hash: string) => {
const tab = hash.replace('#', '');
if (tab === ROLE_DETAIL_TABS.PERMISSIONS) return ROLE_DETAIL_TABS.PERMISSIONS;
- if (tab === ROLE_DETAIL_TABS.COMPARISON && !isCustom) return ROLE_DETAIL_TABS.COMPARISON;
+ if (tab === ROLE_DETAIL_TABS.COMPARISON) return ROLE_DETAIL_TABS.COMPARISON;
return ROLE_DETAIL_TABS.MEMBERS;
};
@@ -155,20 +154,18 @@ const RoleDetailPage = () => {
)}
-
+
+
+
+
- {!isCustom && (
-
-
-
- )}
);
diff --git a/src/authz-module/role-detail/messages.ts b/src/authz-module/role-detail/messages.ts
index 22cb2a02..a6e012ec 100644
--- a/src/authz-module/role-detail/messages.ts
+++ b/src/authz-module/role-detail/messages.ts
@@ -86,6 +86,56 @@ const messages = defineMessages({
defaultMessage: 'No users assigned to this role',
description: 'Message displayed when the members table is empty',
},
+ 'authz.tabs.permissionsRoles.courses.alert.title': {
+ id: 'authz.tabs.permissionsRoles.courses.alert.title',
+ defaultMessage: 'Course Roles',
+ description: 'Libraries AuthZ title for the course roles alert',
+ },
+ 'authz.tabs.permissionsRoles.courses.tab': {
+ id: 'authz.tabs.permissionsRoles.courses.tab',
+ defaultMessage: 'Courses',
+ description: 'Libraries AuthZ title for the course roles tab',
+ },
+ 'authz.tabs.permissionsRoles.libraries.tab': {
+ id: 'authz.tabs.permissionsRoles.libraries.tab',
+ defaultMessage: 'Libraries',
+ description: 'Libraries AuthZ title for the libraries roles tab',
+ },
+ 'authz.tabs.permissionsRoles.libraries.tab.title': {
+ id: 'authz.tabs.permissionsRoles.libraries.tab.title',
+ defaultMessage: 'Library Roles',
+ description: 'Libraries AuthZ title for the library roles table',
+ },
+ 'authz.tabs.permissionsRoles.courses.tab.title': {
+ id: 'authz.tabs.permissionsRoles.courses.tab.title',
+ defaultMessage: 'Course Roles',
+ description: 'Libraries AuthZ title for the course roles table',
+ },
+ 'authz.tabs.permissionsRoles.courses.alert.note': {
+ id: 'authz.tabs.permissionsRoles.courses.alert.note',
+ defaultMessage: 'Note:',
+ description: 'Libraries AuthZ note for the course roles alert',
+ },
+ 'authz.tabs.permissionsRoles.courses.alert.description': {
+ id: 'authz.tabs.permissionsRoles.courses.alert.description',
+ defaultMessage: 'This list shows the permissions currently available in Authoring Studio. Some roles may grant additional permissions managed outside this interface.',
+ description: 'Libraries AuthZ description for the course roles alert',
+ },
+ 'authz.tabs.permissionsRoles.courses.alert.link': {
+ id: 'authz.tabs.permissionsRoles.courses.alert.link',
+ defaultMessage: 'See full documentation',
+ description: 'Libraries AuthZ link for the course roles alert',
+ },
+ 'authz.tabs.permissionsRoles.loading': {
+ id: 'authz.tabs.permissionsRoles.loading',
+ defaultMessage: 'Loading roles and permissions',
+ description: 'Libraries AuthZ screen reader text while the roles and permissions are loading',
+ },
+ 'authz.tabs.roleComparison.error': {
+ id: 'authz.tabs.roleComparison.error',
+ defaultMessage: 'The roles and permissions could not be loaded. Please try again later.',
+ description: 'Libraries AuthZ message shown when the roles and permissions fail to load',
+ },
});
export default messages;
diff --git a/src/authz-module/role-detail/permissions/RolePermissionEditor.tsx b/src/authz-module/role-detail/permissions/RolePermissionEditor.tsx
new file mode 100644
index 00000000..53aa8cfb
--- /dev/null
+++ b/src/authz-module/role-detail/permissions/RolePermissionEditor.tsx
@@ -0,0 +1,5 @@
+const RolePermissionEditor = () => {
+ return
;
+};
+
+export default RolePermissionEditor;
diff --git a/src/authz-module/roles-permissions/RolesPermissions.test.tsx b/src/authz-module/role-detail/permissions/RolesPermissions.test.tsx
similarity index 84%
rename from src/authz-module/roles-permissions/RolesPermissions.test.tsx
rename to src/authz-module/role-detail/permissions/RolesPermissions.test.tsx
index c0c49d9a..2adb309d 100644
--- a/src/authz-module/roles-permissions/RolesPermissions.test.tsx
+++ b/src/authz-module/role-detail/permissions/RolesPermissions.test.tsx
@@ -9,7 +9,7 @@ jest.mock('@src/authz-module/catalog/data/hooks', () => ({
useAuthzCatalog: jest.fn(),
}));
-jest.mock('../components/AnchorButton', () => function MockAnchorButton() {
+jest.mock('@src/authz-module/components/AnchorButton', () => function MockAnchorButton() {
return ;
});
@@ -71,6 +71,14 @@ describe('RolesPermissions', () => {
expect(screen.queryByText('See full documentation')).not.toBeInTheDocument();
});
+ it('shows only the given scope type, without the buttons to switch', async () => {
+ renderWithAllProviders();
+ expect(await screen.findByRole('columnheader', { name: 'Library Roles' })).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Courses' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Libraries' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('columnheader', { name: 'Course Roles' })).not.toBeInTheDocument();
+ });
+
it('shows a loading indicator while the catalog loads', () => {
mockAuthzCatalog({ isLoading: true });
renderWithAllProviders();
diff --git a/src/authz-module/roles-permissions/RolesPermissions.tsx b/src/authz-module/role-detail/permissions/RolesPermissions.tsx
similarity index 75%
rename from src/authz-module/roles-permissions/RolesPermissions.tsx
rename to src/authz-module/role-detail/permissions/RolesPermissions.tsx
index 27fab931..65a34c47 100644
--- a/src/authz-module/roles-permissions/RolesPermissions.tsx
+++ b/src/authz-module/role-detail/permissions/RolesPermissions.tsx
@@ -15,9 +15,9 @@ import AnchorButton from '@src/authz-module/components/AnchorButton';
import PermissionTable from '@src/authz-module/components/PermissionTable';
import componentMessages from '@src/authz-module/components/messages';
-import { buildPermissionMatrix } from './utils';
+import { buildPermissionMatrix } from '@src/authz-module/roles-permissions';
-import messages from './messages';
+import messages from '../messages';
// Category of the permissions the catalog sends without one.
const OTHER_CATEGORY_ID = 'other';
@@ -34,20 +34,28 @@ const SCOPE_TYPE_LABELS: Partial {
+const RolesPermissions = ({ scopeType: fixedScopeType }: RolesPermissionsProps) => {
const intl = useIntl();
// The catalog only holds the scope types the user can view.
const {
scopeTypes, getScopeCatalog, isLoading, isError,
} = useAuthzCatalog();
const [selectedScopeType, setSelectedScopeType] = useState();
- const activeScopeType = selectedScopeType ?? scopeTypes[0];
+
+ const canSwitchScopeType = !fixedScopeType;
+ const userScopeType = selectedScopeType ?? scopeTypes[0];
+ const activeScopeType = canSwitchScopeType ? userScopeType : fixedScopeType;
const scopeCatalog = activeScopeType ? getScopeCatalog(activeScopeType) : undefined;
const matrix = useMemo(() => (scopeCatalog ? buildPermissionMatrix(scopeCatalog, {
@@ -73,7 +81,7 @@ const RolesPermissions = () => {
if (isError) {
return (
- {intl.formatMessage(messages['authz.tabs.permissionsRoles.error'])}
+ {intl.formatMessage(messages['authz.tabs.roleComparison.error'])}
);
}
@@ -88,19 +96,21 @@ const RolesPermissions = () => {
return (
<>
-
-
- {scopeTypes.map((scopeType) => (
-
- ))}
-
-
+ {canSwitchScopeType && (
+
+
+ {scopeTypes.map((scopeType) => (
+
+ ))}
+
+
+ )}