From 9b40deeb6178c41f1aa805860a31711d4b15cf58 Mon Sep 17 00:00:00 2001 From: Emiliano Frascaro Date: Tue, 2 Jun 2026 22:38:28 +0200 Subject: [PATCH] =?UTF-8?q?Unifica=20admin=20societ=C3=A0/squadre=20e=20Yo?= =?UTF-8?q?uTube=20Full=20con=20fallback=20MLTV.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Premium Full senza canale società usa il canale piattaforma come Light; in app restano solo Match Live TV e YouTube Live. Co-authored-by: Cursor --- .../app/controllers/admin/clubs_controller.rb | 3 +- .../app/controllers/admin/teams_controller.rb | 2 +- .../services/youtube/credential_resolver.rb | 7 +- backend/app/services/youtube/team_status.rb | 14 ++- backend/app/views/admin/clubs/index.html.erb | 7 +- backend/app/views/admin/clubs/show.html.erb | 50 +++++++++-- .../app/views/admin/dashboard/index.html.erb | 2 +- backend/app/views/admin/teams/index.html.erb | 21 ----- backend/app/views/admin/teams/show.html.erb | 26 +++++- backend/app/views/layouts/admin.html.erb | 3 +- .../app/views/public/teams/_youtube.html.erb | 13 ++- backend/config/routes.rb | 2 +- docs/APP_YOUTUBE_LIVE.md | 33 ++++--- .../setup_wizard/step_transmission.dart | 86 ++----------------- 14 files changed, 125 insertions(+), 144 deletions(-) delete mode 100644 backend/app/views/admin/teams/index.html.erb diff --git a/backend/app/controllers/admin/clubs_controller.rb b/backend/app/controllers/admin/clubs_controller.rb index 08570eb..233ac57 100644 --- a/backend/app/controllers/admin/clubs_controller.rb +++ b/backend/app/controllers/admin/clubs_controller.rb @@ -3,13 +3,14 @@ module Admin before_action :set_club, only: %i[show grant_comped revoke_comped] def index - @clubs = Club.includes(:subscription, subscription: :plan, subscription: :admin_comped_by) + @clubs = Club.includes(:subscription, :teams, subscription: :plan, subscription: :admin_comped_by) .order(:name) end def show @subscription = @club.subscription || @club.build_subscription(plan: Plan["free"], status: "active") @plans = Plan.ordered.reject { |p| p.slug == "free" } + @teams = @club.teams.includes(:youtube_credential).order(:name) end def grant_comped diff --git a/backend/app/controllers/admin/teams_controller.rb b/backend/app/controllers/admin/teams_controller.rb index fb09527..b967885 100644 --- a/backend/app/controllers/admin/teams_controller.rb +++ b/backend/app/controllers/admin/teams_controller.rb @@ -1,7 +1,7 @@ module Admin class TeamsController < Admin::BaseController def index - @teams = Team.all.order(:name) + redirect_to admin_clubs_path, status: :moved_permanently end def show diff --git a/backend/app/services/youtube/credential_resolver.rb b/backend/app/services/youtube/credential_resolver.rb index ed6d4e8..849a1c7 100644 --- a/backend/app/services/youtube/credential_resolver.rb +++ b/backend/app/services/youtube/credential_resolver.rb @@ -6,19 +6,20 @@ module Youtube def initialize(team) @team = team + @status = TeamStatus.new(team) @mode = team.entitlements.plan.youtube_mode end def resolve - if @mode == "matchlivetv_light" && PlatformCredential.configured? + if @status.uses_platform_channel? PlatformCredential.new - else + elsif @mode == "team" @team.youtube_credential end end def uses_platform_channel? - @mode == "matchlivetv_light" && PlatformCredential.configured? + @status.uses_platform_channel? end end end diff --git a/backend/app/services/youtube/team_status.rb b/backend/app/services/youtube/team_status.rb index e83c03b..ff948d0 100644 --- a/backend/app/services/youtube/team_status.rb +++ b/backend/app/services/youtube/team_status.rb @@ -15,7 +15,7 @@ module Youtube when "matchlivetv_light" PlatformCredential.configured? when "team" - @team.youtube_credential.present? + @team.youtube_credential.present? || PlatformCredential.configured? else false end @@ -26,7 +26,15 @@ module Youtube end def uses_platform_channel? - @mode == "matchlivetv_light" && PlatformCredential.configured? + return false unless @ent.youtube_enabled? + + if @mode == "matchlivetv_light" + PlatformCredential.configured? + elsif @mode == "team" + @team.youtube_credential.blank? && PlatformCredential.configured? + else + false + end end def channel_title @@ -38,7 +46,7 @@ module Youtube end def needs_team_oauth? - @mode == "team" && @ent.premium_full? + @mode == "team" && @ent.premium_full? && @team.youtube_credential.blank? && !PlatformCredential.configured? end end end diff --git a/backend/app/views/admin/clubs/index.html.erb b/backend/app/views/admin/clubs/index.html.erb index a09d359..0fdae58 100644 --- a/backend/app/views/admin/clubs/index.html.erb +++ b/backend/app/views/admin/clubs/index.html.erb @@ -1,6 +1,7 @@ -

Società

+

Società e squadre

- Gestisci abbonamenti omaggio (sponsor / promozioni). Per pagamenti Stripe usa <%= link_to "Fatturazione", admin_billing_path %>. + Abbonamenti omaggio (sponsor / promozioni) e stato YouTube per squadra. + Pagamenti Stripe: <%= link_to "Fatturazione", admin_billing_path %>.

