2f740c81c0
- Use `AccountSlug.encode` to generate slug instead of raw ID - Fixes where slug is /1 and will be in the proper format of /0000001
46 lines
1.0 KiB
Ruby
46 lines
1.0 KiB
Ruby
class Account < ApplicationRecord
|
|
include Entropic, Seedeable
|
|
|
|
has_one :join_code
|
|
has_many :users, dependent: :destroy
|
|
has_many :boards, dependent: :destroy
|
|
has_many :cards, dependent: :destroy
|
|
has_many :webhooks, dependent: :destroy
|
|
has_many :tags, dependent: :destroy
|
|
has_many :columns, dependent: :destroy
|
|
has_many :exports, class_name: "Account::Export", dependent: :destroy
|
|
|
|
has_many_attached :uploads
|
|
|
|
before_create :assign_external_account_id
|
|
after_create :create_join_code
|
|
|
|
validates :name, presence: true
|
|
|
|
class << self
|
|
def create_with_owner(account:, owner:)
|
|
create!(**account).tap do |account|
|
|
account.users.create!(role: :system, name: "System")
|
|
account.users.create!(**owner.reverse_merge(role: "owner"))
|
|
end
|
|
end
|
|
end
|
|
|
|
def slug
|
|
"/#{AccountSlug.encode(external_account_id)}"
|
|
end
|
|
|
|
def account
|
|
self
|
|
end
|
|
|
|
def system_user
|
|
users.where(role: :system).first!
|
|
end
|
|
|
|
private
|
|
def assign_external_account_id
|
|
self.external_account_id ||= ExternalIdSequence.next
|
|
end
|
|
end
|