Skip to content

Conversation

@rodmgwgu
Copy link

@rodmgwgu rodmgwgu commented Nov 20, 2025

Description

Related bug: openedx/openedx-authz#139

Adds validating publish permissions based on the new openedx-authz model.

Hook implementation mostly copied from frontend-app-admin-console

Context:

The new openedx-authz authorization model adds the possibility to have fine-grained permissions for different roles in the system. Currently, the MVP involves implementing these new roles over the Content Libraries only.

The new roles are:

  • Library Admin
  • Library Author
  • Library Contributor
  • Library User

The specific permissions for these roles can be found here.

The enforcement mechanism for MFEs as implemented in this PR is described here.

This change mainly concerns the new "Library Contributor" role, which should have permission to edit library content, but not to publish it. This was not taken into account on the previous permission model, because before, anyone with write permissions could publish. This change makes it possible to disable the Publish button for "Library Contributors" by using the new enforcement mechanism.

Screenshots:

Before changes, as a "Library Contributor" user, the Publish button was shown, but the action failed due to lack of permissions:

512953087-074bd6a3-5771-4e51-8bd4-027035ef96fa

After changes, the Publish button is hidden:

Screenshot 2025-11-20 at 4 37 28 p m

Supporting information

Project: RBAC AuthZ

Related bug: openedx/openedx-authz#139

The enforcement mechanism for MFEs as implemented in this PR is described here.

Testing instructions

  1. Create a new non-staff user via tutor with tutor dev do createuser nonstaff [email protected]
  2. Log in as an admin user to Studio
  3. Create a new Content Library (non-legacy Library)
  4. Add the "nonstaff" user to the Library team, as a "Library Contributor"
Screenshot 2025-11-24 at 10 10 13 a m
  1. In an incognito window, log in to studio as the "nonstaff" user
  2. Go to the direct url for the library details page
  3. You should be able to see the Library details page, but the Publish button should not be shown
Screenshot 2025-11-20 at 4 37 28 p m

Other information

I implemented the validateUserPermissions hook and it's related code as an independent module in src/authz, with the idea of externalizing it as a library in the near future, perhaps as a part of frontend-base?

Because of that, I'm not using the helpers in src/testUtils.tsx on the hook tests.

Concern: I'm mocking the validateUserPermissions API call (used by the validateUserPermissions hook) on the initializeMocks util, so it doesn't interfere with several tests that are checking against axios mocks without validating the request url. I'm not sure if this is the best practice or if there is a better way?

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
Copy link

openedx-webhooks commented Nov 20, 2025

Thanks for the pull request, @rodmgwgu!

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.


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
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.86%. Comparing base (ef36156) to head (f7c566f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2685   +/-   ##
=======================================
  Coverage   94.85%   94.86%           
=======================================
  Files        1232     1236    +4     
  Lines       27899    27925   +26     
  Branches     6316     6324    +8     
=======================================
+ Hits        26464    26490   +26     
  Misses       1364     1364           
  Partials       71       71           

☔ View full report in Codecov by Sentry.
📢 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.

@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Nov 25, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Nov 25, 2025
@rodmgwgu rodmgwgu changed the title draft: feat: Implement querying openedx-authz for publish permissions feat: Implement querying openedx-authz for publish permissions Nov 25, 2025
@rodmgwgu rodmgwgu marked this pull request as ready for review November 25, 2025 16:13
Copy link

@MaferMazu MaferMazu left a comment

Choose a reason for hiding this comment

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

Thanks @rodmgwgu, I tested in a Ulmo env, and it works as expected! ✨

The code looks good to me, but I would prefer someone with more frontend skills to help with a review as well.

Before
image
After
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Normally the file for the react query hooks on this repo is called apiHooks.ts. Could you rename it to keep consistency?

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks!

import { validateUserPermissions } from './api';

const adminConsoleQueryKeys = {
all: [appId] as const,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if the appId value follows the same pattern used for query keys, i have see mostly camelCase values.

const permissions = LIBRARY_PERMISSIONS.map(action => ({ action, scope: libraryId }));

const { isLoading: isLoadingUserPermissions, data: userPermissions } = useValidateUserPermissions(permissions);
const canPublish = userPermissions ? userPermissions[0]?.allowed : false;

Choose a reason for hiding this comment

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

Something we could improve is being explicit about the action we are requesting instead of using userPermissions[0].

Copy link
Author

Choose a reason for hiding this comment

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

According to the ADR, the API guarantees that the order of the response will match the requested permissions, that's why I'm not trying to match it explicitly.

@MaferMazu MaferMazu linked an issue Nov 25, 2025 that may be closed by this pull request
@rodmgwgu rodmgwgu force-pushed the rod/authz-publish-permissions branch from a501e16 to f7c566f Compare November 25, 2025 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

Bug: Hide publish library button in Studio.

5 participants