Tips & Tricks - Permission-based display of elements

To display buttons, groupings or grids based on a user's permissions, methods are available in Velocity that can be used in the conditional display. With these methods, information can be shown permission-based even with a VTL Include element. Make sure the expert options have been activated so that all of the dialogs explained in this example are available. Background knowledge in Velocity and application development are an advantage for this workshop.

To begin with, identify the GUIDs of every user group or role that should have permission. In the Users module, the details, which also contain the GUID, can be viewed via the View menu / Details if a user object has been selected. The GUID can then be selected and copied to the clipboard. The GUIDs identified in this manner are then defined in the form of an array in the Velocity context.

#set($groupGuids = ['GUID1','GUID2', … 'GUIDn'])

The memberships of the logged-in user are identified in the second step.

#set($userMembership = $Portal.OrgStructure.getMembershipSets($User))

With the method ".intersects()", you can check whether the user is a member of one of the authorized groups or roles. The method returns "true" if one membership is correct and "false" if there are not any matches. This can be checked in an IF condition.

#if($userMembership.intersects($groupGuids) == true)
  ## Anzeigeinformation oder Code
#end

The following example checks whether the logged-in user is a member of the Administrators user group and displays the relevant information. With the method ".isEmpty()", you can check whether the user is a member of a group or role in general, or whether they have not been assigned to any group or role.

#set($groupGuids = ['EF16F15EDA8562E19D7CD56BF2E43001F119193C'])

#set($userMembership = $Portal.OrgStructure.getMembershipSets($User))

#if($userMembership.intersects($groupGuids) == true)
 Der angemeldeter Benutzer ist Mitglied der Gruppe "Administratoren"
#else
 Der angemeldeter Benutzer ist nicht Mitglied der Gruppe "Administratoren"
#end

#if($userMembership.isEmpty() == true)
 Der angemeldete Benutzer ist keiner Gruppe/Rolle zugeordnet
#end

When you open the editor for the conditional display for the first time, a variable that refers to the current element (button, grouping or grid) has already been defined.

#set($show_simplegroup155043BA = true)

The variable is composed of "$show_" followed by the name attribute of the element. If the value is set to "false", then the element is not generated on the server side. If the value is "true", the element is created and shown. The following example will only display a grouping if the logged-in user is a member of the "Users" user group.

#set($show_simplegroup155043BA = false)

#set($groupGuids = ['6AA80844C3C99EF93BF4536EB18605BF86FDD3C5'])
#set($userMembership = $Portal.OrgStructure.getMembershipSets($User))

#if($userMembership.intersects($groupGuids) == true)
  #set($show_simplegroup155043BA = true)
#end

If buttons, groupings or grids should only be shown to anonymous users, this can be checked with the method ".isAnonymous()".

#set($show_simplegroup9238DAD3 = false)

#if($User.isAnonymous())	
  #set($show_simplegroup9238DAD3 = true)
#end