Skip to content

Update transfer_ownership task to use OwnershipTransfer::Create - #1081

Draft
cocomarine wants to merge 2 commits into
mainfrom
update-transfer-ownership-task-to-use-recent-flow
Draft

cocomarine wants to merge 2 commits into
mainfrom
update-transfer-ownership-task-to-use-recent-flow

Conversation

@cocomarine

@cocomarine cocomarine commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Why?

The school_management:transfer_ownership rake task now uses the same (frontend-led) OwnershipTransfer flow that we implemented recently, instead of editing roles directly.

The old task destroyed and created Role records by hand. That left no OwnershipTransfer record and sent no emails, so it differed from a transfer made through the frontend.

What's changed?

  • It makes the new owner a teacher, then creates an OwnershipTransfer and accepts it straight away.
  • Accepting the transfer archives the old owner role instead of destroying it.
  • The old owner's teacher role is archived unless keep_old_owner_as_teacher is true.
  • It still resets creator_agree_to_ux_contact as before.
  • If creating the transfer fails (for example, a pending transfer already exists), the new teacher role is rolled back and the owner is unchanged.
  • If the old owner isn't a school owner, it logs an error and exits. Before, this raised a nil error.
  • skip_request_email option on OwnershipTransfer and OwnershipTransfer::Create.
    • The task sets it because the request email makes no sense when the transfer is accepted immediately in this flow. The completed emails to the new and previous owners are still sent.

Usage

  • Remains the same as before.
# To transfer ownership from Jane to John and REMOVE Jane as a teacher:
bundle exec rails school_management:transfer_ownership[jane.doe@example.com,john.doe@example.com]

# To transfer ownership from Jane to John and KEEP Jane as a teacher:
bundle exec rails school_management:transfer_ownership[jane.doe@example.com,john.doe@example.com,true]

Steps to perform after deploying to production

@cla-bot cla-bot Bot added the cla-signed label Oct 26, 2026
@cocomarine cocomarine changed the title Update transfer ownership task to use recent flow Update transfer_ownership task to use OwnershipTransfer Oct 26, 2026
@cocomarine cocomarine changed the title Update transfer_ownership task to use OwnershipTransfer Update transfer_ownership task to use OwnershipTransfer::Create Oct 26, 2026
@github-actions

Copy link
Copy Markdown

Test coverage

94.12% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/40363372674

This branch was successfully deployed

1 active deployment
editor-api-p-update-tra-wfntp5 — 25d0e068 Deployed Oct 26, 2026 by raspberrypiherokubot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants