Skip to content

Commit e67c47f

Browse files
committed
feat: refactor Assign Role Wizard and related components for improved clarity and structure
1 parent bf1004c commit e67c47f

3 files changed

Lines changed: 21 additions & 41 deletions

File tree

src/authz-module/roles-permissions/libraries/constants.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ export const CONTENT_LIBRARY_PERMISSIONS = {
2626
// Note: this information will eventually come from the backend API
2727
// but for the MVP we decided to manage it in the frontend
2828
export const libraryRolesMetadata: RoleMetadata[] = [
29-
{ 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.', contextType: 'library' },
30-
{ 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.', contextType: 'library' },
31-
{ role: 'library_contributor', name: 'Library Contributor', description: 'The Library Contributor 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.', contextType: 'library' },
32-
{ role: 'library_user', name: 'Library User', description: 'The Library User can view and reuse content but cannot edit or delete any resource.', contextType: 'library' },
29+
{
30+
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.', contextType: 'library',
31+
},
32+
{
33+
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.', contextType: 'library',
34+
},
35+
{
36+
role: 'library_contributor', name: 'Library Contributor', description: 'The Library Contributor 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.', contextType: 'library',
37+
},
38+
{
39+
role: 'library_user', name: 'Library User', description: 'The Library User can view and reuse content but cannot edit or delete any resource.', contextType: 'library',
40+
},
3341
];
3442

3543
export const libraryResourceTypes: ResourceMetadata[] = [

src/authz-module/wizard/AssignRoleWizard.tsx

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
useState, useCallback, useMemo, useRef, useEffect,
2+
useState, useCallback, useRef, useEffect,
33
} from 'react';
44
import { useIntl } from '@edx/frontend-platform/i18n';
55
import {
@@ -9,18 +9,12 @@ import { SpinnerSimple } from '@openedx/paragon/icons';
99
import SelectUsersAndRoleStep from './SelectUsersAndRoleStep';
1010
import DefineApplicationScopeStep from './DefineApplicationScopeStep';
1111
import { useValidateUsers } from '../data/hooks';
12-
import { CONTENT_LIBRARY_PERMISSIONS, libraryRolesMetadata } from '../roles-permissions/libraries/constants';
13-
import { COURSE_PERMISSIONS, courseRolesMetadata } from '../constants';
14-
import { useValidateUserPermissions } from '../../data/hooks';
12+
import { libraryRolesMetadata } from '../roles-permissions/libraries/constants';
13+
import { courseRolesMetadata } from '../constants';
1514
import messages from './messages';
1615

1716
const allRolesMetadata = [...courseRolesMetadata, ...libraryRolesMetadata];
1817

19-
const CONTEXT_BY_ACTION: Record<string, string> = {
20-
[CONTENT_LIBRARY_PERMISSIONS.MANAGE_LIBRARY_TEAM]: 'library',
21-
[COURSE_PERMISSIONS.MANAGE_COURSE_TEAM]: 'course',
22-
};
23-
2418
const STEPS = {
2519
SELECT_USERS_AND_ROLE: 'select-users-and-role',
2620
DEFINE_APPLICATION_SCOPE: 'define-application-scope',
@@ -30,11 +24,10 @@ type StepKey = typeof STEPS[keyof typeof STEPS];
3024

3125
interface AssignRoleWizardProps {
3226
onClose: () => void;
33-
scope: string;
3427
initialUsers?: string;
3528
}
3629

37-
const AssignRoleWizard = ({ onClose, scope, initialUsers = '' }: AssignRoleWizardProps) => {
30+
const AssignRoleWizard = ({ onClose, initialUsers = '' }: AssignRoleWizardProps) => {
3831
const intl = useIntl();
3932
const [activeStep, setActiveStep] = useState<StepKey>(STEPS.SELECT_USERS_AND_ROLE);
4033
const [users, setUsers] = useState(initialUsers);
@@ -49,29 +42,11 @@ const AssignRoleWizard = ({ onClose, scope, initialUsers = '' }: AssignRoleWizar
4942

5043
const validateUsersMutation = useValidateUsers();
5144

52-
// Filter role groups based on what the current user is allowed to manage
53-
const permissionChecks = useMemo(() => [
54-
{ action: CONTENT_LIBRARY_PERMISSIONS.MANAGE_LIBRARY_TEAM, scope },
55-
{ action: COURSE_PERMISSIONS.MANAGE_COURSE_TEAM, scope },
56-
], [scope]);
57-
58-
const { data: permissionsData } = useValidateUserPermissions(permissionChecks);
59-
6045
const handleUsersChange = useCallback((value: string) => {
6146
setInvalidUsers((prev) => (prev.length > 0 ? [] : prev));
6247
setUsers(value);
6348
}, []);
6449

65-
const filteredRoles = useMemo(() => {
66-
const allowedContextTypes = new Set(
67-
permissionsData
68-
.filter((p) => p.allowed)
69-
.map((p) => CONTEXT_BY_ACTION[p.action])
70-
.filter(Boolean),
71-
);
72-
return allRolesMetadata.filter((r) => allowedContextTypes.has(r.contextType || ''));
73-
}, [permissionsData]);
74-
7550
const handleClose = () => {
7651
setActiveStep(STEPS.SELECT_USERS_AND_ROLE);
7752
setUsers('');
@@ -149,7 +124,7 @@ const AssignRoleWizard = ({ onClose, scope, initialUsers = '' }: AssignRoleWizar
149124
setUsers={handleUsersChange}
150125
selectedRole={selectedRole}
151126
setSelectedRole={setSelectedRole}
152-
roles={filteredRoles}
127+
roles={allRolesMetadata}
153128
validationError={validationError}
154129
invalidUsers={invalidUsers}
155130
inputRef={usersInputRef}

src/authz-module/wizard/AssignRoleWizardPage.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,21 @@ const AssignRoleWizardPage = () => {
1010
const intl = useIntl();
1111
const navigate = useNavigate();
1212
const [searchParams] = useSearchParams();
13-
const scope = searchParams.get('scope')!;
1413
const initialUsers = searchParams.get('users') || '';
15-
const { data: library } = useLibrary(scope);
1614

17-
const teamMembersPath = `/authz${ROUTES.LIBRARIES_TEAM_PATH.replace(':libraryId', scope)}`;
15+
const homePath = '/authz';
1816

1917
return (
2018
<AuthZLayout
21-
context={{ id: scope, title: library.title, org: library.org }}
22-
navLinks={[{ label: intl.formatMessage(messages['wizard.page.breadcrumb']), to: teamMembersPath }]}
19+
context={{ id: '', title: '', org: '' }}
20+
navLinks={[{ label: intl.formatMessage(messages['wizard.page.breadcrumb']), to: homePath }]}
2321
activeLabel={intl.formatMessage(messages['wizard.page.title'])}
2422
pageTitle={intl.formatMessage(messages['wizard.page.title'])}
2523
pageSubtitle=""
2624
actions={[]}
2725
>
2826
<AssignRoleWizard
29-
onClose={() => navigate(teamMembersPath)}
30-
scope={scope}
27+
onClose={() => navigate(homePath)}
3128
initialUsers={initialUsers}
3229
/>
3330
</AuthZLayout>

0 commit comments

Comments
 (0)