Skip to content

feat: add authz permission for the course authoring list#38199

Open
dwong2708 wants to merge 8 commits intoopenedx:masterfrom
WGU-Open-edX:dwong2708/authz-new-perms-course-list-endpoint
Open

feat: add authz permission for the course authoring list#38199
dwong2708 wants to merge 8 commits intoopenedx:masterfrom
WGU-Open-edX:dwong2708/authz-new-perms-course-list-endpoint

Conversation

@dwong2708
Copy link
Contributor

@dwong2708 dwong2708 commented Mar 20, 2026

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

  • Replaced the dual pipeline (AuthZ vs legacy) with a unified loop.
  • Each course is evaluated once using:
    - user_has_course_permission(...)
  • Eliminates duplicated logic and merging complexity.

Scoped full scan to staff users only

  • Staff users still require evaluating all courses (expected behavior).
  • Non-staff users now operate only on candidate course keys, avoiding unnecessary full table scans.
if is_staff_user:
    candidate_keys = CourseOverview.get_all_courses().values_list("id", flat=True)
else:
    candidate_keys = _get_candidate_course_keys(request)

Deferred object fetching

  • Only fetch full CourseOverview objects after access filtering
  • Reduces memory usage and DB overhead

Centralized filtering and ordering

  • Filters (search, active/archived, ordering) are applied once at the end
  • Ensures consistent behavior and avoids repeated processing

Improved readability and maintainability

  • Clear step-based flow:
  1. Determine candidate keys
  2. Evaluate access
  3. Batch fetch
  4. Apply filters
  • Reduced cognitive complexity and branching

Testing Notes

  • Existing tests should continue to pass without modification
  • Recommended additional coverage:
    • Mixed AuthZ + legacy access scenarios
    • Staff vs non-staff behavior
    • Empty access cases

Deadline

Verawood

Other information

Resolves: openedx/openedx-authz#190

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Mar 20, 2026
@openedx-webhooks
Copy link

openedx-webhooks commented Mar 20, 2026

Thanks for the pull request, @dwong2708!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform.

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 Mar 20, 2026
@dwong2708 dwong2708 force-pushed the dwong2708/authz-new-perms-course-list-endpoint branch from 25142ea to 96b100a Compare March 21, 2026 00:03
@dwong2708 dwong2708 changed the title Dwong2708/authz new perms course list endpoint feat: add authz permission for the course authoring list Mar 21, 2026
@dwong2708 dwong2708 marked this pull request as ready for review March 21, 2026 22:58
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Mar 23, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Mar 23, 2026
Copy link
Contributor

@rodmgwgu rodmgwgu left a comment

Choose a reason for hiding this comment

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

It's looking good so far, just some comments

COURSES_VIEW_COURSE.identifier
)

authz_keys = {
Copy link
Contributor

Choose a reason for hiding this comment

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

We will need to update this once openedx/openedx-authz#225 is merged to support org level scopes (OrgGlobData).

Please create a Github issue for this if it's not already there.

# user has global access so no need to get courses from django groups
courses, in_process_course_actions = _accessible_courses_summary_iter(request)
user = request.user
is_staff_user = GlobalStaff().has_user(user) or user.is_superuser
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't GlobalStaff().has_user(user) already checking for user.is_superuser?

# 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that get_in_process_course_actions is validating internally with user_has_course_permission,

But if we already know it's a staff user, do we need to do that?

Or are we using get_in_process_course_actions elsewhere and don't want to break something?

@dwong2708 dwong2708 force-pushed the dwong2708/authz-new-perms-course-list-endpoint branch from 78bf785 to 3cba95e Compare March 24, 2026 19:25
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: Ready for Review

Development

Successfully merging this pull request may close these issues.

Task - RBAC AuthZ - Implement new permissions for Course list

4 participants