Skip to content

Adding permission validations from authz for files page#2941

Open
jacobo-dominguez-wgu wants to merge 3 commits into
openedx:masterfrom
WGU-Open-edX:permission-checks-files-page
Open

Adding permission validations from authz for files page#2941
jacobo-dominguez-wgu wants to merge 3 commits into
openedx:masterfrom
WGU-Open-edX:permission-checks-files-page

Conversation

@jacobo-dominguez-wgu
Copy link
Copy Markdown
Contributor

@jacobo-dominguez-wgu jacobo-dominguez-wgu commented Mar 13, 2026

Description

This pr adds authz permission validations for the files page section on the Content menu from the header.
First this validates the enableAuthzCourseAuthoring waffle flag and if it is enabled it checks the permissions from authz on the files page section.
These are the checks included:

Checks for the courses.view_files permission to display or hide the Files option on the header menu. Also renders a permissions denied alert if used a direct link to the files section.
Checks for courses.create_files to display or hide the "+ Add files" button and the add files drop zone.
Checks for courses.delete_files permission to display or hide the Delete menu option on the actions menu and the options menu in card view and list view.
Checks for courses.edit_files to display or hide the Lock/Unlock item on the info section and in the options menu in card view and list view.

Resolves #2934

Useful information to include:

Supporting information

Link to other information about the change, such as GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.

Testing instructions

Prerequisites

  • Access to a course in Studio
  • Ability to toggle the enableAuthzCourseAuthoring waffle flag
  • Access to the authz service to configure user permissions

Test Scenarios

1. Files & Uploads Page — Authz Disabled (Legacy Behavior)

Setup: Ensure enableAuthzCourseAuthoring waffle flag is disabled

Step Expected Result
Navigate to Files & Uploads page Page loads normally
Verify file upload dropzone Dropzone is visible
Verify file actions (delete, lock) All action buttons are visible and functional

2. Files & Uploads Page — Authz Enabled with Full Permissions

Setup:

  • Enable enableAuthzCourseAuthoring waffle flag
  • Grant user courses.view_files, courses.create_files, courses.edit_files, and courses.delete_files permissions
Step Expected Result
Navigate to Files & Uploads page Page loads normally
Verify file upload dropzone Dropzone is visible
Upload a file File uploads successfully
Delete a file Delete option is visible and functional
Lock/unlock a file Lock option is visible and functional

3. Files & Uploads Page — Authz Enabled with View-Only Permissions

Setup:

  • Enable enableAuthzCourseAuthoring waffle flag
  • Grant user only courses.view_files permission
Step Expected Result
Navigate to Files & Uploads page Page loads, files are visible
Verify file upload dropzone Dropzone is NOT visible
Verify delete option in file menu Delete option is NOT visible
Verify lock option in file menu Lock option is NOT visible

4. Files & Uploads Page — Authz Enabled with No Permissions

Setup:

  • Enable enableAuthzCourseAuthoring waffle flag
  • Remove all file-related permissions
Step Expected Result
Navigate to Files & Uploads page "Permission Denied" alert is displayed
Verify page content Files content is NOT visible

5. Header Settings Menu — Authz Disabled

Setup: Ensure enableAuthzCourseAuthoring waffle flag is disabled

Step Expected Result
Open Settings menu in header Menu displays normally
Verify team management option "Course Team" option is visible
Verify roles option "Roles and Permissions" option is NOT visible

6. Header Settings Menu — Authz Enabled

Setup:

  • Enable enableAuthzCourseAuthoring waffle flag
  • Configure ADMIN_CONSOLE_URL environment variable
Step Expected Result
Open Settings menu in header Menu displays normally
Verify team management option "Course Team" option is NOT visible
Verify roles option "Roles and Permissions" option is visible
Click "Roles and Permissions" Opens Admin Console with correct course scope

7. Header Content Menu — Files Option Visibility

Setup: Enable enableAuthzCourseAuthoring waffle flag

Permissions Expected Result
courses.view_files granted "Files & Uploads" option is visible in Content menu
courses.view_files NOT granted "Files & Uploads" option is NOT visible in Content menu

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 Mar 13, 2026
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Mar 13, 2026

Thanks for the pull request, @jacobo-dominguez-wgu!

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

codecov Bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.56%. Comparing base (36d42b0) to head (a4e5a52).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2941      +/-   ##
==========================================
+ Coverage   95.55%   95.56%   +0.01%     
==========================================
  Files        1393     1393              
  Lines       32992    33030      +38     
  Branches     7644     7427     -217     
==========================================
+ Hits        31524    31566      +42     
+ Misses       1413     1409       -4     
  Partials       55       55              

☔ 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 Mar 17, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Mar 17, 2026
@jacobo-dominguez-wgu jacobo-dominguez-wgu force-pushed the permission-checks-files-page branch from 94a4751 to 4839aab Compare March 31, 2026 02:20
@MaferMazu
Copy link
Copy Markdown
Contributor

@jacobo-dominguez-wgu Is this ready for review?

@jacobo-dominguez-wgu jacobo-dominguez-wgu force-pushed the permission-checks-files-page branch 2 times, most recently from 2bfe88f to 6cde551 Compare May 11, 2026 23:25
@jacobo-dominguez-wgu jacobo-dominguez-wgu marked this pull request as ready for review May 11, 2026 23:43
@jacobo-dominguez-wgu jacobo-dominguez-wgu force-pushed the permission-checks-files-page branch 2 times, most recently from 170a3b2 to 9aed071 Compare May 12, 2026 04:21
@MaferMazu MaferMazu requested a review from bra-i-am May 14, 2026 15:45
Copy link
Copy Markdown
Contributor

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

@jacobo-dominguez-wgu thanks for this PR.

