|
1 | 1 | import type { IntlShape } from '@edx/frontend-platform/i18n'; |
2 | 2 | import { Language, LibraryBooks, School } from '@openedx/paragon/icons'; |
| 3 | +import { allRolesMetadata } from '@src/authz-module/roles-permissions'; |
| 4 | +import { GLOBAL_STAFF_ROLE, MAP_ROLE_KEY_TO_LABEL, SUPERUSER_ROLE } from '@src/authz-module/constants'; |
3 | 5 | import messages from './messages'; |
4 | 6 |
|
5 | | -export const getRolesFiltersOptions = (intl: IntlShape) => [ |
6 | | - { |
7 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.global']), |
8 | | - groupIcon: Language, |
9 | | - displayName: 'Super Admin', |
10 | | - value: 'super_admin', |
11 | | - }, |
12 | | - { |
13 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.global']), |
14 | | - groupIcon: Language, |
15 | | - displayName: 'Global Staff', |
16 | | - value: 'global_staff', |
17 | | - }, |
18 | | - |
19 | | - { |
20 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), |
21 | | - groupIcon: School, |
22 | | - displayName: 'Course Admin', |
23 | | - value: 'course_admin', |
24 | | - }, |
25 | | - { |
26 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), |
27 | | - groupIcon: School, |
28 | | - displayName: 'Course Staff', |
29 | | - value: 'course_staff', |
30 | | - }, |
31 | | - { |
32 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), |
33 | | - groupIcon: School, |
34 | | - displayName: 'Course Editor', |
35 | | - value: 'course_editor', |
36 | | - }, |
37 | | - { |
38 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), |
39 | | - groupIcon: School, |
40 | | - displayName: 'Course Auditor', |
41 | | - value: 'course_auditor', |
42 | | - }, |
43 | | - |
44 | | - { |
45 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), |
46 | | - groupIcon: LibraryBooks, |
47 | | - displayName: 'Library Admin', |
48 | | - value: 'library_admin', |
49 | | - }, |
50 | | - { |
51 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), |
52 | | - groupIcon: LibraryBooks, |
53 | | - displayName: 'Library Author', |
54 | | - value: 'library_author', |
55 | | - }, |
56 | | - { |
57 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), |
58 | | - groupIcon: LibraryBooks, |
59 | | - displayName: 'Library Contributor', |
60 | | - value: 'library_contributor', |
61 | | - }, |
62 | | - { |
63 | | - groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), |
64 | | - groupIcon: LibraryBooks, |
65 | | - displayName: 'Library User', |
66 | | - value: 'library_user', |
67 | | - }, |
68 | | -]; |
69 | | - |
70 | 7 | export const RESOURCE_ICONS = { |
71 | 8 | COURSE: School, |
72 | 9 | LIBRARY: LibraryBooks, |
73 | 10 | GLOBAL: Language, |
74 | 11 | }; |
| 12 | + |
| 13 | +// The API expects the underscore format when roles are sent as filter values, |
| 14 | +// while role data received from the API uses the dotted format (e.g. django.superuser). |
| 15 | +const GLOBAL_ROLE_FILTER_OPTIONS = [ |
| 16 | + { value: 'super_admin', displayName: MAP_ROLE_KEY_TO_LABEL[SUPERUSER_ROLE] }, |
| 17 | + { value: 'global_staff', displayName: MAP_ROLE_KEY_TO_LABEL[GLOBAL_STAFF_ROLE] }, |
| 18 | +]; |
| 19 | + |
| 20 | +export const getRolesFiltersOptions = (intl: IntlShape) => { |
| 21 | + const globalGroup = { |
| 22 | + groupName: intl.formatMessage(messages['authz.team.members.table.group.global']), |
| 23 | + groupIcon: RESOURCE_ICONS.GLOBAL, |
| 24 | + }; |
| 25 | + const contextGroups = { |
| 26 | + course: { |
| 27 | + groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), |
| 28 | + groupIcon: RESOURCE_ICONS.COURSE, |
| 29 | + }, |
| 30 | + library: { |
| 31 | + groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), |
| 32 | + groupIcon: RESOURCE_ICONS.LIBRARY, |
| 33 | + }, |
| 34 | + }; |
| 35 | + |
| 36 | + return [ |
| 37 | + ...GLOBAL_ROLE_FILTER_OPTIONS.map((role) => ({ ...globalGroup, ...role })), |
| 38 | + ...allRolesMetadata.map((meta) => ({ |
| 39 | + ...contextGroups[meta.contextType], |
| 40 | + displayName: meta.name, |
| 41 | + value: meta.role, |
| 42 | + })), |
| 43 | + ]; |
| 44 | +}; |
0 commit comments