@@ -8,6 +9,7 @@ + @@ -19,6 +21,7 @@ +
Società PianoSquadre Omaggio Stripe
<%= club.name %> <%= sub&.plan&.name || "Free" %><%= club.teams.size %> <% if sub&.admin_comped? %> diff --git a/backend/app/views/admin/clubs/show.html.erb b/backend/app/views/admin/clubs/show.html.erb index bdba052..ee2c0fc 100644 --- a/backend/app/views/admin/clubs/show.html.erb +++ b/backend/app/views/admin/clubs/show.html.erb @@ -1,16 +1,52 @@ -

<%= link_to "← Tutte le società", admin_clubs_path %>

+

<%= link_to "← Società e squadre", admin_clubs_path %>

<%= @club.name %>

Sport: <%= @club.sport %> · <%= link_to "Pagamenti e fatture", admin_billing_path(club_id: @club.id) %> + · <%= link_to "Canale YouTube piattaforma", admin_youtube_platform_path %>

<%= render "admin/clubs/comped_form", club: @club, subscription: @subscription, return_to: admin_club_path(@club) %> -

Squadre

-
    - <% @club.teams.order(:name).each do |team| %> -
  • <%= link_to team.name, admin_team_path(team) %>
  • - <% end %> -
+

Squadre

+<% if @teams.empty? %> +

Nessuna squadra registrata.

+<% else %> + + + + + + + + + + + <% @teams.each do |team| %> + <% yt = Youtube::TeamStatus.new(team) %> + + + + + + + <% end %> + +
SquadraSportYouTube
<%= team.name %><%= team.sport %> + <% if yt.selectable? %> + <% if yt.uses_platform_channel? %> + Match Live TV + <% if team.youtube_credential.blank? && team.entitlements.premium_full? %> + (default Full) + <% end %> + <% else %> + ✓ <%= yt.channel_title.presence || "Canale società" %> + <% end %> + <% elsif team.entitlements.youtube_enabled? %> + In configurazione + <% else %> + — + <% end %> + <%= link_to "Partite e dettagli", admin_team_path(team) %>
+<% end %> diff --git a/backend/app/views/admin/dashboard/index.html.erb b/backend/app/views/admin/dashboard/index.html.erb index f8ab7b1..4d3f993 100644 --- a/backend/app/views/admin/dashboard/index.html.erb +++ b/backend/app/views/admin/dashboard/index.html.erb @@ -123,7 +123,7 @@ <% end %> <% if @stats[:teams_count] > @teams.size %> -

<%= link_to "Vedi tutte (#{@stats[:teams_count]})", admin_teams_path %>

+

<%= link_to "Vedi società (#{@stats[:teams_count]} squadre)", admin_clubs_path %>

<% end %> diff --git a/backend/app/views/admin/teams/index.html.erb b/backend/app/views/admin/teams/index.html.erb deleted file mode 100644 index 767e11f..0000000 --- a/backend/app/views/admin/teams/index.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -

Teams

- - - - <% @teams.each do |t| %> - - - - - - - - <% end %> - -
NomeSocietàSportYouTubeFatture
<%= link_to t.name, admin_team_path(t) %><%= t.club&.name || "—" %><%= t.sport %><%= t.youtube_credential.present? ? "✓" : "—" %> - <% if t.club %> - <%= link_to "Fatturazione", admin_billing_path(club_id: t.club.id) %> - <% else %> - — - <% end %> -
diff --git a/backend/app/views/admin/teams/show.html.erb b/backend/app/views/admin/teams/show.html.erb index e1a76fa..86810a5 100644 --- a/backend/app/views/admin/teams/show.html.erb +++ b/backend/app/views/admin/teams/show.html.erb @@ -1,14 +1,32 @@ +<% if @team.club %> +

<%= link_to "← #{@team.club.name}", admin_club_path(@team.club) %>

+<% end %> +

<%= @team.name %>

Sport: <%= @team.sport %>

<% if @team.club %>

Società: <%= @team.club.name %> · <%= link_to "Pagamenti e fatture", admin_billing_path(club_id: @team.club.id) %>

<% end %> <% yt = Youtube::TeamStatus.new(@team) %> -

YouTube: <%= yt.channel_title || "—" %> · <%= yt.selectable? ? "pronto" : "non pronto" %>

-<% if @team.entitlements.plan.youtube_mode == "team" && @team.youtube_credential.blank? %> -

<%= link_to "Collega (da account titolare sul sito)", public_team_details_path(@team) %>

+

+ YouTube: + <% if yt.selectable? %> + <%= yt.channel_title || "—" %> + <% if yt.uses_platform_channel? %> + (canale piattaforma<%= @team.entitlements.premium_full? && @team.youtube_credential.blank? ? ", default senza OAuth società" : "" %>) + <% else %> + (canale società) + <% end %> + <% else %> + non pronto + <% end %> +

+<% if @team.entitlements.premium_full? && @team.youtube_credential.blank? %> +

+ Senza canale collegato, l’app usa il canale Match Live TV. + <%= link_to "Collega canale (sito pubblico)", public_team_details_path(@team) %>. +

<% end %> -

<%= link_to "Token canale Match Live TV (Light)", admin_youtube_platform_path %>

Partite

    diff --git a/backend/app/views/layouts/admin.html.erb b/backend/app/views/layouts/admin.html.erb index 78037ca..e4a8667 100644 --- a/backend/app/views/layouts/admin.html.erb +++ b/backend/app/views/layouts/admin.html.erb @@ -16,8 +16,7 @@