Skip to content

Commit 97800bb

Browse files
[backport] adding namespace to permissions (#38)
Updating namespaces to permissions to use name spaced identifiers by adding the content_libraries prefix.
1 parent a0dc22c commit 97800bb

8 files changed

Lines changed: 2444 additions & 2119 deletions

File tree

package-lock.json

Lines changed: 2379 additions & 2084 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@testing-library/react": "^16.3.0",
5959
"@testing-library/user-event": "^14.6.1",
6060
"@types/react": "^18",
61-
"@types/react-dom": "^18"
61+
"@types/react-dom": "^18",
62+
"ts-jest": "^29.4.5"
6263
}
6364
}

src/authz-module/libraries-manager/LibrariesTeamManager.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useLibrary, useUpdateLibrary } from '@src/authz-module/data/hooks';
66
import { useLibraryAuthZ } from './context';
77
import LibrariesTeamManager from './LibrariesTeamManager';
88
import { ToastManagerProvider } from './ToastManagerContext';
9+
import { CONTENT_LIBRARY_PERMISSIONS } from './constants';
910

1011
jest.mock('./context', () => {
1112
const actual = jest.requireActual('./context');
@@ -71,8 +72,8 @@ describe('LibrariesTeamManager', () => {
7172
},
7273
],
7374
permissions: [
74-
{ key: 'view_library', label: 'view', resource: 'library' },
75-
{ key: 'edit_library', label: 'edit', resource: 'library' },
75+
{ key: CONTENT_LIBRARY_PERMISSIONS.VIEW_LIBRARY, label: 'view', resource: 'library' },
76+
{ key: CONTENT_LIBRARY_PERMISSIONS.EDIT_LIBRARY_COLLECTION, label: 'edit', resource: 'library' },
7677
],
7778
resources: [{ key: 'library', label: 'Library' }],
7879
canManageTeam: true,

src/authz-module/libraries-manager/components/AddNewTeamMemberModal/AddNewTeamMemberTrigger.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { act } from 'react';
22
import { screen, waitFor } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { renderWrapper } from '@src/setupTest';
@@ -360,9 +360,11 @@ describe('AddNewTeamMemberTrigger', () => {
360360
await user.click(saveButton);
361361

362362
// should now reflect isPending = true
363-
const loadingIndicator = await screen.findByTestId('loading-indicator');
364-
expect(loadingIndicator).toBeInTheDocument();
365-
expect(loadingIndicator).toHaveTextContent('Loading...');
363+
act(async () => {
364+
const loadingIndicator = await screen.findByRole('status', { name: 'Adding team member loader' });
365+
expect(loadingIndicator).toBeInTheDocument();
366+
expect(loadingIndicator).toHaveTextContent('Loading...');
367+
});
366368

367369
expect(mutateMock).toHaveBeenCalledWith(
368370
{

src/authz-module/libraries-manager/components/TeamTable/index.test.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { renderWrapper } from '@src/setupTest';
44
import { useTeamMembers } from '@src/authz-module/data/hooks';
55
import { useLibraryAuthZ } from '@src/authz-module/libraries-manager/context';
66
import { ToastManagerProvider } from '@src/authz-module/libraries-manager/ToastManagerContext';
7+
import { CONTENT_LIBRARY_PERMISSIONS } from '@src/authz-module/libraries-manager/constants';
78
import TeamTable from './index';
89

910
const mockNavigate = jest.fn();
@@ -45,9 +46,9 @@ describe('TeamTable', () => {
4546
{
4647
role: 'admin',
4748
permissions: [
48-
'delete_library',
49-
'publish_library',
50-
'manage_library_team',
49+
CONTENT_LIBRARY_PERMISSIONS.DELETE_LIBRARY,
50+
CONTENT_LIBRARY_PERMISSIONS.PUBLISH_LIBRARY_CONTENT,
51+
CONTENT_LIBRARY_PERMISSIONS.MANAGE_LIBRARY_TEAM,
5152
],
5253
userCount: 3,
5354
name: 'Admin',
@@ -56,8 +57,8 @@ describe('TeamTable', () => {
5657
{
5758
role: 'editor',
5859
permissions: [
59-
'edit_library',
60-
'publish_library',
60+
CONTENT_LIBRARY_PERMISSIONS.EDIT_LIBRARY_CONTENT,
61+
CONTENT_LIBRARY_PERMISSIONS.PUBLISH_LIBRARY_CONTENT,
6162
],
6263
userCount: 3,
6364
name: 'Editor',
@@ -66,7 +67,7 @@ describe('TeamTable', () => {
6667
{
6768
role: 'viewer',
6869
permissions: [
69-
'view_library',
70+
CONTENT_LIBRARY_PERMISSIONS.VIEW_LIBRARY,
7071
],
7172
userCount: 3,
7273
name: 'Viewer',
Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
import { PermissionMetadata, ResourceMetadata, RoleMetadata } from 'types';
22

3+
export const CONTENT_LIBRARY_PERMISSIONS = {
4+
DELETE_LIBRARY: 'content_libraries.delete_library',
5+
MANAGE_LIBRARY_TAGS: 'content_libraries.manage_library_tags',
6+
VIEW_LIBRARY: 'content_libraries.view_library',
7+
8+
EDIT_LIBRARY_CONTENT: 'content_libraries.edit_library_content',
9+
PUBLISH_LIBRARY_CONTENT: 'content_libraries.publish_library_content',
10+
REUSE_LIBRARY_CONTENT: 'content_libraries.reuse_library_content',
11+
12+
CREATE_LIBRARY_COLLECTION: 'content_libraries.create_library_collection',
13+
EDIT_LIBRARY_COLLECTION: 'content_libraries.edit_library_collection',
14+
DELETE_LIBRARY_COLLECTION: 'content_libraries.delete_library_collection',
15+
16+
MANAGE_LIBRARY_TEAM: 'content_libraries.manage_library_team',
17+
VIEW_LIBRARY_TEAM: 'content_libraries.view_library_team',
18+
};
19+
320
// Note: this information will eventually come from the backend API
421
// but for the MVP we decided to manage it in the frontend
522
export const libraryRolesMetadata: RoleMetadata[] = [
@@ -17,18 +34,18 @@ export const libraryResourceTypes: ResourceMetadata[] = [
1734
];
1835

1936
export const libraryPermissions: PermissionMetadata[] = [
20-
{ key: 'delete_library', resource: 'library', description: 'Allows the user to delete the library and all its contents.' },
21-
{ key: 'manage_library_tags', resource: 'library', description: 'Add or remove tags from content.' },
22-
{ key: 'view_library', resource: 'library', description: 'View content, search, filter, and sort within the library.' },
37+
{ key: CONTENT_LIBRARY_PERMISSIONS.DELETE_LIBRARY, resource: 'library', description: 'Allows the user to delete the library and all its contents.' },
38+
{ key: CONTENT_LIBRARY_PERMISSIONS.MANAGE_LIBRARY_TAGS, resource: 'library', description: 'Add or remove tags from content.' },
39+
{ key: CONTENT_LIBRARY_PERMISSIONS.VIEW_LIBRARY, resource: 'library', description: 'View content, search, filter, and sort within the library.' },
2340

24-
{ key: 'edit_library_content', resource: 'library_content', description: 'Edit content in draft mode' },
25-
{ key: 'publish_library_content', resource: 'library_content', description: 'Publish content, making it available for reuse' },
26-
{ key: 'reuse_library_content', resource: 'library_content', description: 'Reuse published content within a course.' },
41+
{ key: CONTENT_LIBRARY_PERMISSIONS.EDIT_LIBRARY_CONTENT, resource: 'library_content', description: 'Edit content in draft mode' },
42+
{ key: CONTENT_LIBRARY_PERMISSIONS.PUBLISH_LIBRARY_CONTENT, resource: 'library_content', description: 'Publish content, making it available for reuse' },
43+
{ key: CONTENT_LIBRARY_PERMISSIONS.REUSE_LIBRARY_CONTENT, resource: 'library_content', description: 'Reuse published content within a course.' },
2744

28-
{ key: 'create_library_collection', resource: 'library_collection', description: 'Create new collections within a library.' },
29-
{ key: 'edit_library_collection', resource: 'library_collection', description: 'Add or remove content from existing collections.' },
30-
{ key: 'delete_library_collection', resource: 'library_collection', description: 'Delete entire collections from the library.' },
45+
{ key: CONTENT_LIBRARY_PERMISSIONS.CREATE_LIBRARY_COLLECTION, resource: 'library_collection', description: 'Create new collections within a library.' },
46+
{ key: CONTENT_LIBRARY_PERMISSIONS.EDIT_LIBRARY_COLLECTION, resource: 'library_collection', description: 'Add or remove content from existing collections.' },
47+
{ key: CONTENT_LIBRARY_PERMISSIONS.DELETE_LIBRARY_COLLECTION, resource: 'library_collection', description: 'Delete entire collections from the library.' },
3148

32-
{ key: 'manage_library_team', resource: 'library_team', description: 'View the list of users who have access to the library.' },
33-
{ key: 'view_library_team', resource: 'library_team', description: 'Add, remove, and assign roles to users within the library.' },
49+
{ key: CONTENT_LIBRARY_PERMISSIONS.MANAGE_LIBRARY_TEAM, resource: 'library_team', description: 'View the list of users who have access to the library.' },
50+
{ key: CONTENT_LIBRARY_PERMISSIONS.VIEW_LIBRARY_TEAM, resource: 'library_team', description: 'Add, remove, and assign roles to users within the library.' },
3451
];

src/authz-module/libraries-manager/context.test.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useValidateUserPermissions } from '@src/data/hooks';
55
import { renderWrapper } from '@src/setupTest';
66
import { usePermissionsByRole } from '@src/authz-module/data/hooks';
77
import { CustomErrors } from '@src/constants';
8+
import { CONTENT_LIBRARY_PERMISSIONS } from './constants';
89
import { LibraryAuthZProvider, useLibraryAuthZ } from './context';
910

1011
jest.mock('react-router-dom', () => ({
@@ -15,16 +16,10 @@ jest.mock('react-router-dom', () => ({
1516
jest.mock('@src/data/hooks', () => ({
1617
useValidateUserPermissions: jest.fn(),
1718
}));
19+
20+
// Move the mock after imports and use actual values
1821
jest.mock('@src/authz-module/data/hooks', () => ({
19-
usePermissionsByRole: jest.fn().mockReturnValue({
20-
data: [
21-
{
22-
role: 'library_author',
23-
permissions: ['view_library_team', 'edit_library'],
24-
user_count: 12,
25-
},
26-
],
27-
}),
22+
usePermissionsByRole: jest.fn(),
2823
}));
2924

3025
class ErrorBoundary extends Component<{ children: ReactNode }, { hasError: boolean; error?: Error }> {
@@ -67,6 +62,14 @@ describe('LibraryAuthZProvider', () => {
6762
(useParams as jest.Mock).mockReturnValue({ libraryId: 'lib123' });
6863
(usePermissionsByRole as jest.Mock).mockReturnValue({
6964
data: [
65+
{
66+
role: 'library_author',
67+
permissions: [
68+
CONTENT_LIBRARY_PERMISSIONS.VIEW_LIBRARY_TEAM,
69+
CONTENT_LIBRARY_PERMISSIONS.EDIT_LIBRARY_CONTENT,
70+
],
71+
user_count: 12,
72+
},
7073
{
7174
role: 'instructor',
7275
description: 'Can create and edit content',

src/authz-module/libraries-manager/context.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import { useValidateUserPermissions } from '@src/data/hooks';
77
import { usePermissionsByRole } from '@src/authz-module/data/hooks';
88
import { PermissionMetadata, ResourceMetadata, Role } from 'types';
99
import { CustomErrors } from '@src/constants';
10-
import { libraryPermissions, libraryResourceTypes, libraryRolesMetadata } from './constants';
10+
import {
11+
CONTENT_LIBRARY_PERMISSIONS, libraryPermissions, libraryResourceTypes, libraryRolesMetadata,
12+
} from './constants';
1113

12-
const LIBRARY_TEAM_PERMISSIONS = ['view_library_team', 'manage_library_team'];
14+
const LIBRARY_TEAM_PERMISSIONS = [
15+
CONTENT_LIBRARY_PERMISSIONS.VIEW_LIBRARY_TEAM,
16+
CONTENT_LIBRARY_PERMISSIONS.MANAGE_LIBRARY_TEAM,
17+
];
1318

1419
export type AppContextType = {
1520
authenticatedUser: {

0 commit comments

Comments
 (0)