Tips & Tricks - Rights-dependent display of elements
To display buttons, groupings or grids depending on a user's authorization, Velocity provides methods that can be used in the conditional display. These methods can also be used to display information with a VTL include element on a rights-dependent basis. Activate the expert options so that all dialogs mentioned in this example are accessible. Background knowledge in Velocity and application development are an advantage for this workshop.
First determine the GUIDs of all user groups or roles that are to be authorized. In the "User" module, the details, which also contain the GUID, can be displayed with the main menu "View / Details" as soon as a user object is 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))
The ".intersects()" method can be used to check whether the user is a member of one of the authorized groups or roles. The method returns "true" if there is at least one membership and "false" if there is no match. This can be checked in an IF condition.
#if($userMembership.intersects($groupGuids) == true)
## Display information or code
#end
The following example checks whether the logged-in user is a member of the Administrators user group and displays the relevant information. The ".isEmpty()" method can be used to check whether the user is generally a member of a group or role or whether they have not been assigned to a group or role.
#set($groupGuids = ['EF16F15EDA8562E19D7CD56BF2E43001F119193C'])
#set($userMembership = $Portal.OrgStructure.getMembershipSets($User))
#if($userMembership.intersects($groupGuids) == true)
The logged-in user is a member of the "Administrators" group
#else
The logged-in user is not a member of the "Administrators" group
#end
#if($userMembership.isEmpty() == true)
The logged in user is not assigned to any group/role
#end
When you open the conditional display editor for the first time, a variable relating to the current element (button, grouping or grid) is already predefined there.
#set($show_simplegroup155043BA = true)
The variable is made up of "$show_" followed by the name attribute of the element. If the value is set to "false", the element is not created on the server side. If "true", the element is created and displayed. The following example only shows 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 are only to be displayed for anonymous users, the currently logged in user can be checked using the ".isAnonymous()" method.
#set($show_simplegroup9238DAD3 = false)
#if($User.isAnonymous())
#set($show_simplegroup9238DAD3 = true)
#end