Initial commit: monorepo Match Live TV.
Rails API, app Flutter, infrastruttura Docker/MediaMTX, sito marketing e documentazione di deploy. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
28
backend/app/models/team_invitation.rb
Normal file
28
backend/app/models/team_invitation.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class TeamInvitation < ApplicationRecord
|
||||
STAFF_KINDS = %w[transmission regia].freeze
|
||||
|
||||
belongs_to :team
|
||||
|
||||
validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
||||
validates :token_digest, presence: true, uniqueness: true
|
||||
validates :role, inclusion: { in: UserTeam::ROLES }
|
||||
validates :staff_kind, inclusion: { in: STAFF_KINDS }
|
||||
|
||||
scope :pending, -> { where(accepted_at: nil).where("expires_at > ?", Time.current) }
|
||||
|
||||
def self.generate_token
|
||||
SecureRandom.urlsafe_base64(32)
|
||||
end
|
||||
|
||||
def accept!(user)
|
||||
ut = UserTeam.find_or_initialize_by(user: user, team: team)
|
||||
ut.role = role
|
||||
ut.staff_kind = staff_kind
|
||||
ut.save!
|
||||
update!(accepted_at: Time.current)
|
||||
end
|
||||
|
||||
def expired?
|
||||
expires_at.past?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user