简体   繁体   中英

View show page for menu item in Active Admin

I would like to dynamically change the menu based on the permissions of the viewing user. I would like the superadmin user to have access to the normal Resource actions (index, show, update, etc). So when an admin clicks on a menu item, it would take them to the index of that resource. I would like to restrict the normal admin user to just viewing a specific show page.

The menu route for the superadmin would be: /admin/resource
The menu route for the normal admin would be: /admin/resource/id

I would also like to restrict normal admin access to the index view, or other resources that they don't have access to. I have been able to achieve both these things, but I have yet to be able to map a menu item to a specific show page. I know I could create a custom page and view, but I really would like to share the custom DSL for the show and edit pages between superadmin and the normal admin.

Anyone know how to make this happen.

Ok, so I figured a way to get what I want. I am not sure if exactly fulfills what I wanted. (meaning, it would be nice to create custom menu items that are mapped to specific resources)

I just overwrote the index controller action to redirect to the specific show page. Because the super admin needs access to the original Store resource, I had to alias it with :as.

ActiveAdmin.register Store, :as => 'My Store' do
  menu :if => proc{ !current_user.is_admin? },
       :label => 'My Store'

  actions :show, :edit, :update

  controller do
    def index
      redirect_to(admin_my_store_url(current_user.store))
    end
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM