Aggiunge i tornei con hub, pagina pubblica e tabellone per semifinali e finali.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,16 +12,19 @@ class User < ApplicationRecord
|
||||
has_many :owned_clubs, -> { where(club_memberships: { role: "owner" }) }, through: :club_memberships, source: :club
|
||||
has_many :stream_sessions, dependent: :nullify
|
||||
has_many :stream_concurrency_violations, dependent: :nullify
|
||||
has_many :tournament_broadcast_assignments, dependent: :destroy
|
||||
|
||||
def manageable_teams
|
||||
staff_ids = teams.select(:id)
|
||||
owner_ids = Team.where(club_id: owned_clubs.select(:id)).select(:id)
|
||||
owner_ids = Team.visible.where(club_id: owned_clubs.select(:id)).select(:id)
|
||||
Team.where(id: staff_ids).or(Team.where(id: owner_ids))
|
||||
end
|
||||
|
||||
# Squadre da cui l'utente può programmare partite e avviare lo streaming (app).
|
||||
def streamable_teams
|
||||
manageable_teams.includes(:club).select { |team| can_stream_for?(team) }
|
||||
listed = manageable_teams.includes(:club).select { |team| can_stream_for?(team) }
|
||||
owned_broadcast = Team.tournament_broadcast.where(club_id: owned_clubs.select(:id)).includes(:club)
|
||||
(listed + owned_broadcast.to_a).uniq
|
||||
end
|
||||
|
||||
def club_admin?(club)
|
||||
@@ -29,6 +32,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def can_schedule_for?(team)
|
||||
return false if team.tournament_broadcast?
|
||||
return true if team.club&.owned_by?(self)
|
||||
|
||||
membership = user_teams.find_by(team: team)
|
||||
@@ -38,7 +42,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def schedulable_teams_for(club)
|
||||
teams = club.teams.order(:name).to_a
|
||||
teams = club.teams.visible.order(:name).to_a
|
||||
return teams if club.owned_by?(self)
|
||||
|
||||
teams.select { |team| can_schedule_for?(team) }
|
||||
@@ -55,6 +59,14 @@ class User < ApplicationRecord
|
||||
Teams::StaffCoverage.new(team).covers_both_roles?(membership)
|
||||
end
|
||||
|
||||
def can_broadcast_match?(match)
|
||||
return true if match.team.club&.owned_by?(self)
|
||||
return false unless can_stream_for?(match.team)
|
||||
return true unless match.tournament_match?
|
||||
|
||||
tournament_broadcast_assignments.exists?(match_id: match.id)
|
||||
end
|
||||
|
||||
def staff_role_for(team)
|
||||
return "owner" if team.club&.owned_by?(self)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user