0
votes

I'm using ActiveAdmin with CanCan gem and I have the next situation:

  • Two roles: admin, other.
  • The admin's header with three links: link1 | link2 | link3
  • Link 3 represents a Video resource.
  • The admin user can see links 1, 2 and 3
  • The other user can see link 1 and 2 but NOT 3

So, to make link 3 disappear. I can have an abilities.rb file with:

can :manage, Video #for admin users

and nothing for other users. This will make link 3 disappear. But, in other sections of my app I want other users with ability to "read Videos". When I add this ability, the link appears into the header again.

The question is: How can I preserve my :

can :read, Video #for other users

and disappear link 3 at the same time?

2
Why would you want the menu link to be missing if the user has permissions to view that resource?seanlinsley
It's a client requirement. The "other" user can analyze videos from app side but clients don't want those users seeing videos from admin side (yes, "other user" can access other things on admin side). I just don't want active admin adding links automatically based on defined abilities.Leantraxxx

2 Answers

1
votes

You should be able to override the default menu visibility for those people who have CanCan access but shouldn't see the menu item:

ActiveAdmin.register Video do
  menu false if current_user.other?

  # ...
end
1
votes
ActiveAdmin.register Video do
  menu :if => proc { !current_user.other? }

  # ...
end