CanCan and ActiveRecord. How to limit file downloads to a certain role

83 views Asked by At

If I have an Admin and SuperAdmin role. How can I limit downloads to the SuperAdmin only.

index download_links: current_user.super_admin? do
    column :email
    column :query
    default_actions
end

Gives the following error for current_user and current_admin_user:

undefined local variable or method `current_admin_user' for #<ActiveAdmin::ResourceDSL:

Anyway to extract this into CanCan user ability? Also even when I hide the links for a certain user, going to URL.csv still downloads the links. Who can I block this?

1

There are 1 answers

2
Timo Schilling On

You need to put the current_user.super_admin? in a Proc.

index download_links: ->{ current_user.super_admin? } do
    column :email
    column :query
    default_actions
end