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



如何根据用户删除后台中的按钮操作?我能够通过在canPerform方法中添加一个条件来禁用该按钮,如下所示

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

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

我希望你已经有一个自定义的后台扩展,如果没有,那么按照本教程创建一个。

现在,在您的自定义后台-后台-配置中.xml您可以使用您希望允许用户/组的操作为您的项目类型声明列表视图操作组件。然后,您需要将该用户的角色/组分配给主体属性。

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

在此处查找更详细的步骤

最新更新