如何根据用户角色在后台隐藏操作按钮?

时间:2019-11-28 16:12:54

标签: hybris backoffice

如何根据用户删除后台中的按钮操作?通过像这样

canPerform 方法中添加条件,我可以禁用该按钮
public boolean canPerform(final ActionContext<String> ctx)
    {
      final UserModel currentUser = userService.getCurrentUser();
      final boolean isUserMemberOfGroup = this.userService.isMemberOfGroup(currentUser,"group_name");
      return isUserMemberOfGroup;
    }

但是我想隐藏按钮,而不是使其禁用。

1 个答案:

答案 0 :(得分:2)

我希望您已经有了一个自定义的后台扩展,如果没有的话,请按照this tutorial创建一个扩展。

现在,在您的custombackoffice-backoffice-config.xml 中,您可以为您的项目类型声明 listviewactions 组件,其中包含您要允许用户/组使用的那些操作。然后,您需要将该用户的角色/组分配给principal属性。

例如,有两个后台角色“ 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

相关问题