Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/payee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Payee < ApplicationRecord

validate :managed_legal_entity_constraints

normalizes :email, with: ->(email) { email.strip.downcase }

scope :not_archived, -> { where(archived_at: nil) }

pg_search_scope :search, against: [:display_name, :email], using: { tsearch: { prefix: true, dictionary: "english" } }
Expand Down
5 changes: 4 additions & 1 deletion app/policies/payroll/position_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def review?
end

def onboarding?
user&.auditor? || record.payee.legal_entity&.users&.include?(user) || user&.email == record.payee.email
return true if user&.auditor?
return true if record.payee.legal_entity&.users&.include?(user)

user&.email.present? && user.email.casecmp?(record.payee.email.to_s)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return true if user&.auditor?
return true if record.payee.legal_entity&.users&.include?(user)
user&.email.present? && user.email.casecmp?(record.payee.email.to_s)
return false if user.nil?
return true if user.auditor?
return true if record.payee.legal_entity&.users&.include?(user)
user.email == record.payee.email

Instead of using casecmp, we should update production data to downcase all existing emails.

It looks like in all cases, the page should not be accessible in transparency mode (when user is nil). I added it as a guard clause at the very beginning to simplify the logic in this method.

end

private
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20260805120000_downcase_payee_emails.rb

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a maintenance task.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class DowncasePayeeEmails < ActiveRecord::Migration[8.1]
disable_ddl_transaction!

def up
Payee.where("email <> lower(btrim(email))").in_batches(of: 1_000) do |batch|
batch.update_all("email = lower(btrim(email))")
end
end

def down
# irreversible
end

end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_08_04_120000) do
ActiveRecord::Schema[8.1].define(version: 2026_08_05_120000) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "pg_catalog.plpgsql"
Expand Down