---
url: /process-functions/userSecurity-user.md
description: >-
  Represents an individual user within the system, providing methods to manage
  their properties and groups.
---

# User&#x20;

Represents an individual user within the system, providing methods to manage their properties and groups.

This same user object is returned by `userSecurity.users` and by [security.application(...).users](/process-functions/security-application-users-interface).

## Identity

* ### getId()

  Retrieves the unique identifier of the user.

  * #### Returns:
    * The user's ID as an integer.

* ### getName()

  Retrieves the name of the user.

  * #### Returns:
    * The user's name.

* ### getEmail()

  Retrieves the email address of the user.

  * #### Returns:
    * The user's email address.

* ### isTwoFactorEnabled()

  Checks if two-factor authentication is enabled for the user.

  * #### Returns:
    * `true` if two-factor authentication is enabled, otherwise `false`.

* ### getRole()

  Retrieves the role of the user within the system.

  * #### Returns:
    * The name of the user's role, (eg. MODLLER, COLLABORATOR, ANALYST).

* ### hasGroup(group)

  Checks if the user is a member of a specific group.

  * #### Parameters:
    * `group` - An instance of a `Group` interface representing the group.
  * #### Returns:
    * `true` if the user is a member of the specified group, otherwise `false`.

* ### hasAdminGroup()

  Checks if the user is a part of the admin group.

  * #### Returns:
    * `true` if the user is a member of the admin group, otherwise `false`.

  ***

* ### addGroup(group)

  Adds the user to a specified group.

  * #### Parameters:
    * `group` - An instance of a `Group` interface representing the group to add.
  * #### Returns:
    * `true` if the user was successfully added to the group, otherwise `false`.

* ### removeGroup(group)

  Removes the user from a specified group.

  * #### Parameters:
    * `group` - An instance of a `Group` interface representing the group to remove.
  * #### Returns:
    * `true` if the user was successfully removed from the group, otherwise `false`.

* ### hasGroup(name)

  Checks if the user is a member of a specific group by name.

  * #### Parameters:
    * `name` - The name of the group.
  * #### Returns:
    * `true` if the user is a member of the group, otherwise `false`.

* ### addGroup(name)

  Adds the user to a specified group by name.

  * #### Parameters:
    * `name` - The name of the group to add.
  * #### Returns:
    * `true` if the user was successfully added to the group, otherwise `false`.

* ### removeGroup(name)

  Removes the user from a specified group by name.

  * #### Parameters:
    * `name` - The name of the group to remove.
  * #### Returns:
    * `true` if the user was successfully removed from the group, otherwise `false`.

* ### clearGroups()

  Clears all group memberships for the user.

  * #### Returns:
    * `true` if all groups were successfully cleared, otherwise `false`.

* ### groups()

  Lists all groups the user is a member of, including the primary group.

  * #### Returns:
    * A object containing the information on the user's groups and primary group.

* ### setPrimaryGroup(group)

  Sets the primary group for the user.

  * #### Parameters:
    * `group` - An instance of a `Group` interface representing the group to set as primary.
  * #### Returns:
    * `true` if the primary group was successfully set, otherwise `false`.

* ### setPrimaryGroup(name)

  Sets the primary group for the user by name.

  * #### Parameters:
    * `name` - The name of the group to set as primary.
  * #### Returns:
    * `true` if the primary group was successfully set, otherwise `false`.

## Security Group Access

* ### getModelAccessLevel(modelIdOrName)

  Retrieves the access level of the user for a specific model.

  * #### Parameters:
    * `modelIdOrName` - The identifier or name of the model.
  * #### Returns:
    * The access level name as a string.

* ### getObjectAccessLevel(modelIdOrName, objectType, objectKey, breakOnAccessLevel)

  Retrieves the effective access level of the user for a specific object within a model.

  * #### Parameters:
    * `modelIdOrName` - Identifier or name of the model.
    * `objectType` - Type of the object within the model, such as `CUBES`, `CARDS`, `WORKVIEWS`, `DIMENSIONS`, `PROCESSES`, `SCHEDULES`, `TABLES`, `APPLICATIONS`, `MAPPINGS`, or `VARIABLES`.
    * `objectKey` - Identifier of the specific object.
    * `breakOnAccessLevel` - Optional access level to stop the check.
  * #### Returns:
    * The effective access level name as a string.

* ### getElementAccessLevel(modelIdOrName, dimensionIdOrName, elementName, breakOnAccessLevel)

  Retrieves the access level of the user for a specific element within a model's dimension.

  * #### Parameters:
    * `modelIdOrName` - Identifier or name of the model.
    * `dimensionIdOrName` - Identifier or name of the dimension.
    * `elementName` - Name of the element.
    * `breakOnAccessLevel` - Optional access level to stop the check.
  * #### Returns:
    * The access level name as a string.

