Alfresco – Customizing actions and document details by User Group

Below a method to hide actions and document details to users not belonging a given Alfresco Group is shown. In this case we are using ALFRESCO_PERMISSIONS group, Manage Permissions action and Permissions document detail section.

alfresco-permissions-document-detail

1. Creating ALFRESCO_PERMISSIONS group from Alfresco Share

alfresco-create-group

2. Defining document-details share template extension (/document-details/src/main/amp/config/alfresco/web-extension/site-data/extensions/document-details.xml)

<extension>
  <modules>
    <module>
      <id>Hide document detail permissions</id>
      <version>1.0</version>
      <auto-deploy>true</auto-deploy>
      <components>
        <component>
          <scope>template</scope>
          <region-id>document-permissions</region-id>
          <source-id>document-details</source-id>
          <sub-components>
            <sub-component id="default">
              <evaluations>
                <evaluation id="hide">
                  <evaluators>
                    <evaluator type="group.component.evaluator">
                      <params>
                        <groups>GROUP_ALFRESCO_PERMISSIONS</groups>
                        <negate>true</negate>
                      </params>
                    </evaluator>
                  </evaluators>
                  <render>false</render>
                </evaluation>
              </evaluations>
            </sub-component>
          </sub-components>
        </component>
      </components>
    </module>
  </modules>
</extension>

3. Customizing action visibility(share-config-custom.xml)

<config evaluator="string-compare" condition="DocLibActions">
 <actions>
   <action id="document-manage-granular-permissions" type="link"
       icon="document-manage-permissions" label="actions.document.manage-permissions">
      <param name="href">{managePermissionsUrl}</param>
     <permissions>
       <permission allow="true">ChangePermissions</permission>
     </permissions>
     <evaluator>evaluator.doclib.action.siteBased</evaluator>
     <evaluator negate="true">evaluator.doclib.action.isWorkingCopy</evaluator>
     <evaluator negate="true">es.keensoft.evaluator.doclib.action.isPermissionManager</evaluator>
   </action>
 </actions>
</config>

4. Declaring Spring bean for action evaluator (/document-details/src/main/amp/config/alfresco/module/document-details/context/service-context.xml)

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN'
   'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
    <bean id="es.keensoft.evaluator.doclib.action.isPermissionManager"
    	parent="evaluator.doclib.action.groupMembership">
        <property name="groups">
            <list>
                <value>GROUP_ALFRESCO_PERMISSIONS</value>
            </list>
        </property>
   </bean>
</beans>

From now, Manage Permissions action and document detail Permissions will only be visible for users in ALFRESCO_PERMISSIONS group.

Many Alfresco customizations can be achieved without developing any source code line.

EDITED: Alternative implementation

Thanks to Charles Le Seac’h for his contribution. Below a one and only file version to get this functionality. Evaluator has been moved to module section and a new configuration section disables permissions action button for users not belonging to ALFRESCO_PERMISSIONS group.

1. Defining document-details share template extension (/document-details/src/main/amp/config/alfresco/web-extension/site-data/extensions/document-details.xml)

<extension>
  <modules>
    <module>
      <id>Hide document detail permissions</id>
      <version>1.0</version>
      <auto-deploy>true</auto-deploy>
      <evaluator type="group.module.evaluator">
        <params>
          <groups>GROUP_ALFRESCO_PERMISSIONS</groups>
          <negate>true</negate>
        </params>
      </evaluator>    
      <components>
        <component>
          <scope>template</scope>
          <region-id>document-permissions</region-id>
          <source-id>document-details</source-id>
          <sub-components>
            <sub-component id="default">
              <evaluations>
                <evaluation id="hide">
                  <render>false</render>
                </evaluation>
              </evaluations>
            </sub-component>
          </sub-components>
        </component>
      </components>
      <configurations>
        <config evaluator="string-compare" condition="DocLibActions">
          <actions>
            <action id="document-manage-granular-permissions" type="link" 
                    icon="document-manage-permissions" 
                    label="actions.document.manage-permissions">
              <param name="href">{managePermissionsUrl}</param>
              <permissions>
                <permission allow="true">ChangePermissions</permission>
              </permissions>
              <evaluator>evaluator.doclib.action.disableAction</evaluator>
            </action>
          </actions>
        </config>
      </configurations>
    </module>
  </modules>
</extension>

Sometimes Alfresco it’s so easy.

2 comentarios en “Alfresco – Customizing actions and document details by User Group

  1. Hello Angel,

    Thank you for this article: it’s a good example of how easy it is to customize Share !

    For this type of customization, I think you can put everything in your Share extension module :

    Hide document detail permissions
    1.0
    true

    GROUP_ALFRESCO_PERMISSIONS
    true

    template
    document-permissions
    document-details

    false

    {managePermissionsUrl}

    ChangePermissions

    evaluator.doclib.action.disableAction
    evaluator.doclib.action.isWorkingCopy

    This extensions module will only apply when user is not in ALFRESCO_PERMISSIONS group (cf. evaluator at module level)
    Then I can remove evaluator at sub-component level and avoid creating one for the config section.
    Concerning the action, I disabled it using “evaluator.doclib.action.disableAction” evaluator.

    I didn’t made a lots of tests, but I think it should work well.
    Warning : “configurations” section in an extension module is supported since 4.2 (for community version) and 4.1 (for enterprise version) .

    What do you think about this ?

    Best regards,
    Charles

  2. Charles, your code has been lost without the marks. I’ve understand you are using “configurations” section in order to show/hide permissions action. If you want to share with me that code, I’ll update this entry to show it in a proper format.

    Thanks!

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s