Files
MatchLiveTv/backend/app/services/youtube/credential_resolver.rb
Emiliano Frascaro 1fb5cd5aa2 App: scelta canale YouTube MLTV/società, privacy e condivisione link.
Premium Full può forzare il canale piattaforma; visibilità non in elenco o privato;
share_url unificato per Match Live TV e YouTube.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 22:52:07 +02:00

62 lines
1.4 KiB
Ruby

module Youtube
class CredentialResolver
VALID_CHANNELS = %w[platform team].freeze
def self.for_team(team, channel: nil)
new(team, channel: channel).resolve
end
def initialize(team, channel: nil)
@team = team
@channel = channel.to_s.presence
@channel = nil unless VALID_CHANNELS.include?(@channel)
@ent = team.entitlements
@mode = @ent.plan.youtube_mode
end
def resolve
case effective_channel
when :platform
PlatformCredential.configured? ? PlatformCredential.new : nil
when :team
@team.youtube_credential
end
end
def uses_platform_channel?
effective_channel == :platform
end
def platform_available?
@ent.youtube_enabled? && PlatformCredential.configured?
end
def team_channel_available?
@ent.youtube_enabled? && @ent.premium_full? && @mode == "team" && @team.youtube_credential.present?
end
def effective_channel
if @channel == "platform"
return :platform if platform_available?
elsif @channel == "team"
return :team if team_channel_available?
end
auto_channel
end
private
def auto_channel
if @mode == "matchlivetv_light"
return :platform if platform_available?
elsif @mode == "team"
return :team if team_channel_available?
return :platform if platform_available?
end
nil
end
end
end