Skip to content

Commit

Permalink
[docs] how-to: access currentUser properties (ToolJet#3977)
Browse files Browse the repository at this point in the history
* how to user and group

* hot-to/access current user props
  • Loading branch information
withshubh authored Sep 8, 2022
1 parent 789b089 commit 430c991
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docs/docs/how-to/access-users-groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
id: access-currentuser
title: Enable/Disable a component using current user's property
---

# Enable/Disable a component using current user's property

Let's take look at the exposed variables of the current user property:

- **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}}`
- **lastName** : The value can accessed using `{{globals.currentUser.lastName}}`
- **groups** : By default, the admin will be in the two groups `all_users` and `admin`, and any user who is not admin will always be in the `all_users` group by default. Since the **groups** is an array you’ll have to provide the index ([0], [1], and so on) to return the group name. The value can be acccessed using `{{globals.currentUser.groups[1]}}`.

<div style={{textAlign: 'center'}}>

<img className="screenshot-full" src="/img/how-to/access-currentuser/props.png" alt="Properties of current user" />

</div>

### 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.

<div style={{textAlign: 'center'}}>

<img className="screenshot-full" src="/img/how-to/access-currentuser/button.png" alt="Properties of button" />

</div>

- Set a condition on the Disable field so that if the the user who is using the app does not have **admin** value in the first index of **groups** array return **true**. The condition can be:

```javascript
{{globals.currentUser.groups[1] !== "admin" ? true : false}}
```

<div style={{textAlign: 'center'}}>

<img className="screenshot-full" src="/img/how-to/access-currentuser/disable.png" alt="Disable Property of button" />

</div>

- Now, when you'll **release** the app, if the user is not is not admin the button will be disabled.
<div style={{textAlign: 'center'}}>
<img className="screenshot-full" src="/img/how-to/access-currentuser/released.png" alt="Released button disabled when user is not admin" />
</div>
:::info
In this how-to we have used the **Groups** property of the **Current User**. You can use any of the exposed variables mentioned above according to your use.
:::
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const sidebars = {
'how-to/run-actions-from-runjs',
'how-to/bulk-update-multiple-rows',
'how-to/access-cellvalue-rowdata',
'how-to/access-currentuser',
'how-to/oauth2-authorization',
'how-to/upload-files-aws',
'how-to/upload-files-gcs',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 430c991

Please sign in to comment.