Repository navigation
feat: add the endpoint to check a custom role name - #666
Conversation
|
Thanks for the pull request, @rodmgwgu! 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. |
b08e9a1 to
8add488
Compare
8add488 to
80c0739
Compare
80c0739 to
db743ca
Compare
5e09b35 to
05fea51
Compare
jacobo-dominguez-wgu
left a comment
There was a problem hiding this comment.
Tested locally on the admin console ui and postman and works as expected!
BryanttV
left a comment
There was a problem hiding this comment.
Thanks @rodmgwgu!
Two non-blocking notes on the name rules:
-
(pre-existing)
str.strip()keeps U+200B, so a zero-width space is reported as available. Names also aren't Unicode-normalized. Could we reject names with no visible characters and normalize to NFC, without banning joiners used by emoji and some scripts? A U+200B inside a name would need separate handling. Fine as a follow-up. -
(nit) DRF's
CharFieldcoerces numbers, so{"display_name": 123}returns 200 with"123", but the ADR says non-text values return 400 and the name is returned as sent. Since create also coerces, could we update the ADR (or use a strict string field in both) and add a numeric test case?
71e4a56 to
44333de
Compare
Thanks @BryanttV, I applied both fixes in this PR. |
44333de to
1a72398
Compare
BryanttV
left a comment
There was a problem hiding this comment.
Thanks for addressing my comments, LGTM!
7a4d57d to
9621955
Compare
9621955 to
f0f7d61
Compare
Part of: #571
Needed for openedx/frontend-app-admin-console#293 (comment)
Problem
The create custom role wizard asks for the name on step 1 but only learns that the name is taken from the 409 of
POST /api/authz/v1/roles/on the last step, after the administrator has picked the permissions. No endpoint checks a name on its own, andGET /api/authz/v1/roles/?search=can't do it: it matches part of the translated name in the requested scope types, while the ADR 0036 rule compares the whole stored name across every resource type.Approach
POST /api/authz/v1/roles/validate-name/with{"display_name": "..."}. It always returns 200 withdisplay_name(as sent),available, andreason(taken,invalidornull) andmessage. The shape followsPOST /users/validate/, which the assign role wizard already uses.api.validate_custom_role_name, which applies the name rules ofcreate_custom_rolewithout writing anything. Both share_clean_display_name, so they can't drift apart.PrivilegedWritePermission, as for create.Manual testing instructions
As a staff user in the LMS:
/api/authz/v1/roles/validate-name/with{"display_name": "Library Designer"}. It returnsavailable: true.{"display_name": "LIBRARY AUTHOR"}. It returnsavailable: false,reason: "taken".{"display_name": " "}. It returnsavailable: false,reason: "invalid".Unit tests:
pytest src/openedx_authz/tests/api/test_custom_roles.py src/openedx_authz/tests/rest_api/test_views.py -k "TestValidateCustomRoleName or TestRoleNameValidationView".Rollback plan
Revert this PR. No migration and no stored data.
Retro compatibility
No existing endpoint changes.
create_custom_rolebehaves the same.AI Usage
🤖 This change was made with assistance from Kiro, with human guidance on the decisions and validation against ADR 0036.
Merge checklist: