How to Dynamically Assign User Groups to Models

available from version 15.2

Managing Model editing and viewing user groups can be complex and error‑prone. Instead of relying on manual updates, you can automate assignments with a calculation logic that runs whenever a Model Object is created. Based on the values entered in the Model’s input fields, the logic dynamically assigns the appropriate groups to edit and view permissions for the new Model.

Configuration

  1. Create a calculation logic - the names of the elements must be the same as the names of the fields which the elements should update. Typically, the roles will be assigned based on the value of an input field entered by the user (e.g., the selected Model Class).

    AssignUserGroupsToModels01.png
  2. Add a new advanced configuration option mo_FormUGTemplateLogic and enter the name of the previously created logic as its value.

    AssignUserGroupsToModels02.png

Logic Code Samples

When writing a logic, user groups must be referenced by their uniqueName. User inputs must be referenced by their technical name (as used by the API): uniqueName, label, modelClassUN, userGroupEdit, userGroupViewDetails, metaDescription.

The following code samples cover a few typical use cases:

  • You want to update only UserGroupViewDetails, not UserGroupEdit. – You simply omit the UserGroupEdit element from the logic.

  • You want to assign always the same role(s) regardless of user entry:

    Groovy
    return ['channel_analyst']
    
  • You want to assign roles based on the data entered by the user:

    Groovy
    if(api.stringUserEntry("modelClassUN")=="Clustering")
    {
       return ['channel_analyst']
    }
    
  • You want to extend the roles with some specifications:

    Groovy
    def groups = []
    
    if(api.stringUserEntry("userGroupViewDetails")){
      groups = api.stringUserEntry("userGroupViewDetails").split(',') as List
    }
    
    groups << 'compliance'
    
    return groups
    

How It Works

  1. User fills in (at least) the required fields in the Create New Model dialog and clicks Create.

  2. The system checks if there is the mo_FormUGTemplateLogic advanced configuration option specified.

  3. If it is, the system calls the specified logic via API.

    1. In the payload, it sends all the data from the form.

    2. The API returns the logic elements with results in the List(Array) format.

    3. The system updates the original payload with the returned results. Only fields returned from the API are updated, the rest is kept untouched.

  4. The system sends a request to create a new model with relevant payload.