Files
fizzy/app/models/user.rb
T
2025-04-22 11:26:56 +02:00

31 lines
896 B
Ruby

class User < ApplicationRecord
include Accessor, Assignee, Avatar, Mentionable, Named, Role, Transferable
has_many :sessions, dependent: :destroy
has_secure_password validations: false
has_many :comments, inverse_of: :creator, dependent: :destroy
has_many :notifications, dependent: :destroy
has_many :filters, foreign_key: :creator_id, inverse_of: :creator, dependent: :destroy
has_many :closures, dependent: :nullify
has_many :pins, dependent: :destroy
has_many :pinned_cards, through: :pins, source: :card
normalizes :email_address, with: ->(value) { value.strip.downcase }
def deactivate
transaction do
sessions.delete_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