Files
fizzy/app/models/user.rb
T
Mike Dalessio 8f39c015ea Tests now pass with local authentication
This is the first step of a multi-step SaaS engine extraction.

Looking ahead to an open source release, we need to make sure that
local authentication is treated as an "official" option, and not just
a hack I added for Kevin to do load testing outside our DC. So this PR
gets to green, and adds a CI step in "local authentication" mode.

This all probably feels a little hacky to you, Reader, but the goal of
this change is to ease the next step, which will be extracting the
37id and Queenbee integrations into a proprietary "SaaS mode" engine.

In service of that goal, this commit simply wraps all of the dependent
code and tests with a conditional check on
`config.x.local_authentication`.
2025-09-13 15:21:00 -04:00

35 lines
1.1 KiB
Ruby

class User < ApplicationRecord
include Accessor, AiQuota, Assignee, Attachable, Configurable, Conversational, Highlights,
Mentionable, Named, Notifiable, Role, Searcher, SignalUser, Staff, Transferable
include Timelined # Depends on Accessor
has_one_attached :avatar
has_many :sessions, dependent: :destroy
has_secure_password validations: false
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 :commands, dependent: :destroy
normalizes :email_address, with: ->(value) { value.strip.downcase }
def deactivate
sessions.delete_all
accesses.destroy_all
unless Rails.application.config.x.local_authentication
SignalId::Database.on_master { signal_user&.destroy }
end
update! active: false, email_address: deactived_email_address
end
private
def deactived_email_address
email_address.sub(/@/, "-deactivated-#{SecureRandom.uuid}@")
end
end