diff --git a/backend/app/controllers/public/tournament_matches_controller.rb b/backend/app/controllers/public/tournament_matches_controller.rb index 8f827ae..f3fd130 100644 --- a/backend/app/controllers/public/tournament_matches_controller.rb +++ b/backend/app/controllers/public/tournament_matches_controller.rb @@ -16,7 +16,7 @@ module Public Tournaments::Entitlements.new(@club).assert_writable! match = @tournament.matches.find(params[:match_id]) attrs = match_params - if match.played? || match.result_status.to_s.start_with?("walkover") + if match.result_recorded? attrs = attrs.except(:home_participant_id, :away_participant_id) end match.update!(attrs) diff --git a/backend/app/helpers/public/tournaments_helper.rb b/backend/app/helpers/public/tournaments_helper.rb index 289e82f..872bcce 100644 --- a/backend/app/helpers/public/tournaments_helper.rb +++ b/backend/app/helpers/public/tournaments_helper.rb @@ -100,7 +100,7 @@ module Public def tournament_public_board_state(match) return :live if tournament_public_live_session(match) return :replay if tournament_public_recording(match) - return :ended if match.played? || match.result_status.to_s.start_with?("walkover") || match.home_score.present? + return :ended if match.result_recorded? return :scheduled if match.scheduled_upcoming? :waiting @@ -129,7 +129,7 @@ module Public end def tournament_match_sides_locked?(match) - match.played? || match.result_status.to_s.start_with?("walkover") + match.result_recorded? end def tournament_phase_label(match) diff --git a/backend/app/models/match.rb b/backend/app/models/match.rb index 3eff3db..4b88b10 100644 --- a/backend/app/models/match.rb +++ b/backend/app/models/match.rb @@ -94,10 +94,15 @@ class Match < ApplicationRecord opponent_primary_color.presence || DEFAULT_OPPONENT_COLOR end + def result_recorded? + played? || result_status.to_s.start_with?("walkover") || (home_score.present? && away_score.present?) + end + def coach_hub_visible? active = active_stream_session return true if active&.resumable? return true if active&.idle? + return false if result_recorded? return false if stream_completed? return true if scheduled_on_calendar? return true if tournament_open_for_late_stream? diff --git a/backend/app/views/public/tournaments/_tab_calendario.html.erb b/backend/app/views/public/tournaments/_tab_calendario.html.erb index a784d92..ea36a33 100644 --- a/backend/app/views/public/tournaments/_tab_calendario.html.erb +++ b/backend/app/views/public/tournaments/_tab_calendario.html.erb @@ -51,7 +51,7 @@
<%= t("tournaments.hub.result") %> - <% if match.played? || match.result_status.to_s.start_with?("walkover") %> + <% if match.result_recorded? %>

<%= match.home_score %>–<%= match.away_score %>

<% else %> diff --git a/backend/spec/models/match_scheduling_spec.rb b/backend/spec/models/match_scheduling_spec.rb index 92614a4..2934ed4 100644 --- a/backend/spec/models/match_scheduling_spec.rb +++ b/backend/spec/models/match_scheduling_spec.rb @@ -83,6 +83,48 @@ RSpec.describe Match, "scheduling scopes" do expect(match.coach_hub_visible?).to be(false) end + it "nasconde partita con risultato inserito dal portale anche senza diretta" do + match = team.matches.create!( + opponent_name: "Squadra 4", + scheduled_at: 2.hours.ago, + sets_to_win: 3, + home_score: 11, + away_score: 10, + result_status: "played" + ) + + expect(match.coach_hub_visible?).to be(false) + end + + it "nasconde walkover anche se il torneo è ancora aperto" do + broadcast = club.teams.create!( + name: "Torneo Walkover", + sport_key: "pallavolo", + internal_kind: Tournament::INTERNAL_TEAM_KIND + ) + tournament = Tournament.create!( + club: club, + name: "Torneo Walkover", + sport_key: "pallavolo", + starts_on: Date.current, + ends_on: Date.current, + format_kind: "free", + status: "published", + broadcast_team: broadcast + ) + match = broadcast.matches.create!( + opponent_name: "TBD", + scheduled_at: 1.hour.ago, + sets_to_win: 3, + tournament: tournament, + result_status: "walkover_home", + home_score: 1, + away_score: 0 + ) + + expect(match.coach_hub_visible?).to be(false) + end + it "mostra partita di oggi già passata d'orario se non è stata trasmessa" do match = team.matches.create!( opponent_name: "Late",