在Active Admin中查看菜单项的显示页面

时间:2022-11-19 23:21:38

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.

我想根据查看用户的权限动态更改菜单。我希望superadmin用户能够访问正常的Resource操作(索引,显示,更新等)。因此,当管理员点击菜单项时,它会将它们带到该资源的索引。我想限制普通管理员用户只查看特定的节目页面。

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

superadmin的菜单路由是:/ admin / resource普通管理员的菜单路由是:/ 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.

我还想限制对索引视图或他们无权访问的其他资源的正常管理员访问权限。我已经能够实现这两个目标,但我还没有能够将菜单项映射到特定的显示页面。我知道我可以创建一个自定义页面和视图,但我真的想在superadmin和普通管理员之间共享显示和编辑页面的自定义DSL。

Anyone know how to make this happen.

任何人都知道如何实现这一目标。

1 个解决方案

#1


1  

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.

我刚刚覆盖索引控制器操作以重定向到特定的显示页面。因为超级管理员需要访问原始商店资源,所以我必须使用: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

#1


1  

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.

我刚刚覆盖索引控制器操作以重定向到特定的显示页面。因为超级管理员需要访问原始商店资源,所以我必须使用: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