* ### Examples

  ```js
  // Check if user is part of a specific group
  var isUserInGroup = currentUser.hasGroup("Test Group");
  console.log("Is User in Test Group? " + (isUserInGroup ? "Yes" : "No"));

  // Add user to a new group
  var addGroupSuccess = currentUser.addGroup("Example Group");
  console.log(
      "User added to Example Group: " +
          (addGroupSuccess ? "Successful" : "Failed"),
  );

  // Remove user from a group
  var removeGroupSuccess = currentUser.removeGroup("Example Group");
  console.log(
      "User removed from Example Group: " +
          (removeGroupSuccess ? "Successful" : "Failed"),
  );

  // List all groups a user belongs to
  var userGroups = currentUser.groups();
  console.log("User Groups: ", userGroups);
  ```

## Access Tag Security&#x20;

* ### hasTag(application, tagNameOrId)

  Checks if the user has a specific tag within an application.

  * #### Parameters:
    * `application` - The application name or id.
    * `tagNameOrId` - The tag name or id.
  * #### Returns:
    * `true` if the user has the tag, otherwise `false`.

* ### hasTag(tag)

  Checks if the user has a specific tag object.

  * #### Parameters:
    * `tag` - The tag object.
  * #### Returns:
    * `true` if the user has the tag, otherwise `false`.

  ***

* ### addTag(application, tagNameOrId)

  Adds a tag to the user.

  * #### Parameters:
    * `application` - The application name or id.
    * `tagNameOrId` - The tag name or id.
  * #### Returns:
    * `true` if the tag was successfully added, otherwise `false`.

* ### addTag(application, tag)

  Adds a tag object to the user.

  * #### Parameters:
    * `application` - The application name or id.
    * `tag` - The tag object.
  * #### Returns:
    * `true` if the tag was successfully added, otherwise `false`.

  ***

* ### removeTag(application, tagNameOrId)

  Removes a tag from the user.

  * #### Parameters:
    * `application` - The application name or id.
    * `tagNameOrId` - The tag name or id.
  * #### Returns:
    * `true` if the tag was successfully removed, otherwise `false`.

* ### removeTag(application, tag)

  Removes a tag object from the user.

  * #### Parameters:
    * `application` - The application name or id.
    * `tag` - The tag object.
  * #### Returns:
    * `true` if the tag was successfully removed, otherwise `false`.

  ***

* ### clearTags(application)

  Clears all tags for the user in the specified application.

  * #### Parameters:
    * `application` - The application name or id.
  * #### Returns:
    * `true` if all tags were successfully cleared, otherwise `false`.

* ### setTags(application, tagNames)

  Sets the user's tags using tag names.

  * #### Parameters:
    * `application` - The application name or id.
    * `tagNames` - An array of tag names.
  * #### Returns:
    * `true` if tags were successfully set, otherwise `false`.

* ### setTags(application, tags)

  Sets the user's tags using tag objects.

  * #### Parameters:
    * `application` - The application name or id.
    * `tags` - An array of tag objects.
  * #### Returns:
    * `true` if tags were successfully set, otherwise `false`.

  ***

* ### tags(application)

  Lists all tags assigned to the user for the application.

  * #### Parameters:
    * `application` - The application name or id.
  * #### Returns:
    * An array of [ElementTag](/process-functions/security-application-elementtag) and [ScreenTag](/process-functions/security-application-screentag) interfaces.

* ### screenTags(application)

  Lists all screen tags assigned to the user.

  * #### Parameters:
    * `application` - The application name or id.
  * #### Returns:
    * An array of [ScreenTag](/process-functions/security-application-screentag) interfaces.

* ### elementTags(application)

  Lists all element tags assigned to the user.

  * #### Parameters:
    * `application` - The application name or id.
  * #### Returns:
    * An array of [ElementTag](/process-functions/security-application-elementtag) interfaces.

  ***

* ### getElementAccessTagLevel(application, dimension, element)

  Retrieves the effective access level from tags for a specific element.

  * #### Parameters:
    * `application` - The application name or id.
    * `dimension` - The dimension name or id.
    * `element` - The element name.
  * #### Returns:
    * The effective access level.

* ### getAvailableScreens(application)

  Retrieves the screens available to the user based on tag access.

  * #### Parameters:
    * `application` - The application name or id.
  * #### Returns:
    * A list of available [ApplicationScreen](/process-functions/security-application-screen) objects or screen identifiers, depending on the application configuration.
