discourse/app/models/email_change_request.rb
David Taylor 3332e9f4c3
DEV: Always pass --force to annotaterb and reorder annotations (#39977)
`.annotaterb.yml` has carried `classified_sort: true` since the project
switched from `annotate` to `annotaterb` (commit 0eab7daea4, July 2025),
but annotaterb's default behaviour is to compare the existing schema
block against what it would generate and skip the rewrite when the
column list matches — even when the *ordering* of those columns differs.
The result is that models which haven't had a schema change since the
config landed never get reordered, and `classified_sort` drift
accumulates indefinitely.

`--force` makes annotaterb always rewrite, so a single `bin/rake
annotate:clean` run brings every model into the canonical format and
keeps them there. Every schema block is now grouped primary-key →
regular columns → timestamps → foreign keys (alphabetical within each
group). Pure annotation comment change — no code modifications.

Also cleans up the rake task to avoid string interpolation for `system`
calls.
2026-05-13 14:12:48 +01:00

52 lines
1.6 KiB
Ruby
Vendored

# frozen_string_literal: true
class EmailChangeRequest < ActiveRecord::Base
belongs_to :user
belongs_to :old_email_token, class_name: "EmailToken", dependent: :destroy
belongs_to :new_email_token, class_name: "EmailToken", dependent: :destroy
belongs_to :requested_by, class_name: "User", foreign_key: :requested_by_user_id
validates :new_email, presence: true, format: { with: EmailAddressValidator.email_regex }
def self.states
@states ||= Enum.new(authorizing_old: 1, authorizing_new: 2, complete: 3)
end
def self.find_by_new_token(token)
EmailChangeRequest
.joins(
"INNER JOIN email_tokens ON email_tokens.id = email_change_requests.new_email_token_id",
)
.where("email_tokens.token_hash = ?", EmailToken.hash_token(token))
.last
end
def requested_by_admin?
self.requested_by&.admin? && !self.requested_by_self?
end
def requested_by_self?
self.requested_by_user_id == self.user_id
end
end
# == Schema Information
#
# Table name: email_change_requests
#
# id :integer not null, primary key
# change_state :integer not null
# new_email :string not null
# old_email :string
# created_at :datetime not null
# updated_at :datetime not null
# new_email_token_id :integer
# old_email_token_id :integer
# requested_by_user_id :integer
# user_id :integer not null
#
# Indexes
#
# idx_email_change_requests_on_requested_by (requested_by_user_id)
# index_email_change_requests_on_user_id (user_id)
#