Set Sentry context for RailsAdmin
This commit is contained in:
8
app/controllers/rails_admin_controller.rb
Normal file
8
app/controllers/rails_admin_controller.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class RailsAdminController < ApplicationController
|
||||||
|
# RailsAdmin does not include translations. Therefore, we fallback to English locales
|
||||||
|
skip_around_action :switch_locale
|
||||||
|
# We check for permissions in the RailsAdmin config. Therefore, we skip Pundit checks here.
|
||||||
|
skip_after_action :verify_authorized
|
||||||
|
end
|
@ -15,7 +15,10 @@ RailsAdmin.config do |config|
|
|||||||
|
|
||||||
## == Pundit ==
|
## == Pundit ==
|
||||||
# config.authorize_with :pundit
|
# config.authorize_with :pundit
|
||||||
|
config.parent_controller = '::RailsAdminController'
|
||||||
|
|
||||||
config.authorize_with do
|
config.authorize_with do
|
||||||
|
# Important! We need to check the authorization here, we skip Pundit checks in the RailsAdminController.
|
||||||
unless current_user&.admin?
|
unless current_user&.admin?
|
||||||
flash[:alert] = t('application.not_authorized')
|
flash[:alert] = t('application.not_authorized')
|
||||||
redirect_to main_app.root_path
|
redirect_to main_app.root_path
|
||||||
|
Reference in New Issue
Block a user