Reputation: 6645
How to manage access to custom_page actions? I have this code:
ActiveAdmin.register_page 'Import' do
menu false
content do
panel t('views.import.title') do
render 'form'
end
end
page_action :parse, method: :post do
@import = current_user.imports.new(params[:import])
if @import.save
@import.process
end
end
page_action :check_status do
imports = current_user.imports.finished.unreaded
size = imports.size
imports.update_all readed: true
render json: {has_new_ended: size}
end
end
Now, access to this action has only admin, cuz the his rules looks like
can :manage, :all
But I need access this actions to other roles. If I do this for some role, it's not helps.
can [:check_status, :parse], ActiveAdmin::Page, name: 'Import'
And this
can [:manage, :parse, :check_status], Import
Upvotes: 1
Views: 1878
Reputation: 1244
You need to use your action name and page name.
can :parse, ActiveAdmin::Page, name: 'Import'
can :check_status, ActiveAdmin::Page, name: 'Import'
Upvotes: 0
Reputation: 11
By using following code in ability.rb
, you should be able to get all the permissions for the current user when he is in the custom page.
can :read, ActiveAdmin::Page, name: "Dashboard", namespace_name: "admin"
Upvotes: 1
Reputation: 2960
You have to authorize the actions. See more: https://github.com/ryanb/cancan#2-check-abilities--authorization
Upvotes: 0