ToolJet/docs/versioned_docs/version-2.68.0/how-to/access-users-groups.md
Aman Regu bdfe3270e2
[docs]: v2.68.0-Beta (#10755)
* docs: jira

* docs: formatting + Client Credentials grant type

* docs: connection string pgsql

* docs: parameterized queries mysql

* docs: parameterized queries in PostgreSQL

* docs: update mysql example

* docs: TJDB sql editor

* docs: add metadata to REST API

* docs: add, update  postgresql media

* docs: add metadata to graphql

* docs: update parameterized queries

* docs: add parameterized queries for mssql

* docs: add SSL Cert to mysql

* docs: TJDB SQL restricted commands

* docs: update JIRA token location

* docs: update delete issue example

* docs: update find user by query example

* docs: remove session id from get assignable users

* docs: use correct image for get issues for board

* docs: update create issue example

* docs: update delete issue media

* docs: update assignable users media

* docs: update examples

* docs: update key desc

* docs: v2.68.0-Beta
2024-09-13 19:23:19 +05:30

2.4 KiB

id title
access-currentuser Enable/Disable a Component Using Current User's Property

Let's take a look at the exposed variables of the currentUser property by clicking on the inspector icon on the left sidebar:

  • email : The value can accessed using {{globals.currentUser.email}}
  • firstName : The value can accessed using {{globals.currentUser.firstName}}
  • lastName : The value can accessed using {{globals.currentUser.lastName}}
  • groups: The groups attribute is an array representing the groups a user belongs to. By default, every user, including admins, is part of the all_users group. Additionally, admins are also part of the admin group. To access a specific group name, you need to specify the array index, such as [0] for the first group, [1] for the second, and so on. For example, you can retrieve the name of the second group a user belongs to with {{globals.currentUser.groups[1]}}.

Example: Disable a Button if a User is Not Admin

  • Click on the Button handle to open its properties. On the Styles tab, go to the Disable property.
Properties of button
  • Configure the Disable field with a condition that checks the user's group membership. If the user is not an admin, as determined by the absence of the admin value in the first position (index [1]) of the groups array, the field should be disabled. Use the following JavaScript condition for this purpose:
{{globals.currentUser.groups[1] !== "admin" ? true : false}}
Disable Property of button
  • Now, when you release the app, if the user is not a part of the admin group, the button will be disabled.
Released button disabled when user is not admin