Adding permission validations from authz for files page#2941
Adding permission validations from authz for files page#2941jacobo-dominguez-wgu wants to merge 3 commits into
Conversation
|
Thanks for the pull request, @jacobo-dominguez-wgu! 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 #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. 🚀 New features to boost your workflow:
|
94a4751 to
4839aab
Compare
|
@jacobo-dominguez-wgu Is this ready for review? |
2bfe88f to
6cde551
Compare
170a3b2 to
9aed071
Compare
MaferMazu
left a comment
There was a problem hiding this comment.
@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.
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.
|
Also, I asked Gemini for major issues and mentioned the following:
(Please judge these suggestions, because they came from AI) |
|
Yes, those are good suggestions - please ensure all hooks are fully typed and handle errors. |
bra-i-am
left a comment
There was a problem hiding this comment.
@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
55ef2a6 to
407a45d
Compare
bra-i-am
left a comment
There was a problem hiding this comment.
@jacobo-dominguez-wgu, thanks for addressing my comments!
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! |
|
@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
407a45d to
a4e5a52
Compare
MaferMazu
left a comment
There was a problem hiding this comment.
Thanks for addressing my comments ✅
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
enableAuthzCourseAuthoringwaffle flagTest Scenarios
1. Files & Uploads Page — Authz Disabled (Legacy Behavior)
Setup: Ensure
enableAuthzCourseAuthoringwaffle flag is disabled2. Files & Uploads Page — Authz Enabled with Full Permissions
Setup:
enableAuthzCourseAuthoringwaffle flagcourses.view_files,courses.create_files,courses.edit_files, andcourses.delete_filespermissions3. Files & Uploads Page — Authz Enabled with View-Only Permissions
Setup:
enableAuthzCourseAuthoringwaffle flagcourses.view_filespermission4. Files & Uploads Page — Authz Enabled with No Permissions
Setup:
enableAuthzCourseAuthoringwaffle flag5. Header Settings Menu — Authz Disabled
Setup: Ensure
enableAuthzCourseAuthoringwaffle flag is disabled6. Header Settings Menu — Authz Enabled
Setup:
enableAuthzCourseAuthoringwaffle flagADMIN_CONSOLE_URLenvironment variable7. Header Content Menu — Files Option Visibility
Setup: Enable
enableAuthzCourseAuthoringwaffle flagcourses.view_filesgrantedcourses.view_filesNOT grantedBest 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'