refactor: centralize role/route constants and derive role maps from metadata#164
refactor: centralize role/route constants and derive role maps from metadata#164dcoa wants to merge 3 commits into
Conversation
|
Thanks for the pull request, @dcoa! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
| const RenderAdminRole = ({ role }: RenderAdminRoleProps) => { | ||
| const intl = useIntl(); | ||
| // Determine which message to show based on role | ||
| const messageKey = role?.toLowerCase().includes('admin') |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #164 +/- ##
=======================================
Coverage 97.44% 97.44%
=======================================
Files 66 66
Lines 1525 1526 +1
Branches 361 387 +26
=======================================
+ Hits 1486 1487 +1
Misses 39 39 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| 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'; |
There was a problem hiding this comment.
Backend reference https://github.com/openedx/openedx-authz/blob/main/openedx_authz/rest_api/v1/serializers.py#L399
Before was validating django.globalstaff


Summary
Establishes a single source of truth for role metadata and route/scope helpers in the authz module, removing duplicated hardcoded role lists and unused constants.
This is the base PR of a larger cleanup; subsequent PR build on top of it (I will open it soon and reference it).
What & why
MAP_ROLE_KEY_TO_LABELandgetRolesFiltersOptionsare now generated fromallRolesMetadatainstead of separate lists, so adding/renaming a role only happens in one place.buildUserPath(),getScopeContextType(), and theSUPERUSER_ROLE/GLOBAL_STAFF_ROLE/DJANGO_MANAGED_ROLESconstants.GLOBAL_STAFF_ROLEto match backend.AUTHZ_HOME_PATHwithROUTES.HOME_PATH.ContextType = 'course' | 'library'union and applies it toRoleMetadata.contextTypeand the wizard scope hooks, replacing loose string.SKELETON_ROWS,RoleOperationErrorStatus,RESOURCE_TYPES/ResourceType.ADMIN_URLinside the component, the value needs to be resolved at runtime otherwise will not redirect properly.RenderAdminRoleand display the right message.formatRoleAssignmentErrornow resolves messages via a KNOWN_ERRORS lookup instead of an if-chain.AI use acknowledgement
Supported by Claude Code