AEM Cloud Service - Render condition to show Reprocess Assets button for configured group

Goal


AEM Cloud Version : 2021.4.5226.20210427T070726Z-210325 (April 27, 2021)

A sample Render Condition to allow specific users (part of a group) reprocess assets (by clicking the Reprocess Assets in action bar). The group configuration is provided in Tools > Experience AEM > EAEM Configuration



Tools Navigation



Group Configuration



Saved in CRX

                                 /conf/global/settings/dam/eaem-dam-config




Reprocess Assets




Solution


1) Create a custom widget /apps/eaem-cs-smart-crop-rc/dam-tools/userpicker/userpicker.jsp to read the values from config resource /conf/global/settings/dam/eaem-dam-config. It extends otb user picker /libs/granite/ui/components/coral/foundation/form/userpicker using a sling:include, for setting the granite.ui.form.contentpath attribute to read values from config location  /conf/global/settings/dam/eaem-dam-config
<%@include file="/libs/granite/ui/global.jsp" %>

<%@page session="false"%>

<%
    String CONFIG_RES = "/conf/global/settings/dam/eaem-dam-config";

    request.setAttribute("granite.ui.form.contentpath", CONFIG_RES);
%>

<sling:include resourceType="<%= "/libs/granite/ui/components/coral/foundation/form/userpicker" %>"/>
  


2) Create the tools navigation /apps/cq/core/content/nav/tools/eaem-dam-tools/eaem-dam-config.

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
          jcr:description="EAEM Custom Configuration"
          jcr:primaryType="nt:unstructured"
          jcr:title="EAEM Configuration"
          href="/apps/eaem-cs-smart-crop-rc/dam-tools/eaem-dam-config.html/conf/global/settings/dam/eaem-dam-config"
          icon="asset"
          id="eaem-dam-config"
          size="XL"/>
  


3) Create the configuration page /apps/eaem-cs-smart-crop-rc/dam-tools/eaem-dam-config for selecting the group name and save to /conf/global/settings/dam/eaem-dam-config@processAssetsGroup accessed using Tools > Experience AEM EAEM Configuration or https://author-pxxxxx-exxxxx.adobeaemcloud.com/apps/eaem-cs-restrict-assets-size/dam-tools/eaem-dam-config.html/conf/global/settings/dam/eaem-dam-config

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="cq:Page">
    <jcr:content
        jcr:mixinTypes="[sling:VanityPath]"
        jcr:primaryType="nt:unstructured"
        jcr:title="EAEM DAM Configuration"
        sling:resourceType="granite/ui/components/coral/foundation/page">
        <head jcr:primaryType="nt:unstructured">
            <favicon
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/coral/foundation/page/favicon"/>
            <viewport
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/coral/foundation/admin/page/viewport"/>
            <clientlibs
                jcr:primaryType="nt:unstructured"
                sling:resourceType="granite/ui/components/coral/foundation/includeclientlibs"
                categories="[coralui3,granite.ui.coral.foundation,granite.ui.shell,dam.gui.admin.coral]"/>
        </head>
        <body
            jcr:primaryType="nt:unstructured"
            sling:resourceType="granite/ui/components/coral/foundation/page/body">
            <items jcr:primaryType="nt:unstructured">
                <content
                    jcr:primaryType="nt:unstructured"
                    sling:resourceType="granite/ui/components/coral/foundation/form"
                    action="/conf/global/settings/dam/eaem-dam-config"
                    foundationForm="{Boolean}true"
                    maximized="{Boolean}true"
                    method="post"
                    novalidate="{Boolean}true"
                    style="vertical">
                    <successresponse
                        jcr:primaryType="nt:unstructured"
                        jcr:title="Success"
                        sling:resourceType="granite/ui/components/coral/foundation/form/responses/openprompt"
                        open="/assets.html"
                        redirect="/apps/eaem-cs-smart-crop-rc/dam-tools/eaem-dam-config.html/conf/global/settings/dam/eaem-dam-config"
                        text="Configuration saved"/>
                    <items jcr:primaryType="nt:unstructured">
                        <type
                            jcr:primaryType="nt:unstructured"
                            sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
                            name="./jcr:primaryType"
                            value="nt:unstructured"/>
                        <wizard
                            jcr:primaryType="nt:unstructured"
                            jcr:title="Configuration"
                            sling:resourceType="granite/ui/components/coral/foundation/wizard">
                            <items jcr:primaryType="nt:unstructured">
                                <area
                                    jcr:primaryType="nt:unstructured"
                                    jcr:title="Configure Thumbnails"
                                    sling:resourceType="granite/ui/components/coral/foundation/container"
                                    maximized="{Boolean}true">
                                    <items jcr:primaryType="nt:unstructured">
                                        <columns
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"
                                            margin="{Boolean}true">
                                            <items jcr:primaryType="nt:unstructured">
                                                <column
                                                    jcr:primaryType="nt:unstructured"
                                                    sling:resourceType="granite/ui/components/coral/foundation/container">
                                                    <items jcr:primaryType="nt:unstructured">
                                                        <process-assets-group
                                                            jcr:primaryType="nt:unstructured"
                                                            sling:resourceType="/apps/eaem-cs-smart-crop-rc/dam-tools/userpicker"
                                                            fieldDescription="Select the group with process assets access"
                                                            fieldLabel="Group name"
                                                            groupsOnly="{Boolean}true"
                                                            hideServiceUsers="{Boolean}true"
                                                            multiple="{Boolean}false"
                                                            name="./processAssetsGroup"/>
                                                    </items>
                                                </column>
                                            </items>
                                        </columns>
                                    </items>
                                    <parentConfig jcr:primaryType="nt:unstructured">
                                        <prev
                                            granite:class="foundation-wizard-control"
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="granite/ui/components/coral/foundation/anchorbutton"
                                            href="/aem/start.html"
                                            text="Cancel">
                                            <granite:data
                                                jcr:primaryType="nt:unstructured"
                                                foundation-wizard-control-action="cancel"/>
                                        </prev>
                                        <next
                                            granite:class="foundation-wizard-control"
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="granite/ui/components/coral/foundation/button"
                                            text="Save"
                                            type="submit"
                                            variant="primary">
                                            <granite:data
                                                jcr:primaryType="nt:unstructured"
                                                foundation-wizard-control-action="next"/>
                                        </next>
                                    </parentConfig>
                                </area>
                            </items>
                        </wizard>
                    </items>
                </content>
            </items>
        </body>
    </jcr:content>
