Files
fizzy/app/models/user.rb
T
Mike Dalessio b75d2ae6d8 Validate User name presence and handle blank names gracefully
Addresses an issue where User#familiar_name assumed `name` was always
present, potentially raising an exception during view rendering. Now
User validates name presence, and User#familiar_name handles blank
strings without error, in case any existing invalid records exist.
2025-12-16 10:44:10 -05:00

44 lines
1.1 KiB
Ruby

class User < ApplicationRecord
include Accessor, Assignee, Attachable, Avatar, Configurable, EmailAddressChangeable,
Mentionable, Named, Notifiable, Role, Searcher, Watcher
include Timelined # Depends on Accessor
belongs_to :account
belongs_to :identity, optional: true
validates :name, presence: true
has_many :comments, inverse_of: :creator, 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
has_many :exports, class_name: "Account::Export", dependent: :destroy
def deactivate
transaction do
accesses.destroy_all
update! active: false, identity: nil
close_remote_connections
end
end
def setup?
name != identity.email_address
end
def verified?
verified_at.present?
end
def verify
update!(verified_at: Time.current) unless verified?
end
private
def close_remote_connections
ActionCable.server.remote_connections.where(current_user: self).disconnect(reconnect: false)
end
end