Fases 4, 5 e 6 — Job 1h + Auditoria + Consolidação + Wizard de validação
This commit is contained in:
@@ -4,26 +4,24 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
before_action :authenticate_user!
|
||||
before_action :set_tema
|
||||
after_action :verify_authorized, except: :index, unless: :skip_pundit?
|
||||
after_action :verify_policy_scoped, only: :index, unless: :skip_pundit?
|
||||
|
||||
rescue_from Pundit::NotAuthorizedError, with: :usuario_nao_autorizado
|
||||
|
||||
protect_from_forgery with: :exception
|
||||
# Pundit: redireciona se não autorizado
|
||||
rescue_from Pundit::NotAuthorizedError do |e|
|
||||
flash[:alert] = "Você não tem permissão para realizar esta ação."
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_tema
|
||||
# Lê o tema da sessão (padrão: escuro)
|
||||
@tema = session[:tema] || 'dark'
|
||||
@tema = current_user&.tema_preferido || 'dark'
|
||||
end
|
||||
|
||||
def skip_pundit?
|
||||
devise_controller? || params[:controller] =~ /rails\/|action_mailbox|action_text/
|
||||
end
|
||||
|
||||
def usuario_nao_autorizado
|
||||
flash[:alert] = 'Acesso negado. Você não tem permissão para esta ação.'
|
||||
redirect_back(fallback_location: dashboard_path)
|
||||
def after_sign_in_path_for(resource)
|
||||
if resource.motorista?
|
||||
motorista_dashboard_path
|
||||
else
|
||||
dashboard_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user