Skip to content

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

Open
dwong2708 wants to merge 7 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 7 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.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

Task - RBAC AuthZ - Implement new permissions for Course list

2 participants