-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: centralize role/route constants and derive role maps from metadata #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dcoa
wants to merge
3
commits into
openedx:master
Choose a base branch
from
eduNEXT:dcoa/fix-maps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,74 +1,44 @@ | ||
| import type { IntlShape } from '@edx/frontend-platform/i18n'; | ||
| import { Language, LibraryBooks, School } from '@openedx/paragon/icons'; | ||
| import { allRolesMetadata } from '@src/authz-module/roles-permissions'; | ||
| import { GLOBAL_STAFF_ROLE, MAP_ROLE_KEY_TO_LABEL, SUPERUSER_ROLE } from '@src/authz-module/constants'; | ||
| import messages from './messages'; | ||
|
|
||
| export const getRolesFiltersOptions = (intl: IntlShape) => [ | ||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.global']), | ||
| groupIcon: Language, | ||
| displayName: 'Super Admin', | ||
| value: 'super_admin', | ||
| }, | ||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.global']), | ||
| groupIcon: Language, | ||
| displayName: 'Global Staff', | ||
| value: 'global_staff', | ||
| }, | ||
|
|
||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), | ||
| groupIcon: School, | ||
| displayName: 'Course Admin', | ||
| value: 'course_admin', | ||
| }, | ||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), | ||
| groupIcon: School, | ||
| displayName: 'Course Staff', | ||
| value: 'course_staff', | ||
| }, | ||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), | ||
| groupIcon: School, | ||
| displayName: 'Course Editor', | ||
| value: 'course_editor', | ||
| }, | ||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), | ||
| groupIcon: School, | ||
| displayName: 'Course Auditor', | ||
| value: 'course_auditor', | ||
| }, | ||
|
|
||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), | ||
| groupIcon: LibraryBooks, | ||
| displayName: 'Library Admin', | ||
| value: 'library_admin', | ||
| }, | ||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), | ||
| groupIcon: LibraryBooks, | ||
| displayName: 'Library Author', | ||
| value: 'library_author', | ||
| }, | ||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), | ||
| groupIcon: LibraryBooks, | ||
| displayName: 'Library Contributor', | ||
| value: 'library_contributor', | ||
| }, | ||
| { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), | ||
| groupIcon: LibraryBooks, | ||
| displayName: 'Library User', | ||
| value: 'library_user', | ||
| }, | ||
| ]; | ||
|
|
||
| export const RESOURCE_ICONS = { | ||
| COURSE: School, | ||
| LIBRARY: LibraryBooks, | ||
| GLOBAL: Language, | ||
| }; | ||
|
|
||
| // The API expects the underscore format when roles are sent as filter values, | ||
| // while role data received from the API uses the dotted format (e.g. django.superuser). | ||
| const GLOBAL_ROLE_FILTER_OPTIONS = [ | ||
| { value: 'super_admin', displayName: MAP_ROLE_KEY_TO_LABEL[SUPERUSER_ROLE] }, | ||
| { value: 'global_staff', displayName: MAP_ROLE_KEY_TO_LABEL[GLOBAL_STAFF_ROLE] }, | ||
| ]; | ||
|
|
||
| export const getRolesFiltersOptions = (intl: IntlShape) => { | ||
| const globalGroup = { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.global']), | ||
| groupIcon: RESOURCE_ICONS.GLOBAL, | ||
| }; | ||
| const contextGroups = { | ||
| course: { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.courses']), | ||
| groupIcon: RESOURCE_ICONS.COURSE, | ||
| }, | ||
| library: { | ||
| groupName: intl.formatMessage(messages['authz.team.members.table.group.libraries']), | ||
| groupIcon: RESOURCE_ICONS.LIBRARY, | ||
| }, | ||
| }; | ||
|
|
||
| return [ | ||
| ...GLOBAL_ROLE_FILTER_OPTIONS.map((role) => ({ ...globalGroup, ...role })), | ||
| ...allRolesMetadata.map((meta) => ({ | ||
| ...contextGroups[meta.contextType], | ||
| displayName: meta.name, | ||
| value: meta.role, | ||
| })), | ||
| ]; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| const ORG_AGGREGATE_SCOPE_BUILDERS = { | ||
| import type { ContextType } from '@src/types'; | ||
| import { allRolesMetadata } from './roles-permissions'; | ||
|
|
||
| const ORG_AGGREGATE_SCOPE_BUILDERS: Record<ContextType, (orgSlug: string) => string> = { | ||
| course: (orgSlug: string) => `course-v1:${orgSlug}+*`, | ||
| library: (orgSlug: string) => `lib:${orgSlug}:*`, | ||
| }; | ||
|
|
@@ -9,21 +12,19 @@ export const getOrgAggregateScopeKey = (contextType: string, orgSlug: string): s | |
| return builder(orgSlug); | ||
| }; | ||
|
|
||
| export const getScopeContextType = (scope: string): ContextType => (scope.startsWith('lib') ? 'library' : 'course'); | ||
|
|
||
| export const DEFAULT_TOAST_DELAY = 5000; | ||
| export const RETRY_TOAST_DELAY = 120_000; // 2 minutes | ||
| export const SKELETON_ROWS = Array.from({ length: 10 }).map(() => ({ | ||
| username: 'skeleton', | ||
| name: '', | ||
| email: '', | ||
| roles: [], | ||
| })); | ||
|
|
||
| export const ROUTES = { | ||
| HOME_PATH: '/authz', | ||
| AUDIT_USER_PATH: '/user/:username', | ||
| ASSIGN_ROLE_WIZARD_PATH: '/assign-role', | ||
| }; | ||
|
|
||
| export const buildUserPath = (username: string) => `${ROUTES.HOME_PATH}${ROUTES.AUDIT_USER_PATH.replace(':username', encodeURIComponent(username))}`; | ||
|
|
||
| export const buildWizardPath = (options?: { users?: string; from?: string }) => { | ||
| const base = `${ROUTES.HOME_PATH}${ROUTES.ASSIGN_ROLE_WIZARD_PATH}`; | ||
| if (!options) { return base; } | ||
|
|
@@ -34,42 +35,20 @@ export const buildWizardPath = (options?: { users?: string; from?: string }) => | |
| return query ? `${base}?${query}` : base; | ||
| }; | ||
|
|
||
| export enum RoleOperationErrorStatus { | ||
| USER_NOT_FOUND = 'user_not_found', | ||
| USER_ALREADY_HAS_ROLE = 'user_already_has_role', | ||
| USER_DOES_NOT_HAVE_ROLE = 'user_does_not_have_role', | ||
| ROLE_ASSIGNMENT_ERROR = 'role_assignment_error', | ||
| ROLE_REMOVAL_ERROR = 'role_removal_error', | ||
| } | ||
|
|
||
| export const MAX_TABLE_FILTERS_APPLIED = 10; | ||
|
|
||
| export const AUTHZ_HOME_PATH = '/authz'; | ||
| // Role data received from the API uses the dotted format for Django-managed roles. | ||
| export const SUPERUSER_ROLE = 'django.superuser'; | ||
| export const GLOBAL_STAFF_ROLE = 'django.staff'; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Backend reference https://github.com/openedx/openedx-authz/blob/main/openedx_authz/rest_api/v1/serializers.py#L399 Before was validating |
||
| export const DJANGO_MANAGED_ROLES = [SUPERUSER_ROLE, GLOBAL_STAFF_ROLE]; | ||
|
|
||
| export const MAP_ROLE_KEY_TO_LABEL: Record<string, string> = { | ||
| library_admin: 'Library Admin', | ||
| library_author: 'Library Author', | ||
| library_contributor: 'Library Contributor', | ||
| library_user: 'Library User', | ||
| course_admin: 'Course Admin', | ||
| course_staff: 'Course Staff', | ||
| course_editor: 'Course Editor', | ||
| course_auditor: 'Course Auditor', | ||
| 'django.superuser': 'Super Admin', | ||
| 'django.globalstaff': 'Global Staff', | ||
| ...Object.fromEntries(allRolesMetadata.map((meta) => [meta.role, meta.name])), | ||
| [SUPERUSER_ROLE]: 'Super Admin', | ||
| [GLOBAL_STAFF_ROLE]: 'Global Staff', | ||
| }; | ||
|
|
||
| export const DJANGO_MANAGED_ROLES = ['django.superuser', 'django.globalstaff']; | ||
|
|
||
| export const TABLE_DEFAULT_PAGE_SIZE = 10; | ||
|
|
||
| export const DEFAULT_FILTER_PAGE_SIZE = 5; | ||
| export const ADMIN_ROLES = ['course_admin', 'library_admin']; | ||
|
|
||
| // Resource Type Definitions | ||
| export const RESOURCE_TYPES = { | ||
| LIBRARY: 'library', | ||
| COURSE: 'course', | ||
| } as const; | ||
|
|
||
| export type ResourceType = typeof RESOURCE_TYPES[keyof typeof RESOURCE_TYPES]; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a small fix for the release too
Current message (Verawood sandbox)
After the change
@MaferMazu