</jcr:root>
  


4) Add a render condition script /apps/eaem-cs-smart-crop-rc/smart-crops-render-condition/smart-crops-render-condition.jsp checking if the user is member of group set in /conf/global/settings/dam/eaem-dam-config@processAssetsGroup.

<%@page session="false"
        import="org.apache.sling.api.resource.Resource,
                com.adobe.granite.ui.components.rendercondition.RenderCondition,
                com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition" %>
<%@ page import="org.apache.jackrabbit.api.security.user.UserManager" %>
<%@ page import="org.apache.jackrabbit.api.security.user.Authorizable" %>
<%@ page import="org.apache.jackrabbit.api.security.user.Group" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.2" %>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %>

<sling:defineObjects/>
<cq:defineObjects/>

<%
    boolean allowed = false;

    try{
        String CONFIG_RES = "/conf/global/settings/dam/eaem-dam-config";
        Resource configRes = resourceResolver.getResource(CONFIG_RES);
        String assetProcessGroup = configRes.getValueMap().get("processAssetsGroup", String.class);

        if(StringUtils.isNotEmpty(assetProcessGroup)){
            UserManager userManager = resourceResolver.adaptTo(UserManager.class);

            Authorizable user = userManager.getAuthorizable(slingRequest.getUserPrincipal().getName());
            Group group = (Group)userManager.getAuthorizable(assetProcessGroup);

            allowed = ((group != null) && group.isMember(user));
        }
    }catch(Exception e){
        allowed = false;
    }

    request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(allowed));
%>
  


5) Create a overlay configuration of Reprocess Assets button in Assets console, Asset Details, Omni Search, Collections and set the render condition...

               /apps/dam/gui/content/assets/jcr:content/actions/selection/reprocessassets/granite:rendercondition/process-assets

              /apps/dam/gui/content/assetdetails/jcr:content/actions/reprocessassets/granite:rendercondition/process-assets

              /apps/dam/gui/content/collections/collectiondetails/jcr:content/actions/selection/reprocessassets/granite:rendercondition/process-assets

              /apps/granite/omnisearch/content/metadata/asset/actions/selection/reprocessassets/granite:rendercondition/process-assets






1 comment:

  1. Hi Sreekanth , Thanks for this amazing article it really helped . Is there a reason we are not able to hide this option via ACL permission . For example if we give only read permission for the DAM user , then I thought it should be hidden .

    ReplyDelete