fix: gate studio home roles button on manage-team permission - #3205
fix: gate studio home roles button on manage-team permission#3205Anas12091101 wants to merge 1 commit into
Conversation
|
Thanks for the pull request, @Anas12091101! 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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3205 +/- ##
==========================================
+ Coverage 95.91% 95.92% +0.01%
==========================================
Files 1397 1397
Lines 33558 33581 +23
Branches 7914 7921 +7
==========================================
+ Hits 32187 32214 +27
+ Misses 1312 1308 -4
Partials 59 59 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Updates Studio Home’s “Roles and permissions” button to require team-management permission, preventing view-only users from entering an assignment flow they cannot complete.
Changes:
- Gates the button on course or library
manage_*_teampermissions. - Adds the course team-management permission constant.
- Updates permission-helper and Studio Home tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/studio-home/StudioHome.tsx |
Uses manage-team permissions for button visibility. |
src/studio-home/StudioHome.test.tsx |
Tests manage-team visibility behavior. |
src/authz/permissionHelpers.ts |
Provides scope-less manage-team checks. |
src/authz/permissionHelpers.test.ts |
Verifies manage-team actions and scope behavior. |
src/authz/constants.ts |
Adds MANAGE_COURSE_TEAM. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Hi @Anas12091101 what are you describing is not an issue of Authoring workflow, the button is correctly wrapped in view permission. The described issue in openedx/wg-build-test-release#590 is referring to admin console MFE (Assign Role button) where is already solved here openedx/frontend-app-admin-console#172 and backported to Verawood openedx/frontend-app-admin-console#177. The issue was duplicated openedx/wg-build-test-release#603, so I missed to close the one you worked on. My apologize for that. Understanding that we can safety close this PR. |
Description
The "Roles and permissions" button on the Studio Home page is gated on whether the user can view a team on any course or library (
courses.view_course_team/content_libraries.view_library_team). However, the admin console's role assignment flow requires the corresponding manage permissions:RoleUserAPIView.put/deleteinopenedx-authzare decorated with@authz_permissions([MANAGE_LIBRARY_TEAM, COURSES_MANAGE_COURSE_TEAM]).Of the four course roles, only
course_adminholdscourses.manage_course_team;course_staff,course_editorandcourse_auditorholdcourses.view_course_teamonly. Those three therefore see the button, can walk the entire role assignment wizard, and only fail on the final step with a403 permission_denied. The same applies on the library side, where onlylibrary_adminholdscontent_libraries.manage_library_team.This changes the gate to the two
manage_*_teampermissions, so the button is only shown to users who can actually complete the action. The waffle flag andADMIN_CONSOLE_URLconditions are unchanged.Useful information to include:
Before
Studio Home as a user holding
course_staff— the "Roles and permissions" button is rendered, and completing the assignment wizard from it fails with a 403.After
Same user, same page — the button is no longer rendered.
A user holding
course_adminstill sees it.Supporting information
Upstream issue: openedx/wg-build-test-release#590
The original report was raised internally at MIT and is not publicly readable, so repeating it here:
The "no role" half of that report was fixed by #3072 and #3151; this PR covers the Course Staff / Editor / Auditor half.
Testing instructions
You need a devstack/tutor with Studio and this MFE running. Total time: ~5 minutes.
Step 1 — Set up the flag, two users, and their roles
Open a Studio (CMS) Python shell:
tutor dev exec cms ./manage.py cms shellmake studio-shell, then./manage.py cms shellChange
COURSEto any course that exists in your environment, then paste the whole block:That turns on the
authz.enable_course_authoringwaffle flag and creates two users, each with the password equal to their username:team_admin@example.comteam_adminteam_staff@example.comteam_staffStep 2 — Make sure
ADMIN_CONSOLE_URLis setIn your MFE config (e.g.
.env.development):The admin console MFE does not need to be running — this test is only about whether the button appears. Restart the dev server if you changed this value.
Step 3 — Sign in as the Course Admin
Go to Studio home (e.g.
http://localhost:2001/home) and sign in asteam_admin@example.com/team_admin.✅ Expected: the "Roles and permissions" button is in the top-right of the header.
Step 4 — Sign in as the Course Staff
Open a new incognito window (so you don't have to log out), go to Studio home, and sign in as
team_staff@example.com/team_staff.✅ Expected: the "Roles and permissions" button is not there. The rest of the page is unchanged — same courses, same tabs.
Step 5 — Confirm the permission check is what hid it (optional but recommended)
With the Course Staff window open, DevTools → Network → filter for
validate. You should see aPOSTto<STUDIO_BASE_URL>/api/authz/v1/permissions/validate/mewith this request body:[{"action": "courses.manage_course_team"}, {"action": "content_libraries.manage_library_team"}]and this response:
[{"action": "courses.manage_course_team", "allowed": false}, {"action": "content_libraries.manage_library_team", "allowed": false}]For
team_admin,courses.manage_course_teamcomes backtrue.If that request is missing entirely, then the button was hidden by the waffle flag or by
ADMIN_CONSOLE_URLinstead of by permissions — re-check steps 1 and 2.Step 6 — See the old, broken behaviour (optional)
Temporarily put the gate back on the
viewpermissions:Reload Studio home as
team_staff: the button reappears, and clicking through the role assignment wizard ends in403 permission_deniedfromPUT /api/authz/v1/roles/users/— the bug this PR fixes.Restore the fix with:
Automated tests
npm run test -- src/studio-home/StudioHome.test.tsx src/authz/permissionHelpers.test.tsOther information
courses.manage_course_teamalready exists inopenedx-authz(verified against 1.21.1) and is the permission its role assignment endpoints enforce; this PR only adds the constant to this repo'sCOURSE_PERMISSIONSmap.getManageTeamPermissions(renamed fromgetViewTeamPermissions) has a single consumer,StudioHome. The separate course-scopedgetCourseTeamPermissionshelper is untouched and still checksview_course_team, so the course-level "Roles and permissions" nav item and the help/info sidebar links are unaffected — reaching a read-only team list with view access is intended there.validateUserPermissionsfills any missing response key withfalse, so if a deployment's backend does not recognise the action the button hides rather than appearing without permission — the safe direction.openedx-authzendpoints already enforced these permissions, which is why the previous behaviour surfaced as a late 403 rather than an actual privilege escalation.frontend-app-admin-consolelists candidate scopes viauseScopes()without themanagement_permission_onlyparameter, so it can still offer scopes the user may only view. That is a separate fix in that repo.Best Practices Checklist
We're trying to move away from some deprecated patterns in this codebase. Please
check if your PR meets these recommendations before asking for a review:
.ts,.tsx).propTypesanddefaultPropsin any new or modified code.src/testUtils.tsx(specificallyinitializeMocks)apiHooks.tsin this repo for examples.messages.tsfiles have adescriptionfor translators to use.../in import paths. To import from parent folders, use@src, e.g.import { initializeMocks } from '@src/testUtils';instead offrom '../../../../testUtils'