Skip to content

feat: course authoring automatic migration#259

Merged
mariajgrimaldi merged 29 commits intoopenedx:mainfrom
eduNEXT:bav/course-authoring-automatic-migration
Apr 22, 2026
Merged

feat: course authoring automatic migration#259
mariajgrimaldi merged 29 commits intoopenedx:mainfrom
eduNEXT:bav/course-authoring-automatic-migration

Conversation

@BryanttV
Copy link
Copy Markdown
Contributor

@BryanttV BryanttV commented Apr 14, 2026

Closes: #223

Description

This PR implements the automatic course authoring migration feature, which triggers a migration between the legacy CourseAccessRole system and the new AuthZ (Casbin-based) system whenever the authz.enable_course_authoring waffle flag is toggled for a course or organization.

Changes

New Model: AuthzCourseAuthoringMigrationRun

  • Tracks the full lifecycle of each migration run (forward or rollback).
  • Supports the following statuses: running, completed, partial_success, failed, skipped.
  • Scopes can be course or org.
  • Enforces a database-level uniqueness constraint to prevent concurrent runs for the same scope.
  • Stores structured metadata (success/error counts, error details, skip reasons) as JSON.

New Core Function: run_course_authoring_migration

  • Orchestrates a full migration run with tracking and concurrency protection.
  • Uses transaction.atomic() to create the tracking record atomically. An IntegrityError from the unique constraint skips the run instead of crashing.
  • Delegates to migrate_legacy_course_roles_to_authz (forward) or migrate_authz_to_legacy_course_roles (rollback).
  • Unhandled exceptions mark the run as failed (outside the inner transaction, so the tracking record is always persisted).

Signal Handlers

  • Connects post_save signals from WaffleFlagCourseOverrideModel and WaffleFlagOrgOverrideModel.
  • handle_course_waffle_flag_change / handle_org_waffle_flag_change → delegate to trigger_course_authoring_migration.
  • trigger_course_authoring_migration:
    • Guards against execution when ENABLE_AUTOMATIC_AUTHZ_COURSE_AUTHORING_MIGRATION = False.
    • Ignores saves for unrelated waffle flags.
    • Detects no-op saves (flag value didn't actually change) by comparing against the previous record.
    • Determines migration direction: FORWARD when flag is enabled, ROLLBACK when disabled.

New Setting

  • ENABLE_AUTOMATIC_AUTHZ_COURSE_AUTHORING_MIGRATION defaults to False. Must be explicitly opted in to activate automatic migrations.

Testing Instructions

Related PR

Merge checklist

Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, 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 Apr 14, 2026
@openedx-webhooks
Copy link
Copy Markdown

openedx-webhooks commented Apr 14, 2026

Thanks for the pull request, @BryanttV!

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 Apr 14, 2026
@BryanttV BryanttV force-pushed the bav/course-authoring-automatic-migration branch 2 times, most recently from 248c2ab to 03a33e8 Compare April 14, 2026 14:19
@BryanttV BryanttV force-pushed the bav/course-authoring-automatic-migration branch 5 times, most recently from 0665267 to 639be47 Compare April 15, 2026 14:48
@BryanttV BryanttV marked this pull request as ready for review April 15, 2026 16:31
@BryanttV BryanttV force-pushed the bav/course-authoring-automatic-migration branch from b307678 to 05ae570 Compare April 15, 2026 18:44
@BryanttV
Copy link
Copy Markdown
Contributor Author

BryanttV commented Apr 15, 2026

Note to the reviewer:

I was running tests to verify that the UniqueConstraint was working, but it wasn’t. After investigating a bit, I found that in MySQL, the conditions are ignored because they are not supported 1 2. Therefore, I implemented validation by overriding the save() method, preventing the creation of additional records with the same scope_type and scope_key if one already exists in a running state.

Footnotes

  1. https://docs.djangoproject.com/en/5.2/ref/models/constraints/#django.db.models.UniqueConstraint.condition

  2. https://docs.djangoproject.com/en/5.2/ref/models/indexes/#django.db.models.Index.condition

Copy link
Copy Markdown
Contributor

@dwong2708 dwong2708 left a comment

Choose a reason for hiding this comment

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

Impressive work. Just a couple of comments. Thanks!

Comment thread openedx_authz/models/authz_migration.py
Comment thread openedx_authz/settings/common.py Outdated
Comment thread openedx_authz/handlers.py
Comment thread openedx_authz/engine/utils.py
Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

Thanks a lot for all the effort!

Comment thread openedx_authz/engine/utils.py
Comment thread openedx_authz/models/authz_migration.py Outdated
Comment thread openedx_authz/models/authz_migration.py Outdated
Comment thread openedx_authz/handlers.py Outdated
@BryanttV BryanttV force-pushed the bav/course-authoring-automatic-migration branch from 8048c22 to dca9107 Compare April 16, 2026 15:06
BryanttV added 23 commits April 21, 2026 09:24
@BryanttV BryanttV force-pushed the bav/course-authoring-automatic-migration branch from ab1b229 to fb803ac Compare April 21, 2026 14:25
Copy link
Copy Markdown
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.

Thanks for all this work!

Copy link
Copy Markdown
Contributor

@dwong2708 dwong2708 left a comment

Choose a reason for hiding this comment

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

LGTM! Great job on this.

Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

LGTM!

Let's not forget to document this thoroughly for operators ;) thanks all!

@mariajgrimaldi mariajgrimaldi merged commit 7afbff4 into openedx:main Apr 22, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from In Eng Review to Done in Contributions Apr 22, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

Task – RBAC AuthZ – Waffle flag - Automatic Migration Trigger

6 participants