Tips & Tricks - User administration by process
This article demonstrates how user groups can be created via a process. It also explains how to automate the creation and assignment of users to user groups. Finally, it provides a Groovy script for reading group memberships.
Create user group
User groups with a data group action can be created in each process. To do this, first create a source for the data, e.g. an event handler. In the properties of the event handler, you can specify the origin of the data for the new user group, e.g. the name. Connect a data group action to the event source.
Select the "Add data set" action in the properties of the data group action.
Select the "Set" data group from the "User" system application as the target data group.
In the field assignment, at least the following values should now be assigned to the target - the new user group in the user administration:
-
a GUID that can be easily created and then assigned by clicking on
"User-defined value"
-
the class ID 6 (integer), which can also be created by clicking on "User-defined value" and then assigned
-
The object name
Once the settings and process have been saved, the new user group will be created.
Create user
New users can be created and added to a user group via a process. A Groovy action takes over the insertion with the following script:
def user = g_om.createUser{
container = "System"
name = "user-${now().withoutFractionalSeconds}"
loginName = "UserU-${now().withoutFractionalSeconds}"
emailBiz = "user@example.org"
description = "User created with Groovy at ${now().withoutFractionalSeconds}"
memberOf = ["Users", "6AA80844C3F99EF93BF4598EB18605BF86FDD3C5"]
}
The "g_om" access object provides a structure that can be used to perform operations in the user administration and organizational structure of a portal. When a user is created in this example, the following properties will be set, of which ""name"" and ""loginName"" are mandatory. All of the other properties are optional.
-
container: Container in which the user object is to be created. You can specify the unique name (in our example "System", the GUID or the path of the container
- name: The unique object name
- loginName: The unique login name
- emailBiz: The e-mail address of the user
- description: Description of the user object
- memberOf: The user's group memberships are defined here.
you can enter the unique name, the GUID (in our example "6AA80844C3F99EF93BF4598EB18605BF86FDD3C5") or the path of the group.
A time stamp is used to ensure the uniqueness of the user name and login ID. If the uniqueness of a user name and a login is not guaranteed in a user administration using an ID or a timestamp, but another format is used instead, such as firstname.surname, it must be checked when creating a new user whether a user with the same data already exists and, if necessary, appropriate error handling must be carried out.
Read user's memberships
The following script can be used to determine the group memberships of a user.
def user = g_om.getUser(g_session.user.guid)
def sets = g_om.getMembershipSets(user)
def strAdminGroupGuid = "EF16F15EDA8562E19D7DD75BF2OP3001F119193C"
if (sets*.guid.contains(strAdminGroupGuid))
return adminGroupMemberTrue
else
return adminGroupMemberFalse
In this example, "g_session.user.guid" is used to read out the GUID of the user currently logged in. "g_om.getMembershipSets(member)" returns a list of all groups - including subordinate groups - in which the transferred user is a member. You can then iterate over the GUIDs of the groups found to determine whether the GUID of the administrator group (which you must replace in the script with your own administrator group GUID) is in the result set provided. Depending on this evaluation - in this example, the evaluation of whether the user is a member of the Administrators group - a corresponding value is returned, which can be used to trigger further process steps in a Groovy condition, for example.