Skip to content

feat: add opt-in course-authoring filtering to authorization endpoints - #361

Open
mariajgrimaldi wants to merge 8 commits into
MJG/authz-domain-adrsfrom
MJG/endpoints-flag-aware
Open

mariajgrimaldi wants to merge 8 commits into
MJG/authz-domain-adrsfrom
MJG/endpoints-flag-aware

Conversation

@mariajgrimaldi

@mariajgrimaldi mariajgrimaldi commented Jul 13, 2026

Copy link
Copy Markdown
Member

Description

This PR adds a public Open edX Filter hook for scope-bearing authorization operations, together with an optional course-authoring pipeline. When that pipeline is configured, stale Casbin assignments cannot approve or modify a course scope whose authz.enable_course_authoring flag resolves to off. Without the pipeline configuration, the affected endpoints keep their existing behavior. The filter contract and the reason for keeping course-authoring policy outside the shared views are documented in ADR 0017.

The implementation has three parts:

  1. AuthorizationDataRequested provides a domain-neutral filter for authorization data that carries a scope. PermissionValidationMeView and the PUT and DELETE operations in RoleUserAPIView run their data through this filter.
  2. CourseAuthoringVisibilityFilter implements the optional course-authoring rule. It resolves concrete course, organization-glob, and platform-glob scopes against the effective flag state. Library scopes remain available, and staff and superusers bypass this check.
  3. The REST API views and tests are split by ownership. Admin console endpoints live under admin_console, the flag-state endpoint lives under course_authoring, and shared authorization endpoints remain in v1/views.py. The existing URLs do not change.

For POST /validate/me/, a hidden course scope remains in the response with allowed: false. For role assignment and removal, the pipeline rejects hidden scopes before calling the write API and reports scope_not_available through the endpoint's existing 207 Multi-Status response. A multi-scope PUT can still complete operations for visible scopes while reporting the rejected ones. These cases are covered by the REST API tests and pipeline tests.

Configuration

The course-authoring behavior is disabled unless the deployment registers the pipeline:

OPEN_EDX_FILTERS_CONFIG = {
    "org.openedx.authz.authorization_data.requested.v1": {
        "pipeline": [
            "openedx_authz.rest_api.v1.course_authoring.pipeline.CourseAuthoringVisibilityFilter",
        ],
        "fail_silently": False,
    },
}

How to test

To test the behavior in local environment, register the pipeline above. Since the UI is designed to avoid the use of write requests when the flag is off, make the following requests as a regular user who has a Casbin assignment for a course whose course-authoring flag is off:

  • Send the course scope to POST /api/authz/v1/validate/me/. The result for that scope should contain allowed: false. A library scope in the same request should keep its Casbin result.
  • Try to add or remove a role through /api/authz/v1/roles/users/. The response should be 207 Multi-Status, with no completed operation for the hidden course and a scope_not_available error for each rejected user.
  • Repeat as staff or a superuser. The flag should not block the validation or write operation.

Here's a postman collection for you to use to test this:

endpoints-flag-aware.postman_collection.json

Merge checklist:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted concerns, dependencies, migration issues, deadlines, or tickets

@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 Jul 13, 2026
@openedx-webhooks

openedx-webhooks commented Jul 13, 2026

Copy link
Copy Markdown

Thanks for the pull request, @mariajgrimaldi!

This repository is currently maintained by @openedx/committers-openedx-authz.

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 Jul 13, 2026
@mariajgrimaldi
mariajgrimaldi force-pushed the MJG/endpoints-flag-aware branch from 7d9f971 to 1f1f1dd Compare July 13, 2026 12:41
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Jul 13, 2026
@mariajgrimaldi

mariajgrimaldi commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

This PR was meant to partially solve #340 & #341 by supporting the proposal made here openedx/frontend-app-admin-console#176 (comment) for the Verawood release - returning False for scopes based on the waffle flag state. But the approach still needs to address other dimensions, such as the performance and correctness of the entire framework, especially since these issues are release blockers and the modified endpoints are critical to the system's functionality. Internally, we discussed the best solution moving forward, given that we shouldn't introduce big changes that put the framework's correctness at risk, and went ahead with #358 and supporting filtering via the admin-console MFE. This will definitely introduce complexity to the MFE logic, which will be addressed in the next release cycle.

mariajgrimaldi added a commit that referenced this pull request Jul 14, 2026
- get_waffle_flag_states used a manual Flag query for the global tier
instead of enable_authz_course_authoring, and returned flat booleans for
org/course overrides instead of the actual affected orgs/courses, split
by whether the override forces the flag on or off.

