В вашем классе действий (который реализует CockpitAction
) вы должны переопределить метод canPerform
, чтобы он возвращал истину / ложь на основе вашей бизнес-логики.
Например, вы можете обратиться к тому, как Customer Enable/ Отключить действие работает OOTB.
В b2bcommercebackoffice-backoffice-config.xml
вы можете найти
<context merge-by="module" type="B2BCustomer" component="editorareaactions">
<y:actions xmlns:y="http://www.hybris.com/cockpit/config/hybris">
<y:group qualifier="common">
<y:label>actiongroup.common</y:label>
<y:action action-id="de.hybris.platform.b2bcommerce.backoffice.actions.disableb2bcustomeraction" property="currentObject"/>
<y:action action-id="de.hybris.platform.b2bcommerce.backoffice.actions.enableb2bcustomeraction" property="currentObject"/>
</y:group>
</y:actions>
</context>
Теперь обратитесь к disableb2bcustomeraction или enableb2bcustomeraction класс, как они имеютреализован метод canPerform .
например
public boolean canPerform(ActionContext<B2BCustomerModel> ctx) {
Object data = ctx.getData();
if (data != null && data instanceof B2BCustomerModel) {
B2BCustomerModel b2bCustomerModel = (B2BCustomerModel) data;
UserModel currentUser = this.userService.getCurrentUser();
boolean isActive = b2bCustomerModel.getActive();
boolean isUserMemberOfAdminGroup = this.userService.isMemberOfGroup(currentUser,
this.userService.getAdminUserGroup());
boolean isUserMemberOfB2BAdminGroup = this.userService.isMemberOfGroup(currentUser,
this.userService.getUserGroupForUID("b2badmingroup"));
return (isUserMemberOfAdminGroup || isUserMemberOfB2BAdminGroup) && isActive;
} else {
return false;
}
}