Skip to content

Update ownership transfer and mailer - #1019

Merged
cocomarine merged 12 commits into
mainfrom
1766-create-ownership-transfer
Sep 18, 2026
Merged

cocomarine merged 12 commits into
mainfrom
1766-create-ownership-transfer

Conversation

@cocomarine

@cocomarine cocomarine commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Status

What's changed?

  • Added nominated_user_id, requested_by_user_id, and a status enum to ownership_transfers table
  • Validating the nominee holds the owner or teacher role for the school
  • Update SchoolOwnershipMailer to include the nominee's and requester's names in the email body, with model, mailer, and preview specs updated to match

Not covered here:

@cla-bot cla-bot Bot added the cla-signed label Sep 15, 2026
@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown

Test coverage

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

Comment thread app/models/ownership_transfer.rb Outdated
Comment thread app/models/ownership_transfer.rb Outdated
@cocomarine
cocomarine temporarily deployed to editor-api-p-1766-creat-p1koes September 17, 2026 08:15 Inactive
@cocomarine cocomarine changed the title Create ownership transfer Update ownership transfer and mailer Sep 17, 2026
@cocomarine
cocomarine marked this pull request as ready for review September 17, 2026 09:43
Copilot AI lite review requested due to automatic review settings September 17, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The migration and remaining validation, factory, mailer, and preview issues must be addressed.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates ownership transfers with nominee/requester metadata, status tracking, role validation, and personalized notification emails.

Changes:

  • Adds transfer fields, status enum, school association, and nominee role validation.
  • Personalizes ownership-transfer emails and previews.
  • Updates factories and related specs.
File summaries
File Summary
spec/models/school_spec.rb Tests the ownership-transfer association.
spec/models/ownership_transfer_spec.rb Tests transfer validation and statuses.
spec/mailers/school_ownership_mailer_spec.rb Tests personalized email content.
spec/mailers/previews/school_ownership_mailer_preview.rb Updates preview user data. Moderate (3 votes): avoid permanently replacing the API client method; use a scoped stub or dependency injection.
spec/factories/ownership_transfer.rb Updates transfer factory data. Moderate (2 votes): ensure default nominees have valid roles and requesters are resolvable.
db/schema.rb Reflects the updated schema.
db/migrate/20260915093824_add_nominee_and_status_to_ownership_transfers.rb Adds transfer columns. Critical (3 votes): stage nullable columns, backfill or clean up existing rows, then enforce constraints.
app/views/school_ownership_mailer/request_ownership_transfer.text.erb Personalizes email text.
app/models/school.rb Adds the ownership-transfer association.
app/models/ownership_transfer.rb Adds status and nominee validation. Moderate (1 vote): validate the nominee when school_id changes as well.
app/mailers/school_ownership_mailer.rb Loads nominee and requester names. Moderate (2 votes): fetch both users in one API request.
Review details

Suppressed comments (1)

app/models/ownership_transfer.rb:24

  • Because this guard only checks nominated_user_id_changed?, changing an existing transfer's school_id skips the role check, allowing a nominee valid in the old school to be saved against a school where they have no owner or teacher role. Include school changes in the condition, or validate this invariant on every save.
    return unless nominated_user_id_changed? && errors.blank? && school
  • Files reviewed: 11/11 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread db/migrate/20260915093824_add_nominee_and_status_to_ownership_transfers.rb Outdated
Comment thread app/mailers/school_ownership_mailer.rb Outdated
Comment thread spec/factories/ownership_transfer.rb Outdated
Comment thread spec/mailers/previews/school_ownership_mailer_preview.rb
@DNR500

DNR500 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Looks solid overall - the schema, validation, and mailer changes all make sense. Left a few comments from Copilot's review that I think are worth addressing before this merges (the migration's NOT NULL columns, the mailer's duplicate API calls, the factory's invalid default, and the mailer preview permanently patching the API client).

Happy to approve once those are sorted.

@cocomarine
cocomarine temporarily deployed to editor-api-p-1766-creat-p1koes September 17, 2026 14:19 Inactive
@cocomarine
cocomarine temporarily deployed to editor-api-p-1766-creat-p1koes September 17, 2026 15:35 Inactive
@cocomarine
cocomarine temporarily deployed to editor-api-p-1766-creat-p1koes September 17, 2026 16:23 Inactive

@DNR500 DNR500 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good :-)

@cocomarine
cocomarine merged commit 69c1c8e into main Sep 18, 2026
8 checks passed
@cocomarine
cocomarine deleted the 1766-create-ownership-transfer branch September 18, 2026 08:46
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.

5 participants