Files
fizzy/app/models/user.rb
T
David Heinemeier Hansson 8ff017fc5b Only one invocation of this, not carrying the worth of its indirection
Generally I am wary of including global state checks in the belly of
models. It is one thing to do it as a default parameter, but I think it
is too far to do it inside an actual method.
2025-04-05 12:40:08 +02:00

41 lines
1.0 KiB
Ruby

class User < ApplicationRecord
include Accessor, Assignee, Avatar, Role, Transferable
belongs_to :account
has_many :sessions, dependent: :destroy
has_secure_password validations: false
has_many :filters, foreign_key: :creator_id, inverse_of: :creator, dependent: :destroy
has_many :pops, dependent: :nullify
has_many :notifications, dependent: :destroy
has_many :pins, dependent: :destroy
has_many :pinned_bubbles, through: :pins, source: :bubble
normalizes :email_address, with: ->(value) { value.strip.downcase }
scope :alphabetically, -> { order("lower(name)") }
scope :sorted_with_user_first, ->(user) { order(Arel.sql("users.id != ?, lower(name)", user.id)) }
def initials
name.to_s.scan(/\b\p{L}/).join.upcase
end
def deactivate
transaction do
sessions.destroy_all
accesses.destroy_all
update! active: false, email_address: deactived_email_address
end
end
private
def deactived_email_address
email_address.sub(/@/, "-deactivated-#{SecureRandom.uuid}@")
end
end