feat: add authz permission for the course authoring list#38199
feat: add authz permission for the course authoring list#38199dwong2708 wants to merge 10 commits intoopenedx:masterfrom
Conversation
|
Thanks for the pull request, @dwong2708! 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. |
25142ea to
96b100a
Compare
rodmgwgu
left a comment
There was a problem hiding this comment.
It's looking good so far, just some comments
78bf785 to
3cba95e
Compare
| return filter(filter_course, filtered_courses) | ||
|
|
||
|
|
||
| def _get_candidate_course_keys(request): |
There was a problem hiding this comment.
Can you help me understand why we are combining both of the keys? I'm not sure I follow. Thanks!
There was a problem hiding this comment.
Because non-staff users typically have access to a smaller subset of courses, this significantly reduces the number of courses we need to check for access in the next step.
I left the same comment in the code to improve clarity. Thanks for pointing that out and let me know if it is clearer now.
There was a problem hiding this comment.
I wonder about an edge case here where the user has permissions on a course with authz but not in the legacy system, is that even possible?
rodmgwgu
left a comment
There was a problem hiding this comment.
Just some questions and observations
| # and defer fetching the full course objects until after filtering by access | ||
| candidate_keys = CourseOverview.get_all_courses().values_list("id", flat=True) | ||
| # Compute actions once for staff users since they have access to all courses | ||
| in_process_actions = get_in_process_course_actions(request) |
There was a problem hiding this comment.
Are in_process_actions only supposed to be fetched for staff users?
There was a problem hiding this comment.
Yes it is, according to the old code:
There was a problem hiding this comment.
I see that, when we called _accessible_courses_list_from_groups, it in fact meant that in_process_actions was always empty, however, if we got teh AccessListFallback exception, it does call _accessible_courses_summary_iter for non-staff users, which may bring in_process_actions.
| # Step 2: Single-pass decision → collect valid keys | ||
| valid_course_keys = set() | ||
| for course_key in candidate_keys: | ||
| if is_staff_user or user_has_course_permission( |
There was a problem hiding this comment.
Is this check really needed? From what I'm understanding, _get_candidate_course_keys already filtered the courses so we only get the ones the user has permission to see, and the other code path is for staff which should see everything anyway.
Or am I missing something?
There was a problem hiding this comment.
This was something I was unsure about. Based on the old code:
The _accessible_courses_summary_iter function is where the logic for staff users is handled. It iterates through each course and applies has_studio_read_access:
That’s why this code attempts to preserve the previous behavior. However, I agree with you that it seems redundant. I can remove it if you’re okay with that and verify everything with tests.
There was a problem hiding this comment.
I decided to remove this redundant check.
234f420 to
29b8587
Compare
|
Just tested in my local, and it's working correctly. |
| authz_keys = { | ||
| access.course_key | ||
| for access in authz_scopes | ||
| if isinstance(access, CourseOverviewData) and access.course_key |
There was a problem hiding this comment.
Are we expecting something different than CourseOverviewData here or should we trust the get_scopes_for_user_and_permission signature?
Refactor course access listing to single-pass hybrid AuthZ + legacy approach
Summary
This PR refactors get_courses_accessible_to_user to improve performance, readability, and maintainability by introducing a single-pass hybrid access evaluation model.
Instead of splitting courses into separate AuthZ and legacy pipelines and merging results afterward, this implementation evaluates access per course in a single pass, then performs a single batched query to retrieve the final course list.
Key Improvements
Single-pass access evaluation
-
user_has_course_permission(...)Scoped full scan to staff users only
Deferred object fetching
Centralized filtering and ordering
Improved readability and maintainability
Testing Notes
Deadline
Verawood
Other information
Resolves: openedx/openedx-authz#190