- Adds test coverage for get_waffle_flag_states and WaffleFlagStatesAPIView,
and an ADR documenting why this endpoint (issue #358) supersedes PR #361's
approach of enforcing the flag cascade inside release-blocking endpoints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mariajgrimaldi added a commit that referenced this pull request Jul 14, 2026
- get_waffle_flag_states used a manual Flag query for the global tier
instead of enable_authz_course_authoring, and returned flat booleans for
org/course overrides instead of the actual affected orgs/courses, split
by whether the override forces the flag on or off.

- Adds test coverage for get_waffle_flag_states and WaffleFlagStatesAPIView,
and an ADR documenting why this endpoint (issue #358) supersedes PR #361's
approach of enforcing the flag cascade inside release-blocking endpoints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
MaferMazu pushed a commit to eduNEXT/openedx-authz that referenced this pull request Jul 14, 2026
- get_waffle_flag_states used a manual Flag query for the global tier
instead of enable_authz_course_authoring, and returned flat booleans for
org/course overrides instead of the actual affected orgs/courses, split
by whether the override forces the flag on or off.

- Adds test coverage for get_waffle_flag_states and WaffleFlagStatesAPIView,
and an ADR documenting why this endpoint (issue openedx#358) supersedes PR openedx#361's
approach of enforcing the flag cascade inside release-blocking endpoints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
MaferMazu added a commit that referenced this pull request Jul 15, 2026
* feat: add waffle flag states rest api and util

* fix: address PR #358 review comments on get_waffle_flag_states

- get_waffle_flag_states used a manual Flag query for the global tier
instead of enable_authz_course_authoring, and returned flat booleans for
org/course overrides instead of the actual affected orgs/courses, split
by whether the override forces the flag on or off.

- Adds test coverage for get_waffle_flag_states and WaffleFlagStatesAPIView,
and an ADR documenting why this endpoint (issue #358) supersedes PR #361's
approach of enforcing the flag cascade inside release-blocking endpoints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix: rollback to use Flag instead of enable_authz_course_authoring,
because that needs an argument

* fix: quality tests

* docs: bumpversion to 1.21.0

* docs: update the adr

---------

Co-authored-by: Maria Grimaldi <maria.grimaldi@edunext.co>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
mariajgrimaldi added a commit that referenced this pull request Jul 29, 2026
…line

ADR 0016 records the domain-ownership audit of openedx_authz.rest_api:
which endpoints are Authorization's own data, which is the one
exception (WaffleFlagStatesAPIView), and why generic endpoints must not
depend on another domain's concepts (the rationale PR #361 ran into).

ADR 0017 names the package-layout convention the admin_console/ and
course_authoring/ subpackages apply, so a future endpoint has a
placement rule instead of a fresh discussion.

ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual
toggle_target_removal_date (2027-06-09) and upstream tracking issue for
the flag, and the confirmed details of openedx-platform's own
ToggleStateView as prior art for the rejected /api/toggles/v0/state/
alternative.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mariajgrimaldi added a commit that referenced this pull request Jul 29, 2026
…line

ADR 0016 records the domain-ownership audit of openedx_authz.rest_api:
which endpoints are Authorization's own data, which is the one
exception (WaffleFlagStatesAPIView), and why generic endpoints must not
depend on another domain's concepts (the rationale PR #361 ran into).

ADR 0017 names the package-layout convention the admin_console/ and
course_authoring/ subpackages apply, so a future endpoint has a
placement rule instead of a fresh discussion.

ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual
toggle_target_removal_date (2027-06-09) and upstream tracking issue for
the flag, and the confirmed details of openedx-platform's own
ToggleStateView as prior art for the rejected /api/toggles/v0/state/
alternative.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mariajgrimaldi added a commit that referenced this pull request Sep 8, 2026
…line

ADR 0016 records the domain-ownership audit of openedx_authz.rest_api:
which endpoints are Authorization's own data, which is the one
exception (WaffleFlagStatesAPIView), and why generic endpoints must not
depend on another domain's concepts (the rationale PR #361 ran into).

ADR 0017 names the package-layout convention the admin_console/ and
course_authoring/ subpackages apply, so a future endpoint has a
placement rule instead of a fresh discussion.

ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual
toggle_target_removal_date (2027-06-09) and upstream tracking issue for
the flag, and the confirmed details of openedx-platform's own
ToggleStateView as prior art for the rejected /api/toggles/v0/state/
alternative.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mariajgrimaldi added a commit that referenced this pull request Sep 15, 2026
… Filter

Removes PR #361's is_scope_visible/has_visible_scope from rest_api/utils.py
and replaces them with AuthorizationDataRequested (openedx_authz/filters.py),
a domain-neutral Open edX Filter. PermissionValidationMeView, ScopesAPIView,
AssignmentsAPIView, and TeamMemberAssignmentsAPIView call it directly; the
actual course-authoring visibility logic lives in the isolated, opt-in
CourseAuthoringVisibilityFilter pipeline step, disabled by default.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mariajgrimaldi
mariajgrimaldi force-pushed the MJG/endpoints-flag-aware branch from 1f1f1dd to ef87646 Compare September 15, 2026 15:59
@mariajgrimaldi
mariajgrimaldi changed the base branch from main to MJG/authz-domain-adrs September 15, 2026 16:05
@mariajgrimaldi
mariajgrimaldi added this pull request to stack #452 September 15, 2026 16:05
mariajgrimaldi added a commit that referenced this pull request Sep 15, 2026
…line

ADR 0016 records the domain-ownership audit of openedx_authz.rest_api:
which endpoints are Authorization's own data, which is the one
exception (WaffleFlagStatesAPIView), and why generic endpoints must not
depend on another domain's concepts (the rationale PR #361 ran into).

ADR 0017 names the package-layout convention the admin_console/ and
course_authoring/ subpackages apply, so a future endpoint has a
placement rule instead of a fresh discussion.

ADR 0015 gains an addendum reflecting ADR 0016's conclusion, the actual
toggle_target_removal_date (2027-06-09) and upstream tracking issue for
the flag, and the confirmed details of openedx-platform's own
ToggleStateView as prior art for the rejected /api/toggles/v0/state/
alternative.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mariajgrimaldi and others added 5 commits September 15, 2026 18:45
Moves the five Admin-Console-shaped endpoints (AdminConsoleOrgsAPIView,
ScopesAPIView, TeamMembersAPIView, TeamMemberAssignmentsAPIView,
AssignmentsAPIView) into a new admin_console/ subpackage, and
WaffleFlagStatesAPIView into a new course_authoring/ subpackage, per
the ownership and layout rules being recorded in ADR 0016 and ADR 0017.
PermissionValidationMeView, RoleUserAPIView, RoleListView, and
UserValidationAPIView remain in views.py as generic Authorization
endpoints, with no reference to any specific consumer's packaging;
that reasoning lives in admin_console/course_authoring's own docstrings
and in ADR 0017. No URLs change; tests move alongside their views.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
pylint 4.0.4/astroid 4.0.4 no longer needs the too-many-positional-arguments
suppression on these test/model signatures, flagging the old comments as
useless-suppression. Also trims trailing blank lines flagged by
trailing-newlines, fixes a line-too-long, and drops an unused import in the
new admin_console test module.

openedx_authz/rest_api/v1/filters.py was left behind, byte-identical and
unreferenced, after admin_console/filters.py replaced it in the package
layout split (ADR 0017).
The validate/me endpoint only checked Casbin permissions, so it could say
a user is allowed on a course whose waffle flag is off. An additional
check is needed: whether the scope is visible at the platform (site-wide),
org, or course level, meaning the waffle flag actually resolves to on for
that scope (see ADR 0015).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Staff/superusers already bypass the Casbin permission check in
is_user_allowed_in_scope. has_visible_scope now grants the same bypass for
flag visibility, so staff see flag-disabled courses as an operational
escape hatch instead of getting denied with no way to inspect them.

Updates ADR 0015's decision and consequences to match, and adds test
coverage for the new bypass in both has_visible_scope and the
validate/me endpoint.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
has_visible_scope reads a request-cached waffle flag, cheaper than
is_user_allowed_in_scope's Casbin policy evaluation. Check the cheap one
first so the expensive one only runs when it can still change the result.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mariajgrimaldi and others added 2 commits September 15, 2026 18:45
… Filter

Removes PR #361's is_scope_visible/has_visible_scope from rest_api/utils.py
and replaces them with AuthorizationDataRequested (openedx_authz/filters.py),
a domain-neutral Open edX Filter. PermissionValidationMeView, ScopesAPIView,
AssignmentsAPIView, and TeamMemberAssignmentsAPIView call it directly; the
actual course-authoring visibility logic lives in the isolated, opt-in
CourseAuthoringVisibilityFilter pipeline step, disabled by default.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mariajgrimaldi
mariajgrimaldi force-pushed the MJG/endpoints-flag-aware branch from ef87646 to d6c08db Compare September 15, 2026 16:45
@mariajgrimaldi mariajgrimaldi changed the title feat: make PermissionValidationMeView aware of the course-authoring flag feat: add opt-in course-authoring filtering to authorization endpoints Sep 16, 2026
@mariajgrimaldi
mariajgrimaldi marked this pull request as ready for review September 16, 2026 09:03
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). 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.

3 participants