Skip to content

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

Merged
cocomarine merged 3 commits into
mainfrom
update-transfer-ownership-task-to-use-recent-flow
Oct 29, 2026
Merged

cocomarine merged 3 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 old school_management:transfer_ownership rake task destroyed and created Role records by hand. That left no OwnershipTransfer record and sent no emails, so it differed from the (frontend-led) OwnershipTransfer flow that we implemented recently,

It now uses the recent OwnershipTransfer flow instead of editing roles directly.

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]

Possible future iteration

  • We could add an option for calling OwnershipTransfer::Create and then stopping so that the task is used only for nomination. The nominee (current teacher or newly created teacher) gets the email and accepts on the frontend, following the front-end led flow after the nomination step.
  • This will remove the manual process of confirming T&C before the task is run.
  • We need to think about things like below:
    • What should requested_by_user_id be? It's required, and the mailers treat it as "the previous owner".
    • Setting it to a support personnel gives a more honest audit trail, but then "previous owner" emails go to support.
    • May need a small schema or mailer tweak, such as a nullable requester or a "requested by support" marker.

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

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Test coverage

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

@raspberrypiherokubot
raspberrypiherokubot temporarily deployed to editor-api-p-update-tra-wfntp5 October 26, 2026 16:57 Inactive
@cocomarine
cocomarine marked this pull request as ready for review October 29, 2026 08:40
@cocomarine cocomarine self-assigned this Oct 29, 2026
Comment thread lib/tasks/school_management.rake Outdated
So that it aligns with how OwnershipTransfer::Accept handles it.
@cocomarine
cocomarine temporarily deployed to editor-api-p-update-tra-wfntp5 October 29, 2026 08:56 Inactive
Comment thread lib/tasks/school_management.rake
@cocomarine
cocomarine merged commit d0cc560 into main Oct 29, 2026
9 checks passed
@cocomarine
cocomarine deleted the update-transfer-ownership-task-to-use-recent-flow branch October 29, 2026 15:39

This branch was previously deployed

1 inactive deployment
editor-api-p-update-tra-wfntp5 — 5f59fe61 Deployed Oct 29, 2026 by cocomarine
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.

3 participants