I managed to test the following:
✅ Checks for the courses.view_files permission to display or hide the Files option on the header menu. Also renders a permissions denied alert if used a direct link to the files section.
✅ Checks for courses.create_files to display or hide the "+ Add files" button and the add files drop zone.
✅ Checks for courses.delete_files permission to display or hide the Delete menu option on the actions menu and the options menu in card view and list view.
⚠️ Checks for courses.edit_files to display or hide the Lock/Unlock item on the info section and in the options menu in card view and list view.

As course_auditor, I shouldn't be able to edit (so based on your description, I shouldn't be able to see the lock/unlock)

Image

I think we should hide the lock/unlock.

@MaferMazu
Copy link
Copy Markdown
Contributor

Also, I asked Gemini for major issues and mentioned the following:

  1. Generic Type Erasure in Hooks
    The useUserPermissionsWithAuthzCourse hook is currently typed with a fixed interface (UseUserPermissionsWithAuthzCourseReturn) rather than maintaining the query's generic type.
    Why it matters: By forcing the return type to a generic PermissionValidationAnswer (which is just Record<string, boolean>), you lose TypeScript's ability to validate the specific permission keys passed in the query (e.g., canViewFiles).
    Impact: Developers won't get IntelliSense or compile-time warnings if they attempt to access a permission key that wasn't actually requested in the permissions object, leading to potential runtime errors or accidental "false" evaluations.

  2. Lack of API Error Handling
    The hook does not capture or handle the isError state from the useUserPermissions call.
    Why it matters: If the openedx-authz service is down or returns a 500 error, the hook will stop loading, and the permissions will silently default to false based on the current logic.
    Impact: Users will be met with a "Permission Denied" alert without any technical feedback, making it impossible to distinguish between a legitimate lack of permissions and a critical infrastructure failure.

(Please judge these suggestions, because they came from AI)

@bradenmacdonald
Copy link
Copy Markdown
Contributor

Yes, those are good suggestions - please ensure all hooks are fully typed and handle errors.

Copy link
Copy Markdown
Contributor

@bra-i-am bra-i-am left a comment

Choose a reason for hiding this comment

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

@jacobo-dominguez-wgu, thanks for this PR! ✨

It is working as expected! Here are some videos with the tests:

Course Auditor
Can access only to read the files
https://github.com/user-attachments/assets/356c00d1-84b7-4556-9929-02089c92ed54

Course Editor
Can access files and modify them, but can't delete them
https://github.com/user-attachments/assets/e7e9c764-c0ca-4e03-924c-ada80b58e059

Course Staff & Course Admin
Have total access to the files
https://github.com/user-attachments/assets/2483bd3d-71db-4533-8247-29e8e093857b

Now, regarding the code, I left some comments about some things I noticed

Comment thread src/authz/hooks.ts
Comment thread src/files-and-videos/files-page/CourseFilesTable.tsx Outdated
Comment thread src/files-and-videos/files-page/FilesPage.jsx Outdated
Comment thread src/header/hooks.tsx Outdated
@jacobo-dominguez-wgu jacobo-dominguez-wgu force-pushed the permission-checks-files-page branch 3 times, most recently from 55ef2a6 to 407a45d Compare May 15, 2026 21:31
Copy link
Copy Markdown
Contributor

@bra-i-am bra-i-am left a comment

Choose a reason for hiding this comment

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

@jacobo-dominguez-wgu, thanks for addressing my comments!

@jacobo-dominguez-wgu
Copy link
Copy Markdown
Contributor Author

@jacobo-dominguez-wgu thanks for this PR.

I managed to test the following: ✅ Checks for the courses.view_files permission to display or hide the Files option on the header menu. Also renders a permissions denied alert if used a direct link to the files section. ✅ Checks for courses.create_files to display or hide the "+ Add files" button and the add files drop zone. ✅ Checks for courses.delete_files permission to display or hide the Delete menu option on the actions menu and the options menu in card view and list view. ⚠️ Checks for courses.edit_files to display or hide the Lock/Unlock item on the info section and in the options menu in card view and list view.

As course_auditor, I shouldn't be able to edit (so based on your description, I shouldn't be able to see the lock/unlock)
I think we should hide the lock/unlock.

I have addressed the lock/unlock option, also the recommendations from gemini were not longer needed since I removed the custom hook, thanks for your feedback!

@bra-i-am
Copy link
Copy Markdown
Contributor

bra-i-am commented May 15, 2026

@jacobo-dominguez-wgu, just one last thing, I just noticed that here is happening the same that I mentioned in this comment: #2938 (review)

Screencast.from.15-05-26.17.03.51.webm

…nEditFiles

- Remove useUserPermissionsWithAuthzCourse in favor of useCourseUserPermissions
  which provides the same functionality with better generic typing
- Migrate all consumers (CourseFilesTable, FilesPage, header hooks) to use
  useCourseUserPermissions with flat destructuring
- Hide Lock/Unlock option in FileMenu, MoreInfoColumn, and FileInfoModalSidebar
  when canEditFiles is false (course_auditor should not see lock/unlock)
- Add unit tests for lock/unlock visibility based on permissions
- Fix clipboard mock in tests using Object.defineProperty
- Update FilesPage.test.jsx mocks to match new flat return shape
@jacobo-dominguez-wgu jacobo-dominguez-wgu force-pushed the permission-checks-files-page branch from 407a45d to a4e5a52 Compare May 15, 2026 22:43
Copy link
Copy Markdown
Contributor

@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 for addressing my comments ✅

@MaferMazu MaferMazu requested a review from bradenmacdonald May 20, 2026 01:06
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). 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.

Task - RBAC Authz - Implement frontend check for Files page

6 participants