Skip to content

fix: wrap library redirect in course unit with authz permission - #3246

Open
dcoa wants to merge 1 commit into
openedx:masterfrom
eduNEXT:dcoa/library-unit-info-alert
Open

dcoa wants to merge 1 commit into
openedx:masterfrom
eduNEXT:dcoa/library-unit-info-alert

Conversation

@dcoa

@dcoa dcoa commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

When a unit comes from a Library, the Unit overview displays an alert with a link that redirects to the unit's page in library authoring (upstreamInfo.upstreamLink). That link was shown to everyone, including users who have no access to the source library, who then land on a page they are not allowed to see.

This PR shows the link only when the current user has content_libraries.view_library on the source library:

  • With the permission: "library content" is a link to the library, as before.
image
  • Without the permission: the alert is still shown with the same text, but "library content" is plain text.
image

For that:

  • The check uses useUserPermissions directly, understanding that openedx-authz is enable by default in libraries scope.
  • The request is only sent when the unit has an upstreamRef.
  • While permissions are loading, or if the request fails, "library content" is rendered as plain text. It never links to a page the user may not be able to access.

Supporting information

Part of the fine-grained permissions (openedx-authz) work for course authoring. It closes openedx/openedx-authz#450

Testing instructions

Testing instructions

  1. Set up a Studio instance with openedx-authz enabled.
  2. In a content library, create and publish a unit, then add it to a course unit.
  3. Log in as a user who has a role on both the course and the library (e.g. library admin).
    • Open the course unit.
    • The alert "Only certain edits are possible for library content. Learn More" is shown.
    • "library content" is a link, and it opens the unit in library authoring.
  4. Log in as a user who has a role on the course but no role on the library.
    • Open the same course unit.
    • The alert is shown with the same text.
    • "library content" is plain text, not a link.
    • "Learn More" is still a link.
  5. Open a unit that was not imported from a library. No alert is shown, and no permission request for a library is made.

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 Sep 14, 2026
@openedx-webhooks

openedx-webhooks commented Sep 14, 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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Sep 14, 2026
@dcoa
dcoa marked this pull request as ready for review September 14, 2026 02:20
@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.03%. Comparing base (87cba01) to head (6c66036).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3246   +/-   ##
=======================================
  Coverage   96.03%   96.03%           
=======================================
  Files        1407     1407           
  Lines       34287    34297   +10     
  Branches     7882     7888    +6     
=======================================
+ Hits        32928    32938   +10     
  Misses       1318     1318           
  Partials       41       41           

☔ 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 self-assigned this Sep 14, 2026

@BryanttV BryanttV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tested these changes on my local and they work correctly. I used various role types and course and library assignments, and the link is displayed or not depending on the user's permissions. LGTM!

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). 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.

Remove the link to the library in a unit when the user does not have permission for that specific library

3 participants