Adding Restrictions

You can add restrictions in different ways to the assistedservicesstorefront AddOn.

Adding Path Restrictions to the AddOn

Context

You add a new path restriction to the asagentsalesgroup.

Procedure

  1. Go to the assistedservicestorefront\resources\assistedservicestorefront\web\spring directory and open the assistedservicestorefront-web-spring.xml file for editing.
  2. In the assistedservicesstorefront-web-spring.xml file, add the new URL to the defaultAsmSalesGroupRestrictedPathsList bean definition:
    <alias name="defaultAsmSalesGroupRestrictedPathsList" alias="asmSalesGroupRestrictedPathsList" />
    	<util:list id="defaultAsmSalesGroupRestrictedPathsList" value-type="java.lang.String">
    		<value>/checkout/multi/summary/placeOrder</value>
    		<value>/your_custom_path</value>
    </util:list>

Adding Path Restrictions to a Custom Extension

Context

You add a new path restriction to the asagentsalesgroup in your custom extension.

Procedure

  1. Navigate to the <yourcustomextensionname>/resources directory and open the <yourcustomextensionname>-spring.xml file for editing.
  2. Add your custom restriction bean definition to the <yourcustomextensionname>-spring.xml file:
    <bean id="customSalesGroupRestrictedPathsListMergeDirective" depends-on="asmSalesGroupRestrictedPathsList" parent="listMergeDirective">
        <property name="add" value="/your_new_restricted_path_here"/>
    </bean>

Adding Usergroups to a Path Restriction

Procedure

  1. Navigate to the assistedservicestorefront/resources directory and open the assistedservicestorefront-spring.xml file for editing.
  2. In the assistedservicestrefront-spring.xml file, add your custom restriction bean:
    <bean id="customRestrictionListMergeDirective" depends-on="assistedServicePathRestrictionsList" parent="listMergeDirective">
        <property name="add" ref="yourCustomRestriction"/>
    </bean>
  3. In the assistedservicestrefront-spring.xml file, add the bean definition of your custom restriction:
    <bean id="yourCustomRestriction" parent="assistedServicePathRestriction" 
    class="de.hybris.platform.assistedservicestorefront.restrictions.YourCustomRestriction">
    		<property name="paths" ref="asmSalesGroupRestrictedPathsList" />
    </bean>
  4. In the de.hybris.platform.assistedservicestorefront.restrictions package, create a new class for your custom restriction and implement your custom behavior there, for example:
    public class YourCustomRestriction extends AssistedServicePathRestriction
    {
    	private final static Logger LOG = Logger.getLogger(YourCustomRestriction.class);
    	private List<String> paths;
    	@Override
    	public boolean evaluate(final HttpServletRequest httpservletrequest, final HttpServletResponse httpservletresponse)
    	{
    		if (getPaths().contains(httpservletrequest.getServletPath()))
    		{
    			if (getAssistedServiceFacade().isAssistedServiceAgentLoggedIn())
    			{
    				final UserGroupModel managerGroup = getUserService().getUserGroupForUID(
    						AssistedservicefacadesConstants.AS_MANAGER_AGENT_GROUP_UID);
    				final UserModel agent = getAssistedServiceFacade().getAsmSession().getAgent();
    				// restrict access in case agent is not in manager group
    				if (!getUserService().isMemberOfGroup(agent, managerGroup))
    				{
    					try
    					{
    						final String previousPage = (String) ObjectUtils.defaultIfNull(httpservletrequest.getHeader("referer"), "/");
    						httpservletresponse.sendRedirect(previousPage);
    						getAssistedServiceFacade().getAsmSession().setFlashErrorMessage("asm.action.restricted");
    						LOG.debug(String.format("Agent [%s] is not allowed to proceed with page [%s], has been redirected to [%s]",
    								agent, httpservletrequest.getServletPath(), previousPage));
    					}
    					catch (final IOException e)
    					{
    						LOG.error("Failed to send redirect from AssistedServiceCheckoutPathRestriction class.");
    					}
    					return false;
    				}
    			}
    		}
    		return true;
    	}
    	/**
    	 * @return the paths
    	 */
    	protected List<String> getPaths()
    	{
    		return paths;
    	}
    	/**
    	 * @param paths
    	 *           the paths to set
    	 */
    	@Required
    	public void setPaths(final List<String> paths)
    	{
    		this.paths = paths;
    	}
    }