Compare commits
135
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05ef56c56d | ||
|
|
35dfa923e3 | ||
|
|
9d8b35c06c | ||
|
|
873e0ea55c | ||
|
|
4573edfedc | ||
|
|
b301868774 | ||
|
|
b87a0f7bc0 | ||
|
|
70fccc493e | ||
|
|
406a90ae5b | ||
|
|
8e7bbdf8b2 | ||
|
|
b84321346f | ||
|
|
8a07c5d569 | ||
|
|
cc96c0396a | ||
|
|
79c48b226e | ||
|
|
c9b75065bc | ||
|
|
4ca9f3af8b | ||
|
|
f02782d0f0 | ||
|
|
fb82b74e92 | ||
|
|
60dfe7a75b | ||
|
|
a07f231417 | ||
|
|
43d5003de8 | ||
|
|
eadfc29da3 | ||
|
|
50d3e2cf16 | ||
|
|
55e71ca838 | ||
|
|
5b723bf844 | ||
|
|
e502844b88 | ||
|
|
0702cb699c | ||
|
|
e09b3ffcf8 | ||
|
|
41d4235258 | ||
|
|
a51d5e8da5 | ||
|
|
5bcb4170c7 | ||
|
|
e436f5ece4 | ||
|
|
1e4e0560f1 | ||
|
|
841a6a15be | ||
|
|
dd94bf7e66 | ||
|
|
baa6283a15 | ||
|
|
bfb3115a64 | ||
|
|
db8b14ba4e | ||
|
|
46244fe066 | ||
|
|
3ed70b6999 | ||
|
|
b05b1acd7a | ||
|
|
c777853c97 | ||
|
|
9225318e1a | ||
|
|
061b7fad8b | ||
|
|
be7957c078 | ||
|
|
91667e1bfd | ||
|
|
f92ab3a813 | ||
|
|
1fecccaafd | ||
|
|
d100c8030f | ||
|
|
bc2257efd2 | ||
|
|
f1906517a9 | ||
|
|
00fde25c50 | ||
|
|
4c5af99efa | ||
|
|
8bf12e7721 | ||
|
|
5a0ca8ef1c | ||
|
|
714602f3da | ||
|
|
baac3a512b | ||
|
|
559284f0b2 | ||
|
|
e5fc925bae | ||
|
|
318a319608 | ||
|
|
0b55d5a8fa | ||
|
|
c3878cdc6d | ||
|
|
4af4fa68ac | ||
|
|
45bdda7c95 | ||
|
|
b926531447 | ||
|
|
da6fc1d523 | ||
|
|
1d1cbf9f3f | ||
|
|
dd9901519a | ||
|
|
53449c5d3c | ||
|
|
db908e3109 | ||
|
|
5857f60d79 | ||
|
|
83a804a709 | ||
|
|
b8694a6b7b | ||
|
|
5daada81b0 | ||
|
|
d85bab30d1 | ||
|
|
7b3256c8a0 | ||
|
|
9bc89fceba | ||
|
|
d5ec266437 | ||
|
|
a448ad59ee | ||
|
|
74a156cedc | ||
|
|
97d787f758 | ||
|
|
ea5da1eb86 | ||
|
|
ff4de33cc5 | ||
|
|
97af398654 | ||
|
|
0a9185347f | ||
|
|
5ff22c7586 | ||
|
|
adceb8f13f | ||
|
|
f2498a9761 | ||
|
|
b88f44ab1c | ||
|
|
fb7068f86c | ||
|
|
1d97271555 | ||
|
|
7d5d66840f | ||
|
|
e20c2ae619 | ||
|
|
793cfaaaf1 | ||
|
|
c92099a41b | ||
|
|
270bf680a4 | ||
|
|
731b43ea88 | ||
|
|
0f69ebcccb | ||
|
|
5c85eb3524 | ||
|
|
a303a94671 | ||
|
|
ed0f913138 | ||
|
|
d8af931bfb | ||
|
|
fbc9bb5858 | ||
|
|
827abf80cb | ||
|
|
594853ed04 | ||
|
|
80813b390b | ||
|
|
5de3a1a1cf | ||
|
|
585332e32e | ||
|
|
b798e0ea06 | ||
|
|
498f6069d0 | ||
|
|
a44d9fbadd | ||
|
|
13390d8a3c | ||
|
|
e1636139a9 | ||
|
|
949a0a01fb | ||
|
|
208664848e | ||
|
|
b802cf3309 | ||
|
|
dc309fbeb0 | ||
|
|
89854869c7 | ||
|
|
da75582dae | ||
|
|
52cfffb83f | ||
|
|
ce8939fffb | ||
|
|
2b7e8b9e36 | ||
|
|
34c97f4447 | ||
|
|
01b7a3c96b | ||
|
|
ad9d67ddb6 | ||
|
|
c0ede48091 | ||
|
|
e727069d43 | ||
|
|
53f9a6a884 | ||
|
|
0621efb839 | ||
|
|
214d276508 | ||
|
|
9177e9e5a2 | ||
|
|
4ed15bc235 | ||
|
|
74eee24293 | ||
|
|
ae36d17adb | ||
|
|
08e800120a |
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
description: Scalare soft limit ingest/autoscaler man mano che crescono i clienti
|
||||||
|
alwaysApply: true
|
||||||
|
---
|
||||||
|
|
||||||
|
# Soft limit stream / autoscaler
|
||||||
|
|
||||||
|
Con la crescita del numero di clienti (e delle dirette concorrenti attese), **alzare i soft limit** prima di restare a corto di capacità.
|
||||||
|
|
||||||
|
Config rilevante (prod, tipicamente `infra/.env` + `StreamNode`):
|
||||||
|
|
||||||
|
| Parametro | Ruolo oggi (post load test 2026-08) |
|
||||||
|
|-----------|--------------------------------------|
|
||||||
|
| `STREAM_NODE_HOME_MAX_PUBLISHERS` | Soft home (es. 6) |
|
||||||
|
| `STREAM_CLOUD_MAX_PUBLISHERS` | Soft per CPX (es. 4; cpx12 ha tenuto 8 in probe) |
|
||||||
|
| `STREAM_AUTOSCALE_MAX_OVERFLOW` / max overflow nodes | Quanti CPX in parallelo (es. 3 → tetto cluster ≈ home + N×cloud) |
|
||||||
|
| `STREAM_AUTOSCALE_SOFT_FREE_SLOTS` | Anticipo scale-out |
|
||||||
|
| Piano `concurrent_streams_limit` | Tetto **per club** (Premium Full = 10): indipendente dal cluster |
|
||||||
|
|
||||||
|
Capienza cluster soft ≈ `home_max + max_overflow × cloud_max` (es. 6+3×4 = **18**).
|
||||||
|
|
||||||
|
Quando si parla di capacity planning, deploy autoscale, o “troppe dirette”, ricordare di rivedere questi valori (e il limite piano) in base ai clienti reali — non lasciare i soft limit di collaudo/early-prod a lungo.
|
||||||
@@ -58,8 +58,13 @@ Vedi [native/android/README.md](native/android/README.md).
|
|||||||
|
|
||||||
## Architettura
|
## Architettura
|
||||||
|
|
||||||
- Video (MVP): Phone → MediaMTX (RTMP) → HLS su `matchlivetv.*` (pagina `/live/:session_id`)
|
Documentazione completa: **[docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)** (rete, edge nginx, flussi video, ops).
|
||||||
- Video (premium): stesso ingest + relay ffmpeg verso YouTube
|
|
||||||
|
In sintesi:
|
||||||
|
|
||||||
|
- Video live: Phone → MediaMTX (RTMP) → HLS via edge `/hls/` (non Puma)
|
||||||
|
- Video replay: Rails auth → redirect `/media/` → Garage (non Puma)
|
||||||
|
- Video premium: stesso ingest + relay ffmpeg verso YouTube
|
||||||
- Controllo: Phone ↔ Action Cable ↔ Rails ↔ PostgreSQL
|
- Controllo: Phone ↔ Action Cable ↔ Rails ↔ PostgreSQL
|
||||||
- Disconnessioni: MediaMTX `alwaysAvailable` slate + timeout 5 min (Sidekiq)
|
- Disconnessioni: MediaMTX `alwaysAvailable` slate + timeout 5 min (Sidekiq)
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ gem "faraday"
|
|||||||
gem "stripe"
|
gem "stripe"
|
||||||
gem "aws-sdk-s3", "~> 1.0", require: false
|
gem "aws-sdk-s3", "~> 1.0", require: false
|
||||||
gem "kamal", require: false
|
gem "kamal", require: false
|
||||||
|
gem "sentry-ruby"
|
||||||
|
gem "sentry-rails"
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
|
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
|
||||||
|
|||||||
@@ -381,6 +381,13 @@ GEM
|
|||||||
rubocop-rails (>= 2.30)
|
rubocop-rails (>= 2.30)
|
||||||
ruby-progressbar (1.13.0)
|
ruby-progressbar (1.13.0)
|
||||||
securerandom (0.4.1)
|
securerandom (0.4.1)
|
||||||
|
sentry-rails (6.6.2)
|
||||||
|
railties (>= 5.2.0)
|
||||||
|
sentry-ruby (~> 6.6.2)
|
||||||
|
sentry-ruby (6.6.2)
|
||||||
|
bigdecimal
|
||||||
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||||
|
logger
|
||||||
sidekiq (8.1.5)
|
sidekiq (8.1.5)
|
||||||
connection_pool (>= 3.0.0)
|
connection_pool (>= 3.0.0)
|
||||||
json (>= 2.16.0)
|
json (>= 2.16.0)
|
||||||
@@ -456,6 +463,8 @@ DEPENDENCIES
|
|||||||
redis (>= 4.0.1)
|
redis (>= 4.0.1)
|
||||||
rspec-rails
|
rspec-rails
|
||||||
rubocop-rails-omakase
|
rubocop-rails-omakase
|
||||||
|
sentry-rails
|
||||||
|
sentry-ruby
|
||||||
sidekiq
|
sidekiq
|
||||||
stripe
|
stripe
|
||||||
tzinfo-data
|
tzinfo-data
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module CableBroadcastable
|
|||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
def broadcast_message(session, data)
|
def broadcast_message(session, data)
|
||||||
broadcast_to(session, method: "receive_message", data: data)
|
broadcast_to(session, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ class SessionChannel < ApplicationCable::Channel
|
|||||||
Sessions::Pause.new(session).call
|
Sessions::Pause.new(session).call
|
||||||
when "resume_stream"
|
when "resume_stream"
|
||||||
Sessions::Resume.new(session).call
|
Sessions::Resume.new(session).call
|
||||||
|
when "mute_audio"
|
||||||
|
Sessions::SetAudioMute.new(session, muted: true).call
|
||||||
|
when "unmute_audio"
|
||||||
|
Sessions::SetAudioMute.new(session, muted: false).call
|
||||||
|
when "set_min_quality"
|
||||||
|
Sessions::SetMinQuality.new(session, preset: data["min_quality_preset"]).call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Admin
|
||||||
|
class AnalyticsController < Admin::BaseController
|
||||||
|
def index
|
||||||
|
@filters = {
|
||||||
|
from: parse_date(params[:from]) || 7.days.ago.to_date,
|
||||||
|
to: parse_date(params[:to]) || Time.zone.today,
|
||||||
|
device: params[:device].presence
|
||||||
|
}
|
||||||
|
|
||||||
|
scope = AnalyticsPageStat.where(day: @filters[:from]..@filters[:to])
|
||||||
|
scope = scope.where(device: @filters[:device]) if @filters[:device].present? && AnalyticsEvent::DEVICES.include?(@filters[:device])
|
||||||
|
|
||||||
|
cell_scope = AnalyticsPageCell.where(day: @filters[:from]..@filters[:to])
|
||||||
|
cell_scope = cell_scope.where(device: @filters[:device]) if @filters[:device].present? && AnalyticsEvent::DEVICES.include?(@filters[:device])
|
||||||
|
|
||||||
|
clicks_by_path = cell_scope.group(:page_path).sum(:click_count)
|
||||||
|
moves_by_path = cell_scope.group(:page_path).sum(:move_count)
|
||||||
|
pageviews_by_path = scope.group(:page_path).sum(:pageview_count)
|
||||||
|
scroll_samples_by_path = scope.group(:page_path).sum(:scroll_samples)
|
||||||
|
scroll_sum_by_path = scope.group(:page_path).sum(:scroll_sum_pct)
|
||||||
|
max_scroll_by_path = scope.group(:page_path).maximum(:max_scroll_pct)
|
||||||
|
|
||||||
|
paths = (pageviews_by_path.keys + clicks_by_path.keys + moves_by_path.keys).uniq
|
||||||
|
@pages = paths.map do |path|
|
||||||
|
samples = scroll_samples_by_path[path].to_i
|
||||||
|
{
|
||||||
|
page_path: path,
|
||||||
|
pageviews: pageviews_by_path[path].to_i,
|
||||||
|
clicks: clicks_by_path[path].to_i,
|
||||||
|
moves: moves_by_path[path].to_i,
|
||||||
|
scroll_samples: samples,
|
||||||
|
scroll_sum: scroll_sum_by_path[path].to_i,
|
||||||
|
max_scroll: max_scroll_by_path[path].to_i
|
||||||
|
}
|
||||||
|
end.sort_by { |r| [-r[:pageviews], -r[:moves], -r[:clicks], r[:page_path]] }
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@page_path = params[:page_path].to_s
|
||||||
|
redirect_to admin_analytics_path, alert: t("admin.analytics.missing_path") and return if @page_path.blank?
|
||||||
|
|
||||||
|
@filters = {
|
||||||
|
from: parse_date(params[:from]) || 7.days.ago.to_date,
|
||||||
|
to: parse_date(params[:to]) || Time.zone.today,
|
||||||
|
device: params[:device].presence,
|
||||||
|
layer: params[:layer].to_s
|
||||||
|
}
|
||||||
|
|
||||||
|
cells = AnalyticsPageCell.where(page_path: @page_path, day: @filters[:from]..@filters[:to])
|
||||||
|
cells = cells.where(device: @filters[:device]) if @filters[:device].present? && AnalyticsEvent::DEVICES.include?(@filters[:device])
|
||||||
|
|
||||||
|
@click_total = cells.sum(:click_count)
|
||||||
|
@move_total = cells.sum(:move_count)
|
||||||
|
@filters[:layer] =
|
||||||
|
if %w[move click].include?(@filters[:layer])
|
||||||
|
@filters[:layer]
|
||||||
|
elsif @move_total.positive?
|
||||||
|
"move"
|
||||||
|
else
|
||||||
|
"click"
|
||||||
|
end
|
||||||
|
|
||||||
|
counter = @filters[:layer] == "click" ? :click_count : :move_count
|
||||||
|
@cells = cells.group(:cell_x, :cell_y).sum(counter)
|
||||||
|
@max_weight = @cells.values.max.to_i
|
||||||
|
@total_points = @cells.values.sum
|
||||||
|
|
||||||
|
stats = AnalyticsPageStat.where(page_path: @page_path, day: @filters[:from]..@filters[:to])
|
||||||
|
stats = stats.where(device: @filters[:device]) if @filters[:device].present? && AnalyticsEvent::DEVICES.include?(@filters[:device])
|
||||||
|
@pageviews = stats.sum(:pageview_count)
|
||||||
|
@scroll_samples = stats.sum(:scroll_samples)
|
||||||
|
@scroll_sum = stats.sum(:scroll_sum_pct)
|
||||||
|
@max_scroll = stats.maximum(:max_scroll_pct).to_i
|
||||||
|
@avg_scroll = @scroll_samples.positive? ? (@scroll_sum.to_f / @scroll_samples).round : 0
|
||||||
|
@grid = AnalyticsPageCell::GRID_SIZE
|
||||||
|
@snapshot = find_snapshot(@page_path, @filters[:device])
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def parse_date(value)
|
||||||
|
return nil if value.blank?
|
||||||
|
|
||||||
|
Date.parse(value.to_s)
|
||||||
|
rescue ArgumentError, TypeError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_snapshot(page_path, device)
|
||||||
|
scope = AnalyticsPageSnapshot.where(page_path: page_path)
|
||||||
|
if device.present? && AnalyticsEvent::DEVICES.include?(device)
|
||||||
|
snap = scope.find_by(device: device)
|
||||||
|
return snap if snap&.image&.attached?
|
||||||
|
end
|
||||||
|
|
||||||
|
scope.order(captured_at: :desc).detect { |s| s.image.attached? }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
module Admin
|
||||||
|
class AnnouncementsController < Admin::BaseController
|
||||||
|
before_action :set_announcement, only: %i[edit update destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@announcements = AppAnnouncement.newest
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@announcement = AppAnnouncement.new(
|
||||||
|
kind: "info",
|
||||||
|
severity: "info",
|
||||||
|
status: "draft",
|
||||||
|
show_on_android: true,
|
||||||
|
show_on_ios: true,
|
||||||
|
show_on_web_public: true,
|
||||||
|
show_on_web_private: true,
|
||||||
|
dismissible: true
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@announcement = AppAnnouncement.new(announcement_params)
|
||||||
|
@announcement.created_by_admin = current_admin_account
|
||||||
|
if @announcement.save
|
||||||
|
redirect_to admin_announcements_path, notice: t("admin.flash.announcement_created")
|
||||||
|
else
|
||||||
|
flash.now[:alert] = @announcement.errors.full_messages.join(", ")
|
||||||
|
render :new, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit; end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @announcement.update(announcement_params)
|
||||||
|
redirect_to admin_announcements_path, notice: t("admin.flash.announcement_updated")
|
||||||
|
else
|
||||||
|
flash.now[:alert] = @announcement.errors.full_messages.join(", ")
|
||||||
|
render :edit, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@announcement.destroy!
|
||||||
|
redirect_to admin_announcements_path, notice: t("admin.flash.announcement_destroyed")
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_announcement
|
||||||
|
@announcement = AppAnnouncement.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def announcement_params
|
||||||
|
params.require(:app_announcement).permit(
|
||||||
|
:kind, :severity, :status, :title, :body,
|
||||||
|
:action_url, :action_label, :dismissible, :starts_at, :ends_at,
|
||||||
|
:show_on_android, :show_on_ios, :show_on_web_public, :show_on_web_private,
|
||||||
|
translations: {
|
||||||
|
en: AppAnnouncement::COPY_KEYS,
|
||||||
|
fr: AppAnnouncement::COPY_KEYS,
|
||||||
|
de: AppAnnouncement::COPY_KEYS,
|
||||||
|
es: AppAnnouncement::COPY_KEYS
|
||||||
|
}
|
||||||
|
).tap do |permitted|
|
||||||
|
%i[dismissible show_on_android show_on_ios show_on_web_public show_on_web_private].each do |key|
|
||||||
|
permitted[key] = ActiveModel::Type::Boolean.new.cast(permitted[key])
|
||||||
|
end
|
||||||
|
%i[starts_at ends_at action_url action_label].each do |key|
|
||||||
|
permitted[key] = nil if permitted[key].blank?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class AuthController < Admin::BaseController
|
class AuthController < Admin::BaseController
|
||||||
skip_before_action :require_admin_login, only: %i[new create]
|
skip_before_action :require_admin_login, only: %i[new create]
|
||||||
|
# Same as public logout: tolerate stale CSRF after long-lived admin tabs.
|
||||||
|
skip_before_action :verify_authenticity_token, only: :destroy
|
||||||
|
|
||||||
def new
|
def new
|
||||||
redirect_to admin_root_path if admin_logged_in?
|
redirect_to admin_root_path if admin_logged_in?
|
||||||
@@ -10,16 +12,16 @@ module Admin
|
|||||||
account = AdminAccount.find_by(username: params[:username]&.strip)
|
account = AdminAccount.find_by(username: params[:username]&.strip)
|
||||||
if account&.authenticate(params[:password])
|
if account&.authenticate(params[:password])
|
||||||
session[:admin_account_id] = account.id
|
session[:admin_account_id] = account.id
|
||||||
redirect_to session.delete(:admin_return_to) || admin_root_path, notice: "Accesso effettuato"
|
redirect_to session.delete(:admin_return_to) || admin_root_path, notice: t("admin.flash.login_success")
|
||||||
else
|
else
|
||||||
flash.now[:alert] = "Username o password non validi"
|
flash.now[:alert] = t("admin.flash.invalid_credentials")
|
||||||
render :new, status: :unauthorized
|
render :new, status: :unauthorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
reset_session
|
reset_session
|
||||||
redirect_to admin_login_path, notice: "Disconnesso"
|
redirect_to admin_login_path, notice: t("admin.flash.logout_success")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,18 +3,40 @@ module Admin
|
|||||||
layout "admin"
|
layout "admin"
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
|
before_action :set_admin_locale
|
||||||
before_action :require_admin_login
|
before_action :require_admin_login
|
||||||
|
|
||||||
include ::AdminHelper
|
include ::AdminHelper
|
||||||
helper_method :current_admin_account, :admin_logged_in?
|
helper ApplicationHelper
|
||||||
|
helper RecordingsArchiveHelper
|
||||||
|
helper_method :current_admin_account, :admin_logged_in?, :current_locale, :language_options, :current_language_option
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_admin_locale
|
||||||
|
I18n.locale = LocaleResolver.resolve(
|
||||||
|
cookie_jar: request.cookie_jar,
|
||||||
|
accept_language: request.get_header("HTTP_ACCEPT_LANGUAGE")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_locale
|
||||||
|
I18n.locale
|
||||||
|
end
|
||||||
|
|
||||||
|
def language_options
|
||||||
|
LocaleResolver.language_options
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_language_option
|
||||||
|
LocaleResolver.current_language_option
|
||||||
|
end
|
||||||
|
|
||||||
def require_admin_login
|
def require_admin_login
|
||||||
return if admin_logged_in?
|
return if admin_logged_in?
|
||||||
|
|
||||||
session[:admin_return_to] = request.fullpath unless request.path == admin_login_path
|
session[:admin_return_to] = request.fullpath unless request.path == admin_login_path
|
||||||
redirect_to admin_login_path, alert: "Accedi per continuare"
|
redirect_to admin_login_path, alert: t("admin.flash.login_required")
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_admin_account
|
def current_admin_account
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ module Admin
|
|||||||
class BillingController < BaseController
|
class BillingController < BaseController
|
||||||
def index
|
def index
|
||||||
@pending_payments = pending_scope.recent
|
@pending_payments = pending_scope.recent
|
||||||
|
@pending_transfers = transfer_scope
|
||||||
@completed_payments = Billing::Payment.with_invoice_pdf.includes(:club, :invoice).recent.limit(40)
|
@completed_payments = Billing::Payment.with_invoice_pdf.includes(:club, :invoice).recent.limit(40)
|
||||||
@filter_club = Club.find_by(id: params[:club_id]) if params[:club_id].present?
|
@filter_club = Club.find_by(id: params[:club_id]) if params[:club_id].present?
|
||||||
@clubs = Club.order(:name)
|
@clubs = Club.order(:name)
|
||||||
@@ -11,13 +12,32 @@ module Admin
|
|||||||
payment = Billing::Payment.find(params[:payment_id])
|
payment = Billing::Payment.find(params[:payment_id])
|
||||||
Billing::AttachPaymentInvoice.call(payment: payment, pdf: params[:pdf])
|
Billing::AttachPaymentInvoice.call(payment: payment, pdf: params[:pdf])
|
||||||
redirect_to admin_billing_path(billing_redirect_params(payment)),
|
redirect_to admin_billing_path(billing_redirect_params(payment)),
|
||||||
notice: "Fattura caricata e inviata a #{payment.club.billing_email}."
|
notice: t("admin.flash.invoice_uploaded", email: payment.club.billing_email)
|
||||||
rescue Billing::AttachPaymentInvoice::Error, Billing::IssueInvoice::Error => e
|
rescue Billing::AttachPaymentInvoice::Error, Billing::IssueInvoice::Error => e
|
||||||
payment ||= Billing::Payment.find_by(id: params[:payment_id])
|
payment ||= Billing::Payment.find_by(id: params[:payment_id])
|
||||||
redirect_to admin_billing_path(payment ? billing_redirect_params(payment) : {}),
|
redirect_to admin_billing_path(payment ? billing_redirect_params(payment) : {}),
|
||||||
alert: e.message
|
alert: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def confirm_transfer
|
||||||
|
order = Billing::TransferOrder.find(params[:id])
|
||||||
|
Billing::ConfirmBankTransfer.call(
|
||||||
|
order: order,
|
||||||
|
admin: current_admin_account,
|
||||||
|
pdf: params[:pdf]
|
||||||
|
)
|
||||||
|
redirect_to admin_billing_path(club_id: order.club_id),
|
||||||
|
notice: t("admin.flash.transfer_confirmed", plan: order.plan.name, club: order.club.name)
|
||||||
|
rescue Billing::ConfirmBankTransfer::Error, Billing::AttachPaymentInvoice::Error, Billing::IssueInvoice::Error => e
|
||||||
|
redirect_to admin_billing_path, alert: e.message
|
||||||
|
end
|
||||||
|
|
||||||
|
def cancel_transfer
|
||||||
|
order = Billing::TransferOrder.find(params[:id])
|
||||||
|
order.cancel!
|
||||||
|
redirect_to admin_billing_path(club_id: order.club_id), notice: t("admin.flash.transfer_cancelled")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def pending_scope
|
def pending_scope
|
||||||
@@ -26,6 +46,12 @@ module Admin
|
|||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def transfer_scope
|
||||||
|
scope = Billing::TransferOrder.awaiting_payment.includes(:club, :requested_by_user)
|
||||||
|
scope = scope.where(club_id: params[:club_id]) if params[:club_id].present?
|
||||||
|
scope
|
||||||
|
end
|
||||||
|
|
||||||
def billing_redirect_params(payment)
|
def billing_redirect_params(payment)
|
||||||
{ club_id: payment.club_id, anchor: "payment-#{payment.id}" }.compact
|
{ club_id: payment.club_id, anchor: "payment-#{payment.id}" }.compact
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
redirect_to admin_billing_path(club_id: @club.id), alert: "Carica il PDF dalla lista «Pagamenti da fatturare»."
|
redirect_to admin_billing_path(club_id: @club.id), alert: t("admin.flash.invoice_upload_hint")
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -18,7 +18,7 @@ module Admin
|
|||||||
|
|
||||||
if @invoice.save
|
if @invoice.save
|
||||||
redirect_to edit_admin_club_billing_invoice_path(@club, @invoice),
|
redirect_to edit_admin_club_billing_invoice_path(@club, @invoice),
|
||||||
notice: "Bozza creata. Carica il PDF dalla pagina Fatturazione o qui sotto."
|
notice: t("admin.flash.invoice_draft_created")
|
||||||
else
|
else
|
||||||
@payment = @invoice.billing_payment
|
@payment = @invoice.billing_payment
|
||||||
flash.now[:alert] = @invoice.errors.full_messages.join(", ")
|
flash.now[:alert] = @invoice.errors.full_messages.join(", ")
|
||||||
@@ -36,9 +36,9 @@ module Admin
|
|||||||
if issuing?
|
if issuing?
|
||||||
Billing::IssueInvoice.call(invoice: @invoice, pdf: params.dig(:billing_invoice, :pdf))
|
Billing::IssueInvoice.call(invoice: @invoice, pdf: params.dig(:billing_invoice, :pdf))
|
||||||
redirect_to admin_billing_path(club_id: @club.id),
|
redirect_to admin_billing_path(club_id: @club.id),
|
||||||
notice: "Fattura #{@invoice.number} emessa e inviata a #{@club.billing_email}."
|
notice: t("admin.flash.invoice_issued", number: @invoice.number, email: @club.billing_email)
|
||||||
elsif @invoice.save
|
elsif @invoice.save
|
||||||
redirect_to admin_billing_path(club_id: @club.id), notice: "Fattura #{@invoice.number} aggiornata."
|
redirect_to admin_billing_path(club_id: @club.id), notice: t("admin.flash.invoice_updated", number: @invoice.number)
|
||||||
else
|
else
|
||||||
@payment = @invoice.billing_payment
|
@payment = @invoice.billing_payment
|
||||||
flash.now[:alert] = @invoice.errors.full_messages.join(", ")
|
flash.now[:alert] = @invoice.errors.full_messages.join(", ")
|
||||||
@@ -61,7 +61,7 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
def issuing?
|
def issuing?
|
||||||
params[:commit].to_s == "Emetti e invia via email"
|
params[:commit_action].to_s == "issue"
|
||||||
end
|
end
|
||||||
|
|
||||||
def invoice_params
|
def invoice_params
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
module Admin
|
||||||
|
class ClubRecordingsController < BaseController
|
||||||
|
include Recordings::ClubArchiveActions
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def archive_namespace
|
||||||
|
:admin
|
||||||
|
end
|
||||||
|
|
||||||
|
def authorize_recording_management!
|
||||||
|
# Admin può gestire tutti i replay della società senza vincoli di ruolo utente.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class ClubsController < BaseController
|
class ClubsController < BaseController
|
||||||
before_action :set_club, only: %i[show grant_comped revoke_comped]
|
before_action :set_club, only: %i[show grant_comped revoke_comped set_quote revoke_quote]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@clubs = Club.includes(:teams, subscription: %i[plan admin_comped_by])
|
@clubs = Club.includes(:teams, :billing_quote, subscription: %i[plan admin_comped_by])
|
||||||
.order(:name)
|
.order(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@ module Admin
|
|||||||
@subscription = @club.subscription || @club.build_subscription(plan: Plan["free"], status: "active")
|
@subscription = @club.subscription || @club.build_subscription(plan: Plan["free"], status: "active")
|
||||||
@plans = Plan.ordered.reject { |p| p.slug == "free" }
|
@plans = Plan.ordered.reject { |p| p.slug == "free" }
|
||||||
@teams = @club.teams.order(:name)
|
@teams = @club.teams.order(:name)
|
||||||
|
@quote = @club.active_billing_quote
|
||||||
end
|
end
|
||||||
|
|
||||||
def grant_comped
|
def grant_comped
|
||||||
@@ -20,18 +21,44 @@ module Admin
|
|||||||
reason: params[:reason],
|
reason: params[:reason],
|
||||||
admin: current_admin_account
|
admin: current_admin_account
|
||||||
)
|
)
|
||||||
redirect_back_or_club notice: "Abbonamento omaggio #{Plan[params[:plan_slug]].name} attivato per #{@club.name}."
|
redirect_back_or_club notice: t("admin.flash.comped_granted", plan: Plan[params[:plan_slug]].name, club: @club.name)
|
||||||
rescue Billing::AdminCompedSubscription::Error, ActiveRecord::RecordInvalid => e
|
rescue Billing::AdminCompedSubscription::Error, ActiveRecord::RecordInvalid => e
|
||||||
redirect_back_or_club alert: e.message
|
redirect_back_or_club alert: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
def revoke_comped
|
def revoke_comped
|
||||||
Billing::AdminCompedSubscription.revoke(club: @club, admin: current_admin_account)
|
Billing::AdminCompedSubscription.revoke(club: @club, admin: current_admin_account)
|
||||||
redirect_back_or_club notice: "Abbonamento omaggio revocato per #{@club.name}."
|
redirect_back_or_club notice: t("admin.flash.comped_revoked", club: @club.name)
|
||||||
rescue Billing::AdminCompedSubscription::Error => e
|
rescue Billing::AdminCompedSubscription::Error => e
|
||||||
redirect_back_or_club alert: e.message
|
redirect_back_or_club alert: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_quote
|
||||||
|
quote = Billing::SetClubQuote.upsert(
|
||||||
|
club: @club,
|
||||||
|
plan_slug: params.require(:plan_slug),
|
||||||
|
interval: params[:interval],
|
||||||
|
amount_euros: params[:amount_euros],
|
||||||
|
note: params[:note],
|
||||||
|
admin: current_admin_account
|
||||||
|
)
|
||||||
|
redirect_back_or_club notice: t(
|
||||||
|
"admin.flash.quote_saved",
|
||||||
|
club: @club.name,
|
||||||
|
plan: quote.plan.name,
|
||||||
|
amount: quote.formatted_amount
|
||||||
|
)
|
||||||
|
rescue Billing::SetClubQuote::Error, ActionController::ParameterMissing => e
|
||||||
|
redirect_back_or_club alert: e.message
|
||||||
|
end
|
||||||
|
|
||||||
|
def revoke_quote
|
||||||
|
Billing::SetClubQuote.revoke(club: @club, admin: current_admin_account)
|
||||||
|
redirect_back_or_club notice: t("admin.flash.quote_revoked", club: @club.name)
|
||||||
|
rescue Billing::SetClubQuote::Error => e
|
||||||
|
redirect_back_or_club alert: e.message
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_club
|
def set_club
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ module Admin
|
|||||||
@host = HostMetrics.new.sample!
|
@host = HostMetrics.new.sample!
|
||||||
@active_sessions = StreamSession
|
@active_sessions = StreamSession
|
||||||
.where(status: DashboardStats::ACTIVE_STATUSES)
|
.where(status: DashboardStats::ACTIVE_STATUSES)
|
||||||
.includes(match: :team)
|
.includes(:stream_node, match: :team)
|
||||||
.order(started_at: :desc)
|
.order(started_at: :desc)
|
||||||
@teams = Team.includes(:matches).order(:name).limit(8)
|
@teams = Team.includes(:matches).order(:name).limit(8)
|
||||||
end
|
end
|
||||||
@@ -13,7 +13,22 @@ module Admin
|
|||||||
def metrics
|
def metrics
|
||||||
host = HostMetrics.new.sample!
|
host = HostMetrics.new.sample!
|
||||||
stats = DashboardStats.new.call
|
stats = DashboardStats.new.call
|
||||||
render json: { host: host, stats: stats, at: Time.current.iso8601 }
|
render json: {
|
||||||
|
host: host,
|
||||||
|
stats: stats,
|
||||||
|
ops_summary: ops_summary,
|
||||||
|
at: Time.current.iso8601
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def ops_summary
|
||||||
|
{
|
||||||
|
open_critical: Ops::Incident.critical_open.count,
|
||||||
|
open_warning: Ops::Incident.open.where(severity: "warning").count,
|
||||||
|
open_total: Ops::Incident.open.count
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
module Admin
|
||||||
|
class LocalesController < BaseController
|
||||||
|
skip_before_action :require_admin_login
|
||||||
|
|
||||||
|
def update
|
||||||
|
locale = LocaleResolver.persist!(cookies, params[:locale])
|
||||||
|
I18n.locale = locale
|
||||||
|
redirect_back fallback_location: admin_root_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
module Admin
|
||||||
|
class OpsController < Admin::BaseController
|
||||||
|
def index
|
||||||
|
@open_incidents = Ops::Incident.open.recent.limit(50)
|
||||||
|
@resolved_incidents = Ops::Incident.where(status: "resolved").since(30.days.ago).recent.limit(30)
|
||||||
|
@summary = ops_summary
|
||||||
|
end
|
||||||
|
|
||||||
|
def acknowledge
|
||||||
|
incident = Ops::Incident.find(params[:id])
|
||||||
|
incident.acknowledge!
|
||||||
|
redirect_to admin_ops_path, notice: t("admin.flash.ops_acknowledged")
|
||||||
|
end
|
||||||
|
|
||||||
|
def resolve
|
||||||
|
incident = Ops::Incident.find(params[:id])
|
||||||
|
incident.resolve!
|
||||||
|
redirect_to admin_ops_path, notice: t("admin.flash.ops_resolved")
|
||||||
|
end
|
||||||
|
|
||||||
|
def mute
|
||||||
|
incident = Ops::Incident.find(params[:id])
|
||||||
|
incident.mute!(duration: 24.hours)
|
||||||
|
redirect_to admin_ops_path, notice: t("admin.flash.ops_muted")
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def ops_summary
|
||||||
|
{
|
||||||
|
open_critical: Ops::Incident.critical_open.count,
|
||||||
|
open_warning: Ops::Incident.open.where(severity: "warning").count,
|
||||||
|
open_total: Ops::Incident.open.count
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,22 +5,32 @@ module Admin
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
unless current_admin_account.authenticate(params[:current_password])
|
unless current_admin_account.authenticate(params[:current_password])
|
||||||
flash.now[:alert] = "Password attuale non corretta"
|
flash.now[:alert] = t("admin.flash.password_current_incorrect")
|
||||||
return render :edit, status: :unprocessable_entity
|
|
||||||
end
|
|
||||||
|
|
||||||
if params[:password].blank? || params[:password].length < 8
|
|
||||||
flash.now[:alert] = "La nuova password deve avere almeno 8 caratteri"
|
|
||||||
return render :edit, status: :unprocessable_entity
|
return render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:password] != params[:password_confirmation]
|
if params[:password] != params[:password_confirmation]
|
||||||
flash.now[:alert] = "Le password non coincidono"
|
flash.now[:alert] = t("admin.flash.password_mismatch")
|
||||||
|
return render :edit, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
if (code = PasswordComplexity.violation(params[:password]))
|
||||||
|
key = case code
|
||||||
|
when :blank, :too_short then :password_too_short
|
||||||
|
when :too_long then :password_too_long
|
||||||
|
else :password_too_weak
|
||||||
|
end
|
||||||
|
flash.now[:alert] = t("admin.flash.#{key}")
|
||||||
|
return render :edit, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
if PasswordComplexity.same_as_current?(current_admin_account, params[:password])
|
||||||
|
flash.now[:alert] = t("admin.flash.password_same_as_current")
|
||||||
return render :edit, status: :unprocessable_entity
|
return render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
if current_admin_account.update(password: params[:password])
|
if current_admin_account.update(password: params[:password])
|
||||||
redirect_to admin_root_path, notice: "Password aggiornata"
|
redirect_to admin_root_path, notice: t("admin.flash.password_updated")
|
||||||
else
|
else
|
||||||
flash.now[:alert] = current_admin_account.errors.full_messages.to_sentence
|
flash.now[:alert] = current_admin_account.errors.full_messages.to_sentence
|
||||||
render :edit, status: :unprocessable_entity
|
render :edit, status: :unprocessable_entity
|
||||||
|
|||||||
@@ -1,26 +1,122 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class SessionsController < Admin::BaseController
|
class SessionsController < Admin::BaseController
|
||||||
def index
|
def index
|
||||||
@sessions = StreamSession.includes(:match, :user).order(created_at: :desc).limit(50)
|
@filters = session_filters
|
||||||
|
scope = filtered_sessions
|
||||||
|
@total_count = scope.count
|
||||||
|
@sessions = scope
|
||||||
|
.includes(:stream_node, :user, match: { team: :club })
|
||||||
|
.order(Arel.sql("COALESCE(stream_sessions.started_at, stream_sessions.created_at) DESC"))
|
||||||
|
.limit(100)
|
||||||
|
@clubs = Club.order(:name)
|
||||||
|
@nodes = StreamNode.order(:slug)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@session = StreamSession.find(params[:id])
|
@session = StreamSession
|
||||||
@events = @session.stream_events.recent.limit(50)
|
.includes(:stream_node, :user, :device_states, :recording, match: { team: :club })
|
||||||
|
.find(params[:id])
|
||||||
|
@events = @session.stream_events.recent.limit(100)
|
||||||
|
@club = @session.match.team.club
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
@session = StreamSession.find(params[:id])
|
@session = StreamSession.find(params[:id])
|
||||||
if @session.terminal?
|
if @session.terminal?
|
||||||
redirect_to admin_session_path(@session), alert: "Sessione già terminata (#{@session.status})."
|
redirect_to admin_session_path(@session), alert: t("admin.flash.session_already_terminated", status: @session.status)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
Sessions::Stop.new(@session).call
|
Sessions::Stop.new(@session).call
|
||||||
redirect_to admin_session_path(@session), notice: "Sessione terminata."
|
redirect_to admin_session_path(@session), notice: t("admin.flash.session_stopped")
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
Rails.logger.error("[admin] stop session #{@session.id}: #{e.class} #{e.message}")
|
Rails.logger.error("[admin] stop session #{@session.id}: #{e.class} #{e.message}")
|
||||||
redirect_to admin_session_path(@session), alert: "Errore durante la chiusura: #{e.message}"
|
redirect_to admin_session_path(@session), alert: t("admin.flash.session_stop_error", error: e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def regia_link
|
||||||
|
@session = StreamSession.find(params[:id])
|
||||||
|
if @session.terminal?
|
||||||
|
redirect_to admin_session_path(@session), alert: t("admin.flash.session_terminated_no_regia")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
access = Sessions::RegiaAccess.new(@session)
|
||||||
|
token = access.issue_token!
|
||||||
|
redirect_to admin_session_path(@session),
|
||||||
|
notice: t("admin.flash.session_regia_generated"),
|
||||||
|
flash: {
|
||||||
|
regia_url: access.url(token),
|
||||||
|
regia_expires_at: @session.regia_token_expires_at&.iso8601
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def session_filters
|
||||||
|
{
|
||||||
|
q: params[:q].to_s.strip.presence,
|
||||||
|
status: params[:status].to_s.strip.presence,
|
||||||
|
platform: params[:platform].to_s.strip.presence,
|
||||||
|
club_id: params[:club_id].to_s.strip.presence,
|
||||||
|
stream_node_id: params[:stream_node_id].to_s.strip.presence,
|
||||||
|
from: params[:from].to_s.strip.presence,
|
||||||
|
to: params[:to].to_s.strip.presence
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def filtered_sessions
|
||||||
|
scope = StreamSession.left_outer_joins(match: { team: :club })
|
||||||
|
|
||||||
|
if @filters[:q].present?
|
||||||
|
term = "%#{ActiveRecord::Base.sanitize_sql_like(@filters[:q])}%"
|
||||||
|
scope = scope.where(
|
||||||
|
"teams.name ILIKE :term OR matches.opponent_name ILIKE :term OR clubs.name ILIKE :term OR matches.location ILIKE :term",
|
||||||
|
term: term
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if @filters[:status].present? && StreamSession::STATUSES.include?(@filters[:status])
|
||||||
|
scope = scope.where(stream_sessions: { status: @filters[:status] })
|
||||||
|
end
|
||||||
|
if @filters[:platform].present? && StreamSession::LIVE_PLATFORMS.include?(@filters[:platform])
|
||||||
|
scope = scope.where(stream_sessions: { platform: @filters[:platform] })
|
||||||
|
end
|
||||||
|
if @filters[:club_id].present?
|
||||||
|
scope = scope.where(teams: { club_id: @filters[:club_id] })
|
||||||
|
end
|
||||||
|
if @filters[:stream_node_id].present?
|
||||||
|
node = StreamNode.find_by(id: @filters[:stream_node_id])
|
||||||
|
if node
|
||||||
|
scope = scope.where(
|
||||||
|
"stream_sessions.stream_node_id = :id OR stream_sessions.ingest_slug = :slug",
|
||||||
|
id: node.id,
|
||||||
|
slug: node.slug
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (from_time = parse_filter_date(@filters[:from], end_of_day: false))
|
||||||
|
scope = scope.where(
|
||||||
|
"COALESCE(stream_sessions.started_at, stream_sessions.created_at) >= ?",
|
||||||
|
from_time
|
||||||
|
)
|
||||||
|
end
|
||||||
|
if (to_time = parse_filter_date(@filters[:to], end_of_day: true))
|
||||||
|
scope = scope.where(
|
||||||
|
"COALESCE(stream_sessions.started_at, stream_sessions.created_at) <= ?",
|
||||||
|
to_time
|
||||||
|
)
|
||||||
|
end
|
||||||
|
scope
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_filter_date(value, end_of_day:)
|
||||||
|
return nil if value.blank?
|
||||||
|
|
||||||
|
date = Date.parse(value)
|
||||||
|
end_of_day ? date.end_of_day : date.beginning_of_day
|
||||||
|
rescue ArgumentError, TypeError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Admin
|
||||||
|
class StreamNodesController < Admin::BaseController
|
||||||
|
def index
|
||||||
|
Streams::NodeRegistry.ensure_home_from_env!
|
||||||
|
@nodes = StreamNode.order(:role, :slug)
|
||||||
|
@dns_provider = ENV.fetch("STREAM_DNS_PROVIDER", "lab")
|
||||||
|
@cloud_provider = ENV.fetch("STREAM_CLOUD_PROVIDER", "local_lab")
|
||||||
|
@lab_hosts = lab_dns_snippet
|
||||||
|
@hetzner_configured = ENV["HCLOUD_TOKEN"].present?
|
||||||
|
@autoscale_metrics = Streams::Autoscaler.metrics
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
kind = params[:kind].to_s
|
||||||
|
node =
|
||||||
|
if kind == "cloud"
|
||||||
|
Streams::NodeProvisioner.new.provision_cloud!
|
||||||
|
else
|
||||||
|
Streams::NodeProvisioner.new.provision_lab!
|
||||||
|
end
|
||||||
|
redirect_to admin_stream_nodes_path,
|
||||||
|
notice: t("admin.flash.stream_node_created", slug: node.slug)
|
||||||
|
rescue Streams::NodeProvisioner::Error, Streams::CloudProviders::Error, Streams::DnsProviders::Error,
|
||||||
|
KeyError => e
|
||||||
|
redirect_to admin_stream_nodes_path, alert: e.message
|
||||||
|
end
|
||||||
|
|
||||||
|
def drain
|
||||||
|
node = StreamNode.find(params[:id])
|
||||||
|
Streams::NodeProvisioner.new.drain!(node)
|
||||||
|
redirect_to admin_stream_nodes_path, notice: t("admin.flash.stream_node_draining", slug: node.slug)
|
||||||
|
rescue Streams::NodeProvisioner::Error => e
|
||||||
|
redirect_to admin_stream_nodes_path, alert: e.message
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
node = StreamNode.find(params[:id])
|
||||||
|
Streams::NodeProvisioner.new.decommission!(node)
|
||||||
|
redirect_to admin_stream_nodes_path, notice: t("admin.flash.stream_node_destroyed", slug: node.slug)
|
||||||
|
rescue Streams::NodeProvisioner::BusyError, Streams::NodeProvisioner::Error,
|
||||||
|
Streams::CloudProviders::Error, Streams::DnsProviders::Error => e
|
||||||
|
redirect_to admin_stream_nodes_path, alert: e.message
|
||||||
|
end
|
||||||
|
|
||||||
|
def kill_switch
|
||||||
|
Streams::Autoscaler.engage_kill_switch!
|
||||||
|
redirect_to admin_stream_nodes_path, notice: t("admin.flash.autoscale_kill_on")
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_kill_switch
|
||||||
|
Streams::Autoscaler.clear_kill_switch!
|
||||||
|
redirect_to admin_stream_nodes_path, notice: t("admin.flash.autoscale_kill_off")
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def lab_dns_snippet
|
||||||
|
return "" unless @dns_provider == "lab"
|
||||||
|
|
||||||
|
Streams::DnsProviders::Lab.new.hosts_file_snippet
|
||||||
|
rescue Redis::BaseError
|
||||||
|
""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -2,7 +2,7 @@ module Admin
|
|||||||
class YoutubeController < Admin::BaseController
|
class YoutubeController < Admin::BaseController
|
||||||
def platform
|
def platform
|
||||||
if ENV["YOUTUBE_CLIENT_ID"].blank?
|
if ENV["YOUTUBE_CLIENT_ID"].blank?
|
||||||
redirect_to admin_root_path, alert: "Configura YOUTUBE_CLIENT_ID e YOUTUBE_CLIENT_SECRET in .env"
|
redirect_to admin_root_path, alert: t("admin.flash.youtube_not_configured")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Analytics
|
||||||
|
class EventsController < ActionController::API
|
||||||
|
def create
|
||||||
|
payload = parse_payload
|
||||||
|
result = Analytics::Ingest.new(events: payload, remote_ip: request.remote_ip).call
|
||||||
|
|
||||||
|
if result.rate_limited
|
||||||
|
return head :too_many_requests
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: { accepted: result.accepted, rejected: result.rejected }, status: :accepted
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def parse_payload
|
||||||
|
body = request.request_parameters
|
||||||
|
return body["events"] if body.is_a?(Hash) && body["events"].is_a?(Array)
|
||||||
|
return body if body.is_a?(Array)
|
||||||
|
|
||||||
|
raw = request.raw_post
|
||||||
|
return [] if raw.blank?
|
||||||
|
|
||||||
|
parsed = JSON.parse(raw)
|
||||||
|
return parsed["events"] if parsed.is_a?(Hash) && parsed["events"].is_a?(Array)
|
||||||
|
return parsed if parsed.is_a?(Array)
|
||||||
|
|
||||||
|
[]
|
||||||
|
rescue JSON::ParserError
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Analytics
|
||||||
|
class SnapshotsController < ActionController::API
|
||||||
|
def create
|
||||||
|
result = Analytics::SnapshotIngest.new(
|
||||||
|
path: params[:path] || params[:page_path],
|
||||||
|
device: params[:device],
|
||||||
|
width: params[:width],
|
||||||
|
height: params[:height],
|
||||||
|
image: params[:image],
|
||||||
|
remote_ip: request.remote_ip
|
||||||
|
).call
|
||||||
|
|
||||||
|
return head :too_many_requests if result.rate_limited
|
||||||
|
return render json: { ok: false, error: result.error }, status: :unprocessable_content unless result.ok
|
||||||
|
|
||||||
|
render json: { ok: true, skipped: result.skipped }, status: :accepted
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
module Api
|
||||||
|
module V1
|
||||||
|
class AccountsController < ApplicationController
|
||||||
|
def show
|
||||||
|
render json: user_json(current_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
name = params[:name].to_s.strip
|
||||||
|
if name.blank?
|
||||||
|
return render json: { error: I18n.t("flash.accounts.name_required") }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
if current_user.update(name: name)
|
||||||
|
render json: user_json(current_user)
|
||||||
|
else
|
||||||
|
render json: { error: current_user.errors.full_messages.join(", ") }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def password
|
||||||
|
result = Users::ChangePassword.call(
|
||||||
|
user: current_user,
|
||||||
|
current_password: params[:current_password],
|
||||||
|
password: params[:password],
|
||||||
|
password_confirmation: params[:password_confirmation]
|
||||||
|
)
|
||||||
|
|
||||||
|
unless result.ok?
|
||||||
|
return render json: { error: password_error_message(result.error) }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: { message: I18n.t("flash.accounts.password_updated") }
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def user_json(user)
|
||||||
|
{
|
||||||
|
id: user.id,
|
||||||
|
email: user.email,
|
||||||
|
name: user.name,
|
||||||
|
role: user.role
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def password_error_message(code)
|
||||||
|
case code
|
||||||
|
when :current_incorrect then I18n.t("flash.accounts.password_current_incorrect")
|
||||||
|
when :too_short then I18n.t("flash.accounts.password_too_short")
|
||||||
|
when :too_long then I18n.t("flash.accounts.password_too_long")
|
||||||
|
when :too_weak then I18n.t("flash.accounts.password_too_weak")
|
||||||
|
when :same_as_current then I18n.t("flash.accounts.password_same_as_current")
|
||||||
|
when :mismatch then I18n.t("flash.accounts.password_mismatch")
|
||||||
|
else I18n.t("flash.accounts.password_update_failed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
module Api
|
||||||
|
module V1
|
||||||
|
class AnnouncementsController < BaseController
|
||||||
|
skip_before_action :authenticate_request!
|
||||||
|
|
||||||
|
def index
|
||||||
|
platform = params[:platform].to_s.presence
|
||||||
|
announcements = AppAnnouncement.for_platform(platform).newest
|
||||||
|
render json: announcements.map { |item| item.as_api_json(platform: platform) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class AuthController < ApplicationController
|
class AuthController < ApplicationController
|
||||||
skip_before_action :authenticate_request!, only: %i[login refresh register]
|
skip_before_action :authenticate_request!, only: %i[login refresh register forgot_password]
|
||||||
|
|
||||||
def register
|
def register
|
||||||
user = User.new(
|
user = User.new(
|
||||||
@@ -22,18 +22,18 @@ module Api
|
|||||||
if user&.authenticate(params[:password])
|
if user&.authenticate(params[:password])
|
||||||
render json: token_response(user), status: :ok
|
render json: token_response(user), status: :ok
|
||||||
else
|
else
|
||||||
render json: { error: "Invalid credentials" }, status: :unauthorized
|
render json: { error: I18n.t("flash.sessions.invalid_credentials") }, status: :unauthorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def logout
|
def logout
|
||||||
render json: { message: "Logged out" }
|
render json: { message: I18n.t("flash.sessions.logged_out") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh
|
def refresh
|
||||||
payload = JsonWebToken.decode(params[:refresh_token] || bearer_token)
|
payload = JsonWebToken.decode(params[:refresh_token] || bearer_token)
|
||||||
user = User.find_by(id: payload&.dig(:user_id))
|
user = User.find_by(id: payload&.dig(:user_id))
|
||||||
return render json: { error: "Invalid token" }, status: :unauthorized unless user
|
return render json: { error: I18n.t("flash.sessions.invalid_token") }, status: :unauthorized unless user
|
||||||
|
|
||||||
render json: token_response(user)
|
render json: token_response(user)
|
||||||
end
|
end
|
||||||
@@ -42,6 +42,13 @@ module Api
|
|||||||
render json: user_json(current_user)
|
render json: user_json(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def forgot_password
|
||||||
|
Users::RequestPasswordReset.call(email: params[:email])
|
||||||
|
render json: {
|
||||||
|
message: I18n.t("flash.password_resets.email_sent")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def token_response(user)
|
def token_response(user)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ module Api
|
|||||||
module V1
|
module V1
|
||||||
class BaseController < ApplicationController
|
class BaseController < ApplicationController
|
||||||
rescue_from Teams::EntitlementError, with: :render_entitlement_error
|
rescue_from Teams::EntitlementError, with: :render_entitlement_error
|
||||||
|
rescue_from Streams::IngestUnavailableError, with: :render_ingest_unavailable
|
||||||
|
rescue_from BrandingAttachments::CoverUploadError, with: :render_cover_upload_error
|
||||||
rescue_from Youtube::BroadcastService::Error, with: :render_youtube_error
|
rescue_from Youtube::BroadcastService::Error, with: :render_youtube_error
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -20,6 +22,17 @@ module Api
|
|||||||
billing_url: error.billing_url
|
billing_url: error.billing_url
|
||||||
}, status: :forbidden
|
}, status: :forbidden
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_ingest_unavailable(error)
|
||||||
|
render json: {
|
||||||
|
error: error.message,
|
||||||
|
error_code: error.code
|
||||||
|
}, status: :service_unavailable
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_cover_upload_error(error)
|
||||||
|
render json: { error: error.message, error_code: "cover_upload_invalid" }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class MatchesController < BaseController
|
class MatchesController < BaseController
|
||||||
|
include Api::UrlHelper
|
||||||
|
include Api::CoverJson
|
||||||
|
include BrandingAttachments
|
||||||
|
|
||||||
before_action :set_team, only: %i[index create]
|
before_action :set_team, only: %i[index create]
|
||||||
before_action :set_match, only: %i[show update destroy]
|
before_action :set_match, only: %i[show update destroy]
|
||||||
|
|
||||||
@@ -8,11 +12,17 @@ module Api
|
|||||||
matches = @team.matches
|
matches = @team.matches
|
||||||
.includes(:team, :stream_sessions)
|
.includes(:team, :stream_sessions)
|
||||||
.order(Arel.sql("scheduled_at ASC NULLS LAST"), created_at: :desc)
|
.order(Arel.sql("scheduled_at ASC NULLS LAST"), created_at: :desc)
|
||||||
|
.select(&:coach_hub_visible?)
|
||||||
render json: matches.map { |m| match_json(m) }
|
render json: matches.map { |m| match_json(m) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
match = @team.matches.create!(match_params)
|
attrs = match_params.to_h
|
||||||
|
attrs["sport_key"] = @team.sport_key
|
||||||
|
normalize_scoring_rules!(attrs)
|
||||||
|
match = @team.matches.create!(attrs)
|
||||||
|
attach_opponent_logo(match)
|
||||||
|
attach_match_cover(match)
|
||||||
render json: match_json(match), status: :created
|
render json: match_json(match), status: :created
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -21,7 +31,12 @@ module Api
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@match.update!(match_params)
|
attrs = match_params.to_h
|
||||||
|
normalize_scoring_rules!(attrs)
|
||||||
|
normalize_opponent_color!(attrs)
|
||||||
|
@match.update!(attrs)
|
||||||
|
attach_opponent_logo(@match)
|
||||||
|
attach_match_cover(@match)
|
||||||
render json: match_json(@match)
|
render json: match_json(@match)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -46,41 +61,86 @@ module Api
|
|||||||
|
|
||||||
def set_match
|
def set_match
|
||||||
team_ids = current_user.streamable_teams.map(&:id)
|
team_ids = current_user.streamable_teams.map(&:id)
|
||||||
@match = Match.where(team_id: team_ids).find(params[:id])
|
@match = Match.includes(:team).where(team_id: team_ids).find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_params
|
def match_params
|
||||||
params.require(:match).permit(
|
p = params.require(:match).permit(
|
||||||
:opponent_name, :location, :scheduled_at, :sport, :sets_to_win,
|
:opponent_name, :location, :scheduled_at, :sport, :sport_key, :sets_to_win,
|
||||||
:category, :phase, roster_numbers: [],
|
:category, :opponent_primary_color, :overlay_kind,
|
||||||
scoring_rules: %i[points_per_set points_deciding_set min_point_lead]
|
scoring_rules: {}
|
||||||
)
|
)
|
||||||
|
if p[:sport].present? && p[:sport_key].blank?
|
||||||
|
p[:sport_key] = p.delete(:sport)
|
||||||
|
end
|
||||||
|
p[:overlay_kind] = nil if p.key?(:overlay_kind) && p[:overlay_kind].blank?
|
||||||
|
p
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize_scoring_rules!(attrs)
|
||||||
|
return unless attrs.key?("scoring_rules")
|
||||||
|
|
||||||
|
rules = attrs["scoring_rules"]
|
||||||
|
attrs["scoring_rules"] = {} if rules.blank?
|
||||||
|
if attrs["sets_to_win"].present? && attrs["scoring_rules"].is_a?(Hash)
|
||||||
|
attrs["scoring_rules"]["sets_to_win"] ||= attrs["sets_to_win"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize_opponent_color!(attrs)
|
||||||
|
return unless attrs.key?("opponent_primary_color")
|
||||||
|
|
||||||
|
attrs["opponent_primary_color"] = normalize_hex_color(
|
||||||
|
attrs["opponent_primary_color"],
|
||||||
|
Match::DEFAULT_OPPONENT_COLOR
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def attach_opponent_logo(match)
|
||||||
|
file = params[:opponent_logo_file]
|
||||||
|
match.opponent_logo_file.attach(file) if file.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def attach_match_cover(match)
|
||||||
|
attach_cover_image(match, entitlements: match.team.entitlements)
|
||||||
|
enqueue_cover_slate_generation(match)
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_json(match, detail: false)
|
def match_json(match, detail: false)
|
||||||
active = active_session_for(match)
|
active = active_session_for(match)
|
||||||
|
team = match.team
|
||||||
{
|
{
|
||||||
id: match.id,
|
id: match.id,
|
||||||
team_id: match.team_id,
|
team_id: match.team_id,
|
||||||
team_name: match.team.name,
|
team_name: team.name,
|
||||||
opponent_name: match.opponent_name,
|
opponent_name: match.opponent_name,
|
||||||
location: match.location,
|
location: match.location,
|
||||||
scheduled_at: match.scheduled_at,
|
scheduled_at: match.scheduled_at,
|
||||||
sport: match.sport,
|
sport: match.sport_key,
|
||||||
|
sport_key: match.sport_key,
|
||||||
|
sport_label: match.sport_label,
|
||||||
|
board_type: match.effective_board_type,
|
||||||
|
overlay_kind: match.overlay_kind,
|
||||||
|
effective_overlay_kind: match.effective_overlay_kind,
|
||||||
sets_to_win: match.sets_to_win,
|
sets_to_win: match.sets_to_win,
|
||||||
scoring_rules: match.scoring_rules.presence,
|
scoring_rules: match.scoring_rules.presence,
|
||||||
roster_numbers: match.roster_numbers,
|
effective_scoring_rules: match.effective_scoring_rules,
|
||||||
category: match.category,
|
category: match.category,
|
||||||
phase: match.phase,
|
home_primary_color: team.effective_primary_color,
|
||||||
|
home_secondary_color: team.effective_secondary_color,
|
||||||
|
home_logo_url: api_absolute_url(team.effective_logo_url),
|
||||||
|
opponent_primary_color: match.effective_opponent_primary_color,
|
||||||
|
opponent_logo_url: api_absolute_url(match.opponent_logo_url),
|
||||||
|
**match_cover_json(match),
|
||||||
active_session_id: active&.id,
|
active_session_id: active&.id,
|
||||||
active_session_status: active&.status
|
active_session_status: active&.status,
|
||||||
|
stream_completed: match.stream_completed?,
|
||||||
|
coach_hub_visible: match.coach_hub_visible?
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_session_for(match)
|
def active_session_for(match)
|
||||||
match.stream_sessions
|
match.active_stream_session
|
||||||
.order(created_at: :desc)
|
|
||||||
.find { |s| !%w[ended error].include?(s.status) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,13 +5,18 @@ module Api
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
authorize_manage!
|
authorize_manage!
|
||||||
@recording.update!(recording_update_attrs)
|
attrs = recording_update_attrs
|
||||||
|
privacy_changed = attrs.key?(:privacy_status) && attrs[:privacy_status] != @recording.privacy_status
|
||||||
|
@recording.update!(attrs)
|
||||||
|
Recordings::SyncYoutubePrivacyJob.perform_async(@recording.id) if privacy_changed && @recording.youtube_video_id.present?
|
||||||
render json: recording_json(@recording)
|
render json: recording_json(@recording)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
authorize_manage!
|
authorize_manage!
|
||||||
Recordings::Delete.new(@recording).call
|
scope = params[:delete_scope].to_s
|
||||||
|
scope = "both" unless Recordings::Delete::SCOPES.include?(scope)
|
||||||
|
Recordings::Delete.new(@recording, scope: scope).call
|
||||||
head :no_content
|
head :no_content
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -92,11 +97,15 @@ module Api
|
|||||||
replay_url: recording.replay_url,
|
replay_url: recording.replay_url,
|
||||||
playback_url: recording.playback_stream_url,
|
playback_url: recording.playback_stream_url,
|
||||||
thumbnail_url: recording.thumbnail_url,
|
thumbnail_url: recording.thumbnail_url,
|
||||||
download_enabled: ent.phone_download_enabled?,
|
download_enabled: ent.phone_download_enabled? && recording.storage_key.present?,
|
||||||
youtube_video_id: recording.youtube_video_id,
|
youtube_video_id: recording.youtube_video_id,
|
||||||
youtube_watch_url: recording.youtube_watch_url,
|
youtube_watch_url: recording.youtube_watch_url,
|
||||||
youtube_publish_enabled: ent.premium_full? && ent.youtube_enabled?,
|
youtube_publish_enabled: ent.premium_full? && ent.youtube_enabled? && recording.storage_key.present? && recording.youtube_video_id.blank?,
|
||||||
|
replay_source: recording.replay_source,
|
||||||
|
source_platform: recording.source_platform,
|
||||||
|
source_platform_label: recording.source_platform_label,
|
||||||
expires_at: recording.expires_at,
|
expires_at: recording.expires_at,
|
||||||
|
days_until_expiry: recording.days_until_expiry,
|
||||||
metadata: recording.metadata
|
metadata: recording.metadata
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
module Api
|
||||||
|
module V1
|
||||||
|
class SportsController < BaseController
|
||||||
|
def index
|
||||||
|
render json: ::Sports::Catalog.as_api_list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -34,11 +34,31 @@ module Api
|
|||||||
render json: session_json(@session)
|
render json: session_json(@session)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def audio_mute
|
||||||
|
muted = params.key?(:muted) ? params[:muted] : true
|
||||||
|
Sessions::SetAudioMute.new(@session, muted: muted).call
|
||||||
|
render json: session_json(@session)
|
||||||
|
end
|
||||||
|
|
||||||
def score
|
def score
|
||||||
Scoring::SyncState.new(session: @session, payload: score_sync_params).call
|
Scoring::SyncState.new(session: @session, payload: score_sync_params).call
|
||||||
render json: session_json(@session, detail: true)
|
render json: session_json(@session, detail: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def score_action
|
||||||
|
action = params[:score_action].presence
|
||||||
|
raise ArgumentError, "Azione mancante" if action.blank?
|
||||||
|
|
||||||
|
result = Scoring::ApplyAction.new(session: @session, action: action).call
|
||||||
|
render json: session_json(@session, detail: true).merge(
|
||||||
|
set_won: result.set_won,
|
||||||
|
match_won: result.match_won,
|
||||||
|
winner: result.winner&.to_s
|
||||||
|
)
|
||||||
|
rescue ArgumentError => e
|
||||||
|
render json: { error: e.message }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
def events
|
def events
|
||||||
events = @session.stream_events.recent.limit(100)
|
events = @session.stream_events.recent.limit(100)
|
||||||
render json: events.map { |e| event_json(e) }
|
render json: events.map { |e| event_json(e) }
|
||||||
@@ -54,8 +74,10 @@ module Api
|
|||||||
current_bitrate: params[:current_bitrate],
|
current_bitrate: params[:current_bitrate],
|
||||||
target_bitrate: params[:target_bitrate],
|
target_bitrate: params[:target_bitrate],
|
||||||
fps: params[:fps],
|
fps: params[:fps],
|
||||||
|
thermal_state: sanitized_thermal_state,
|
||||||
last_seen_at: Time.current
|
last_seen_at: Time.current
|
||||||
)
|
)
|
||||||
|
Sessions::ApplyClientInfo.call(@session, params[:client]) if params[:client].present?
|
||||||
sync_publisher_when_streaming!(params[:fps].to_f)
|
sync_publisher_when_streaming!(params[:fps].to_f)
|
||||||
SessionChannel.broadcast_message(@session, state.as_cable_payload)
|
SessionChannel.broadcast_message(@session, state.as_cable_payload)
|
||||||
head :no_content
|
head :no_content
|
||||||
@@ -100,13 +122,38 @@ module Api
|
|||||||
end
|
end
|
||||||
|
|
||||||
def network_test
|
def network_test
|
||||||
|
upload_mbps = params[:upload_mbps].to_f
|
||||||
|
preset = Sessions::SelectQuality.call(upload_mbps: upload_mbps)
|
||||||
|
@session.update!(
|
||||||
|
quality_preset: preset[:id],
|
||||||
|
target_bitrate: preset[:target_bitrate],
|
||||||
|
target_fps: preset[:target_fps]
|
||||||
|
)
|
||||||
@session.stream_events.create!(
|
@session.stream_events.create!(
|
||||||
event_type: "network_test",
|
event_type: "network_test",
|
||||||
metadata: params.permit(:download_mbps, :upload_mbps, :latency_ms, :network_type).to_h,
|
metadata: params.permit(:download_mbps, :upload_mbps, :latency_ms, :network_type)
|
||||||
|
.to_h.merge(
|
||||||
|
"quality_preset" => preset[:id],
|
||||||
|
"target_bitrate" => preset[:target_bitrate]
|
||||||
|
),
|
||||||
occurred_at: Time.current
|
occurred_at: Time.current
|
||||||
)
|
)
|
||||||
ready = params[:upload_mbps].to_f >= (@session.target_bitrate / 1_000_000.0 * 0.8)
|
target_upload = preset[:target_bitrate] / 1_000_000.0
|
||||||
render json: { ready: ready, target_upload_mbps: @session.target_bitrate / 1_000_000.0 }
|
ready = upload_mbps >= (target_upload * Sessions::SelectQuality::UPLOAD_HEADROOM)
|
||||||
|
render json: {
|
||||||
|
ready: ready,
|
||||||
|
target_upload_mbps: target_upload,
|
||||||
|
quality_preset: preset[:id],
|
||||||
|
target_bitrate: preset[:target_bitrate],
|
||||||
|
target_fps: preset[:target_fps]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def min_quality
|
||||||
|
Sessions::SetMinQuality.new(@session, preset: params[:min_quality_preset]).call
|
||||||
|
render json: session_json(@session)
|
||||||
|
rescue ArgumentError => e
|
||||||
|
render json: { error: e.message }, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
def youtube_stats
|
def youtube_stats
|
||||||
@@ -128,13 +175,24 @@ module Api
|
|||||||
.find(params[:id])
|
.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sanitized_thermal_state
|
||||||
|
value = params[:thermal_state].to_s.downcase.presence
|
||||||
|
value if value.in?(%w[nominal fair serious critical])
|
||||||
|
end
|
||||||
|
|
||||||
def session_params
|
def session_params
|
||||||
params.permit(:platform, :privacy_status, :quality_preset, :target_bitrate, :target_fps, :youtube_channel)
|
params.permit(
|
||||||
|
:platform, :privacy_status, :quality_preset, :target_bitrate, :target_fps, :youtube_channel,
|
||||||
|
client: %i[os client_os app_version app_build version build build_number
|
||||||
|
device_manufacturer manufacturer device_model model
|
||||||
|
os_version system_version carrier network_operator operator]
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def score_sync_params
|
def score_sync_params
|
||||||
params.permit(
|
params.permit(
|
||||||
:home_sets, :away_sets, :home_points, :away_points, :current_set,
|
:home_sets, :away_sets, :home_points, :away_points, :current_set,
|
||||||
|
:clock_secs, :clock_running, :period, :home_score, :away_score, :overtime,
|
||||||
set_partials: %i[set home away]
|
set_partials: %i[set home away]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@@ -147,6 +205,7 @@ module Api
|
|||||||
platform: session.platform,
|
platform: session.platform,
|
||||||
rtmp_ingest_url: session.rtmp_ingest_url,
|
rtmp_ingest_url: session.rtmp_ingest_url,
|
||||||
hls_playback_url: session.hls_playback_url,
|
hls_playback_url: session.hls_playback_url,
|
||||||
|
stream_node: session.stream_node&.slug,
|
||||||
watch_page_url: session.matchlivetv_platform? ? session.watch_page_url : nil,
|
watch_page_url: session.matchlivetv_platform? ? session.watch_page_url : nil,
|
||||||
share_url: session.share_url,
|
share_url: session.share_url,
|
||||||
youtube_watch_url: session.youtube_watch_url,
|
youtube_watch_url: session.youtube_watch_url,
|
||||||
@@ -154,9 +213,11 @@ module Api
|
|||||||
youtube_ready: session.youtube_ready?,
|
youtube_ready: session.youtube_ready?,
|
||||||
privacy_status: session.privacy_status,
|
privacy_status: session.privacy_status,
|
||||||
quality_preset: session.quality_preset,
|
quality_preset: session.quality_preset,
|
||||||
|
min_quality_preset: session.min_quality_preset,
|
||||||
target_bitrate: session.target_bitrate,
|
target_bitrate: session.target_bitrate,
|
||||||
started_at: session.started_at,
|
started_at: session.started_at,
|
||||||
disconnection_count: session.disconnection_count
|
disconnection_count: session.disconnection_count,
|
||||||
|
audio_muted: session.audio_muted
|
||||||
}
|
}
|
||||||
if detail
|
if detail
|
||||||
data[:score] = session.score_state&.as_cable_payload
|
data[:score] = session.score_state&.as_cable_payload
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class TeamsController < BaseController
|
class TeamsController < BaseController
|
||||||
|
include Api::UrlHelper
|
||||||
|
include BrandingAttachments
|
||||||
|
|
||||||
def index
|
def index
|
||||||
teams = current_user.streamable_teams
|
teams = current_user.streamable_teams
|
||||||
render json: teams.map { |t| team_json(t) }
|
render json: teams.map { |t| team_json(t) }
|
||||||
@@ -18,10 +21,11 @@ module Api
|
|||||||
}, status: :unprocessable_entity
|
}, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
club = Club.create!(name: team_params[:name], sport: team_params[:sport] || "volleyball",
|
sport_key = ::Sports::Catalog.normalize_key(team_params[:sport_key] || team_params[:sport] || "pallavolo")
|
||||||
|
club = Club.create!(name: team_params[:name], sport: sport_key,
|
||||||
primary_color: "#e53935", secondary_color: "#ffffff")
|
primary_color: "#e53935", secondary_color: "#ffffff")
|
||||||
ClubMembership.create!(user: current_user, club: club, role: "owner")
|
ClubMembership.create!(user: current_user, club: club, role: "owner")
|
||||||
team = club.teams.create!(name: team_params[:name], sport: club.sport)
|
team = club.teams.create!(name: team_params[:name], sport_key: sport_key)
|
||||||
Billing::AssignPlan.call(club: club, plan_slug: "free")
|
Billing::AssignPlan.call(club: club, plan_slug: "free")
|
||||||
render json: team_json(team), status: :created
|
render json: team_json(team), status: :created
|
||||||
end
|
end
|
||||||
@@ -39,6 +43,7 @@ module Api
|
|||||||
|
|
||||||
recs = team.recordings.not_deleted
|
recs = team.recordings.not_deleted
|
||||||
.where(status: %w[ready processing])
|
.where(status: %w[ready processing])
|
||||||
|
.where("expires_at IS NULL OR expires_at > ?", Time.current)
|
||||||
.includes(stream_session: :match)
|
.includes(stream_session: :match)
|
||||||
.order(recorded_at: :desc, created_at: :desc)
|
.order(recorded_at: :desc, created_at: :desc)
|
||||||
.limit(50)
|
.limit(50)
|
||||||
@@ -48,6 +53,7 @@ module Api
|
|||||||
def update
|
def update
|
||||||
team = current_user.manageable_teams.find(params[:id])
|
team = current_user.manageable_teams.find(params[:id])
|
||||||
team.update!(team_params)
|
team.update!(team_params)
|
||||||
|
attach_team_logo(team)
|
||||||
render json: team_json(team)
|
render json: team_json(team)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -69,7 +75,23 @@ module Api
|
|||||||
private
|
private
|
||||||
|
|
||||||
def team_params
|
def team_params
|
||||||
params.require(:team).permit(:name, :sport, :logo_url)
|
p = params.require(:team).permit(:name, :sport, :sport_key, :logo_url, :primary_color, :secondary_color)
|
||||||
|
if p[:sport].present? && p[:sport_key].blank?
|
||||||
|
p[:sport_key] = p.delete(:sport)
|
||||||
|
end
|
||||||
|
p
|
||||||
|
if p[:primary_color].present?
|
||||||
|
p[:primary_color] = normalize_hex_color(p[:primary_color], p[:primary_color])
|
||||||
|
end
|
||||||
|
if p[:secondary_color].present?
|
||||||
|
p[:secondary_color] = normalize_hex_color(p[:secondary_color], p[:secondary_color])
|
||||||
|
end
|
||||||
|
p
|
||||||
|
end
|
||||||
|
|
||||||
|
def attach_team_logo(team)
|
||||||
|
file = params[:logo_file]
|
||||||
|
team.logo_file.attach(file) if file.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def team_json(team, detail: false)
|
def team_json(team, detail: false)
|
||||||
@@ -79,8 +101,11 @@ module Api
|
|||||||
data = {
|
data = {
|
||||||
id: team.id,
|
id: team.id,
|
||||||
name: team.name,
|
name: team.name,
|
||||||
sport: team.sport,
|
sport: team.sport_key,
|
||||||
logo_url: team.effective_logo_url,
|
sport_key: team.sport_key,
|
||||||
|
sport_label: team.sport_label,
|
||||||
|
board_type: team.effective_board_type,
|
||||||
|
logo_url: api_absolute_url(team.effective_logo_url),
|
||||||
primary_color: team.effective_primary_color,
|
primary_color: team.effective_primary_color,
|
||||||
secondary_color: team.effective_secondary_color,
|
secondary_color: team.effective_secondary_color,
|
||||||
club_id: team.club_id,
|
club_id: team.club_id,
|
||||||
@@ -112,7 +137,8 @@ module Api
|
|||||||
youtube_mode: ent.plan.youtube_mode,
|
youtube_mode: ent.plan.youtube_mode,
|
||||||
staff_role: current_user.staff_role_for(team),
|
staff_role: current_user.staff_role_for(team),
|
||||||
can_stream: current_user.can_stream_for?(team),
|
can_stream: current_user.can_stream_for?(team),
|
||||||
can_connect_youtube: team.club.owned_by?(current_user) && ent.premium_full? && ent.youtube_enabled?
|
can_connect_youtube: team.club.owned_by?(current_user) && ent.premium_full? && ent.youtube_enabled?,
|
||||||
|
custom_cover_enabled: ent.can_use_custom_cover?
|
||||||
}
|
}
|
||||||
if detail
|
if detail
|
||||||
data[:members] = team.user_teams.includes(:user).where.not(role: "owner").map do |ut|
|
data[:members] = team.user_teams.includes(:user).where.not(role: "owner").map do |ut|
|
||||||
@@ -145,13 +171,17 @@ module Api
|
|||||||
replay_url: recording.replay_url,
|
replay_url: recording.replay_url,
|
||||||
playback_url: recording.playback_stream_url,
|
playback_url: recording.playback_stream_url,
|
||||||
thumbnail_url: recording.thumbnail_url,
|
thumbnail_url: recording.thumbnail_url,
|
||||||
download_enabled: ent.phone_download_enabled?,
|
download_enabled: ent.phone_download_enabled? && recording.storage_key.present?,
|
||||||
view_count: recording.view_count,
|
view_count: recording.view_count,
|
||||||
views_label: recording.views_label,
|
views_label: recording.views_label,
|
||||||
youtube_video_id: recording.youtube_video_id,
|
youtube_video_id: recording.youtube_video_id,
|
||||||
youtube_watch_url: recording.youtube_watch_url,
|
youtube_watch_url: recording.youtube_watch_url,
|
||||||
youtube_publish_enabled: ent.premium_full? && ent.youtube_enabled?,
|
youtube_publish_enabled: ent.premium_full? && ent.youtube_enabled? && recording.storage_key.present? && recording.youtube_video_id.blank?,
|
||||||
|
replay_source: recording.replay_source,
|
||||||
|
source_platform: recording.source_platform,
|
||||||
|
source_platform_label: recording.source_platform_label,
|
||||||
expires_at: recording.expires_at,
|
expires_at: recording.expires_at,
|
||||||
|
days_until_expiry: recording.days_until_expiry,
|
||||||
metadata: recording.metadata
|
metadata: recording.metadata
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
class ApplicationController < ActionController::API
|
class ApplicationController < ActionController::API
|
||||||
include ActionController::HttpAuthentication::Token::ControllerMethods
|
include ActionController::HttpAuthentication::Token::ControllerMethods
|
||||||
|
|
||||||
|
before_action :set_api_locale
|
||||||
before_action :authenticate_request!
|
before_action :authenticate_request!
|
||||||
|
|
||||||
attr_reader :current_user
|
attr_reader :current_user
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_api_locale
|
||||||
|
explicit = LocaleResolver.normalize(request.headers["X-Locale"])
|
||||||
|
I18n.locale = explicit ||
|
||||||
|
LocaleResolver.from_accept_language(request.headers["Accept-Language"]) ||
|
||||||
|
I18n.default_locale
|
||||||
|
end
|
||||||
|
|
||||||
def authenticate_request!
|
def authenticate_request!
|
||||||
token = bearer_token
|
token = bearer_token
|
||||||
payload = JsonWebToken.decode(token)
|
payload = JsonWebToken.decode(token)
|
||||||
@current_user = User.find_by(id: payload[:user_id]) if payload
|
@current_user = User.find_by(id: payload[:user_id]) if payload
|
||||||
render json: { error: "Unauthorized" }, status: :unauthorized unless @current_user
|
render json: { error: I18n.t("flash.sessions.unauthorized") }, status: :unauthorized unless @current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def bearer_token
|
def bearer_token
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
module Api
|
||||||
|
module CoverJson
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def match_cover_json(match)
|
||||||
|
resolver = Streams::CoverResolver.new(match)
|
||||||
|
{
|
||||||
|
effective_cover_url: api_absolute_url(resolver.effective_cover_url),
|
||||||
|
cover_source: resolver.cover_source,
|
||||||
|
custom_cover_enabled: match.team.entitlements.can_use_custom_cover?
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
module Api
|
||||||
|
module UrlHelper
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def api_absolute_url(path_or_url)
|
||||||
|
return nil if path_or_url.blank?
|
||||||
|
return path_or_url if path_or_url.match?(/\Ahttps?:\/\//i)
|
||||||
|
|
||||||
|
base = request.base_url
|
||||||
|
path = path_or_url.start_with?("/") ? path_or_url : "/#{path_or_url}"
|
||||||
|
"#{base}#{path}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,6 +8,48 @@ module BrandingAttachments
|
|||||||
record.logo_file.attach(file) if file.present?
|
record.logo_file.attach(file) if file.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attach_cover_image(record, entitlements:)
|
||||||
|
remove_flag = params[:remove_cover].to_s == "1" || params.dig(:match, :remove_cover).to_s == "1"
|
||||||
|
if remove_flag
|
||||||
|
record.cover_image.purge if record.cover_image.attached?
|
||||||
|
record.cover_slate.purge if record.cover_slate.attached?
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
file = params.dig(:branding, :cover_image) || params[:cover_image]
|
||||||
|
return if file.blank?
|
||||||
|
|
||||||
|
entitlements.assert_can_upload_cover!
|
||||||
|
validate_cover_file!(file)
|
||||||
|
record.cover_slate.purge if record.cover_slate.attached?
|
||||||
|
record.cover_image.attach(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_cover_file!(file)
|
||||||
|
allowed_types = Coverable::COVER_IMAGE_TYPES
|
||||||
|
|
||||||
|
# Rileva MIME dal contenuto (magic bytes) ignorando il declared_type del client.
|
||||||
|
io = file.respond_to?(:tempfile) ? file.tempfile : file
|
||||||
|
io.rewind if io.respond_to?(:rewind)
|
||||||
|
detected = Marcel::MimeType.for(io, name: file.respond_to?(:original_filename) ? file.original_filename : nil)
|
||||||
|
io.rewind if io.respond_to?(:rewind)
|
||||||
|
|
||||||
|
unless detected.in?(allowed_types)
|
||||||
|
raise CoverUploadError, I18n.t("coverable.errors.invalid_type")
|
||||||
|
end
|
||||||
|
|
||||||
|
byte_size = file.respond_to?(:size) ? file.size : File.size(file.path)
|
||||||
|
if byte_size > Coverable::MAX_COVER_BYTES
|
||||||
|
raise CoverUploadError, I18n.t("coverable.errors.too_large")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class CoverUploadError < StandardError; end
|
||||||
|
|
||||||
|
def enqueue_cover_slate_generation(record)
|
||||||
|
GenerateCoverSlateJob.enqueue_for(record) if record.cover_image.attached?
|
||||||
|
end
|
||||||
|
|
||||||
def normalize_hex_color(value, fallback)
|
def normalize_hex_color(value, fallback)
|
||||||
v = value.to_s.strip
|
v = value.to_s.strip
|
||||||
v = "##{v}" if v.match?(/\A[0-9A-Fa-f]{6}\z/)
|
v = "##{v}" if v.match?(/\A[0-9A-Fa-f]{6}\z/)
|
||||||
|
|||||||
@@ -4,11 +4,20 @@ module MediamtxPlayback
|
|||||||
private
|
private
|
||||||
|
|
||||||
def mediamtx_paths_index
|
def mediamtx_paths_index
|
||||||
@mediamtx_paths_index ||= Mediamtx::Client.new.list_paths.index_by { |i| i["name"] }
|
mediamtx_paths_index_for_url(MatchLiveTv.mediamtx_api_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
def mediamtx_paths_index_for(session)
|
||||||
|
mediamtx_paths_index_for_url(session.mediamtx_api_base_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
def mediamtx_paths_index_for_url(api_url)
|
||||||
|
@mediamtx_paths_by_origin ||= {}
|
||||||
|
@mediamtx_paths_by_origin[api_url] ||= Mediamtx::Client.new(base_url: api_url).list_paths.index_by { |i| i["name"] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def mediamtx_path_info(session, path_name: mediamtx_playback_path_name(session))
|
def mediamtx_path_info(session, path_name: mediamtx_playback_path_name(session))
|
||||||
mediamtx_paths_index[path_name]
|
mediamtx_paths_index_for(session)[path_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
def mediamtx_playback_path_name(session)
|
def mediamtx_playback_path_name(session)
|
||||||
@@ -28,7 +37,7 @@ module MediamtxPlayback
|
|||||||
end
|
end
|
||||||
|
|
||||||
def mediamtx_publisher_online?(session)
|
def mediamtx_publisher_online?(session)
|
||||||
info = mediamtx_paths_index[session.mediamtx_path_name]
|
info = mediamtx_paths_index_for(session)[session.mediamtx_path_name]
|
||||||
info && info["online"]
|
info && info["online"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
module Recordings
|
||||||
|
module ClubArchiveActions
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
include RecordingsArchiveHelper
|
||||||
|
|
||||||
|
included do
|
||||||
|
before_action :set_club
|
||||||
|
before_action :set_recording, only: %i[update destroy publish_youtube]
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
load_archive
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if admin_expiry_update_requested?
|
||||||
|
apply_admin_expiry_update!
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
permitted = recording_update_params
|
||||||
|
attrs = {}
|
||||||
|
privacy = permitted[:privacy_status]
|
||||||
|
attrs[:privacy_status] = privacy if privacy.in?(Recording::PRIVACY_STATUSES)
|
||||||
|
title = permitted[:title]
|
||||||
|
attrs[:title] = title if title.present?
|
||||||
|
privacy_changed = attrs.key?(:privacy_status) && attrs[:privacy_status] != @recording.privacy_status
|
||||||
|
@recording.update!(attrs)
|
||||||
|
Recordings::SyncYoutubePrivacyJob.perform_async(@recording.id) if privacy_changed && @recording.youtube_video_id.present?
|
||||||
|
redirect_to archive_index_path, notice: "Replay aggiornato"
|
||||||
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
|
redirect_to archive_index_path, alert: e.record.errors.full_messages.join(", ")
|
||||||
|
rescue Recordings::ExtendExpiry::Error => e
|
||||||
|
redirect_to archive_index_path, alert: e.message
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
scope = delete_scope_param
|
||||||
|
Recordings::Delete.new(@recording, scope: scope).call
|
||||||
|
redirect_to archive_index_path, notice: delete_notice_for(scope)
|
||||||
|
end
|
||||||
|
|
||||||
|
def publish_youtube
|
||||||
|
ent = @recording.team.entitlements
|
||||||
|
unless ent.premium_full? && ent.youtube_enabled?
|
||||||
|
redirect_to archive_index_path, alert: "Republicazione YouTube con Premium Full"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
Recordings::PublishToYoutubeJob.perform_async(@recording.id)
|
||||||
|
redirect_to archive_index_path, notice: "Pubblicazione su YouTube avviata"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_archive
|
||||||
|
archive = Recordings::ClubArchive.new(@club, params: params)
|
||||||
|
@stats = archive.stats
|
||||||
|
@recordings = archive.recordings
|
||||||
|
@teams = archive.teams
|
||||||
|
@filter_team_id = archive.filter_team_id
|
||||||
|
@filter_status = archive.filter_status
|
||||||
|
@archive_paths = recordings_archive_paths(@club, namespace: archive_namespace)
|
||||||
|
@archive_filter_params = archive.filter_params
|
||||||
|
end
|
||||||
|
|
||||||
|
def archive_index_path
|
||||||
|
archive_paths.index + archive_query_string
|
||||||
|
end
|
||||||
|
|
||||||
|
def archive_query_string
|
||||||
|
q = @archive_filter_params.presence
|
||||||
|
return "" if q.blank?
|
||||||
|
|
||||||
|
"?#{q.to_query}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def archive_paths
|
||||||
|
@archive_paths ||= recordings_archive_paths(@club, namespace: archive_namespace)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_club
|
||||||
|
@club = Club.find(params[:club_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_recording
|
||||||
|
@recording = Recording.for_club(@club).not_deleted.find(params[:id])
|
||||||
|
authorize_recording_management!
|
||||||
|
end
|
||||||
|
|
||||||
|
def authorize_recording_management!
|
||||||
|
# overridden in Public::ClubRecordingsController
|
||||||
|
end
|
||||||
|
|
||||||
|
def archive_namespace
|
||||||
|
raise NotImplementedError
|
||||||
|
end
|
||||||
|
|
||||||
|
def recording_update_params
|
||||||
|
params.require(:recording).permit(:privacy_status, :title, :expires_at, :extend_days)
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_scope_param
|
||||||
|
value = params[:delete_scope].to_s
|
||||||
|
Recordings::Delete::SCOPES.include?(value) ? value : "both"
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_notice_for(scope)
|
||||||
|
case scope
|
||||||
|
when "site"
|
||||||
|
"Replay eliminato dal sito (YouTube invariato)"
|
||||||
|
when "youtube"
|
||||||
|
"Video rimosso da YouTube (resta disponibile sul sito)"
|
||||||
|
else
|
||||||
|
"Replay eliminato dal sito e da YouTube"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_expiry_update_requested?
|
||||||
|
return false unless archive_namespace == :admin
|
||||||
|
|
||||||
|
permitted = recording_update_params
|
||||||
|
permitted[:extend_days].present? || permitted[:expires_at].present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply_admin_expiry_update!
|
||||||
|
permitted = recording_update_params
|
||||||
|
extender = Recordings::ExtendExpiry.new(@recording)
|
||||||
|
|
||||||
|
if permitted[:extend_days].present?
|
||||||
|
extender.by_days(permitted[:extend_days])
|
||||||
|
redirect_to archive_index_path, notice: "Scadenza replay prolungata di #{permitted[:extend_days].to_i} giorni"
|
||||||
|
else
|
||||||
|
expires_at = Time.zone.parse(permitted[:expires_at].to_s)&.end_of_day
|
||||||
|
extender.to_time(expires_at)
|
||||||
|
redirect_to archive_index_path, notice: "Scadenza replay aggiornata"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,38 +1,110 @@
|
|||||||
class HlsProxyController < ActionController::Base
|
class HlsProxyController < ActionController::Base
|
||||||
# Proxy pubblico verso MediaMTX HLS (NPM inoltra tutto a Rails :3000).
|
# Proxy pubblico verso MediaMTX HLS.
|
||||||
|
# Dev: tutto passa da Rails (/hls/*).
|
||||||
|
# Prod: edge inoltra /hls/ a MediaMTX; il redirect cookie di MediaMTX punta a
|
||||||
|
# /live/match_{uuid}/… che deve essere gestito da #live_match (fallback).
|
||||||
def show
|
def show
|
||||||
upstream_path = params[:path].to_s
|
proxy_mediamtx_path(params[:path].to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
def live_match
|
||||||
|
session_id = params[:session_id].to_s
|
||||||
|
return head :not_found unless session_id.match?(/\A[0-9a-f-]{36}\z/i)
|
||||||
|
|
||||||
|
segments = params[:segments].presence || "index.m3u8"
|
||||||
|
proxy_mediamtx_path("live/match_#{session_id}/#{segments}")
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def proxy_mediamtx_path(upstream_path)
|
||||||
return head :not_found if upstream_path.blank?
|
return head :not_found if upstream_path.blank?
|
||||||
|
|
||||||
upstream = "#{MatchLiveTv.mediamtx_hls_url}/#{upstream_path}"
|
origin = hls_origin_for(upstream_path)
|
||||||
|
upstream = "#{origin}/#{upstream_path}"
|
||||||
upstream = "#{upstream}?#{request.query_string}" if request.query_string.present?
|
upstream = "#{upstream}?#{request.query_string}" if request.query_string.present?
|
||||||
cookie = request.headers["Cookie"].presence || "cookieCheck=1"
|
cookie = request.headers["Cookie"].presence || "cookieCheck=1"
|
||||||
response = hls_conn.get(upstream) { |req| req.headers["Cookie"] = cookie }
|
|
||||||
|
|
||||||
if response.status == 302
|
5.times do
|
||||||
location = response.headers["location"].to_s
|
response = hls_conn.get(upstream) { |req| req.headers["Cookie"] = cookie }
|
||||||
follow_url = if location.start_with?("http")
|
|
||||||
location
|
if response.status.in?([301, 302, 307, 308])
|
||||||
else
|
location = response.headers["location"].to_s
|
||||||
"#{MatchLiveTv.mediamtx_hls_url.sub(%r{/$}, "")}#{location}"
|
cookie = cookie_from_set_header(response.headers["set-cookie"]).presence || cookie
|
||||||
end
|
upstream = resolve_upstream_url(location, origin)
|
||||||
set_cookie = response.headers["set-cookie"].to_s
|
next
|
||||||
cookie = set_cookie.presence || cookie
|
end
|
||||||
response = hls_conn.get(follow_url) { |req| req.headers["Cookie"] = cookie }
|
|
||||||
|
return render_proxied_response(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
response.headers.each do |key, value|
|
head :bad_gateway
|
||||||
next if %w[transfer-encoding connection].include?(key.downcase)
|
|
||||||
|
|
||||||
headers[key] = value
|
|
||||||
end
|
|
||||||
render body: response.body, status: response.status
|
|
||||||
rescue Faraday::Error => e
|
rescue Faraday::Error => e
|
||||||
Rails.logger.warn("[HlsProxy] #{upstream_path}: #{e.message}")
|
Rails.logger.warn("[HlsProxy] #{upstream_path}: #{e.message}")
|
||||||
head :bad_gateway
|
head :bad_gateway
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def hls_origin_for(upstream_path)
|
||||||
|
session_id = upstream_path[/\Alive\/match_([0-9a-f-]{36})/i, 1]
|
||||||
|
if session_id
|
||||||
|
session = StreamSession.find_by(id: session_id)
|
||||||
|
node_hls = session&.stream_node&.internal_hls_url.presence
|
||||||
|
return node_hls.sub(%r{/$}, "") if node_hls.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
MatchLiveTv.mediamtx_hls_url.sub(%r{/$}, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
def resolve_upstream_url(location, origin)
|
||||||
|
return location if location.start_with?("http://", "https://")
|
||||||
|
|
||||||
|
base = origin.to_s.sub(%r{/$}, "")
|
||||||
|
location.start_with?("/") ? "#{base}#{location}" : "#{base}/#{location}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_proxied_response(response)
|
||||||
|
body = response.body.to_s
|
||||||
|
content_type = response.headers["content-type"].to_s
|
||||||
|
|
||||||
|
if m3u8_playlist?(content_type, body)
|
||||||
|
public_hls_base = "#{request.base_url}/hls"
|
||||||
|
body = body.gsub(%r{(?<=["'(\s])/live/(match_[0-9a-f-]{36}/)}, "/hls/live/\\1")
|
||||||
|
body = body.gsub(%r{\A/live/(match_[0-9a-f-]{36}/)}, "/hls/live/\\1")
|
||||||
|
end
|
||||||
|
|
||||||
|
response.headers.each do |key, value|
|
||||||
|
next if %w[transfer-encoding connection content-length content-encoding].include?(key.downcase)
|
||||||
|
|
||||||
|
if key.downcase == "location"
|
||||||
|
headers[key] = rewrite_public_location(value)
|
||||||
|
else
|
||||||
|
headers[key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
render body: body, status: response.status, content_type: content_type.presence
|
||||||
|
end
|
||||||
|
|
||||||
|
def rewrite_public_location(location)
|
||||||
|
loc = location.to_s
|
||||||
|
if loc.start_with?("/live/match_")
|
||||||
|
return loc.sub(%r{\A/live/}, "/hls/")
|
||||||
|
end
|
||||||
|
if loc.include?("/live/match_")
|
||||||
|
return loc.gsub(%r{/(live/match_[0-9a-f-]{36}/)}, "/hls/live/\\1")
|
||||||
|
end
|
||||||
|
loc
|
||||||
|
end
|
||||||
|
|
||||||
|
def m3u8_playlist?(content_type, body)
|
||||||
|
return true if content_type.include?("mpegurl") || content_type.include?("m3u8")
|
||||||
|
|
||||||
|
body.lstrip.start_with?("#EXTM3U")
|
||||||
|
end
|
||||||
|
|
||||||
|
def cookie_from_set_header(set_cookie_header)
|
||||||
|
set_cookie_header.to_s[/cookieCheck=[^;]+/]
|
||||||
|
end
|
||||||
|
|
||||||
def hls_conn
|
def hls_conn
|
||||||
@hls_conn ||= Faraday.new do |f|
|
@hls_conn ||= Faraday.new do |f|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
module Ops
|
||||||
|
class HealthController < ActionController::API
|
||||||
|
before_action :authorize_deep_health!
|
||||||
|
|
||||||
|
def show
|
||||||
|
summary = Ops::HealthChecks.new.summary
|
||||||
|
status_code = case summary[:status]
|
||||||
|
when "ok" then :ok
|
||||||
|
when "degraded" then :service_unavailable
|
||||||
|
else :service_unavailable
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: summary, status: status_code
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def authorize_deep_health!
|
||||||
|
token = ENV["OPS_HEALTH_TOKEN"].presence
|
||||||
|
return if token.blank?
|
||||||
|
|
||||||
|
provided = request.headers["X-Ops-Token"].presence || params[:token].presence
|
||||||
|
return head :unauthorized if provided.blank?
|
||||||
|
|
||||||
|
head :unauthorized unless ActiveSupport::SecurityUtils.secure_compare(provided, token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
module Public
|
||||||
|
class AccountsController < WebBaseController
|
||||||
|
before_action :require_login!
|
||||||
|
|
||||||
|
def show
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
name = params[:name].to_s.strip
|
||||||
|
if name.blank?
|
||||||
|
flash.now[:alert] = t("flash.accounts.name_required")
|
||||||
|
return render :show, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
if current_user.update(name: name)
|
||||||
|
redirect_to public_account_path, notice: t("flash.accounts.profile_updated")
|
||||||
|
else
|
||||||
|
flash.now[:alert] = current_user.errors.full_messages.to_sentence
|
||||||
|
render :show, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_password
|
||||||
|
result = Users::ChangePassword.call(
|
||||||
|
user: current_user,
|
||||||
|
current_password: params[:current_password],
|
||||||
|
password: params[:password],
|
||||||
|
password_confirmation: params[:password_confirmation]
|
||||||
|
)
|
||||||
|
|
||||||
|
unless result.ok?
|
||||||
|
redirect_to public_account_path, alert: t("flash.accounts.password_#{result.error}")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to public_account_path, notice: t("flash.accounts.password_updated")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,13 +11,17 @@ module Public
|
|||||||
@club.assign_attributes(billing_profile_params)
|
@club.assign_attributes(billing_profile_params)
|
||||||
if @club.save(context: :billing_profile)
|
if @club.save(context: :billing_profile)
|
||||||
if premium_checkout_return_params.present? && @club.billing_profile_complete?
|
if premium_checkout_return_params.present? && @club.billing_profile_complete?
|
||||||
redirect_to public_club_checkout_path(
|
if @club.active_billing_quote.present?
|
||||||
@club,
|
redirect_to public_club_billing_path(@club), notice: t("flash.club_billing.profile_updated")
|
||||||
plan: premium_checkout_return_params[:plan],
|
else
|
||||||
interval: premium_checkout_return_params[:interval]
|
redirect_to public_club_checkout_path(
|
||||||
), notice: "Dati salvati. Procedi con il pagamento."
|
@club,
|
||||||
|
plan: premium_checkout_return_params[:plan],
|
||||||
|
interval: premium_checkout_return_params[:interval]
|
||||||
|
), notice: t("flash.club_billing.profile_saved_proceed_payment")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
redirect_to public_club_billing_path(@club), notice: "Dati di fatturazione aggiornati."
|
redirect_to public_club_billing_path(@club), notice: t("flash.club_billing.profile_updated")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
flash.now[:alert] = @club.errors.full_messages.join(", ")
|
flash.now[:alert] = @club.errors.full_messages.join(", ")
|
||||||
@@ -27,25 +31,48 @@ module Public
|
|||||||
|
|
||||||
def cancel_subscription
|
def cancel_subscription
|
||||||
unless MatchLiveTv.stripe_enabled?
|
unless MatchLiveTv.stripe_enabled?
|
||||||
redirect_to public_club_billing_path(@club), alert: "Stripe non configurato."
|
redirect_to public_club_billing_path(@club), alert: t("flash.club_billing.stripe_not_configured")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
Billing::Stripe::CancelSubscription.call(club: @club)
|
Billing::Stripe::CancelSubscription.call(club: @club)
|
||||||
sub = @club.subscription.reload
|
sub = @club.subscription.reload
|
||||||
date = sub.current_period_end ? helpers.l_local(sub.current_period_end.to_date) : "fine periodo"
|
date = sub.current_period_end ? helpers.l_local(sub.current_period_end.to_date) : t("billing.subscription_status.end_of_period")
|
||||||
redirect_to public_club_billing_path(@club),
|
redirect_to public_club_billing_path(@club),
|
||||||
notice: "Abbonamento disdetto. Resta attivo fino al #{date}; da quel giorno passerai al piano Free."
|
notice: t("flash.club_billing.subscription_canceled", date: date)
|
||||||
rescue ArgumentError, RuntimeError => e
|
rescue ArgumentError, RuntimeError => e
|
||||||
redirect_to public_club_billing_path(@club), alert: e.message
|
redirect_to public_club_billing_path(@club), alert: e.message
|
||||||
rescue ::Stripe::StripeError => e
|
rescue ::Stripe::StripeError => e
|
||||||
redirect_to public_club_billing_path(@club), alert: "Errore Stripe: #{e.message}"
|
redirect_to public_club_billing_path(@club), alert: t("flash.club_billing.stripe_error", message: e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def request_bank_transfer
|
||||||
|
if @club.subscription&.admin_comped?
|
||||||
|
redirect_to public_club_billing_path(@club), alert: t("flash.clubs.comped_change_denied")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
unless @club.billing_profile_complete?
|
||||||
|
redirect_to public_club_billing_profile_path(@club, plan: params[:plan], interval: params[:interval]),
|
||||||
|
alert: t("flash.clubs.complete_billing_first")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
Billing::RequestBankTransfer.call(
|
||||||
|
club: @club,
|
||||||
|
user: current_user,
|
||||||
|
plan_slug: params[:plan],
|
||||||
|
interval: params[:interval]
|
||||||
|
)
|
||||||
|
redirect_to public_club_billing_path(@club), notice: t("flash.club_billing.bank_transfer_requested")
|
||||||
|
rescue Billing::RequestBankTransfer::Error, ArgumentError => e
|
||||||
|
redirect_to public_club_billing_path(@club), alert: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_invoice
|
def download_invoice
|
||||||
invoice = @club.billing_invoices.find(params[:invoice_id])
|
invoice = @club.billing_invoices.find(params[:invoice_id])
|
||||||
unless invoice.pdf.attached?
|
unless invoice.pdf.attached?
|
||||||
redirect_to public_club_billing_path(@club), alert: "PDF fattura non disponibile."
|
redirect_to public_club_billing_path(@club), alert: t("flash.club_billing.invoice_pdf_unavailable")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ module Public
|
|||||||
@selected_team = @schedulable_teams.find { |t| t.id.to_s == params[:team_id].to_s }
|
@selected_team = @schedulable_teams.find { |t| t.id.to_s == params[:team_id].to_s }
|
||||||
unless @selected_team
|
unless @selected_team
|
||||||
@match = default_match_for_form
|
@match = default_match_for_form
|
||||||
flash.now[:alert] = "Seleziona una squadra valida."
|
flash.now[:alert] = t("flash.club_matches.invalid_team")
|
||||||
return render :new, status: :unprocessable_entity
|
return render :new, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ module Public
|
|||||||
match_params.merge(sport: @selected_team.sport, sets_to_win: 3)
|
match_params.merge(sport: @selected_team.sport, sets_to_win: 3)
|
||||||
)
|
)
|
||||||
redirect_to public_live_index_path(club_id: @club.id),
|
redirect_to public_live_index_path(club_id: @club.id),
|
||||||
notice: "Partita programmata: #{@selected_team.name} vs #{@match.opponent_name}."
|
notice: t("flash.club_matches.scheduled", team: @selected_team.name, opponent: @match.opponent_name)
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
@match = @selected_team.matches.build(match_params)
|
@match = @selected_team.matches.build(match_params)
|
||||||
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
||||||
@@ -44,7 +44,7 @@ module Public
|
|||||||
return if @schedulable_teams.any?
|
return if @schedulable_teams.any?
|
||||||
|
|
||||||
redirect_to public_live_index_path(club_id: @club.id),
|
redirect_to public_live_index_path(club_id: @club.id),
|
||||||
alert: "Non hai permessi per programmare partite in questa società."
|
alert: t("flash.club_matches.no_schedulable_teams")
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_selected_team
|
def resolve_selected_team
|
||||||
|
|||||||
@@ -1,55 +1,28 @@
|
|||||||
module Public
|
module Public
|
||||||
class ClubRecordingsController < WebBaseController
|
class ClubRecordingsController < WebBaseController
|
||||||
|
include Recordings::ClubArchiveActions
|
||||||
|
helper RecordingsArchiveHelper
|
||||||
|
|
||||||
before_action :require_login!
|
before_action :require_login!
|
||||||
before_action :set_club
|
before_action :require_club_recording_manager!
|
||||||
before_action -> { require_club_owner!(@club) }
|
|
||||||
before_action :set_recording, only: %i[update destroy publish_youtube]
|
|
||||||
|
|
||||||
def index
|
|
||||||
@stats = Recordings::ClubStats.new(@club).call
|
|
||||||
@recordings = Recording.for_club(@club)
|
|
||||||
.not_deleted
|
|
||||||
.includes(stream_session: { match: :team })
|
|
||||||
.order(recorded_at: :desc, created_at: :desc)
|
|
||||||
@teams = @club.teams.order(:name)
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
privacy = params.require(:recording).permit(:privacy_status, :title)[:privacy_status]
|
|
||||||
attrs = {}
|
|
||||||
attrs[:privacy_status] = privacy if privacy.in?(Recording::PRIVACY_STATUSES)
|
|
||||||
title = params.dig(:recording, :title)
|
|
||||||
attrs[:title] = title if title.present?
|
|
||||||
@recording.update!(attrs)
|
|
||||||
redirect_to public_club_recordings_path(@club), notice: "Replay aggiornato"
|
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
|
||||||
redirect_to public_club_recordings_path(@club), alert: e.record.errors.full_messages.join(", ")
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
|
||||||
Recordings::Delete.new(@recording).call
|
|
||||||
redirect_to public_club_recordings_path(@club), notice: "Replay eliminato"
|
|
||||||
end
|
|
||||||
|
|
||||||
def publish_youtube
|
|
||||||
ent = @recording.team.entitlements
|
|
||||||
unless ent.premium_full? && ent.youtube_enabled?
|
|
||||||
redirect_to public_club_recordings_path(@club), alert: "Republicazione YouTube con Premium Full"
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
Recordings::PublishToYoutubeJob.perform_async(@recording.id)
|
|
||||||
redirect_to public_club_recordings_path(@club), notice: "Pubblicazione su YouTube avviata"
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_club
|
def archive_namespace
|
||||||
@club = current_user.owned_clubs.find(params[:club_id])
|
:public
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_recording
|
def authorize_recording_management!
|
||||||
@recording = Recording.for_club(@club).not_deleted.find(params[:id])
|
return if Recordings::AccessPolicy.new(@recording, viewer: current_user).manage_allowed?
|
||||||
|
|
||||||
|
raise ActiveRecord::RecordNotFound
|
||||||
|
end
|
||||||
|
|
||||||
|
def require_club_recording_manager!
|
||||||
|
return if current_user.owned_clubs.exists?(id: @club.id)
|
||||||
|
return if current_user.manageable_teams.joins(:club).exists?(clubs: { id: @club.id })
|
||||||
|
|
||||||
|
redirect_to public_clubs_path, alert: t("flash.club_recordings.not_authorized")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ module Public
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
if current_user.owned_clubs.exists?
|
if current_user.owned_clubs.exists?
|
||||||
redirect_to public_club_path(current_user.primary_club), alert: "Hai già registrato una società"
|
redirect_to public_club_path(current_user.primary_club), alert: t("flash.clubs.already_registered")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -22,26 +22,31 @@ module Public
|
|||||||
|
|
||||||
ClubMembership.create!(user: current_user, club: club, role: "owner")
|
ClubMembership.create!(user: current_user, club: club, role: "owner")
|
||||||
|
|
||||||
first_team_name = params.dig(:first_team, :name).presence || "Prima squadra"
|
first_team_name = params.dig(:first_team, :name).presence || t("club.new.default_first_team_name")
|
||||||
club.teams.create!(
|
first_team = club.teams.create!(
|
||||||
name: first_team_name,
|
name: first_team_name,
|
||||||
sport: club.sport
|
sport: club.sport
|
||||||
)
|
)
|
||||||
|
|
||||||
plan = params[:plan].presence_in(%w[free premium_light premium_full]) || "free"
|
desired_plan = params[:plan].presence_in(%w[free premium_light premium_full]) || "free"
|
||||||
Billing::AssignPlan.call(club: club, plan_slug: plan)
|
Billing::AssignPlan.call(club: club, plan_slug: "free")
|
||||||
|
Teams::StaffAssignment.designate_club_owner!(team: first_team, user: current_user)
|
||||||
|
|
||||||
if plan.in?(%w[premium_light premium_full]) && MatchLiveTv.stripe_enabled?
|
if desired_plan.in?(%w[premium_light premium_full])
|
||||||
unless club.billing_profile_complete?
|
interval = Billing::Stripe::PriceCatalog::DEFAULT_INTERVAL
|
||||||
redirect_to public_club_billing_profile_path(club, plan: plan, interval: checkout_interval_param),
|
if MatchLiveTv.stripe_enabled?
|
||||||
alert: "Completa i dati di fatturazione prima di attivare un piano premium."
|
unless club.billing_profile_complete?
|
||||||
return
|
redirect_to public_club_billing_profile_path(club, plan: desired_plan, interval: interval),
|
||||||
|
alert: t("flash.clubs.complete_billing_first")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to public_club_checkout_path(club, plan: desired_plan, interval: interval)
|
||||||
|
else
|
||||||
|
redirect_to public_club_billing_path(club), notice: t("flash.clubs.created_complete_subscription")
|
||||||
end
|
end
|
||||||
|
|
||||||
interval = checkout_interval_param
|
|
||||||
redirect_to public_club_checkout_path(club, plan: plan, interval: interval)
|
|
||||||
else
|
else
|
||||||
redirect_to public_club_path(club), notice: "Società e prima squadra create."
|
redirect_to public_club_path(club), notice: t("flash.clubs.created")
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
||||||
@@ -59,17 +64,26 @@ module Public
|
|||||||
|
|
||||||
def edit
|
def edit
|
||||||
require_club_owner!(@club)
|
require_club_owner!(@club)
|
||||||
|
@entitlements = @club.teams.first&.entitlements
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
require_club_owner!(@club)
|
require_club_owner!(@club)
|
||||||
|
@entitlements = @club.teams.first!.entitlements
|
||||||
@club.assign_attributes(club_params)
|
@club.assign_attributes(club_params)
|
||||||
attach_branding_logo(@club)
|
attach_branding_logo(@club)
|
||||||
|
attach_cover_image(@club, entitlements: @entitlements)
|
||||||
@club.save!
|
@club.save!
|
||||||
redirect_to public_club_path(@club), notice: "Società aggiornata."
|
enqueue_cover_slate_generation(@club)
|
||||||
|
redirect_to public_club_path(@club), notice: t("flash.clubs.updated")
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
|
@entitlements = @club.teams.first&.entitlements
|
||||||
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
||||||
render :edit, status: :unprocessable_entity
|
render :edit, status: :unprocessable_entity
|
||||||
|
rescue Teams::EntitlementError, BrandingAttachments::CoverUploadError => e
|
||||||
|
@entitlements = @club.teams.first&.entitlements
|
||||||
|
flash.now[:alert] = e.message
|
||||||
|
render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
def billing
|
def billing
|
||||||
@@ -82,18 +96,26 @@ module Public
|
|||||||
@entitlements = @team.entitlements
|
@entitlements = @team.entitlements
|
||||||
@plans = Plan.ordered
|
@plans = Plan.ordered
|
||||||
@payments = @club.billing_payments.recent.includes(:invoice).limit(50)
|
@payments = @club.billing_payments.recent.includes(:invoice).limit(50)
|
||||||
|
@quote = @club.active_billing_quote
|
||||||
|
@pending_transfer = @club.billing_transfer_orders.awaiting_payment.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def checkout
|
def checkout
|
||||||
require_club_owner!(@club)
|
require_club_owner!(@club)
|
||||||
if @club.subscription&.admin_comped?
|
if @club.subscription&.admin_comped?
|
||||||
redirect_to public_club_billing_path(@club),
|
redirect_to public_club_billing_path(@club),
|
||||||
alert: "Il piano è un abbonamento omaggio gestito da Match Live TV. Per passare a un abbonamento a pagamento contatta il supporto."
|
alert: t("flash.clubs.comped_change_denied")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if @club.active_billing_quote.present?
|
||||||
|
redirect_to public_club_billing_path(@club),
|
||||||
|
alert: t("flash.club_billing.quote_checkout_denied")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
unless MatchLiveTv.stripe_enabled?
|
unless MatchLiveTv.stripe_enabled?
|
||||||
redirect_to public_club_billing_path(@club), alert: "Pagamenti non ancora configurati sul server"
|
redirect_to public_club_billing_path(@club), alert: t("flash.clubs.stripe_not_configured")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -105,15 +127,15 @@ module Public
|
|||||||
if sub&.stripe_subscription_id.present? && sub.active? &&
|
if sub&.stripe_subscription_id.present? && sub.active? &&
|
||||||
sub.plan.slug == plan_slug && sub.billing_interval == interval && !sub.plan_change_pending?
|
sub.plan.slug == plan_slug && sub.billing_interval == interval && !sub.plan_change_pending?
|
||||||
redirect_to public_club_billing_path(@club),
|
redirect_to public_club_billing_path(@club),
|
||||||
notice: "Sei già su #{target_plan.name} (#{Billing::Stripe::PriceCatalog.label(plan_slug: plan_slug, interval: interval)})."
|
notice: t("flash.clubs.already_on_plan", plan: target_plan.name, price: Billing::Stripe::PriceCatalog.label(plan_slug: plan_slug, interval: interval))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if sub&.plan_change_pending? && sub.pending_plan&.slug == plan_slug &&
|
if sub&.plan_change_pending? && sub.pending_plan&.slug == plan_slug &&
|
||||||
sub.pending_billing_interval == interval
|
sub.pending_billing_interval == interval
|
||||||
when_label = sub.current_period_end.present? ? I18n.l(sub.current_period_end, format: :long) : "il prossimo rinnovo"
|
when_label = sub.current_period_end.present? ? I18n.l(sub.current_period_end, format: :long) : t("billing.messages.next_renewal")
|
||||||
redirect_to public_club_billing_path(@club),
|
redirect_to public_club_billing_path(@club),
|
||||||
notice: "Il passaggio a #{target_plan.name} è già programmato dal #{when_label}."
|
notice: t("flash.clubs.change_already_scheduled", plan: target_plan.name, date: when_label)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -134,7 +156,7 @@ module Public
|
|||||||
redirect_to public_club_billing_path(@club), alert: e.message
|
redirect_to public_club_billing_path(@club), alert: e.message
|
||||||
rescue ::Stripe::StripeError => e
|
rescue ::Stripe::StripeError => e
|
||||||
Rails.logger.warn("[Stripe checkout] #{e.message}")
|
Rails.logger.warn("[Stripe checkout] #{e.message}")
|
||||||
redirect_to public_club_billing_path(@club), alert: "Errore Stripe: #{e.message}"
|
redirect_to public_club_billing_path(@club), alert: t("flash.clubs.stripe_error", message: e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def youtube_connect
|
def youtube_connect
|
||||||
@@ -143,7 +165,7 @@ module Public
|
|||||||
entitlements.assert_can_connect_youtube!
|
entitlements.assert_can_connect_youtube!
|
||||||
|
|
||||||
if ENV["YOUTUBE_CLIENT_ID"].blank?
|
if ENV["YOUTUBE_CLIENT_ID"].blank?
|
||||||
redirect_to public_club_path(@club), alert: "YouTube OAuth non configurato sul server"
|
redirect_to public_club_path(@club), alert: t("flash.clubs.youtube_oauth_not_configured")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -161,13 +183,13 @@ module Public
|
|||||||
def youtube_disconnect
|
def youtube_disconnect
|
||||||
require_club_owner!(@club)
|
require_club_owner!(@club)
|
||||||
@club.youtube_credential&.destroy!
|
@club.youtube_credential&.destroy!
|
||||||
redirect_to public_club_path(@club), notice: "Canale YouTube della società scollegato"
|
redirect_to public_club_path(@club), notice: t("flash.clubs.youtube_disconnected")
|
||||||
end
|
end
|
||||||
|
|
||||||
def portal
|
def portal
|
||||||
require_club_owner!(@club)
|
require_club_owner!(@club)
|
||||||
unless MatchLiveTv.stripe_enabled?
|
unless MatchLiveTv.stripe_enabled?
|
||||||
redirect_to public_club_billing_path(@club), alert: "Portale pagamenti non configurato"
|
redirect_to public_club_billing_path(@club), alert: t("flash.clubs.portal_not_configured")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -190,6 +212,7 @@ module Public
|
|||||||
)
|
)
|
||||||
p[:primary_color] = normalize_hex_color(p[:primary_color], "#e53935")
|
p[:primary_color] = normalize_hex_color(p[:primary_color], "#e53935")
|
||||||
p[:secondary_color] = normalize_hex_color(p[:secondary_color], "#ffffff")
|
p[:secondary_color] = normalize_hex_color(p[:secondary_color], "#ffffff")
|
||||||
|
p[:sport] = Sports::Catalog.normalize_key(p[:sport]) if p[:sport].present?
|
||||||
p
|
p
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -203,7 +226,7 @@ module Public
|
|||||||
@club,
|
@club,
|
||||||
plan: plan_slug,
|
plan: plan_slug,
|
||||||
interval: params[:interval].presence
|
interval: params[:interval].presence
|
||||||
), alert: "Completa i dati di fatturazione prima di attivare un piano premium."
|
), alert: t("flash.clubs.complete_billing_first")
|
||||||
end
|
end
|
||||||
|
|
||||||
def checkout_interval_param
|
def checkout_interval_param
|
||||||
@@ -235,10 +258,10 @@ module Public
|
|||||||
def apply_checkout_flash!
|
def apply_checkout_flash!
|
||||||
case params[:checkout]
|
case params[:checkout]
|
||||||
when "success"
|
when "success"
|
||||||
plan_name = @subscription&.plan&.name || "premium"
|
plan_name = @subscription&.plan&.name || "Premium"
|
||||||
flash.now[:notice] = "Pagamento completato! Piano attivo: #{plan_name}."
|
flash.now[:notice] = t("flash.clubs.checkout_success", plan: plan_name)
|
||||||
when "canceled"
|
when "canceled"
|
||||||
flash.now[:alert] = "Pagamento annullato. Nessun addebito è stato effettuato."
|
flash.now[:alert] = t("flash.clubs.checkout_canceled")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
module Public
|
||||||
|
class ContactsController < WebBaseController
|
||||||
|
def show
|
||||||
|
@inquiry = empty_inquiry
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
result = Contacts::SubmitInquiry.call(params: inquiry_params, ip: request.remote_ip)
|
||||||
|
|
||||||
|
if result.ok
|
||||||
|
redirect_to public_contatti_path, notice: t("flash.contacts.sent")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@inquiry = inquiry_params
|
||||||
|
flash.now[:alert] = t("flash.contacts.#{result.error}")
|
||||||
|
render :show, status: result.error == :throttled ? :too_many_requests : :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def inquiry_params
|
||||||
|
{
|
||||||
|
name: params[:name].to_s,
|
||||||
|
email: params[:email].to_s,
|
||||||
|
club_name: params[:club_name].to_s,
|
||||||
|
topic: params[:topic].to_s,
|
||||||
|
message: params[:message].to_s,
|
||||||
|
website: params[:website].to_s,
|
||||||
|
accept_privacy: params[:accept_privacy].to_s
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def empty_inquiry
|
||||||
|
{
|
||||||
|
name: "",
|
||||||
|
email: "",
|
||||||
|
club_name: "",
|
||||||
|
topic: "commercial",
|
||||||
|
message: "",
|
||||||
|
website: "",
|
||||||
|
accept_privacy: ""
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4,24 +4,24 @@ module Public
|
|||||||
@token = params[:token]
|
@token = params[:token]
|
||||||
@invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(@token.to_s))
|
@invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(@token.to_s))
|
||||||
unless @invitation
|
unless @invitation
|
||||||
redirect_to public_pricing_path, alert: "Invito non valido o scaduto"
|
redirect_to public_pricing_path, alert: t("flash.invitations.invalid_or_expired")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept
|
def accept
|
||||||
invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(params[:token].to_s))
|
invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(params[:token].to_s))
|
||||||
return redirect_to public_pricing_path, alert: "Invito non valido" unless invitation
|
return redirect_to public_pricing_path, alert: t("flash.invitations.invalid") unless invitation
|
||||||
|
|
||||||
if logged_in?
|
if logged_in?
|
||||||
if current_user.email.downcase != invitation.email.downcase
|
if current_user.email.downcase != invitation.email.downcase
|
||||||
redirect_to public_pricing_path, alert: "Questo invito è per #{invitation.email}"
|
redirect_to public_pricing_path, alert: t("flash.invitations.wrong_email", email: invitation.email)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
invitation.accept!(current_user)
|
invitation.accept!(current_user)
|
||||||
redirect_to public_team_details_path(invitation.team), notice: "Sei entrato nella squadra!"
|
redirect_to public_team_details_path(invitation.team), notice: t("flash.invitations.joined_team")
|
||||||
else
|
else
|
||||||
session[:pending_invite_token] = params[:token]
|
session[:pending_invite_token] = params[:token]
|
||||||
redirect_to public_signup_path, notice: "Registrati con #{invitation.email} per accettare l'invito"
|
redirect_to public_signup_path, notice: t("flash.invitations.signup_to_accept", email: invitation.email)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ module Public
|
|||||||
@session.status.in?(%w[connecting live reconnecting paused])
|
@session.status.in?(%w[connecting live reconnecting paused])
|
||||||
)
|
)
|
||||||
@publisher_online = !@stream_closed && mediamtx_publisher_online?(@session)
|
@publisher_online = !@stream_closed && mediamtx_publisher_online?(@session)
|
||||||
|
@cover_poster_url = Streams::CoverResolver.new(@match).effective_cover_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
module Public
|
||||||
|
class LocalesController < SiteBaseController
|
||||||
|
def update
|
||||||
|
locale = LocaleResolver.persist!(cookies, params[:locale])
|
||||||
|
I18n.locale = locale
|
||||||
|
redirect_back fallback_location: root_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -25,7 +25,7 @@ module Public
|
|||||||
match_params.merge(sport: @team.sport, sets_to_win: match_params[:sets_to_win].presence || 3)
|
match_params.merge(sport: @team.sport, sets_to_win: match_params[:sets_to_win].presence || 3)
|
||||||
)
|
)
|
||||||
redirect_to public_team_matches_path(@team),
|
redirect_to public_team_matches_path(@team),
|
||||||
notice: "Partita programmata: #{@match.opponent_name}. Avvia lo streaming dall’app quando sei in palestra."
|
notice: t("flash.matches.scheduled", opponent: @match.opponent_name)
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
@match = @team.matches.build(match_params)
|
@match = @team.matches.build(match_params)
|
||||||
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
||||||
@@ -37,7 +37,7 @@ module Public
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
@match.update!(match_params)
|
@match.update!(match_params)
|
||||||
redirect_to public_team_matches_path(@team), notice: "Partita aggiornata."
|
redirect_to public_team_matches_path(@team), notice: t("flash.matches.updated")
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
||||||
render :edit, status: :unprocessable_entity
|
render :edit, status: :unprocessable_entity
|
||||||
@@ -47,12 +47,12 @@ module Public
|
|||||||
active = active_session_for(@match)
|
active = active_session_for(@match)
|
||||||
if active&.resumable?
|
if active&.resumable?
|
||||||
redirect_to public_team_matches_path(@team),
|
redirect_to public_team_matches_path(@team),
|
||||||
alert: "Chiudi la diretta prima di eliminare questa partita."
|
alert: t("flash.matches.close_live_before_delete")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@match.destroy!
|
@match.destroy!
|
||||||
redirect_to public_team_matches_path(@team), notice: "Partita eliminata."
|
redirect_to public_team_matches_path(@team), notice: t("flash.matches.deleted")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -66,7 +66,7 @@ module Public
|
|||||||
return if current_user.can_schedule_for?(@team)
|
return if current_user.can_schedule_for?(@team)
|
||||||
|
|
||||||
redirect_to public_team_details_path(@team),
|
redirect_to public_team_details_path(@team),
|
||||||
alert: "Solo un responsabile trasmissione o il titolare della società possono programmare le partite."
|
alert: t("flash.matches.schedule_denied")
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_match
|
def set_match
|
||||||
@@ -94,9 +94,7 @@ module Public
|
|||||||
end
|
end
|
||||||
|
|
||||||
def active_session_for(match)
|
def active_session_for(match)
|
||||||
match.stream_sessions
|
match.active_stream_session
|
||||||
.order(created_at: :desc)
|
|
||||||
.find { |s| !%w[ended error].include?(s.status) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,17 +11,8 @@ module Public
|
|||||||
load_club_billing_context_for_pricing
|
load_club_billing_context_for_pricing
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def support
|
||||||
|
@app_store_review_chrome = true
|
||||||
def load_club_billing_context_for_pricing
|
|
||||||
return unless logged_in?
|
|
||||||
|
|
||||||
@club = current_user.primary_club
|
|
||||||
return unless @club
|
|
||||||
|
|
||||||
@subscription = @club.subscription
|
|
||||||
@team = @club.teams.order(:name).first
|
|
||||||
@entitlements = @team&.entitlements
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def privacy
|
def privacy
|
||||||
@@ -38,5 +29,18 @@ module Public
|
|||||||
|
|
||||||
def pallavolo
|
def pallavolo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_club_billing_context_for_pricing
|
||||||
|
return unless logged_in?
|
||||||
|
|
||||||
|
@club = current_user.primary_club
|
||||||
|
return unless @club
|
||||||
|
|
||||||
|
@subscription = @club.subscription
|
||||||
|
@team = @club.teams.order(:name).first
|
||||||
|
@entitlements = @team&.entitlements
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,21 +4,17 @@ module Public
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
user = User.find_by(email: params[:email]&.downcase&.strip)
|
Users::RequestPasswordReset.call(email: params[:email])
|
||||||
if user
|
|
||||||
token = user.generate_password_reset!
|
|
||||||
UserMailer.password_reset(user, token).deliver_now
|
|
||||||
end
|
|
||||||
|
|
||||||
redirect_to public_login_path,
|
redirect_to public_login_path,
|
||||||
notice: "Se l'email è registrata, riceverai a breve un link per reimpostare la password."
|
notice: t("flash.password_resets.email_sent")
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@user = User.find_by_password_reset_token(params[:token])
|
@user = User.find_by_password_reset_token(params[:token])
|
||||||
if @user.nil? || @user.password_reset_expired?
|
if @user.nil? || @user.password_reset_expired?
|
||||||
redirect_to new_public_password_reset_path,
|
redirect_to public_password_forgot_path,
|
||||||
alert: "Link non valido o scaduto. Richiedi un nuovo reset password."
|
alert: t("flash.password_resets.invalid_or_expired_link")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@token = params[:token]
|
@token = params[:token]
|
||||||
@@ -27,26 +23,32 @@ module Public
|
|||||||
def update
|
def update
|
||||||
@user = User.find_by_password_reset_token(params[:token])
|
@user = User.find_by_password_reset_token(params[:token])
|
||||||
if @user.nil? || @user.password_reset_expired?
|
if @user.nil? || @user.password_reset_expired?
|
||||||
redirect_to new_public_password_reset_path,
|
redirect_to public_password_forgot_path,
|
||||||
alert: "Link non valido o scaduto. Richiedi un nuovo reset password."
|
alert: t("flash.password_resets.invalid_or_expired_link")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:password].blank? || params[:password].length < 8
|
if params[:password] != params[:password_confirmation]
|
||||||
flash.now[:alert] = "La password deve avere almeno 8 caratteri"
|
flash.now[:alert] = t("flash.password_resets.password_mismatch")
|
||||||
@token = params[:token]
|
@token = params[:token]
|
||||||
return render :edit, status: :unprocessable_entity
|
return render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:password] != params[:password_confirmation]
|
if (code = PasswordComplexity.violation(params[:password]))
|
||||||
flash.now[:alert] = "Le password non coincidono"
|
flash.now[:alert] = t("flash.password_resets.password_#{code == :blank ? :too_short : code}")
|
||||||
|
@token = params[:token]
|
||||||
|
return render :edit, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
if PasswordComplexity.same_as_current?(@user, params[:password])
|
||||||
|
flash.now[:alert] = t("flash.password_resets.password_same_as_current")
|
||||||
@token = params[:token]
|
@token = params[:token]
|
||||||
return render :edit, status: :unprocessable_entity
|
return render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@user.update!(password: params[:password])
|
@user.update!(password: params[:password])
|
||||||
@user.clear_password_reset!
|
@user.clear_password_reset!
|
||||||
redirect_to public_login_path, notice: "Password aggiornata. Ora puoi accedere."
|
redirect_to public_login_path, notice: t("flash.password_resets.password_updated")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,26 +1,30 @@
|
|||||||
module Public
|
module Public
|
||||||
class RegiaController < SiteBaseController
|
class RegiaController < SiteBaseController
|
||||||
include Public::LiveHelper
|
include Public::LiveHelper
|
||||||
|
include Public::RegiaHelper
|
||||||
include MediamtxPlayback
|
include MediamtxPlayback
|
||||||
|
|
||||||
layout "regia"
|
layout "regia"
|
||||||
|
|
||||||
protect_from_forgery with: :null_session
|
protect_from_forgery with: :null_session
|
||||||
skip_before_action :verify_authenticity_token, only: %i[score pause stop]
|
skip_before_action :verify_authenticity_token, only: %i[score pause resume stop audio_mute min_quality]
|
||||||
|
|
||||||
before_action :set_session_from_token
|
before_action :set_session_from_token
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@match = @session.match
|
@match = @session.match
|
||||||
@team = @match.team
|
@team = @match.team
|
||||||
@score = @session.score_state || @session.create_score_state!(
|
@score = @session.score_state || Scoring::Engine.ensure_score_for(@session)
|
||||||
home_sets: 0, away_sets: 0, home_points: 0, away_points: 0, current_set: 1, set_partials: []
|
|
||||||
)
|
|
||||||
@rules = Scoring::Rules.from_match(@match)
|
@rules = Scoring::Rules.from_match(@match)
|
||||||
@stream_closed = @session.terminal?
|
@stream_closed = @session.terminal?
|
||||||
@on_air = !@stream_closed && mediamtx_stream_playable?(@session)
|
@on_air = !@stream_closed && (
|
||||||
@share_url = request.original_url
|
mediamtx_stream_playable?(@session) ||
|
||||||
@share_title = "Regia — #{@team.name} vs #{@match.opponent_name}"
|
@session.status.in?(%w[connecting live reconnecting paused])
|
||||||
|
)
|
||||||
|
@regia_share_url = request.original_url
|
||||||
|
@regia_share_title = "Regia — #{@team.name} vs #{@match.opponent_name}"
|
||||||
|
@live_share_url = @session.share_url
|
||||||
|
@live_share_title = "#{@team.name} vs #{@match.opponent_name} — Diretta Match Live TV"
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
@@ -30,6 +34,7 @@ module Public
|
|||||||
def score
|
def score
|
||||||
cmd = params[:cmd].presence || params[:score_action].presence
|
cmd = params[:cmd].presence || params[:score_action].presence
|
||||||
result = Scoring::ApplyAction.new(session: @session, action: cmd).call
|
result = Scoring::ApplyAction.new(session: @session, action: cmd).call
|
||||||
|
@session.reload
|
||||||
render json: status_payload.merge(
|
render json: status_payload.merge(
|
||||||
set_won: result.set_won,
|
set_won: result.set_won,
|
||||||
match_won: result.match_won,
|
match_won: result.match_won,
|
||||||
@@ -44,37 +49,66 @@ module Public
|
|||||||
render json: status_payload
|
render json: status_payload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resume
|
||||||
|
Sessions::Resume.new(@session).call
|
||||||
|
render json: status_payload
|
||||||
|
rescue Teams::EntitlementError => e
|
||||||
|
render json: status_payload.merge(error: e.message), status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
def stop
|
def stop
|
||||||
Sessions::Stop.new(@session).call
|
Sessions::Stop.new(@session).call
|
||||||
render json: status_payload
|
render json: status_payload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def audio_mute
|
||||||
|
muted = params.key?(:muted) ? params[:muted] : !@session.audio_muted
|
||||||
|
Sessions::SetAudioMute.new(@session, muted: muted).call
|
||||||
|
render json: status_payload
|
||||||
|
end
|
||||||
|
|
||||||
|
def min_quality
|
||||||
|
Sessions::SetMinQuality.new(@session, preset: params[:min_quality_preset]).call
|
||||||
|
render json: status_payload
|
||||||
|
rescue ArgumentError => e
|
||||||
|
render json: status_payload.merge(error: e.message), status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def camera_telemetry_payload(publisher_online)
|
||||||
|
cam = @session.device_states.find_by(device_role: "camera")
|
||||||
|
(cam&.as_regia_payload || {}).merge(publisher_online: publisher_online)
|
||||||
|
end
|
||||||
|
|
||||||
def set_session_from_token
|
def set_session_from_token
|
||||||
@session = Sessions::RegiaAccess.find_session_by_token(params[:token])
|
@session = Sessions::RegiaAccess.find_session_by_token(params[:token])
|
||||||
return if @session
|
return if @session
|
||||||
|
|
||||||
render file: Rails.root.join("public/404.html"), status: :not_found, layout: false
|
head :not_found
|
||||||
throw :abort
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_payload
|
def status_payload
|
||||||
score = @session.score_state
|
score = @session.score_state
|
||||||
closed = @session.terminal?
|
closed = @session.terminal?
|
||||||
playable = !closed && mediamtx_stream_playable?(@session)
|
playable = !closed && mediamtx_stream_playable?(@session)
|
||||||
|
publisher_online = !closed && mediamtx_publisher_online?(@session)
|
||||||
{
|
{
|
||||||
status: @session.status,
|
status: @session.status,
|
||||||
paused: @session.paused?,
|
paused: @session.paused?,
|
||||||
|
audio_muted: @session.audio_muted,
|
||||||
stream_closed: closed,
|
stream_closed: closed,
|
||||||
live: !closed && (@session.live? || @session.paused? || mediamtx_publisher_online?(@session)),
|
live: !closed && (@session.live? || @session.paused? || publisher_online),
|
||||||
on_air: playable,
|
on_air: playable || (!closed && @session.status.in?(%w[connecting live reconnecting paused])),
|
||||||
publisher_online: !closed && mediamtx_publisher_online?(@session),
|
publisher_online: publisher_online,
|
||||||
ended_at: @session.ended_at,
|
ended_at: @session.ended_at,
|
||||||
home_name: @session.match.team.name,
|
home_name: @session.match.team.name,
|
||||||
away_name: @session.match.opponent_name,
|
away_name: @session.match.opponent_name,
|
||||||
points_target: Scoring::Rules.from_match(@session.match).points_target(score&.current_set || 1),
|
points_target: Scoring::Rules.points_target_for_match(@session.match, current_set: score&.current_set || 1),
|
||||||
score: score&.as_cable_payload
|
score: score&.as_cable_payload,
|
||||||
|
min_quality_preset: @session.min_quality_preset,
|
||||||
|
min_quality_options: Sessions::SelectQuality.allowed_min_ids(@session.quality_preset),
|
||||||
|
telemetry: camera_telemetry_payload(publisher_online)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module Public
|
|||||||
def create
|
def create
|
||||||
unless params[:accept_terms] == "1"
|
unless params[:accept_terms] == "1"
|
||||||
@user = User.new(user_params.merge(role: "coach"))
|
@user = User.new(user_params.merge(role: "coach"))
|
||||||
flash.now[:alert] = "Devi accettare l’informativa privacy e i termini di servizio per registrarti."
|
flash.now[:alert] = t("flash.registrations.accept_terms_required")
|
||||||
return render :new, status: :unprocessable_entity
|
return render :new, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -20,10 +20,10 @@ module Public
|
|||||||
invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(token))
|
invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(token))
|
||||||
if invitation && invitation.email.downcase == @user.email.downcase
|
if invitation && invitation.email.downcase == @user.email.downcase
|
||||||
invitation.accept!(@user)
|
invitation.accept!(@user)
|
||||||
return redirect_to public_team_details_path(invitation.team), notice: "Benvenuto nella squadra!"
|
return redirect_to public_team_details_path(invitation.team), notice: t("flash.registrations.welcome_to_team")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect_to public_new_club_path, notice: "Account creato. Ora registra la tua società."
|
redirect_to public_new_club_path, notice: t("flash.registrations.account_created")
|
||||||
else
|
else
|
||||||
flash.now[:alert] = @user.errors.full_messages.join(", ")
|
flash.now[:alert] = @user.errors.full_messages.join(", ")
|
||||||
render :new, status: :unprocessable_entity
|
render :new, status: :unprocessable_entity
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
module Public
|
module Public
|
||||||
class ReplayController < SiteBaseController
|
class ReplayController < SiteBaseController
|
||||||
|
include Public::LiveHelper
|
||||||
|
|
||||||
layout "marketing_live"
|
layout "marketing_live"
|
||||||
|
|
||||||
before_action :set_session_and_recording, only: %i[show stream thumbnail download]
|
before_action :set_session_and_recording, only: %i[show stream thumbnail download]
|
||||||
@@ -40,7 +42,7 @@ module Public
|
|||||||
|
|
||||||
def download
|
def download
|
||||||
unless download_allowed?
|
unless download_allowed?
|
||||||
redirect_to public_replay_path(@session), alert: "Download non disponibile"
|
redirect_to public_replay_path(@session), alert: t("flash.replay.download_unavailable")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -50,6 +52,15 @@ module Public
|
|||||||
private
|
private
|
||||||
|
|
||||||
def serve_video(disposition:)
|
def serve_video(disposition:)
|
||||||
|
expires_in = disposition == "attachment" ? MatchLiveTv.replay_download_url_ttl_seconds : MatchLiveTv.replay_presigned_url_ttl_seconds
|
||||||
|
redirect_url = Recordings::PublicMediaUrl.new(
|
||||||
|
key: @recording.storage_key,
|
||||||
|
expires_in: expires_in,
|
||||||
|
disposition: disposition,
|
||||||
|
filename: disposition == "attachment" ? download_filename : nil
|
||||||
|
).call
|
||||||
|
return redirect_to redirect_url, allow_other_host: true if redirect_url.present?
|
||||||
|
|
||||||
Recordings::ServeFromStorage.new(
|
Recordings::ServeFromStorage.new(
|
||||||
key: @recording.storage_key,
|
key: @recording.storage_key,
|
||||||
content_type: "video/mp4",
|
content_type: "video/mp4",
|
||||||
@@ -64,6 +75,9 @@ module Public
|
|||||||
key = @recording.thumbnail_storage_key
|
key = @recording.thumbnail_storage_key
|
||||||
return head :not_found if key.blank?
|
return head :not_found if key.blank?
|
||||||
|
|
||||||
|
redirect_url = Recordings::PublicMediaUrl.new(key: key, expires_in: MatchLiveTv.replay_presigned_url_ttl_seconds).call
|
||||||
|
return redirect_to redirect_url, allow_other_host: true if redirect_url.present?
|
||||||
|
|
||||||
Recordings::ServeFromStorage.new(
|
Recordings::ServeFromStorage.new(
|
||||||
key: key,
|
key: key,
|
||||||
content_type: "image/jpeg",
|
content_type: "image/jpeg",
|
||||||
@@ -91,13 +105,13 @@ module Public
|
|||||||
@recording = Recording.not_deleted.find_by(stream_session: @session)
|
@recording = Recording.not_deleted.find_by(stream_session: @session)
|
||||||
return if @recording
|
return if @recording
|
||||||
|
|
||||||
redirect_to public_live_path(@session), alert: "Replay non disponibile"
|
redirect_to public_live_path(@session), alert: t("flash.replay.not_available")
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorize_replay_access!
|
def authorize_replay_access!
|
||||||
return if Recordings::AccessPolicy.new(@recording, viewer: current_user).allowed?
|
return if Recordings::AccessPolicy.new(@recording, viewer: current_user).allowed?
|
||||||
|
|
||||||
redirect_to public_live_index_path, alert: "Replay non disponibile"
|
redirect_to public_live_index_path, alert: t("flash.replay.not_available")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
module Public
|
module Public
|
||||||
class SessionsController < WebBaseController
|
class SessionsController < WebBaseController
|
||||||
|
# Logout must succeed even with a stale CSRF token (old tab after deploy /
|
||||||
|
# session rotate). SameSite=Lax already blocks cross-site cookie POSTs.
|
||||||
|
skip_before_action :verify_authenticity_token, only: :destroy
|
||||||
|
|
||||||
def new
|
def new
|
||||||
if logged_in? && current_user.primary_club
|
if logged_in? && current_user.primary_club
|
||||||
redirect_to public_club_path(current_user.primary_club)
|
redirect_to public_club_path(current_user.primary_club)
|
||||||
@@ -17,16 +21,16 @@ module Public
|
|||||||
else
|
else
|
||||||
public_new_club_path
|
public_new_club_path
|
||||||
end
|
end
|
||||||
redirect_to dest, notice: "Bentornato!"
|
redirect_to dest, notice: t("flash.sessions.welcome_back")
|
||||||
else
|
else
|
||||||
flash.now[:alert] = "Email o password non validi"
|
flash.now[:alert] = t("flash.sessions.invalid_credentials")
|
||||||
render :new, status: :unauthorized
|
render :new, status: :unauthorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
reset_session
|
reset_session
|
||||||
redirect_to public_pricing_path, notice: "Disconnesso"
|
redirect_to public_pricing_path, notice: t("flash.sessions.logged_out")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,14 +5,31 @@ module Public
|
|||||||
include ::SeoHelper
|
include ::SeoHelper
|
||||||
include ::LegalHelper
|
include ::LegalHelper
|
||||||
helper ApplicationHelper
|
helper ApplicationHelper
|
||||||
helper_method :current_user, :logged_in?
|
helper_method :current_user, :logged_in?, :current_locale, :language_options, :current_language_option
|
||||||
|
|
||||||
|
protect_from_forgery with: :exception
|
||||||
before_action :set_site_locale
|
before_action :set_site_locale
|
||||||
|
before_action :load_site_announcements
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_site_locale
|
def set_site_locale
|
||||||
I18n.locale = :it
|
I18n.locale = LocaleResolver.resolve(
|
||||||
|
cookie_jar: request.cookie_jar,
|
||||||
|
accept_language: request.get_header("HTTP_ACCEPT_LANGUAGE")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_locale
|
||||||
|
I18n.locale
|
||||||
|
end
|
||||||
|
|
||||||
|
def language_options
|
||||||
|
LocaleResolver.language_options
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_language_option
|
||||||
|
LocaleResolver.current_language_option
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_user
|
def current_user
|
||||||
@@ -24,5 +41,27 @@ module Public
|
|||||||
def logged_in?
|
def logged_in?
|
||||||
current_user.present?
|
current_user.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
PRIVATE_WEB_CONTROLLERS = %w[
|
||||||
|
accounts clubs teams club_recordings club_billing
|
||||||
|
club_matches matches team_roster_members
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
def load_site_announcements
|
||||||
|
@site_announcements = if skip_site_announcements?
|
||||||
|
AppAnnouncement.none
|
||||||
|
else
|
||||||
|
channel = private_web_area? ? :web_private : :web_public
|
||||||
|
AppAnnouncement.for_channel(channel).newest
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def skip_site_announcements?
|
||||||
|
controller_name == "regia"
|
||||||
|
end
|
||||||
|
|
||||||
|
def private_web_area?
|
||||||
|
PRIVATE_WEB_CONTROLLERS.include?(controller_name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,12 +8,23 @@ module Public
|
|||||||
{ loc: "#{base}/prezzi", changefreq: "monthly", priority: "0.9" },
|
{ loc: "#{base}/prezzi", changefreq: "monthly", priority: "0.9" },
|
||||||
{ loc: "#{base}/pallavolo-giovanile", changefreq: "monthly", priority: "0.85" },
|
{ loc: "#{base}/pallavolo-giovanile", changefreq: "monthly", priority: "0.85" },
|
||||||
{ loc: "#{base}/faq", changefreq: "monthly", priority: "0.8" },
|
{ loc: "#{base}/faq", changefreq: "monthly", priority: "0.8" },
|
||||||
|
{ loc: "#{base}/contatti", changefreq: "monthly", priority: "0.6" },
|
||||||
{ loc: "#{base}/live", changefreq: "hourly", priority: "0.85" },
|
{ loc: "#{base}/live", changefreq: "hourly", priority: "0.85" },
|
||||||
|
{ loc: "#{base}/squadre", changefreq: "daily", priority: "0.85" },
|
||||||
{ loc: "#{base}/privacy", changefreq: "yearly", priority: "0.3" },
|
{ loc: "#{base}/privacy", changefreq: "yearly", priority: "0.3" },
|
||||||
|
{ loc: "#{base}/support", changefreq: "yearly", priority: "0.3" },
|
||||||
{ loc: "#{base}/cookie", changefreq: "yearly", priority: "0.3" },
|
{ loc: "#{base}/cookie", changefreq: "yearly", priority: "0.3" },
|
||||||
{ loc: "#{base}/termini", changefreq: "yearly", priority: "0.3" }
|
{ loc: "#{base}/termini", changefreq: "yearly", priority: "0.3" }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Team.find_each do |team|
|
||||||
|
@entries << {
|
||||||
|
loc: "#{base}/squadre/#{team.slug}",
|
||||||
|
changefreq: "daily",
|
||||||
|
priority: "0.7"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.xml { render layout: false }
|
format.xml { render layout: false }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
module Public
|
||||||
|
class TeamPagesController < SiteBaseController
|
||||||
|
include Public::LiveHelper
|
||||||
|
|
||||||
|
layout "marketing_live"
|
||||||
|
|
||||||
|
def index
|
||||||
|
@query = params[:q].to_s.strip
|
||||||
|
@sport = params[:sport].to_s.strip.presence
|
||||||
|
@live_filter = params[:live].present?
|
||||||
|
@replays_filter = params[:replays].present?
|
||||||
|
@entries = Teams::PublicDirectory.call(
|
||||||
|
q: @query,
|
||||||
|
sport: @sport,
|
||||||
|
live: @live_filter,
|
||||||
|
replays: @replays_filter
|
||||||
|
)
|
||||||
|
@sport_options = Sports::Catalog.as_api_list
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@team = Team.includes(:club, roster_members: []).find_by!(slug: params[:slug])
|
||||||
|
@club = @team.club
|
||||||
|
load_live_content!
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_live_content!
|
||||||
|
@online_paths = fetch_online_paths
|
||||||
|
|
||||||
|
@live_sessions = StreamSession
|
||||||
|
.broadcasting
|
||||||
|
.publicly_listed
|
||||||
|
.where(platform: "matchlivetv")
|
||||||
|
.includes(:score_state, match: { team: :club })
|
||||||
|
.joins(:match)
|
||||||
|
.where(matches: { team_id: @team.id })
|
||||||
|
.order(Arel.sql("started_at DESC NULLS LAST"), created_at: :desc)
|
||||||
|
|
||||||
|
broadcasting_match_ids = StreamSession.broadcasting.select(:match_id)
|
||||||
|
@upcoming_matches = @team.matches
|
||||||
|
.scheduled_for_live
|
||||||
|
.where.not(id: broadcasting_match_ids)
|
||||||
|
.order(scheduled_at: :asc)
|
||||||
|
.limit(20)
|
||||||
|
|
||||||
|
@recordings = @team.recordings
|
||||||
|
.ready
|
||||||
|
.publicly_listed
|
||||||
|
.includes(stream_session: :match)
|
||||||
|
.order(recorded_at: :desc, created_at: :desc)
|
||||||
|
.limit(12)
|
||||||
|
|
||||||
|
@roster_by_category = @team.roster_public? ? @team.roster_by_category : nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch_online_paths
|
||||||
|
Mediamtx::Client.new.online_path_names
|
||||||
|
rescue Mediamtx::Client::Error, Errno::ECONNREFUSED, SocketError
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -9,7 +9,7 @@ module Public
|
|||||||
member = @team.roster_members.build(member_params)
|
member = @team.roster_members.build(member_params)
|
||||||
attach_photo(member)
|
attach_photo(member)
|
||||||
member.save!
|
member.save!
|
||||||
redirect_to public_team_details_path(@team), notice: "#{member.full_name} aggiunto all'organico."
|
redirect_to public_team_details_path(@team), notice: t("flash.team_roster_members.added", name: member.full_name)
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
redirect_to public_team_details_path(@team), alert: e.record.errors.full_messages.join(", ")
|
redirect_to public_team_details_path(@team), alert: e.record.errors.full_messages.join(", ")
|
||||||
end
|
end
|
||||||
@@ -22,7 +22,7 @@ module Public
|
|||||||
@member.assign_attributes(member_params)
|
@member.assign_attributes(member_params)
|
||||||
attach_photo(@member)
|
attach_photo(@member)
|
||||||
@member.save!
|
@member.save!
|
||||||
redirect_to public_team_details_path(@team), notice: "Scheda aggiornata."
|
redirect_to public_team_details_path(@team), notice: t("flash.team_roster_members.updated")
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
@club = @team.club
|
@club = @team.club
|
||||||
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
||||||
@@ -32,7 +32,7 @@ module Public
|
|||||||
def destroy
|
def destroy
|
||||||
name = @member.full_name
|
name = @member.full_name
|
||||||
@member.destroy!
|
@member.destroy!
|
||||||
redirect_to public_team_details_path(@team), notice: "#{name} rimosso dall'organico."
|
redirect_to public_team_details_path(@team), notice: t("flash.team_roster_members.removed", name: name)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ module Public
|
|||||||
require_club_owner!(@club)
|
require_club_owner!(@club)
|
||||||
team = @club.teams.create!(team_params)
|
team = @club.teams.create!(team_params)
|
||||||
attach_branding_logo(team)
|
attach_branding_logo(team)
|
||||||
redirect_to public_club_path(@club), notice: "Squadra «#{team.name}» aggiunta."
|
Teams::StaffAssignment.designate_club_owner!(team: team, user: current_user)
|
||||||
|
redirect_to public_club_path(@club), notice: t("flash.teams.added", name: team.name)
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
||||||
render :new, status: :unprocessable_entity
|
render :new, status: :unprocessable_entity
|
||||||
@@ -41,24 +42,33 @@ module Public
|
|||||||
def edit
|
def edit
|
||||||
require_club_owner_for_team!(@team)
|
require_club_owner_for_team!(@team)
|
||||||
@club = @team.club
|
@club = @team.club
|
||||||
|
@entitlements = @team.entitlements
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
require_club_owner_for_team!(@team)
|
require_club_owner_for_team!(@team)
|
||||||
@team.assign_attributes(team_params)
|
@team.assign_attributes(team_params)
|
||||||
attach_branding_logo(@team)
|
attach_branding_logo(@team)
|
||||||
|
attach_cover_image(@team, entitlements: @team.entitlements)
|
||||||
attach_team_photo(@team)
|
attach_team_photo(@team)
|
||||||
@team.save!
|
@team.save!
|
||||||
redirect_to public_team_details_path(@team), notice: "Squadra aggiornata."
|
enqueue_cover_slate_generation(@team)
|
||||||
|
redirect_to public_team_details_path(@team), notice: t("flash.teams.updated")
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
@club = @team.club
|
@club = @team.club
|
||||||
|
@entitlements = @team.entitlements
|
||||||
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
flash.now[:alert] = e.record.errors.full_messages.join(", ")
|
||||||
render :edit, status: :unprocessable_entity
|
render :edit, status: :unprocessable_entity
|
||||||
|
rescue Teams::EntitlementError, BrandingAttachments::CoverUploadError => e
|
||||||
|
@club = @team.club
|
||||||
|
@entitlements = @team.entitlements
|
||||||
|
flash.now[:alert] = e.message
|
||||||
|
render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
def invite
|
def invite
|
||||||
require_club_owner_for_team!(@team)
|
require_club_owner_for_team!(@team)
|
||||||
@entitlements = @team.entitlements
|
redirect_to public_team_details_path(@team, anchor: "invita-trasmissione")
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_self_staff
|
def assign_self_staff
|
||||||
@@ -66,7 +76,7 @@ module Public
|
|||||||
membership = current_user.user_teams.find_or_initialize_by(team: @team)
|
membership = current_user.user_teams.find_or_initialize_by(team: @team)
|
||||||
membership.role = "member" if membership.new_record?
|
membership.role = "member" if membership.new_record?
|
||||||
Teams::StaffAssignment.call(team: @team, user: current_user, membership: membership)
|
Teams::StaffAssignment.call(team: @team, user: current_user, membership: membership)
|
||||||
redirect_to public_team_details_path(@team), notice: "Il tuo account è ora responsabile trasmissione."
|
redirect_to public_team_details_path(@team), notice: t("flash.teams.now_staff")
|
||||||
rescue Teams::StaffAssignmentError, Teams::EntitlementError => e
|
rescue Teams::StaffAssignmentError, Teams::EntitlementError => e
|
||||||
redirect_to public_team_details_path(@team), alert: e.message
|
redirect_to public_team_details_path(@team), alert: e.message
|
||||||
end
|
end
|
||||||
@@ -75,7 +85,7 @@ module Public
|
|||||||
require_club_owner_for_team!(@team)
|
require_club_owner_for_team!(@team)
|
||||||
membership = current_user.user_teams.find_by(team: @team)
|
membership = current_user.user_teams.find_by(team: @team)
|
||||||
membership&.update!(staff_kind: nil)
|
membership&.update!(staff_kind: nil)
|
||||||
redirect_to public_team_details_path(@team), notice: "Ruolo staff rimosso dal tuo account."
|
redirect_to public_team_details_path(@team), notice: t("flash.teams.staff_role_removed")
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_invitation
|
def create_invitation
|
||||||
@@ -87,32 +97,46 @@ module Public
|
|||||||
email = params[:email]&.downcase&.strip
|
email = params[:email]&.downcase&.strip
|
||||||
Teams::StaffEmailValidator.assert_available!(team: @team, email: email, staff_kind: staff_kind)
|
Teams::StaffEmailValidator.assert_available!(team: @team, email: email, staff_kind: staff_kind)
|
||||||
token = TeamInvitation.generate_token
|
token = TeamInvitation.generate_token
|
||||||
@team.team_invitations.create!(
|
invitation = @team.team_invitations.create!(
|
||||||
email: email,
|
email: email,
|
||||||
token_digest: Digest::SHA256.hexdigest(token),
|
token_digest: Digest::SHA256.hexdigest(token),
|
||||||
role: "member",
|
role: "member",
|
||||||
staff_kind: staff_kind,
|
staff_kind: staff_kind,
|
||||||
expires_at: 7.days.from_now
|
expires_at: 7.days.from_now
|
||||||
)
|
)
|
||||||
@invite_url = join_public_invitation_url(token: token)
|
invite_url = public_invitation_url(token: token)
|
||||||
flash.now[:notice] = "Link invito generato (valido 7 giorni)"
|
flash[:invite_url] = invite_url
|
||||||
render :invite
|
|
||||||
|
begin
|
||||||
|
Teams::InvitationMailer.transmission_invite(
|
||||||
|
team: @team,
|
||||||
|
invitation: invitation,
|
||||||
|
invite_url: invite_url,
|
||||||
|
invited_by: current_user
|
||||||
|
).deliver_now
|
||||||
|
flash[:notice] = t("flash.teams.invite_email_sent", email: email)
|
||||||
|
rescue StandardError => e
|
||||||
|
Rails.logger.error("[invite_email] #{e.class}: #{e.message}")
|
||||||
|
flash[:alert] = t("flash.teams.invite_email_failed", email: email)
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to public_team_details_path(@team, anchor: "invito-generato")
|
||||||
rescue Teams::EntitlementError, Teams::StaffAssignmentError => e
|
rescue Teams::EntitlementError, Teams::StaffAssignmentError => e
|
||||||
redirect_to public_team_invite_path(@team), alert: e.message
|
redirect_to public_team_details_path(@team, anchor: "invita-trasmissione"), alert: e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_member
|
def remove_member
|
||||||
require_club_owner_for_team!(@team)
|
require_club_owner_for_team!(@team)
|
||||||
ut = @team.user_teams.find_by!(user_id: params[:user_id], role: "member")
|
ut = @team.user_teams.find_by!(user_id: params[:user_id], role: "member")
|
||||||
ut.destroy!
|
ut.destroy!
|
||||||
redirect_to public_team_details_path(@team), notice: "Accesso revocato"
|
redirect_to public_team_details_path(@team), notice: t("flash.teams.access_revoked")
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_invitation
|
def destroy_invitation
|
||||||
require_club_owner_for_team!(@team)
|
require_club_owner_for_team!(@team)
|
||||||
inv = @team.team_invitations.pending.find(params[:invitation_id])
|
inv = @team.team_invitations.pending.find(params[:invitation_id])
|
||||||
inv.destroy!
|
inv.destroy!
|
||||||
redirect_to public_team_details_path(@team), notice: "Invito annullato"
|
redirect_to public_team_details_path(@team), notice: t("flash.teams.invitation_canceled")
|
||||||
end
|
end
|
||||||
|
|
||||||
def youtube_connect
|
def youtube_connect
|
||||||
@@ -125,7 +149,7 @@ module Public
|
|||||||
def youtube_disconnect
|
def youtube_disconnect
|
||||||
require_club_owner_for_team!(@team)
|
require_club_owner_for_team!(@team)
|
||||||
@team.club.youtube_credential&.destroy!
|
@team.club.youtube_credential&.destroy!
|
||||||
redirect_to public_club_path(@team.club), notice: "Canale YouTube della società scollegato"
|
redirect_to public_club_path(@team.club), notice: t("flash.teams.youtube_disconnected")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -165,7 +189,12 @@ module Public
|
|||||||
end
|
end
|
||||||
|
|
||||||
def team_params
|
def team_params
|
||||||
p = params.require(:team).permit(:name, :sport, :description, :logo_url, :primary_color, :secondary_color)
|
p = params.require(:team).permit(:name, :sport, :sport_key, :description, :logo_url, :primary_color, :secondary_color, :slug, :roster_public)
|
||||||
|
if p[:sport].present? && p[:sport_key].blank?
|
||||||
|
p[:sport_key] = p.delete(:sport)
|
||||||
|
elsif p[:sport_key].present?
|
||||||
|
p.delete(:sport)
|
||||||
|
end
|
||||||
p[:primary_color] = p[:primary_color].presence
|
p[:primary_color] = p[:primary_color].presence
|
||||||
p[:secondary_color] = p[:secondary_color].presence
|
p[:secondary_color] = p[:secondary_color].presence
|
||||||
if p[:primary_color].present?
|
if p[:primary_color].present?
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ module Public
|
|||||||
def require_login!
|
def require_login!
|
||||||
return if logged_in?
|
return if logged_in?
|
||||||
|
|
||||||
redirect_to public_login_path, alert: "Accedi per continuare"
|
redirect_to public_login_path, alert: t("flash.web_base.login_required")
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_club_owner!(club)
|
def require_club_owner!(club)
|
||||||
redirect_to public_prezzi_path, alert: "Accesso non consentito" unless club.owned_by?(current_user)
|
redirect_to public_prezzi_path, alert: t("flash.web_base.access_denied") unless club.owned_by?(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_club_owner_for_team!(team)
|
def require_club_owner_for_team!(team)
|
||||||
redirect_to public_prezzi_path, alert: "Accesso non consentito" unless team.club&.owned_by?(current_user)
|
redirect_to public_prezzi_path, alert: t("flash.web_base.access_denied") unless team.club&.owned_by?(current_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Sports
|
||||||
|
class BoardType
|
||||||
|
ALL = %w[volley basket timed racket timer generic].freeze
|
||||||
|
|
||||||
|
def self.valid?(value)
|
||||||
|
ALL.include?(value.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Sports
|
||||||
|
class Catalog
|
||||||
|
LEGACY_SPORT_MAP = {
|
||||||
|
"volleyball" => "pallavolo"
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def all
|
||||||
|
@all ||= load_entries
|
||||||
|
end
|
||||||
|
|
||||||
|
def keys
|
||||||
|
all.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
def find(key)
|
||||||
|
normalized = normalize_key(key)
|
||||||
|
entry = all[normalized]
|
||||||
|
raise KeyError, "Sport sconosciuto: #{key}" unless entry
|
||||||
|
|
||||||
|
entry.merge(key: normalized)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_optional(key)
|
||||||
|
normalized = normalize_key(key)
|
||||||
|
entry = all[normalized]
|
||||||
|
return nil unless entry
|
||||||
|
|
||||||
|
entry.merge(key: normalized)
|
||||||
|
end
|
||||||
|
|
||||||
|
def board_for(key)
|
||||||
|
find(key)[:board]
|
||||||
|
end
|
||||||
|
|
||||||
|
def overlay_for(key)
|
||||||
|
find(key)[:overlay]
|
||||||
|
end
|
||||||
|
|
||||||
|
def allowed_overlays_for(key)
|
||||||
|
find(key)[:allowed_overlays]
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_rules_for(key)
|
||||||
|
deep_stringify_keys(find(key)[:default_rules] || {})
|
||||||
|
end
|
||||||
|
|
||||||
|
def normalize_key(key)
|
||||||
|
raw = key.to_s.strip
|
||||||
|
return "pallavolo" if raw.blank?
|
||||||
|
|
||||||
|
LEGACY_SPORT_MAP.fetch(raw, raw)
|
||||||
|
end
|
||||||
|
|
||||||
|
def as_api_list
|
||||||
|
all.map do |key, entry|
|
||||||
|
{
|
||||||
|
key: key,
|
||||||
|
label: entry[:label],
|
||||||
|
board: entry[:board],
|
||||||
|
overlay: entry[:overlay],
|
||||||
|
allowed_overlays: entry[:allowed_overlays],
|
||||||
|
default_rules: entry[:default_rules] || {}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_entries
|
||||||
|
path = Rails.root.join("config/sports.yml")
|
||||||
|
raw = YAML.safe_load(File.read(path), permitted_classes: [], aliases: true) || {}
|
||||||
|
raw.transform_keys(&:to_s).transform_values do |entry|
|
||||||
|
entry.deep_symbolize_keys
|
||||||
|
end.freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def deep_stringify_keys(value)
|
||||||
|
case value
|
||||||
|
when Hash
|
||||||
|
value.each_with_object({}) do |(k, v), h|
|
||||||
|
h[k.to_s] = deep_stringify_keys(v)
|
||||||
|
end
|
||||||
|
when Array
|
||||||
|
value.map { |v| deep_stringify_keys(v) }
|
||||||
|
else
|
||||||
|
value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Sports
|
||||||
|
class OverlayKind
|
||||||
|
ALL = %w[none volley basket timed racket].freeze
|
||||||
|
|
||||||
|
def self.valid?(value)
|
||||||
|
ALL.include?(value.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Sports
|
||||||
|
class PlayerRoles
|
||||||
|
BY_BOARD = {
|
||||||
|
"volley" => %w[Schiacciatore Opposto Centrale Palleggiatore Libero Universale],
|
||||||
|
"basket" => ["Playmaker", "Guardia", "Ala", "Ala forte", "Centro"],
|
||||||
|
"racket" => %w[Giocatore],
|
||||||
|
"timed" => %w[Portiere Difensore Centrocampista Attaccante],
|
||||||
|
"generic" => %w[Giocatore],
|
||||||
|
"timer" => %w[Giocatore]
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def for_team(team)
|
||||||
|
board = team.effective_board_type
|
||||||
|
BY_BOARD[board] || BY_BOARD["generic"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def for_board(board)
|
||||||
|
BY_BOARD[board.to_s] || BY_BOARD["generic"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Sports
|
||||||
|
class RulesSchema
|
||||||
|
INTEGER_RULES = {
|
||||||
|
"volley" => %w[sets_to_win points_per_set points_deciding_set min_point_lead],
|
||||||
|
"racket" => %w[sets_to_win points_per_set points_deciding_set min_point_lead],
|
||||||
|
"basket" => %w[periods period_duration_secs overtime_duration_secs],
|
||||||
|
"timed" => %w[periods period_duration_secs overtime_duration_secs],
|
||||||
|
"timer" => [],
|
||||||
|
"generic" => []
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
def self.validate!(board_type, rules)
|
||||||
|
board = board_type.to_s
|
||||||
|
return if board == "generic" || board == "timer"
|
||||||
|
|
||||||
|
hash = rules.is_a?(Hash) ? rules : {}
|
||||||
|
INTEGER_RULES.fetch(board, []).each do |key|
|
||||||
|
val = hash[key] || hash[key.to_sym]
|
||||||
|
next if val.blank?
|
||||||
|
|
||||||
|
unless val.is_a?(Integer) || val.to_s.match?(/\A\d+\z/)
|
||||||
|
raise ArgumentError, "#{key} non valido"
|
||||||
|
end
|
||||||
|
int_val = val.to_i
|
||||||
|
raise ArgumentError, "#{key} deve essere positivo" if int_val < 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.validate(board_type, rules)
|
||||||
|
validate!(board_type, rules)
|
||||||
|
true
|
||||||
|
rescue ArgumentError
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -19,4 +19,156 @@ module AdminHelper
|
|||||||
mins = minutes % 60
|
mins = minutes % 60
|
||||||
hours.positive? ? "#{hours}h #{mins}m" : "#{mins} min"
|
hours.positive? ? "#{hours}h #{mins}m" : "#{mins} min"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def admin_session_watch_links(session)
|
||||||
|
links = []
|
||||||
|
if session.matchlivetv_platform?
|
||||||
|
links << { label: I18n.t("admin.common.live_page"), url: session.watch_page_url }
|
||||||
|
end
|
||||||
|
youtube = session.youtube_watch_url
|
||||||
|
links << { label: "YouTube", url: youtube } if youtube.present?
|
||||||
|
links
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_session_ingest_badge_class(role_or_node)
|
||||||
|
role = role_or_node.respond_to?(:role) ? role_or_node.role : role_or_node
|
||||||
|
case role.to_s
|
||||||
|
when "home" then "badge--ingest-home"
|
||||||
|
when "lab" then "badge--ingest-lab"
|
||||||
|
when "cloud" then "badge--ingest-cloud"
|
||||||
|
else "badge--paused"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_session_ingest_role_label(role_or_node)
|
||||||
|
role = role_or_node.respond_to?(:role) ? role_or_node.role : role_or_node
|
||||||
|
I18n.t("admin.sessions.ingest.role.#{role}", default: role.to_s.humanize)
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_session_status_badge_class(status)
|
||||||
|
case status.to_s
|
||||||
|
when "live" then "badge--live"
|
||||||
|
when "connecting", "reconnecting" then "badge--connecting"
|
||||||
|
when "paused", "idle" then "badge--paused"
|
||||||
|
when "ended" then "badge--ended"
|
||||||
|
when "error" then "badge--error"
|
||||||
|
else "badge--paused"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_datetime(time, with_seconds: false)
|
||||||
|
return I18n.t("admin.common.dash") if time.blank?
|
||||||
|
|
||||||
|
format = with_seconds ? "%d/%m/%Y %H:%M:%S" : "%d/%m/%Y %H:%M"
|
||||||
|
time.in_time_zone.strftime(format)
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_session_duration_label(session)
|
||||||
|
secs = session.total_duration_secs.to_i
|
||||||
|
if secs <= 0 && session.started_at
|
||||||
|
end_time = session.ended_at || (session.terminal? ? session.updated_at : Time.current)
|
||||||
|
secs = (end_time - session.started_at).to_i if end_time
|
||||||
|
end
|
||||||
|
return I18n.t("admin.common.dash") if secs <= 0
|
||||||
|
|
||||||
|
hours = secs / 3600
|
||||||
|
mins = (secs % 3600) / 60
|
||||||
|
rem = secs % 60
|
||||||
|
if hours.positive?
|
||||||
|
format("%dh %02dm %02ds", hours, mins, rem)
|
||||||
|
elsif mins.positive?
|
||||||
|
format("%dm %02ds", mins, rem)
|
||||||
|
else
|
||||||
|
"#{rem}s"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_session_client_os_label(session)
|
||||||
|
case session.client_os.to_s
|
||||||
|
when "android" then "Android"
|
||||||
|
when "ios" then "iOS"
|
||||||
|
else I18n.t("admin.common.dash")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_session_client_summary(session)
|
||||||
|
parts = []
|
||||||
|
parts << admin_session_client_os_label(session) if session.client_os.present?
|
||||||
|
if session.app_version.present?
|
||||||
|
ver = session.app_version
|
||||||
|
ver = "#{ver} (#{session.app_build})" if session.app_build.present?
|
||||||
|
parts << "app #{ver}"
|
||||||
|
end
|
||||||
|
device = [session.device_manufacturer, session.device_model].compact_blank.join(" ")
|
||||||
|
parts << device if device.present?
|
||||||
|
parts << "OS #{session.os_version}" if session.os_version.present?
|
||||||
|
parts << session.carrier if session.carrier.present?
|
||||||
|
parts.presence&.join(" · ") || I18n.t("admin.common.dash")
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_format_event_meta(metadata)
|
||||||
|
return content_tag(:span, I18n.t("admin.common.dash"), class: "muted") if metadata.blank?
|
||||||
|
|
||||||
|
pairs = metadata.to_h
|
||||||
|
return content_tag(:span, I18n.t("admin.common.dash"), class: "muted") if pairs.empty?
|
||||||
|
|
||||||
|
content_tag(:dl, class: "admin-event-meta") do
|
||||||
|
safe_join(
|
||||||
|
pairs.map do |key, value|
|
||||||
|
content_tag(:div, class: "admin-event-meta__row") do
|
||||||
|
content_tag(:dt, key.to_s) +
|
||||||
|
content_tag(:dd, admin_event_meta_value(value))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_event_meta_value(value)
|
||||||
|
case value
|
||||||
|
when Hash, Array
|
||||||
|
content_tag(:code, value.to_json)
|
||||||
|
when TrueClass, FalseClass
|
||||||
|
value ? "true" : "false"
|
||||||
|
when NilClass
|
||||||
|
I18n.t("admin.common.dash")
|
||||||
|
else
|
||||||
|
value.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin_regia_expires_label(iso_time)
|
||||||
|
return if iso_time.blank?
|
||||||
|
|
||||||
|
Time.zone.parse(iso_time).strftime("%d/%m/%Y %H:%M")
|
||||||
|
rescue ArgumentError, TypeError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def announcement_status_badge(item)
|
||||||
|
case item.status
|
||||||
|
when "published" then item.severity == "critical" ? "live" : "ready"
|
||||||
|
when "archived" then "paused"
|
||||||
|
else "connecting"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def announcement_window_label(item)
|
||||||
|
start_label = item.starts_at&.in_time_zone&.strftime("%d/%m %H:%M")
|
||||||
|
end_label = item.ends_at&.in_time_zone&.strftime("%d/%m %H:%M")
|
||||||
|
if start_label && end_label
|
||||||
|
"#{start_label} → #{end_label}"
|
||||||
|
elsif start_label
|
||||||
|
I18n.t("admin.announcements.window.from", time: start_label)
|
||||||
|
elsif end_label
|
||||||
|
I18n.t("admin.announcements.window.until", time: end_label)
|
||||||
|
else
|
||||||
|
I18n.t("admin.announcements.window.always")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def announcement_channels_label(item)
|
||||||
|
labels = item.selected_channels.map { |key| I18n.t("admin.announcements.channels.#{key}") }
|
||||||
|
labels.presence&.join(" · ") || I18n.t("admin.common.dash")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,11 +9,58 @@ module ApplicationHelper
|
|||||||
PLAN_ICONS[plan.slug] || "fa-solid fa-circle"
|
PLAN_ICONS[plan.slug] || "fa-solid fa-circle"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Data/ora nel fuso dell'app (Europe/Rome) e nella lingua del sito.
|
# Data/ora nel fuso dell'app (Europe/Rome) e nella lingua corrente.
|
||||||
def l_local(date_or_time, format: :long)
|
def l_local(date_or_time, format: :long)
|
||||||
return nil if date_or_time.blank?
|
return nil if date_or_time.blank?
|
||||||
|
|
||||||
value = date_or_time.respond_to?(:in_time_zone) ? date_or_time.in_time_zone : date_or_time
|
value = date_or_time.respond_to?(:in_time_zone) ? date_or_time.in_time_zone : date_or_time
|
||||||
I18n.with_locale(:it) { I18n.l(value, format: format) }
|
I18n.l(value, format: format)
|
||||||
|
end
|
||||||
|
|
||||||
|
def og_locale_tag
|
||||||
|
{
|
||||||
|
it: "it_IT",
|
||||||
|
en: "en_US",
|
||||||
|
fr: "fr_FR",
|
||||||
|
de: "de_DE",
|
||||||
|
es: "es_ES"
|
||||||
|
}.fetch(I18n.locale.to_sym, "it_IT")
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_lang
|
||||||
|
I18n.locale.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def confirm_dialog_i18n_json
|
||||||
|
{
|
||||||
|
eyebrow: t("common.confirm_eyebrow"),
|
||||||
|
title: t("common.confirm_title"),
|
||||||
|
deleteTitle: t("common.delete_title"),
|
||||||
|
confirmOk: t("common.confirm_ok"),
|
||||||
|
deleteOk: t("common.delete_ok"),
|
||||||
|
cancel: t("common.cancel"),
|
||||||
|
multiDeleteTitle: t("common.multi_delete_title"),
|
||||||
|
multiDeleteMessage: t("common.multi_delete_message"),
|
||||||
|
deleteYoutubeTitle: t("common.delete_youtube_title"),
|
||||||
|
deleteYoutubeMessage: t("common.delete_youtube_message"),
|
||||||
|
deleteYoutubeOk: t("common.delete_youtube_ok"),
|
||||||
|
deleteSiteTitle: t("common.delete_site_title"),
|
||||||
|
deleteSiteMessageWithYoutube: t("common.delete_site_message_with_youtube"),
|
||||||
|
deleteSiteMessageOnly: t("common.delete_site_message_only"),
|
||||||
|
deleteSiteOk: t("common.delete_site_ok"),
|
||||||
|
choiceSiteLabel: t("common.choice_site_label"),
|
||||||
|
choiceSiteHintWithYoutube: t("common.choice_site_hint_with_youtube"),
|
||||||
|
choiceSiteHintOnly: t("common.choice_site_hint_only"),
|
||||||
|
choiceYoutubeLabel: t("common.choice_youtube_label"),
|
||||||
|
choiceYoutubeHintWithSite: t("common.choice_youtube_hint_with_site"),
|
||||||
|
choiceYoutubeHintOnly: t("common.choice_youtube_hint_only"),
|
||||||
|
choiceBothLabel: t("common.choice_both_label"),
|
||||||
|
choiceBothHint: t("common.choice_both_hint")
|
||||||
|
}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def sport_catalog_options(selected = nil)
|
||||||
|
options = Sports::Catalog.as_api_list.map { |entry| [entry[:label], entry[:key]] }
|
||||||
|
options_for_select(options, Sports::Catalog.normalize_key(selected))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module LegalHelper
|
module LegalHelper
|
||||||
def legal_last_updated
|
def legal_last_updated
|
||||||
"3 giugno 2026"
|
"20 agosto 2026"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cookie_policy_last_updated
|
def cookie_policy_last_updated
|
||||||
|
|||||||
@@ -1,26 +1,59 @@
|
|||||||
module Public
|
module Public
|
||||||
module BillingHelper
|
module BillingHelper
|
||||||
def plan_billing_action(current_slug:, target_plan:, stripe_subscription_active:, current_interval: nil, subscription: nil)
|
def plan_billing_action(current_slug:, target_plan:, stripe_subscription_active:, current_interval: nil, subscription: nil, club: nil)
|
||||||
if target_plan.slug == "free"
|
if target_plan.slug == "free"
|
||||||
return { kind: :current, label: "Piano attuale" } if current_slug == "free"
|
return { kind: :current, label: I18n.t("billing.actions.current_plan") } if current_slug == "free"
|
||||||
return { kind: :none } if stripe_subscription_active
|
return { kind: :none } if stripe_subscription_active
|
||||||
|
|
||||||
return { kind: :contact, label: "Per passare al piano Free, contatta il supporto." }
|
return { kind: :contact, label: I18n.t("billing.actions.contact_for_free") }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
quote = club&.active_billing_quote
|
||||||
|
if quote
|
||||||
|
if quote.plan_slug == target_plan.slug
|
||||||
|
if current_paid_plan?(subscription, target_plan)
|
||||||
|
return {
|
||||||
|
kind: :current,
|
||||||
|
label: "#{I18n.t('billing.actions.current_plan')} — #{quote.price_label}"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return { kind: :quoted, plan: target_plan, quote: quote, intervals: [quote.billing_interval] }
|
||||||
|
end
|
||||||
|
|
||||||
|
return { kind: :quoted_other, label: I18n.t("billing.bank_transfer.quoted_other") }
|
||||||
|
end
|
||||||
|
|
||||||
|
intervals = bank_transfer_intervals_for(target_plan)
|
||||||
unless MatchLiveTv.stripe_enabled?
|
unless MatchLiveTv.stripe_enabled?
|
||||||
return { kind: :disabled, label: "Stripe non configurato" }
|
if current_paid_plan?(subscription, target_plan)
|
||||||
|
return { kind: :current, label: current_plan_label(target_plan, subscription) }
|
||||||
|
end
|
||||||
|
if MatchLiveTv.bank_transfer_configured?
|
||||||
|
return { kind: :bank_only, plan: target_plan, intervals: intervals }
|
||||||
|
end
|
||||||
|
|
||||||
|
return { kind: :disabled, label: I18n.t("billing.actions.stripe_not_configured") }
|
||||||
end
|
end
|
||||||
|
|
||||||
intervals = Billing::Stripe::PriceCatalog.available_intervals(plan_slug: target_plan.slug)
|
stripe_intervals = Billing::Stripe::PriceCatalog.available_intervals(plan_slug: target_plan.slug)
|
||||||
return { kind: :disabled, label: "Prezzi Stripe non configurati" } if intervals.empty?
|
if stripe_intervals.empty?
|
||||||
|
if current_paid_plan?(subscription, target_plan)
|
||||||
|
return { kind: :current, label: current_plan_label(target_plan, subscription) }
|
||||||
|
end
|
||||||
|
if MatchLiveTv.bank_transfer_configured?
|
||||||
|
return { kind: :bank_only, plan: target_plan, intervals: intervals }
|
||||||
|
end
|
||||||
|
|
||||||
|
return { kind: :disabled, label: I18n.t("billing.actions.stripe_prices_not_configured") }
|
||||||
|
end
|
||||||
|
|
||||||
active_interval = current_interval.presence || Billing::Stripe::PriceCatalog::DEFAULT_INTERVAL
|
active_interval = current_interval.presence || Billing::Stripe::PriceCatalog::DEFAULT_INTERVAL
|
||||||
|
|
||||||
if current_slug == target_plan.slug && stripe_subscription_active && !subscription&.plan_change_pending?
|
if current_slug == target_plan.slug && stripe_subscription_active && !subscription&.plan_change_pending?
|
||||||
other_intervals = intervals - [active_interval]
|
other_intervals = stripe_intervals - [active_interval]
|
||||||
if other_intervals.empty?
|
if other_intervals.empty?
|
||||||
label = "Piano attuale — #{Billing::Stripe::PriceCatalog.label(plan_slug: target_plan.slug, interval: active_interval)}"
|
label = "#{I18n.t('billing.actions.current_plan')} — #{Billing::Stripe::PriceCatalog.label(plan_slug: target_plan.slug, interval: active_interval)}"
|
||||||
return { kind: :current, label: label }
|
return { kind: :current, label: label }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -34,13 +67,17 @@ module Public
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if current_paid_plan?(subscription, target_plan)
|
||||||
|
return { kind: :current, label: current_plan_label(target_plan, subscription) }
|
||||||
|
end
|
||||||
|
|
||||||
if current_slug == "free" || !stripe_subscription_active
|
if current_slug == "free" || !stripe_subscription_active
|
||||||
{ kind: :checkout_options, plan: target_plan, intervals: intervals, subscription: subscription }
|
{ kind: :checkout_options, plan: target_plan, intervals: stripe_intervals.presence || intervals, subscription: subscription }
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
kind: :change_options,
|
kind: :change_options,
|
||||||
plan: target_plan,
|
plan: target_plan,
|
||||||
intervals: intervals,
|
intervals: stripe_intervals,
|
||||||
current_slug: current_slug,
|
current_slug: current_slug,
|
||||||
current_interval: active_interval,
|
current_interval: active_interval,
|
||||||
subscription: subscription
|
subscription: subscription
|
||||||
@@ -57,6 +94,10 @@ module Public
|
|||||||
Billing::Stripe::PlanChangeMessages.button_label(plan: plan, interval: interval, kind: btn_kind)
|
Billing::Stripe::PlanChangeMessages.button_label(plan: plan, interval: interval, kind: btn_kind)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def plan_cta_name(plan)
|
||||||
|
I18n.t("pages.plans.cta_name.#{plan.slug}", default: plan.name)
|
||||||
|
end
|
||||||
|
|
||||||
def billing_plan_change_info_lines(subscription: nil)
|
def billing_plan_change_info_lines(subscription: nil)
|
||||||
Billing::Stripe::PlanChangeMessages.billing_info_lines(subscription: subscription)
|
Billing::Stripe::PlanChangeMessages.billing_info_lines(subscription: subscription)
|
||||||
end
|
end
|
||||||
@@ -87,10 +128,46 @@ module Public
|
|||||||
|
|
||||||
def billing_profile_incomplete_message(club)
|
def billing_profile_incomplete_message(club)
|
||||||
missing = club.billing_profile_errors
|
missing = club.billing_profile_errors
|
||||||
return "Completa i dati di fatturazione prima di attivare un piano premium." if missing.empty?
|
return I18n.t("billing.actions.profile_incomplete_default") if missing.empty?
|
||||||
|
|
||||||
"Mancano: #{missing.join(", ")}."
|
I18n.t("billing.actions.profile_missing", fields: missing.join(", "))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bank_transfer_intervals_for(plan)
|
||||||
|
Billing::Stripe::PriceCatalog.catalog_intervals(plan_slug: plan.slug)
|
||||||
|
end
|
||||||
|
|
||||||
|
def bank_transfer_price_label(plan, interval, quote: nil)
|
||||||
|
if quote&.matches?(plan.slug, interval)
|
||||||
|
quote.price_label
|
||||||
|
else
|
||||||
|
Billing::Stripe::PriceCatalog.format_interval_price(
|
||||||
|
Billing::Stripe::PriceCatalog.amount_cents(plan_slug: plan.slug, interval: interval),
|
||||||
|
interval
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_bank_transfer_for?(club:, plan:, interval:, quote: nil, pending_transfer: nil)
|
||||||
|
return false unless club.present? && plan.slug != "free"
|
||||||
|
return false unless MatchLiveTv.bank_transfer_configured?
|
||||||
|
return false if quote && !quote.matches?(plan.slug, interval)
|
||||||
|
return false if pending_transfer&.awaiting_payment?
|
||||||
|
return false if current_paid_plan?(club.subscription, plan)
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_paid_plan?(subscription, target_plan)
|
||||||
|
return false unless subscription&.active? && subscription.premium?
|
||||||
|
return false if subscription.plan_change_pending?
|
||||||
|
|
||||||
|
subscription.plan.slug == target_plan.slug
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_plan_label(target_plan, subscription)
|
||||||
|
interval = subscription&.billing_interval.presence || Billing::Stripe::PriceCatalog::DEFAULT_INTERVAL
|
||||||
|
"#{I18n.t('billing.actions.current_plan')} — #{Billing::Stripe::PriceCatalog.label(plan_slug: target_plan.slug, interval: interval)}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
module Public
|
module Public
|
||||||
module LiveHelper
|
module LiveHelper
|
||||||
def live_score_sets_label(score_state)
|
def live_score_sets_label(score_state, match = nil)
|
||||||
return nil unless score_state
|
return nil unless score_state
|
||||||
|
|
||||||
"Set #{score_state.current_set} · Set vinti #{score_state.home_sets}-#{score_state.away_sets}"
|
board = match&.effective_board_type || score_state.effective_board_type
|
||||||
|
case board
|
||||||
|
when "basket", "timed"
|
||||||
|
live_score_period_label(match, score_state)
|
||||||
|
when "timer"
|
||||||
|
t("score.timer_label")
|
||||||
|
when "generic"
|
||||||
|
t("score.generic_label")
|
||||||
|
else
|
||||||
|
t("score.sets_label", set: score_state.current_set, home: score_state.home_sets, away: score_state.away_sets)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def live_score_period_label(match, score_state)
|
||||||
|
return t("score.fallback") unless score_state
|
||||||
|
|
||||||
|
score_state.current_period_label
|
||||||
end
|
end
|
||||||
|
|
||||||
def live_score_partials_label(score_state)
|
def live_score_partials_label(score_state)
|
||||||
return nil unless score_state
|
return nil unless score_state
|
||||||
|
return nil unless score_state.effective_board_type.in?(%w[volley racket])
|
||||||
|
|
||||||
partials = Array(score_state.set_partials)
|
partials = Array(score_state.set_partials)
|
||||||
return nil if partials.empty?
|
return nil if partials.empty?
|
||||||
@@ -18,35 +35,41 @@ module Public
|
|||||||
def live_scheduled_label(datetime)
|
def live_scheduled_label(datetime)
|
||||||
return nil unless datetime
|
return nil unless datetime
|
||||||
|
|
||||||
datetime.in_time_zone.strftime("%d/%m/%Y alle %H:%M")
|
datetime.in_time_zone.strftime(t("score.scheduled_date_format"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def live_scheduled_relative(datetime)
|
def live_scheduled_relative(datetime)
|
||||||
return nil unless datetime
|
return nil unless datetime
|
||||||
|
|
||||||
if datetime.to_date == Time.zone.today
|
if datetime.to_date == Time.zone.today
|
||||||
"Oggi alle #{datetime.strftime('%H:%M')}"
|
t("score.scheduled_today", time: datetime.strftime("%H:%M"))
|
||||||
elsif datetime.to_date == Time.zone.tomorrow
|
elsif datetime.to_date == Time.zone.tomorrow
|
||||||
"Domani alle #{datetime.strftime('%H:%M')}"
|
t("score.scheduled_tomorrow", time: datetime.strftime("%H:%M"))
|
||||||
else
|
else
|
||||||
live_scheduled_label(datetime)
|
live_scheduled_label(datetime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def live_match_card_heading(match)
|
def live_match_card_heading(match, link_team: true)
|
||||||
team = match.team
|
team = match.team
|
||||||
club_name = team.club&.name.presence || "Società"
|
club_name = team.club&.name.presence || t("score.default_club_name")
|
||||||
|
team_slug = team.respond_to?(:slug) ? team.slug : nil
|
||||||
|
team_label = if link_team && team_slug.present?
|
||||||
|
link_to(team.name, public_team_page_path(team_slug), class: "live-card__team-link")
|
||||||
|
else
|
||||||
|
team.name
|
||||||
|
end
|
||||||
content_tag(:h3, class: "live-card__title") do
|
content_tag(:h3, class: "live-card__title") do
|
||||||
safe_join([
|
safe_join([
|
||||||
content_tag(:span, club_name, class: "live-card__club"),
|
content_tag(:span, club_name, class: "live-card__club"),
|
||||||
content_tag(:span, "#{team.name} vs #{match.opponent_name}", class: "live-card__matchup")
|
content_tag(:span, safe_join([team_label, " vs ", match.opponent_name]), class: "live-card__matchup")
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def live_match_page_heading(match)
|
def live_match_page_heading(match)
|
||||||
team = match.team
|
team = match.team
|
||||||
club_name = team.club&.name.presence || "Società"
|
club_name = team.club&.name.presence || t("score.default_club_name")
|
||||||
content_tag(:div, class: "live-page-heading") do
|
content_tag(:div, class: "live-page-heading") do
|
||||||
safe_join([
|
safe_join([
|
||||||
content_tag(:p, club_name, class: "live-page-heading__club"),
|
content_tag(:p, club_name, class: "live-page-heading__club"),
|
||||||
@@ -56,39 +79,33 @@ module Public
|
|||||||
end
|
end
|
||||||
|
|
||||||
def live_score_points_label(match, score_state)
|
def live_score_points_label(match, score_state)
|
||||||
return "—" unless score_state
|
return t("score.fallback") unless score_state
|
||||||
|
|
||||||
"#{match.team.name} #{score_state.home_points} - #{score_state.away_points} #{match.opponent_name}"
|
board = match.effective_board_type
|
||||||
end
|
home = case board
|
||||||
|
when "basket", "timed" then score_state.basket_home_score
|
||||||
|
else score_state.home_points
|
||||||
|
end
|
||||||
|
away = case board
|
||||||
|
when "basket", "timed" then score_state.basket_away_score
|
||||||
|
else score_state.away_points
|
||||||
|
end
|
||||||
|
|
||||||
# Colore ospite sul tabellone: secondario società se leggibile su bianco, altrimenti blu visitatore.
|
t("score.points_label", team: match.team.name, home: home, away: away, opponent: match.opponent_name)
|
||||||
def live_scorebug_away_color(team)
|
|
||||||
club = team.club
|
|
||||||
candidate = club&.effective_secondary_color.presence || "#1565c0"
|
|
||||||
return candidate unless light_hex_color?(candidate)
|
|
||||||
|
|
||||||
"#1565c0"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def light_hex_color?(hex)
|
|
||||||
h = hex.to_s.delete_prefix("#")
|
|
||||||
return false unless h.match?(/\A\h{6}\z/i)
|
|
||||||
|
|
||||||
r = h[0..1].to_i(16)
|
|
||||||
g = h[2..3].to_i(16)
|
|
||||||
b = h[4..5].to_i(16)
|
|
||||||
(0.299 * r + 0.587 * g + 0.114 * b) > 200
|
|
||||||
end
|
|
||||||
|
|
||||||
def format_set_partial_entry(partial)
|
def format_set_partial_entry(partial)
|
||||||
data = partial.respond_to?(:with_indifferent_access) ? partial.with_indifferent_access : partial
|
data = partial.respond_to?(:with_indifferent_access) ? partial.with_indifferent_access : partial
|
||||||
set_no = data[:set] || data["set"]
|
set_no = data[:set] || data["set"]
|
||||||
home = data[:home] || data["home"]
|
home = data[:home] || data["home"]
|
||||||
away = data[:away] || data["away"]
|
away = data[:away] || data["away"]
|
||||||
label = set_no.present? ? "Set #{set_no}" : "Set"
|
if set_no.present?
|
||||||
"#{label} #{home}-#{away}"
|
t("score.partial_entry", set: set_no, home: home, away: away)
|
||||||
|
else
|
||||||
|
t("score.partial_entry_no_number", home: home, away: away)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
module Public
|
||||||
|
module RegiaHelper
|
||||||
|
def regia_board_partial(match)
|
||||||
|
board = match.effective_board_type
|
||||||
|
partial = "public/regia/#{board}"
|
||||||
|
lookup_context.exists?(partial, [], true) ? partial : "public/regia/volley"
|
||||||
|
end
|
||||||
|
|
||||||
|
def regia_header_subtitle(match, score)
|
||||||
|
board = match.effective_board_type
|
||||||
|
case board
|
||||||
|
when "basket", "timed"
|
||||||
|
live_score_period_label(match, score)
|
||||||
|
when "timer"
|
||||||
|
t("regia.board.stopwatch")
|
||||||
|
when "generic"
|
||||||
|
t("regia.board.generic_score")
|
||||||
|
else
|
||||||
|
t("regia.board.set_label", number: score.current_set)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def regia_js_i18n_json
|
||||||
|
{
|
||||||
|
periodUpdated: t("regia.js.period_updated"),
|
||||||
|
nowInPeriodTemplate: t("regia.js.now_in_period", period: "%{period}"),
|
||||||
|
setWonTitle: t("regia.modal.set_won_title"),
|
||||||
|
setWonBodyTemplate: t("regia.js.set_won_body", winner: "%{winner}"),
|
||||||
|
matchWonTitle: t("regia.js.match_won_title"),
|
||||||
|
matchWonBodyTemplate: t("regia.js.match_won_body", winner: "%{winner}"),
|
||||||
|
closeSetTitle: t("regia.board.close_set"),
|
||||||
|
closeSetConfirm: t("regia.js.close_set_confirm"),
|
||||||
|
scoreUpdateError: t("regia.js.score_update_error"),
|
||||||
|
genericError: t("regia.js.generic_error"),
|
||||||
|
setsLineTemplate: t("regia.js.sets_line", current: "%{current}", home: "%{home}", away: "%{away}"),
|
||||||
|
setPartialLabelTemplate: t("regia.board.set_label", number: "%{number}"),
|
||||||
|
freeScore: t("regia.board.free_score"),
|
||||||
|
stopwatch: t("regia.board.stopwatch"),
|
||||||
|
quarterLabelTemplate: t("regia.js.quarter_label", n: "%{n}"),
|
||||||
|
halfLabelTemplate: t("regia.js.half_label", n: "%{n}"),
|
||||||
|
overtimeBasketTemplate: t("regia.js.overtime_basket", n: "%{n}"),
|
||||||
|
overtimeOther: t("regia.js.overtime_other"),
|
||||||
|
unknownPeriod: t("regia.js.unknown_period"),
|
||||||
|
partialsPrefix: t("regia.board.partials_prefix"),
|
||||||
|
resumed: t("regia.js.resumed"),
|
||||||
|
pausedCover: t("regia.js.paused_cover"),
|
||||||
|
muted: t("regia.js.muted"),
|
||||||
|
unmuted: t("regia.js.unmuted"),
|
||||||
|
closed: t("regia.js.closed"),
|
||||||
|
resumeError: t("regia.js.resume_error"),
|
||||||
|
pauseError: t("regia.js.pause_error"),
|
||||||
|
muteError: t("regia.js.mute_error"),
|
||||||
|
closeError: t("regia.js.close_error"),
|
||||||
|
closeConfirm: t("regia.js.close_confirm"),
|
||||||
|
pauseConfirmTitle: t("regia.js.pause_confirm_title"),
|
||||||
|
pauseConfirmBody: t("regia.js.pause_confirm_body"),
|
||||||
|
resumeConfirmTitle: t("regia.js.resume_confirm_title"),
|
||||||
|
resumeConfirmBody: t("regia.js.resume_confirm_body"),
|
||||||
|
muteConfirmTitle: t("regia.js.mute_confirm_title"),
|
||||||
|
muteConfirmBody: t("regia.js.mute_confirm_body"),
|
||||||
|
unmuteConfirmTitle: t("regia.js.unmute_confirm_title"),
|
||||||
|
unmuteConfirmBody: t("regia.js.unmute_confirm_body"),
|
||||||
|
advancePeriodTitle: t("regia.js.advance_period_title"),
|
||||||
|
advancePeriodBody: t("regia.js.advance_period_body"),
|
||||||
|
confirmAction: t("regia.modal.confirm_action"),
|
||||||
|
stopConfirmTitle: t("regia.js.stop_confirm_title"),
|
||||||
|
linkUnavailable: t("regia.js.link_unavailable"),
|
||||||
|
linkCopied: t("regia.js.link_copied"),
|
||||||
|
copyPrompt: t("regia.js.copy_prompt"),
|
||||||
|
shareRegiaText: t("regia.js.share_regia_text"),
|
||||||
|
shareLiveText: t("regia.js.share_live_text"),
|
||||||
|
minQualityUpdated: t("regia.js.min_quality_updated"),
|
||||||
|
minQualityError: t("regia.js.min_quality_error"),
|
||||||
|
minQualityAuto: t("regia.min_quality.auto"),
|
||||||
|
previewWaiting: t("regia.preview_waiting"),
|
||||||
|
streamEnded: t("regia.preview_ended"),
|
||||||
|
previewHide: t("regia.preview_hide"),
|
||||||
|
previewShow: t("regia.preview_show"),
|
||||||
|
previewOffHint: t("regia.preview_off_hint"),
|
||||||
|
resumeLabel: t("regia.resume"),
|
||||||
|
pauseLabel: t("regia.pause"),
|
||||||
|
muteLabel: t("regia.mute"),
|
||||||
|
unmuteLabel: t("regia.unmute"),
|
||||||
|
endedBadge: t("regia.status.ended"),
|
||||||
|
pausedBadge: t("regia.status.paused"),
|
||||||
|
liveBadge: t("regia.status.live"),
|
||||||
|
waitingBadge: t("regia.status.waiting"),
|
||||||
|
subtitlePrefix: t("regia.subtitle_prefix"),
|
||||||
|
telemetryWaiting: t("regia.telemetry.waiting"),
|
||||||
|
telemetryStale: t("regia.telemetry.stale"),
|
||||||
|
telemetryJustNow: t("regia.telemetry.just_now"),
|
||||||
|
telemetrySecondsAgo: t("regia.telemetry.seconds_ago"),
|
||||||
|
telemetryPublisherOn: t("regia.telemetry.publisher_on"),
|
||||||
|
telemetryPublisherOff: t("regia.telemetry.publisher_off"),
|
||||||
|
telemetryThermalNominal: t("regia.telemetry.thermal_nominal"),
|
||||||
|
telemetryThermalFair: t("regia.telemetry.thermal_fair"),
|
||||||
|
telemetryThermalSerious: t("regia.telemetry.thermal_serious"),
|
||||||
|
telemetryThermalCritical: t("regia.telemetry.thermal_critical"),
|
||||||
|
telemetryBitrateMax: t("regia.telemetry.bitrate_max"),
|
||||||
|
telemetryBitrateTitle: t("regia.telemetry.bitrate_title"),
|
||||||
|
telemetryBitrateTap: t("regia.telemetry.bitrate_tap")
|
||||||
|
}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_clock_secs(secs, count_up: false)
|
||||||
|
total = secs.to_i
|
||||||
|
return count_up ? "0:00" : "—" if total <= 0 && !count_up
|
||||||
|
|
||||||
|
m = total / 60
|
||||||
|
s = total % 60
|
||||||
|
format("%d:%02d", m, s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
module Public
|
||||||
|
module TeamPagesHelper
|
||||||
|
def team_page_meta_description(team, club)
|
||||||
|
t("team_pages.show.meta_description", team: team.name, club: club.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_params_for_canonical
|
||||||
|
params.permit(:q, :sport, :live, :replays).to_h.compact_blank
|
||||||
|
end
|
||||||
|
|
||||||
|
def team_page_structured_data(team, club)
|
||||||
|
{
|
||||||
|
"@context" => "https://schema.org",
|
||||||
|
"@type" => "SportsTeam",
|
||||||
|
"name" => team.name,
|
||||||
|
"sport" => team.sport_label,
|
||||||
|
"url" => seo_absolute_url(public_team_page_path(team.slug)),
|
||||||
|
"memberOf" => {
|
||||||
|
"@type" => "SportsOrganization",
|
||||||
|
"name" => club.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
module RecordingsArchiveHelper
|
||||||
|
ArchivePaths = Struct.new(:index, :update, :destroy, :publish_youtube, :back, keyword_init: true)
|
||||||
|
|
||||||
|
def recordings_archive_paths(club, namespace:)
|
||||||
|
case namespace
|
||||||
|
when :admin
|
||||||
|
ArchivePaths.new(
|
||||||
|
index: admin_club_recordings_path(club),
|
||||||
|
update: ->(rec) { admin_club_recording_path(club, rec) },
|
||||||
|
destroy: ->(rec) { admin_club_recording_path(club, rec) },
|
||||||
|
publish_youtube: ->(rec) { publish_youtube_admin_club_recording_path(club, rec) },
|
||||||
|
back: admin_club_path(club)
|
||||||
|
)
|
||||||
|
else
|
||||||
|
ArchivePaths.new(
|
||||||
|
index: public_club_recordings_path(club),
|
||||||
|
update: ->(rec) { public_club_recording_path(club, rec) },
|
||||||
|
destroy: ->(rec) { public_club_recording_path(club, rec) },
|
||||||
|
publish_youtube: ->(rec) { public_club_recording_publish_youtube_path(club, rec) },
|
||||||
|
back: public_club_path(club)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -19,13 +19,14 @@ module RosterHelper
|
|||||||
|
|
||||||
def roster_category_options
|
def roster_category_options
|
||||||
TeamRosterMember::DISPLAY_ORDER.map do |cat|
|
TeamRosterMember::DISPLAY_ORDER.map do |cat|
|
||||||
[TeamRosterMember::CATEGORY_LABELS[cat], cat]
|
[TeamRosterMember.category_label(cat), cat]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def roster_player_role_options(selected = nil)
|
def roster_player_role_options(team, selected = nil)
|
||||||
|
roles = Sports::PlayerRoles.for_team(team)
|
||||||
options_for_select(
|
options_for_select(
|
||||||
[["— Seleziona ruolo —", ""]] + TeamRosterMember::VOLLEYBALL_PLAYER_ROLES.map { |r| [r, r] },
|
[[t("roster.role_select_blank"), ""]] + roles.map { |r| [r, r] },
|
||||||
selected
|
selected
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Analytics
|
||||||
|
class AggregateJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform(purge: false)
|
||||||
|
redis = Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"))
|
||||||
|
lock_key = "analytics:aggregate:lock"
|
||||||
|
acquired = redis.set(lock_key, "1", nx: true, ex: 120)
|
||||||
|
return unless acquired
|
||||||
|
|
||||||
|
begin
|
||||||
|
service = Analytics::Aggregate.new
|
||||||
|
service.call
|
||||||
|
service.purge_old! if purge
|
||||||
|
ensure
|
||||||
|
redis.del(lock_key)
|
||||||
|
end
|
||||||
|
rescue StandardError => e
|
||||||
|
Rails.logger.error("[analytics] aggregate failed: #{e.class} #{e.message}")
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,7 +6,7 @@ class CleanupExpiredSessionsJob
|
|||||||
.where("updated_at < ?", 6.hours.ago)
|
.where("updated_at < ?", 6.hours.ago)
|
||||||
.find_each do |session|
|
.find_each do |session|
|
||||||
session.fail! if session.may_fail?
|
session.fail! if session.may_fail?
|
||||||
Mediamtx::Client.new.delete_path(session)
|
Mediamtx::Client.for_session(session).delete_path(session)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,12 +6,37 @@ class ExpireEndedSubscriptionsJob
|
|||||||
free_plan = Plan["free"]
|
free_plan = Plan["free"]
|
||||||
|
|
||||||
Subscription.where(cancel_at_period_end: true)
|
Subscription.where(cancel_at_period_end: true)
|
||||||
.where("current_period_end <= ?", Time.current)
|
.where("current_period_end <= ?", Time.current)
|
||||||
.where.not(plan_id: free_plan.id)
|
.where.not(plan_id: free_plan.id)
|
||||||
.find_each do |sub|
|
.where(admin_comped: false)
|
||||||
Billing::Stripe::FinalizeSubscription.call(club: sub.club)
|
.find_each do |sub|
|
||||||
|
expire!(sub)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
Rails.logger.warn("[ExpireEndedSubscriptions] club=#{sub.club_id} #{e.message}")
|
Rails.logger.warn("[ExpireEndedSubscriptions] club=#{sub.club_id} #{e.message}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def expire!(sub)
|
||||||
|
if sub.stripe_subscription_id.present?
|
||||||
|
Billing::Stripe::FinalizeSubscription.call(club: sub.club)
|
||||||
|
else
|
||||||
|
Billing::AssignPlan.call(
|
||||||
|
club: sub.club,
|
||||||
|
plan_slug: "free",
|
||||||
|
status: "active",
|
||||||
|
stripe_attrs: {
|
||||||
|
stripe_subscription_id: nil,
|
||||||
|
stripe_schedule_id: nil,
|
||||||
|
current_period_start: nil,
|
||||||
|
current_period_end: nil,
|
||||||
|
cancel_at_period_end: false,
|
||||||
|
billing_interval: nil,
|
||||||
|
pending_plan_id: nil,
|
||||||
|
pending_billing_interval: nil
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
class GenerateCoverSlateJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def self.enqueue_for(record)
|
||||||
|
return unless record&.cover_image&.attached?
|
||||||
|
|
||||||
|
queue = record.is_a?(Match) ? :critical : :default
|
||||||
|
set(queue: queue).perform_later(record.class.name, record.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform(class_name, record_id)
|
||||||
|
record = class_name.constantize.find_by(id: record_id)
|
||||||
|
return unless record&.cover_image&.attached?
|
||||||
|
|
||||||
|
Streams::GenerateCoverSlate.call(record)
|
||||||
|
rescue Streams::GenerateCoverSlate::Error => e
|
||||||
|
Rails.logger.warn("[GenerateCoverSlateJob] #{class_name}##{record_id} #{e.message}")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
module Ops
|
||||||
|
class HealthMonitorJob
|
||||||
|
include Sidekiq::Job
|
||||||
|
|
||||||
|
sidekiq_options retry: 1, queue: "default"
|
||||||
|
|
||||||
|
INTERVAL_SECS = ENV.fetch("OPS_HEALTH_INTERVAL_SECS", "180").to_i
|
||||||
|
REDIS_CHAIN_KEY = "ops:health_monitor:chain"
|
||||||
|
HEARTBEAT_KEY = "ops:health_monitor:last_run"
|
||||||
|
|
||||||
|
def self.ensure_chain
|
||||||
|
return unless redis
|
||||||
|
|
||||||
|
return if redis.get(REDIS_CHAIN_KEY)
|
||||||
|
|
||||||
|
redis.set(REDIS_CHAIN_KEY, "1", ex: INTERVAL_SECS * 2)
|
||||||
|
perform_in(INTERVAL_SECS)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.redis
|
||||||
|
@redis ||= Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"))
|
||||||
|
rescue Redis::CannotConnectError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
self.class.redis&.set(HEARTBEAT_KEY, Time.current.to_i, ex: INTERVAL_SECS * 3)
|
||||||
|
Ops::HealthChecks.new.call
|
||||||
|
ensure
|
||||||
|
self.class.perform_in(INTERVAL_SECS)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
module Recordings
|
||||||
|
class CleanupLocalJob
|
||||||
|
include Sidekiq::Job
|
||||||
|
sidekiq_options retry: 1, queue: "default"
|
||||||
|
|
||||||
|
def perform
|
||||||
|
result = Recordings::CleanupLocal.new.call
|
||||||
|
orphan = Mediamtx::CleanupOrphanPaths.new.call
|
||||||
|
Rails.logger.info(
|
||||||
|
"[Recordings::CleanupLocalJob] removed=#{result.removed} " \
|
||||||
|
"freed=#{result.freed_bytes} skipped=#{result.skipped} " \
|
||||||
|
"orphan_paths=#{orphan.removed}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Recordings
|
||||||
|
class ClearTemporaryMediaJob
|
||||||
|
include Sidekiq::Job
|
||||||
|
sidekiq_options retry: 3, queue: "default"
|
||||||
|
|
||||||
|
def perform(recording_id, reason = "verified")
|
||||||
|
recording = Recording.find_by(id: recording_id)
|
||||||
|
return unless recording
|
||||||
|
|
||||||
|
Recordings::ClearTemporaryMedia.new(
|
||||||
|
recording,
|
||||||
|
reason: reason.to_sym,
|
||||||
|
force: reason.to_s == "verified"
|
||||||
|
).call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Recordings
|
module Recordings
|
||||||
class PostProcessJob
|
class PostProcessJob
|
||||||
include Sidekiq::Job
|
include Sidekiq::Job
|
||||||
@@ -7,10 +9,30 @@ module Recordings
|
|||||||
recording = Recording.find_by(id: recording_id)
|
recording = Recording.find_by(id: recording_id)
|
||||||
return unless recording&.ready?
|
return unless recording&.ready?
|
||||||
|
|
||||||
Recordings::NotifyReady.new(recording).call
|
begin
|
||||||
|
Recordings::NotifyReady.new(recording).call
|
||||||
|
rescue StandardError => e
|
||||||
|
# SMTP/ntfy giù non deve bloccare VerifyYoutubeReplay né il resto del post-process.
|
||||||
|
Rails.logger.warn(
|
||||||
|
"[Recordings::PostProcessJob] notify_failed recording=#{recording.id} " \
|
||||||
|
"#{e.class}: #{e.message}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if recording.temporary_storage?
|
||||||
|
grace = MatchLiveTv.youtube_replay_verify_grace_secs
|
||||||
|
Rails.logger.info(
|
||||||
|
"[Recordings::PostProcessJob] schedule VerifyYoutubeReplay " \
|
||||||
|
"recording=#{recording.id} grace=#{grace}s"
|
||||||
|
)
|
||||||
|
Recordings::VerifyYoutubeReplayJob.perform_in(grace.seconds, recording.id, 0)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Solo MatchLiveTV-only: eventuale re-upload manuale/flag legacy (non per live YouTube).
|
||||||
return unless recording.auto_publish_youtube?
|
return unless recording.auto_publish_youtube?
|
||||||
return if recording.youtube_video_id.present?
|
return if recording.youtube_video_id.present?
|
||||||
|
return if recording.source_platform == "youtube"
|
||||||
|
|
||||||
Recordings::PublishToYoutubeJob.perform_async(recording.id)
|
Recordings::PublishToYoutubeJob.perform_async(recording.id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Recordings
|
||||||
|
# Safety net: elimina copie temp scadute (anche se verify non è mai riuscito).
|
||||||
|
class PurgeTemporaryMediaJob
|
||||||
|
include Sidekiq::Job
|
||||||
|
sidekiq_options retry: 1, queue: "default"
|
||||||
|
|
||||||
|
def perform
|
||||||
|
scope = Recording.temporary_media_pending_purge
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
scope.find_each do |recording|
|
||||||
|
unless recording.youtube_verified_at.present?
|
||||||
|
Rails.logger.warn(
|
||||||
|
"[Recordings::PurgeTemporaryMediaJob] anomaly_unverified_expiry " \
|
||||||
|
"recording=#{recording.id} session=#{recording.stream_session_id} " \
|
||||||
|
"youtube_video_id=#{recording.youtube_video_id.inspect} " \
|
||||||
|
"temp_expires_at=#{recording.temp_expires_at.inspect}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
Recordings::ClearTemporaryMedia.new(
|
||||||
|
recording,
|
||||||
|
reason: :max_retention,
|
||||||
|
force: true
|
||||||
|
).call
|
||||||
|
count += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
Rails.logger.info("[Recordings::PurgeTemporaryMediaJob] processed=#{count}")
|
||||||
|
count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
module Recordings
|
||||||
|
class SyncYoutubePrivacyJob
|
||||||
|
include Sidekiq::Job
|
||||||
|
sidekiq_options retry: 2, queue: "default"
|
||||||
|
|
||||||
|
def perform(recording_id)
|
||||||
|
recording = Recording.find_by(id: recording_id)
|
||||||
|
return unless recording&.youtube_video_id.present?
|
||||||
|
|
||||||
|
Youtube::VideoLifecycleService.new(recording).update_privacy!(
|
||||||
|
privacy_status: recording.privacy_status
|
||||||
|
)
|
||||||
|
rescue Youtube::VideoLifecycleService::Error => e
|
||||||
|
Rails.logger.warn("[SyncYoutubePrivacyJob] #{recording_id}: #{e.message}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Recordings
|
||||||
|
class VerifyYoutubeReplayJob
|
||||||
|
include Sidekiq::Job
|
||||||
|
sidekiq_options retry: 0, queue: "default"
|
||||||
|
|
||||||
|
def perform(recording_id, attempt = 0)
|
||||||
|
recording = Recording.find_by(id: recording_id)
|
||||||
|
return unless recording&.temporary_storage?
|
||||||
|
return if recording.deleted?
|
||||||
|
|
||||||
|
attempt = attempt.to_i
|
||||||
|
max = MatchLiveTv.youtube_replay_verify_max_attempts
|
||||||
|
result = Recordings::VerifyYoutubeReplay.new(recording).call
|
||||||
|
|
||||||
|
if result.ok?
|
||||||
|
Recordings::ClearTemporaryMediaJob.perform_async(recording.id, "verified")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if result.retriable? && attempt + 1 < max
|
||||||
|
delay = backoff_secs(attempt)
|
||||||
|
Rails.logger.info(
|
||||||
|
"[Recordings::VerifyYoutubeReplayJob] retry recording=#{recording.id} " \
|
||||||
|
"attempt=#{attempt + 1}/#{max} in=#{delay}s msg=#{result.message}"
|
||||||
|
)
|
||||||
|
self.class.perform_in(delay.seconds, recording.id, attempt + 1)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
Rails.logger.warn(
|
||||||
|
"[Recordings::VerifyYoutubeReplayJob] give_up recording=#{recording.id} " \
|
||||||
|
"attempts=#{attempt + 1} msg=#{result.message} " \
|
||||||
|
"temp_expires_at=#{recording.temp_expires_at.inspect}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def backoff_secs(attempt)
|
||||||
|
base = MatchLiveTv.youtube_replay_verify_base_interval_secs
|
||||||
|
# 300, 600, 1200, ... capped at 1h
|
||||||
|
[base * (2**attempt), 3600].min
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Streams
|
||||||
|
class AutoscalerJob
|
||||||
|
include Sidekiq::Job
|
||||||
|
|
||||||
|
sidekiq_options retry: 1, queue: "default"
|
||||||
|
|
||||||
|
INTERVAL_SECS = ENV.fetch("STREAM_AUTOSCALE_INTERVAL_SECS", "60").to_i
|
||||||
|
REDIS_CHAIN_KEY = "streams:autoscaler:chain"
|
||||||
|
KICK_DEBOUNCE_KEY = "streams:autoscaler:kick"
|
||||||
|
KICK_DEBOUNCE_SECS = ENV.fetch("STREAM_AUTOSCALE_KICK_DEBOUNCE_SECS", "5").to_i
|
||||||
|
|
||||||
|
def self.ensure_chain
|
||||||
|
return unless redis
|
||||||
|
return if redis.get(REDIS_CHAIN_KEY)
|
||||||
|
|
||||||
|
redis.set(REDIS_CHAIN_KEY, "1", ex: INTERVAL_SECS * 2)
|
||||||
|
perform_in(INTERVAL_SECS)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Kick immediato (es. NoCapacity / soft-free bassi). Debounce anti-flood Sidekiq.
|
||||||
|
def self.kick!
|
||||||
|
return false unless Streams::Autoscaler.enabled?
|
||||||
|
return false unless redis
|
||||||
|
return false unless redis.set(KICK_DEBOUNCE_KEY, "1", nx: true, ex: KICK_DEBOUNCE_SECS)
|
||||||
|
|
||||||
|
perform_async
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.redis
|
||||||
|
@redis ||= Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"))
|
||||||
|
rescue Redis::CannotConnectError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
Streams::Autoscaler.reconcile!
|
||||||
|
ensure
|
||||||
|
self.class.redis&.set(REDIS_CHAIN_KEY, "1", ex: INTERVAL_SECS * 2)
|
||||||
|
self.class.perform_in(INTERVAL_SECS)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Avvia/riavvia il relay YouTube solo nel container sidekiq (YOUTUBE_RELAY_WORKER=1).
|
# Avvia/riavvia il relay YouTube sul worker del nodo (coda youtube_relay_<slug>).
|
||||||
class YoutubeRelayEnsureJob < ApplicationJob
|
class YoutubeRelayEnsureJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as Streams::YoutubeRelay::QUEUE
|
||||||
|
|
||||||
def perform(session_id)
|
def perform(session_id)
|
||||||
session = StreamSession.find_by(id: session_id)
|
session = StreamSession.find_by(id: session_id)
|
||||||
|
|||||||
@@ -1,10 +1,23 @@
|
|||||||
|
# Ferma il relay solo sull'owner. Se il job gira su un altro host, requeue breve.
|
||||||
class YoutubeRelayStopJob < ApplicationJob
|
class YoutubeRelayStopJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as Streams::YoutubeRelay::QUEUE
|
||||||
|
|
||||||
def perform(session_id)
|
discard_on ActiveJob::DeserializationError
|
||||||
|
|
||||||
|
def perform(session_id, attempts = 0)
|
||||||
session = StreamSession.find_by(id: session_id)
|
session = StreamSession.find_by(id: session_id)
|
||||||
return unless session
|
return unless session
|
||||||
|
|
||||||
Streams::YoutubeRelay.stop_on_worker!(session) if Streams::YoutubeRelay.worker?
|
unless Streams::YoutubeRelay.worker?
|
||||||
|
# Solo i worker relay processano questa coda in modo utile.
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
result = Streams::YoutubeRelay.stop_on_worker!(session)
|
||||||
|
return unless result == :wrong_host
|
||||||
|
return if attempts >= 30
|
||||||
|
|
||||||
|
self.class.set(wait: 2.seconds, queue: Streams::YoutubeRelay.queue_for(session))
|
||||||
|
.perform_later(session_id, attempts + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
module Billing
|
||||||
|
class BankTransferMailer < ApplicationMailer
|
||||||
|
def instructions
|
||||||
|
@order = params[:order]
|
||||||
|
@club = @order.club
|
||||||
|
@iban = MatchLiveTv.bank_transfer_iban
|
||||||
|
@holder = MatchLiveTv.bank_transfer_account_holder
|
||||||
|
@bank_name = MatchLiveTv.bank_transfer_bank_name
|
||||||
|
@bic = MatchLiveTv.bank_transfer_bic
|
||||||
|
@proof_email = MatchLiveTv.bank_transfer_proof_email
|
||||||
|
|
||||||
|
mail(
|
||||||
|
to: recipient_email,
|
||||||
|
subject: t("mailers.bank_transfer.instructions.subject", plan: @order.plan.name)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def plan_activated
|
||||||
|
@order = params[:order]
|
||||||
|
@club = @order.club
|
||||||
|
@subscription = @club.subscription
|
||||||
|
|
||||||
|
mail(
|
||||||
|
to: recipient_email,
|
||||||
|
subject: t("mailers.bank_transfer.plan_activated.subject", plan: @order.plan.name)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def recipient_email
|
||||||
|
@club.billing_email.presence || @club.owner&.email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4,15 +4,38 @@ module Billing
|
|||||||
@invoice = params[:invoice]
|
@invoice = params[:invoice]
|
||||||
@club = @invoice.club
|
@club = @invoice.club
|
||||||
|
|
||||||
attachments["fattura-#{@invoice.number.parameterize}.pdf"] = {
|
I18n.with_locale(I18n.locale) do
|
||||||
|
attach_invoice_pdf!
|
||||||
|
mail(
|
||||||
|
to: @club.billing_email,
|
||||||
|
subject: t("mailers.invoice.subject", number: @invoice.display_number)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def plan_activated_with_invoice
|
||||||
|
@invoice = params[:invoice]
|
||||||
|
@club = @invoice.club
|
||||||
|
|
||||||
|
I18n.with_locale(I18n.locale) do
|
||||||
|
attach_invoice_pdf!
|
||||||
|
mail(
|
||||||
|
to: @club.billing_email,
|
||||||
|
subject: t("mailers.invoice_activated.subject",
|
||||||
|
plan: @club.subscription&.plan&.name || @invoice.display_number,
|
||||||
|
number: @invoice.display_number)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def attach_invoice_pdf!
|
||||||
|
prefix = t("mailers.invoice.attachment_prefix")
|
||||||
|
attachments["#{prefix}-#{@invoice.number.parameterize}.pdf"] = {
|
||||||
mime_type: "application/pdf",
|
mime_type: "application/pdf",
|
||||||
content: @invoice.pdf.download
|
content: @invoice.pdf.download
|
||||||
}
|
}
|
||||||
|
|
||||||
mail(
|
|
||||||
to: @club.billing_email,
|
|
||||||
subject: "Fattura #{@invoice.display_number} — Match Live TV"
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
class ContactMailer < ApplicationMailer
|
||||||
|
def inquiry(name:, email:, club_name:, topic:, message:)
|
||||||
|
@name = name
|
||||||
|
@email = email
|
||||||
|
@club_name = club_name.presence
|
||||||
|
@topic = topic
|
||||||
|
@message = message
|
||||||
|
|
||||||
|
mail(
|
||||||
|
to: recipient_for(topic),
|
||||||
|
reply_to: email,
|
||||||
|
subject: t("mailers.contact.subject.#{topic}", name: name)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def recipient_for(topic)
|
||||||
|
if topic == "privacy"
|
||||||
|
MatchLiveTv.privacy_controller_email
|
||||||
|
else
|
||||||
|
MatchLiveTv.support_email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
module Ops
|
||||||
|
class AlertMailer < ApplicationMailer
|
||||||
|
def incident(incident)
|
||||||
|
@incident = incident
|
||||||
|
mail(
|
||||||
|
to: ENV.fetch("OPS_ALERT_EMAIL"),
|
||||||
|
subject: "[Match Live TV Ops] #{incident.severity.upcase}: #{incident.title}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -9,11 +9,14 @@ module Recordings
|
|||||||
@recipient = recipient
|
@recipient = recipient
|
||||||
@replay_url = recording.replay_url
|
@replay_url = recording.replay_url
|
||||||
@expires_at = recording.expires_at
|
@expires_at = recording.expires_at
|
||||||
|
@archive_url = "#{MatchLiveTv.app_public_url.chomp('/')}/clubs/#{@club.id}/replays"
|
||||||
|
|
||||||
mail(
|
I18n.with_locale(I18n.locale) do
|
||||||
to: recipient.email,
|
mail(
|
||||||
subject: "Replay pronto — #{recording.title_or_default}"
|
to: recipient.email,
|
||||||
)
|
subject: t("mailers.replay_ready.subject", title: recording.title_or_default)
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def replay_expiring_soon(recording:, recipient:)
|
def replay_expiring_soon(recording:, recipient:)
|
||||||
@@ -24,11 +27,14 @@ module Recordings
|
|||||||
@replay_url = recording.replay_url
|
@replay_url = recording.replay_url
|
||||||
@expires_at = recording.expires_at
|
@expires_at = recording.expires_at
|
||||||
@days_left = ((recording.expires_at - Time.current) / 1.day).ceil
|
@days_left = ((recording.expires_at - Time.current) / 1.day).ceil
|
||||||
|
@archive_url = "#{MatchLiveTv.app_public_url.chomp('/')}/clubs/#{@club.id}/replays"
|
||||||
|
|
||||||
mail(
|
I18n.with_locale(I18n.locale) do
|
||||||
to: recipient.email,
|
mail(
|
||||||
subject: "Replay in scadenza tra #{@days_left} giorni — #{recording.title_or_default}"
|
to: recipient.email,
|
||||||
)
|
subject: t("mailers.replay_expiring.subject", days: @days_left, title: recording.title_or_default)
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
module Teams
|
||||||
|
class InvitationMailer < ApplicationMailer
|
||||||
|
default from: -> { MatchLiveTv.mail_from }
|
||||||
|
|
||||||
|
def transmission_invite(team:, invitation:, invite_url:, invited_by:)
|
||||||
|
@team = team
|
||||||
|
@club = team.club
|
||||||
|
@invitation = invitation
|
||||||
|
@invite_url = invite_url
|
||||||
|
@invited_by = invited_by
|
||||||
|
@expires_on = I18n.l(invitation.expires_at.to_date, format: :long)
|
||||||
|
|
||||||
|
I18n.with_locale(I18n.locale) do
|
||||||
|
mail(
|
||||||
|
to: invitation.email,
|
||||||
|
subject: t(
|
||||||
|
"mailers.transmission_invite.subject",
|
||||||
|
team: @team.name,
|
||||||
|
club: @club.name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,6 +6,8 @@ class UserMailer < ApplicationMailer
|
|||||||
@reset_url = public_password_reset_url(token: token)
|
@reset_url = public_password_reset_url(token: token)
|
||||||
@expiry_hours = MatchLiveTv.password_reset_expiry_hours
|
@expiry_hours = MatchLiveTv.password_reset_expiry_hours
|
||||||
|
|
||||||
mail to: user.email, subject: "Reimposta la password — Match Live TV"
|
I18n.with_locale(I18n.locale) do
|
||||||
|
mail to: user.email, subject: t("mailers.password_reset.subject")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
class AdminAccount < ApplicationRecord
|
class AdminAccount < ApplicationRecord
|
||||||
|
include PasswordComplexity
|
||||||
|
|
||||||
has_secure_password
|
has_secure_password
|
||||||
|
has_many :app_announcements, foreign_key: :created_by_admin_id, dependent: :nullify, inverse_of: :created_by_admin
|
||||||
|
|
||||||
validates :username, presence: true, uniqueness: true
|
validates :username, presence: true, uniqueness: true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AnalyticsEvent < ApplicationRecord
|
||||||
|
self.table_name = "analytics_events"
|
||||||
|
|
||||||
|
EVENT_TYPES = %w[click scroll pageview move].freeze
|
||||||
|
DEVICES = %w[mobile tablet desktop].freeze
|
||||||
|
|
||||||
|
validates :page_path, presence: true
|
||||||
|
validates :device, inclusion: { in: DEVICES }
|
||||||
|
validates :event_type, inclusion: { in: EVENT_TYPES }
|
||||||
|
validates :occurred_at, presence: true
|
||||||
|
validates :weight, numericality: { greater_than: 0, less_than_or_equal_to: 500 }
|
||||||
|
end
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AnalyticsPageCell < ApplicationRecord
|
||||||
|
self.table_name = "analytics_page_cells"
|
||||||
|
|
||||||
|
GRID_SIZE = 40
|
||||||
|
|
||||||
|
validates :day, :page_path, :device, :cell_x, :cell_y, presence: true
|
||||||
|
validates :device, inclusion: { in: AnalyticsEvent::DEVICES }
|
||||||
|
validates :cell_x, :cell_y, inclusion: { in: 0...(GRID_SIZE) }
|
||||||
|
validates :click_count, numericality: { greater_than_or_equal_to: 0 }
|
||||||
|
validates :move_count, numericality: { greater_than_or_equal_to: 0 }
|
||||||
|
end
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user