Aggiunge gestione archivio replay nel pannello admin.

Gli admin possono vedere, modificare ed eliminare i replay di una società come la squadra proprietaria, riusando la stessa UI e logica dell'archivio pubblico.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-13 09:01:38 +02:00
parent da75582dae
commit 89854869c7
15 changed files with 455 additions and 219 deletions

View File

@@ -6,6 +6,8 @@ module Admin
before_action :require_admin_login
include ::AdminHelper
helper ApplicationHelper
helper RecordingsArchiveHelper
helper_method :current_admin_account, :admin_logged_in?
private

View File

@@ -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

View File

@@ -0,0 +1,91 @@
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
permitted = params.require(:recording).permit(:privacy_status, :title)
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(", ")
end
def destroy
Recordings::Delete.new(@recording).call
redirect_to archive_index_path, notice: "Replay eliminato"
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
end
end

View File

@@ -1,73 +1,21 @@
module Public
class ClubRecordingsController < WebBaseController
include Recordings::ClubArchiveActions
helper RecordingsArchiveHelper
before_action :require_login!
before_action :set_club
before_action :require_club_recording_manager!
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)
if params[:team_id].present?
@recordings = @recordings.where(team_id: params[:team_id])
end
if params[:status].present?
case params[:status]
when "ready"
@recordings = @recordings.ready
when "processing"
@recordings = @recordings.where(status: "processing")
when "expired"
@recordings = @recordings.where(
"recordings.status IN (?) OR (recordings.expires_at IS NOT NULL AND recordings.expires_at <= ?)",
%w[expired failed], Time.current
)
end
end
@teams = @club.teams.order(:name)
@filter_team_id = params[:team_id]
@filter_status = params[:status]
end
def update
permitted = params.require(:recording).permit(:privacy_status, :title)
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 public_club_recordings_path(@club, team_id: params[:team_id], status: params[:status]),
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
def set_club
@club = Club.find(params[:club_id])
def archive_namespace
:public
end
def authorize_recording_management!
return if Recordings::AccessPolicy.new(@recording, viewer: current_user).manage_allowed?
raise ActiveRecord::RecordNotFound
end
def require_club_recording_manager!
@@ -76,12 +24,5 @@ module Public
redirect_to public_clubs_path, alert: "Non autorizzato"
end
def set_recording
@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
end
end