Skip to content

refactor(authz): validate Studio button view access and use useCourseUserPermissions in course-scoped contexts#3151

Open
dcoa wants to merge 5 commits into
openedx:masterfrom
eduNEXT:dcoa/fix-studio-home-authz
Open

refactor(authz): validate Studio button view access and use useCourseUserPermissions in course-scoped contexts#3151
dcoa wants to merge 5 commits into
openedx:masterfrom
eduNEXT:dcoa/fix-studio-home-authz

Conversation

@dcoa

@dcoa dcoa commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

This PR updates all course-scoped permission checks to use useCourseUserPermissions, ensuring a consistent permissions model across course-specific areas.

Additionally, it guards the Roles & Permissions button on the Home page so it is only rendered for users with permission to view team members in at least one course or library.

Implemented changes

  • Centralized course-scoped permission checks on useCourseUserPermissions. Replaced the repeated useUserPermissions + useWaffleFlags + manual isAuthzEnabled/loading/fallback boilerplate in course-scoped contexts with the useCourseUserPermissions hook, which folds the waffle-flag gate, loading state, and "authz-disabled ⇒ allow (legacy behavior)" fallback into one place. Applied to:
    • HelpSidebar
    • AdvancedSettings
    • CourseInfoSidebar (course outline Settings tab)
  • Validated per-link access in the course Settings sidebar. CourseInfoSidebar's Settings tab previously only gated the Advanced settings link. It now validates each link against its own permission — Schedule & details, Grading, Course team, Group configurations, and Advanced settings — mirroring the header navigation.
  • Fixed the Studio Home "Roles & Permissions" button visibility. The button previously appeared for any user whenever AuthZ + ADMIN_CONSOLE_URL were configured. It now only shows to users who can actually view a team somewhere with view_course_team on any course or view_library_team on any library.
  • Hardened the hook against unscoped queries. useCourseUserPermissions now only issues the permission query when both AuthZ is enabled and a courseId is present (shouldValidatePermissions), avoiding unscoped permission lookups.

Supporting information

This fixes

Testing instructions

  • Enter to Studio with a user without permissions, Roles and Permissions button should not be visible. Only 1 request should be launch to validate/me, no scope in there.

No permissions
image

Allowed view team
image

  • Enter a course with the flag off and open settings in the sidebar, you should see Course Team link.
image image
  • Enter a course with flag on and open settings in the sidebar, you should see Roles and Permissions link.
image

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:

  • Any new files are using TypeScript (.ts, .tsx).
  • Avoid propTypes and defaultProps in any new or modified code.
  • Tests should use the helpers in src/testUtils.tsx (specifically initializeMocks)
  • Do not add new fields to the Redux state/store. Use React Context to share state among multiple components.
  • Use React Query to load data from REST APIs. See any apiHooks.ts in this repo for examples.
  • All new i18n messages in messages.ts files have a description for translators to use.
  • Avoid using ../ in import paths. To import from parent folders, use @src, e.g. import { initializeMocks } from '@src/testUtils'; instead of from '../../../../testUtils'

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Jul 22, 2026
@openedx-webhooks

openedx-webhooks commented Jul 22, 2026

Copy link
Copy Markdown

Thanks for the pull request, @dcoa!

This repository is currently maintained by @bradenmacdonald.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.77%. Comparing base (6bcbfcc) to head (26e451d).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...outline-sidebar/info-sidebar/CourseInfoSidebar.tsx 93.33% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #3151    +/-   ##
========================================
  Coverage   95.77%   95.77%            
========================================
  Files        1396     1398     +2     
  Lines       33399    33427    +28     
  Branches     7603     7866   +263     
========================================
+ Hits        31988    32016    +28     
  Misses       1367     1367            
  Partials       44       44            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dcoa
dcoa requested a review from bradenmacdonald July 22, 2026 06:54
} = updateMutation;

const isLoading = isPendingSettingsStatus || (isAuthzEnabled && isLoadingUserPermissions);
const isLoading = isPendingSettingsStatus || isLoadingUserPermissions;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing isAuthzEnabled like in this like but some others like L107 we're not? What's special about this specific case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand. We're checking if it's loading we don't necessarily need to check if authz is enabled, other components might do this for us.

Comment thread src/authz/hooks.ts
} = useUserPermissions(permissions, isAuthzEnabled);
} = useUserPermissions(permissions, shouldValidatePermissions);

const isLoading = isWaffleFlagsLoading || (isAuthzEnabled && isLoadingUserPermissions);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question of L70, we aren't we removing isAuthzEnabled here?

Comment on lines +44 to 45
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

if (isAuthzEnabled && getConfig().ADMIN_CONSOLE_URL) {
if (isAuthzEnabled && adminConsoleBaseUrl && canViewConsoleTeams) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the isAuthzEnabled or the checks in L54-L66 are enough?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused on when to check fo the flag and when we don't.

@mariajgrimaldi mariajgrimaldi added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). create-sandbox open-craft-grove should create a sandbox environment from this PR open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants