Files
MatchLiveTv/backend/app/models/team.rb
Emiliano Frascaro 1f273f849d Aggiunge modulo Replay, Garage dev e YouTube a livello società.
Pipeline registrazione/upload con storage S3, archivio web e app, proxy replay
per il browser, OAuth YouTube sulla pagina club (Premium Full) e footer legale.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-03 07:53:11 +02:00

66 lines
1.4 KiB
Ruby

class Team < ApplicationRecord
include Brandable
belongs_to :club
has_many :user_teams, dependent: :destroy
has_many :users, through: :user_teams
has_many :matches, dependent: :destroy
has_many :recordings, dependent: :destroy
has_many :team_invitations, dependent: :destroy
has_many :roster_members, class_name: "TeamRosterMember", dependent: :destroy
has_one_attached :photo_file
validates :name, presence: true
validate :photo_file_type, if: -> { photo_file.attached? }
def subscription
club.subscription
end
def entitlements
Teams::Entitlements.new(self)
end
# Canale YouTube OAuth è unico per tutta la società (Premium Full).
def youtube_credential
club&.youtube_credential
end
def owner
club&.owner
end
def team_photo_url
if photo_file.attached?
Rails.application.routes.url_helpers.rails_blob_path(photo_file, only_path: true)
end
end
def roster_by_category
TeamRosterMember::DISPLAY_ORDER.index_with do |cat|
roster_members.by_category(cat).to_a
end
end
private
def photo_file_type
return if photo_file.content_type.in?(%w[image/png image/jpeg image/webp])
errors.add(:photo_file, "deve essere PNG, JPEG o WebP")
end
def branding_parent
club
end
def default_primary_color
club&.primary_color.presence || super
end
def default_secondary_color
club&.secondary_color.presence || super
end
end