【问题标题】:How to hide the action button in backoffice based on user roles?如何根据用户角色在后台隐藏操作按钮?
【发布时间】:2020-03-24 08:18:22
【问题描述】:

如何根据用户在后台删除按钮操作?我可以通过在 canPerform 方法中添加一个条件来禁用按钮,就像这样

public boolean canPerform(final ActionContext<String> ctx)
    {
      final UserModel currentUser = userService.getCurrentUser();
      final boolean isUserMemberOfGroup = this.userService.isMemberOfGroup(currentUser,"group_name");
      return isUserMemberOfGroup;
    }

但我想隐藏按钮而不是禁用它。

【问题讨论】:

    标签: hybris backoffice


    【解决方案1】:

    我希望你已经有一个自定义后台扩展,如果没有,请关注this tutorial 创建一个。

    现在,在 yourcustombackoffice-backoffice-config.xml 中,您可以为您的 itemtype 声明 listviewactions 组件,其中包含您希望允许用户/组执行的操作。然后您需要将该用户的角色/组分配给主体属性。

    例如,有两个后台角色“mainRole”和“otherRole”。 “mainRole”角色已分配给 X 用户,“otherRole”角色已分配给 Y 用户。现在使用下面的后台配置,X 用户只能看到创建按钮,Y 用户只能看到删除按钮。

    <contexttype="Media" component="listviewactions" principal="mainRole" module="hideActionB">
    
        <y:actionsxmlns:y="http://www.hybris.com/cockpit/config/hybris"xmlns:advanced-search="http://www.hybris.com/cockpitng/config/advancedsearch"xmlns:df="http://www.hybris.com/cockpitng/component/dynamicForms"xmlns:editorArea="http://www.hybris.com/cockpitng/component/editorArea"xmlns:explorer-tree="http://www.hybris.com/cockpitng/config/explorertree"xmlns:list-view="http://www.hybris.com/cockpitng/component/listView"xmlns:simple-search="http://www.hybris.com/cockpitng/config/simplesearch"xmlns:wz="http://www.hybris.com/cockpitng/config/wizard-config"xmlns:ysl="http://www.hybris.com/cockpitng/config/simplelist">
    
               <y:group qualifier="common">
    
                   <y:label>actiongroup.common</y:label>
    
                   <y:action action-id="com.hybris.cockpitng.action.create" property="pageable.typeCode"/>
    
               </y:group>
    
           </y:actions>
    
    </context>
    
    
    <contexttype="Media" component="listviewactions" principal="otherRole" module="hideActionB">
    
        <y:actionsxmlns:y="http://www.hybris.com/cockpit/config/hybris"xmlns:advanced-search="http://www.hybris.com/cockpitng/config/advancedsearch"xmlns:df="http://www.hybris.com/cockpitng/component/dynamicForms"xmlns:editorArea="http://www.hybris.com/cockpitng/component/editorArea"xmlns:explorer-tree="http://www.hybris.com/cockpitng/config/explorertree"xmlns:list-view="http://www.hybris.com/cockpitng/component/listView"xmlns:simple-search="http://www.hybris.com/cockpitng/config/simplesearch"xmlns:wz="http://www.hybris.com/cockpitng/config/wizard-config"xmlns:ysl="http://www.hybris.com/cockpitng/config/simplelist">
    
               <y:group qualifier="common">
    
                   <y:label>actiongroup.common</y:label>
    
                   <y:action action-id="com.hybris.cockpitng.action.delete" property="currentObject"/>
    
               </y:group>
    
           </y:actions>
    
        </context>
    
    </config>
    

    查找更详细的步骤here

    【讨论】:

    • 非常感谢。我试过这个解决方案,效果很好
    猜你喜欢
    • 2021-03-01
    • 1970-01-01
    • 2021-06-14
    • 2023-03-16
    • 1970-01-01
    • 2019-05-17
    • 2018-07-19
    • 2012-09-16
    • 1970-01-01
    相关资源
    最近更新 更多