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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user