When the `multitenancy_management_mode` is enabled. In order to avoid infinite redirects when regular users try to access the admin section, we're redirecting to the account page in this case. Otherwise, the admin section would redirect to the root path, which would redirect to the admin section, which would redirect to the root path, and so on.
19 lines
535 B
Ruby
19 lines
535 B
Ruby
module AccessDeniedHandler
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
rescue_from CanCan::AccessDenied do |exception|
|
|
respond_to do |format|
|
|
format.html do
|
|
if Rails.application.multitenancy_management_mode?
|
|
redirect_to main_app.account_path, alert: exception.message
|
|
else
|
|
redirect_to main_app.root_path, alert: exception.message
|
|
end
|
|
end
|
|
format.json { render json: { error: exception.message }, status: :forbidden }
|
|
end
|
|
end
|
|
end
|
|
end
|