Completa i18n IT/EN/FR/DE/ES su sito pubblico, area autenticata e admin.
Tutte le view marketing, legali, viewer, dashboard e admin usano t(); mailer utente-facing e flash localizzati; admin con LocaleResolver e selettore lingua. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,16 +10,16 @@ module Admin
|
||||
account = AdminAccount.find_by(username: params[:username]&.strip)
|
||||
if account&.authenticate(params[:password])
|
||||
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
|
||||
flash.now[:alert] = "Username o password non validi"
|
||||
flash.now[:alert] = t("admin.flash.invalid_credentials")
|
||||
render :new, status: :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
reset_session
|
||||
redirect_to admin_login_path, notice: "Disconnesso"
|
||||
redirect_to admin_login_path, notice: t("admin.flash.logout_success")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,20 +3,40 @@ module Admin
|
||||
layout "admin"
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
before_action :set_admin_locale
|
||||
before_action :require_admin_login
|
||||
|
||||
include ::AdminHelper
|
||||
helper ApplicationHelper
|
||||
helper RecordingsArchiveHelper
|
||||
helper_method :current_admin_account, :admin_logged_in?
|
||||
helper_method :current_admin_account, :admin_logged_in?, :current_locale, :language_options, :current_language_option
|
||||
|
||||
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
|
||||
return if admin_logged_in?
|
||||
|
||||
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
|
||||
|
||||
def current_admin_account
|
||||
|
||||
@@ -11,7 +11,7 @@ module Admin
|
||||
payment = Billing::Payment.find(params[:payment_id])
|
||||
Billing::AttachPaymentInvoice.call(payment: payment, pdf: params[:pdf])
|
||||
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
|
||||
payment ||= Billing::Payment.find_by(id: params[:payment_id])
|
||||
redirect_to admin_billing_path(payment ? billing_redirect_params(payment) : {}),
|
||||
|
||||
@@ -8,7 +8,7 @@ module Admin
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def create
|
||||
@@ -18,7 +18,7 @@ module Admin
|
||||
|
||||
if @invoice.save
|
||||
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
|
||||
@payment = @invoice.billing_payment
|
||||
flash.now[:alert] = @invoice.errors.full_messages.join(", ")
|
||||
@@ -36,9 +36,9 @@ module Admin
|
||||
if issuing?
|
||||
Billing::IssueInvoice.call(invoice: @invoice, pdf: params.dig(:billing_invoice, :pdf))
|
||||
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
|
||||
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
|
||||
@payment = @invoice.billing_payment
|
||||
flash.now[:alert] = @invoice.errors.full_messages.join(", ")
|
||||
@@ -61,7 +61,7 @@ module Admin
|
||||
end
|
||||
|
||||
def issuing?
|
||||
params[:commit].to_s == "Emetti e invia via email"
|
||||
params[:commit_action].to_s == "issue"
|
||||
end
|
||||
|
||||
def invoice_params
|
||||
|
||||
@@ -20,14 +20,14 @@ module Admin
|
||||
reason: params[:reason],
|
||||
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
|
||||
redirect_back_or_club alert: e.message
|
||||
end
|
||||
|
||||
def revoke_comped
|
||||
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
|
||||
redirect_back_or_club alert: e.message
|
||||
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
|
||||
@@ -9,19 +9,19 @@ module Admin
|
||||
def acknowledge
|
||||
incident = Ops::Incident.find(params[:id])
|
||||
incident.acknowledge!
|
||||
redirect_to admin_ops_path, notice: "Incidente preso in carico"
|
||||
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: "Incidente risolto"
|
||||
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: "Notifiche sospese per 24 ore"
|
||||
redirect_to admin_ops_path, notice: t("admin.flash.ops_muted")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -5,22 +5,22 @@ module Admin
|
||||
|
||||
def update
|
||||
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"
|
||||
flash.now[:alert] = t("admin.flash.password_too_short")
|
||||
return render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
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 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
|
||||
flash.now[:alert] = current_admin_account.errors.full_messages.to_sentence
|
||||
render :edit, status: :unprocessable_entity
|
||||
|
||||
@@ -12,28 +12,28 @@ module Admin
|
||||
def stop
|
||||
@session = StreamSession.find(params[:id])
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
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: "Sessione terminata: impossibile generare il link regia."
|
||||
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: "Link regia generato.",
|
||||
notice: t("admin.flash.session_regia_generated"),
|
||||
flash: {
|
||||
regia_url: access.url(token),
|
||||
regia_expires_at: @session.regia_token_expires_at&.iso8601
|
||||
|
||||
@@ -2,7 +2,7 @@ module Admin
|
||||
class YoutubeController < Admin::BaseController
|
||||
def platform
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user