Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activeadmin restrict access to non superuser items

I'm using ActiveAdmin on Rails and I'm trying to lock down the section of the site which maintains admin users to non superusers.

Naturally I can hide the menu option like this:

ActiveAdmin.register AdminUser do
  menu :parent => "Settings", :if => proc { current_admin_user.superuser }
end

However the route still works if you bypass the menu and go directly to /admin/admin_users

What is the best practice to lock down the routes and controller for admins in ActiveAdmin.

like image 971
creativetechnologist Avatar asked Dec 04 '22 16:12

creativetechnologist


1 Answers

You can add a before_filter to a controller block where the resource is registered, this is working for me:

ActiveAdmin.register User do

  menu :if => proc{ current_user.superadmin? }

  controller do
    before_filter :superadmin_filter

    def superadmin_filter
      raise ActionController::RoutingError.new('Not Found') unless current_user.superadmin?
    end
  end

source

like image 200
Tom Power Avatar answered Dec 18 '22 00:12

Tom Power