# config/active_admin.rb
ActiveAdmin.setup do |config|
config.authorization_adapter = 'Allow::ActiveAdmin'
end
# app/models/admin_user.rb
class AdminUser < ActiveRecord::Base
include Allow::Model
include Allow::Model::ComaStorage
self.roles_namespace = "Roles::Admin::"
ROLES = ['super_admin', 'manager', 'developer', 'customer_support', 'finance']
# ...
end
# app/models/roles/super_admin.rb
class Roles::Admin::Supreme < Roles::Admin::BaseAdminUser
reset!
can :all
end
# app/models/roles/manager.rb
class Roles::Admin::Manager < Roles::Admin::BaseAdminUser
reset!
can :all
cant :manage, :users
can :see, :users
end
# app/admin/articles.rb
ActiveAdmin.register Article do
menu if: proc { current_admin_user.can?(:read, :articles) }
endIn role defenition
can :read, :"active_admin/comments"To control appearance in top menu use
ActiveAdmin.setup do |config|
config.authorization_adapter = 'Allow::ActiveAdmin'
endBy default ActiveAdmin check permission only for REST actions (:index, :show, :new, :create, :edit, :update, :destroy).
For actions defined via member_action, collection_action and page_action there is 2 solutions:
Call authorize! :action_name in every action
ActiveAdmin.register Dog do
collection_action :private_stats do
authorize! :private_stats
render plain: "Private Dogs Stats"
end
endUse Allow::ActiveAdmin::CheckAll
ActiveAdmin.register_page "Feedback" do
controller do
include Allow::ActiveAdmin::CheckAll
end
endYou also can use Allow::ActiveAdmin::CheckAll for every action in ActiveAdmin
# config/active_admin.rb
ActiveAdmin::ResourceController.class_eval do
include Allow::ActiveAdmin::CheckAll
end