# Scopes

### What is a scope?

A scope is a filter which applies to a collection and all its segments.

It is useful in that it can be used to control what data is available to users. More specifically, scopes can be set up to filter data dynamically on the current user.

{% hint style="warning" %}
**Scopes** are applied to the entire application excluding global Smart Actions, API & SQL charts and Collaboration & Activities.
{% endhint %}

### How to set up a scope

To access the scope management page for a given collection, you'll need to [go to that collection's settings page](https://docs.forestadmin.com/user-guide/manage-your-collection-settings#access-your-collection-settings) using the Layout editor mode.

![](https://85223878-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOx0Wo3NZjrQrGQthTy6o%2Fuploads%2Fgit-blob-878544655de6dfd345c85a8961d0aca0426dea8b%2FCapture%20d%E2%80%99e%CC%81cran%202019-08-13%20a%CC%80%2011.54.36.png?alt=media)

Once on the Scopes tab **(1)**, you can set up your filter **(2)** and save **(3)**. In the above screenshot, only customers with an email ending with *@forestadmin.com* will be displayed in the collection **and** all of its segments. All other customers won't be accessible.

### Using a dynamic scope

Imagine a situation where you have several Operations teams each specialized in a specific country's operations:

* *France* team handles customers from France
* *Germany* team handles customers from Germany
* ...

![](https://85223878-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOx0Wo3NZjrQrGQthTy6o%2Fuploads%2Fgit-blob-520ab2938c7a329c6e3cf5d1d57740d721b682ff%2FCapture%20d%E2%80%99e%CC%81cran%202019-08-21%20a%CC%80%2010.34.44.png?alt=media)

If you set up the following scope...

![](https://85223878-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOx0Wo3NZjrQrGQthTy6o%2Fuploads%2Fgit-blob-ce6986c86e2f66ba494ebdabad46310ae17a57f3%2Fimage.png?alt=media)

...then Marc who belongs to the *France* team will only see customers from France.\
However, Louis who belongs to the *Germany* team will only see customers from Germany.

![After the scope has been set up](https://85223878-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOx0Wo3NZjrQrGQthTy6o%2Fuploads%2Fgit-blob-d88ef70766a3113df57a9de878f9d7091a5bd048%2Fimage.png?alt=media)

#### Dynamic variables

In the example above, we used the team name to filter out what the user sees: `$currentUser.team.name`

Here the exhaustive list of available dynamic variables:

| Syntax                       | Result                                                                 |
| ---------------------------- | ---------------------------------------------------------------------- |
| `$currentUser.id`            | The id of the current user                                             |
| `$currentUser.firstName`     | The first name of the current user                                     |
| `$currentUser.lastName`      | The last name of the current user                                      |
| `$currentUser.fullName`      | The full name of the current user                                      |
| `$currentUser.email`         | The email of the current user                                          |
| `$currentUser.team.id`       | The id of the team of the current user                                 |
| `$currentUser.team.name`     | The name of the team of the current user                               |
| `$currentUser.tags.your-tag` | The value associated with key `your-tag` for the current user, if any. |

#### Using user tags

The above example is only possible if your data matches your users' details (email, team, etc). It's likely that it won't always be the case. This is why we've introduced user tags:

![](https://85223878-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOx0Wo3NZjrQrGQthTy6o%2Fuploads%2Fgit-blob-0ff760cb1739c215f704a45841686045818dd08b%2Fimage.png?alt=media)

User tags are [set from each user's details page](https://docs.forestadmin.com/user-guide/project-settings/teams-and-users/add-and-manage-users#add-user-tags) and allow you to freely associate your users to a value which will match against your data using the `$currentUser.tags.your-tag` dynamic variable:

![](https://85223878-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOx0Wo3NZjrQrGQthTy6o%2Fuploads%2Fgit-blob-9769c78262e3e43cbcf3bf677e756f2dfa725196%2Fimage.png?alt=media)

Using the above scope, the above user would see **1**, **2** but not **3**:

![](https://85223878-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOx0Wo3NZjrQrGQthTy6o%2Fuploads%2Fgit-blob-926161868d77ca8de2aa39e7f2f3f605d335c0fd%2FCapture%20d%E2%80%99e%CC%81cran%202020-04-15%20a%CC%80%2018.58.32%20copie.png?alt=media)
