0

I am new in Alfresco, and currently I am working on small project. The problem that I have is that I need to set one action from multi-select to be visiable just for one user group. This action is on Search window, and it's download action. (Picture attached)

enter image description here

I read that we can use Evaluators, but I am not sure how to do that. This is my code inside xml:

<config evaluator="string-compare" condition="DownloadAll">
                    <multi-select>
                        <action type="action-link" id="onDownloadAllDocumentAsZip" icon="document-download"
                                label="action.download.all.as.zip.label" />
                        <action type="action-link" id="onDownloadAllAsExcel" icon="document-download"
                                label="action.download.all.as.excel.label" />
                        <action type="action-link" id="onDownloadAllStudyNotificationAsExcel" icon="document-download"
                                label="action.download.all.study.notification.as.excel.results.label" />
                        <action type="action-link" id="onDownloadAllAsExcelIUCLID" icon="document-download"
                                label="action.download.all.as.excel.iuclid.label" />
                        <action type="action-link" id="onDownloadAllAsExcelUpdateMetadata" icon="document-download"
                                label="action.download.all.as.excel.update.metadata.label" />
                    </multi-select>
                </config>

I would have to introduce Evaluators or something like that on last action inside this multi-select.

Thanks in advance!

Mike1988B
  • 57
  • 5

1 Answers1

0

Yes, evaluator in share-config-custom.xml is the right way. Check some documentation https://docs.alfresco.com/content-services/latest/develop/share-ext-points/evaluators/. Simply you add tag <evaluator> inside <action> for example:

<action type="action-link" id="onDownloadAllAsExcelUpdateMetadata" icon="document-download" label="action.download.all.as.excel.update.metadata.label">                             
    <evaluator>my.evaluator.doclib.action.isAdmin</evaluator>
</action>

Name of evaluator have to be set properly set in file /share/src/main/resources/alfresco/web-extension/yourprefix-share-slingshot-application-context.xml. Take inspiration in this file with default settings https://github.com/Alfresco/share/blob/master/share/src/main/resources/alfresco/slingshot-documentlibrary-context.xml You can make lot of combinations via Predefined evaluators https://docs.alfresco.com/content-services/latest/develop/reference/share-document-library-ref/ If you wont be able make evaluator for specific group, write own java in path share/src/main/java/your_packages/share/web/extesibility. This is how look my IsAdminEvaluator:

public class IsAdminEvaluator extends org.alfresco.web.evaluator.BaseEvaluator
{
  public IsAdminEvaluator() {}
  
  public boolean evaluate(JSONObject jsonObject)
  {
    RequestContext rc = org.springframework.extensions.surf.support.ThreadLocalRequestContext.getRequestContext();
    User user = rc.getUser();
    
    return (user != null) && (user.isAdmin());
  }
}

and bean in yourprefix-share-slingshot-application-context.xml.

<bean id="my.evaluator.doclib.action.isAdmin" class="your_packages.share.web.extesibility.IsAdminEvaluator" />

If you need call some repo webscript use this.

final RequestContext rc = ThreadLocalRequestContext.getRequestContext();
final Connector conn = rc.getServiceRegistry().getConnectorService().getConnector("alfresco", rc.getUserId(), ServletUtil.getSession());
    // Get nodeRef
    final String nodeRef = (String) jsonObject.get("nodeRef");
    if (nodeRef == null) {
        return false;
    }

    // Create a Pattern object
    Pattern r = Pattern.compile("^(.*):\\/(\\/.*)(\\/.*)$");

    // Create matcher object
    Matcher m = r.matcher(nodeRef.toString());
final Response response = conn.call("/signia/parent?nodeRef=" + m.group(0));

So in the worst way you can call /people/{personId}/groups webscript and look if users is in your group. But I think you can make solution from Predefined evaluators. I hope this help you ;)

David Dejmal
  • 359
  • 1
  • 8