Set Sentry context for RailsAdmin

This commit is contained in:
Sebastian Serth
2023-02-21 11:35:29 +01:00
parent d57a4410dd
commit 7fe0fc02e2
2 changed files with 11 additions and 0 deletions

View 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

View File

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