# Default Entitlement

Canonical page: https://www.adaptabletools.com/docs/handbook-permissioning-default-access-level

- By default every Module has an AccessLevel of Full (unless overridden)
- The one exception is the `StateManagement` (Manage State) Module, which is `Hidden` by default and must be entitled explicitly — setting `defaultAccessLevel` to `Full` does not unhide it
- This default AccessLevel can be changed by developers using either a hard-coded value or a function

Developers can set the **Default Access Level** for Module [Entitlements](https://www.adaptabletools.com/docs/handbook-permissioning/index.md) in AdapTable.

This is the Entitlement `AccessLevel` that will be used if not overridden through explicitly-set [Module Entitlements](https://www.adaptabletools.com/docs/handbook-permissioning-modules/index.md).

The Default Entitlement can be one of 3 values:

- `ReadOnly`
- `Hidden`
- `Full`

The property is set using the `defaultAccessLevel` property in [`Entitlement Options`](https://www.adaptabletools.com/docs/reference/entitlementoptions.md) and it offers 2 ways to provide Entitlements:

- Hard Coded Value - an explicitly provided Default `AccessLevel`
- Function - a Default `AccessLevel` returned from a custom function

### `defaultAccessLevel`

Set the default AccessLevel to use for Entitlements

  [`AccessLevel`](https://www.adaptabletools.com/docs/reference/accesslevel.md)

The `AccessLevel` which will be used for all Entitlements for this user if they are not overridden by `moduleEntitlements` 

The property returns an [`AccessLevel`](https://www.adaptabletools.com/docs/reference/accesslevel.md) and is defined as follows:

```
defaultAccessLevel?: 
  | AccessLevel | ((defaultAccessLevelContext: DefaultAccessLevelContext) => AccessLevel);
```

The [`DefaultAccessLevelContext`](https://www.adaptabletools.com/docs/reference/defaultaccesslevelcontext.md) property is defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [adaptableApi](https://www.adaptabletools.com/docs/reference/basecontext.md#adaptableapi) | [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md) | Adaptable Api object |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/basecontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |
| [adaptableId](https://www.adaptabletools.com/docs/reference/basecontext.md#adaptableid) | `string` | Id of current AdapTable instance |
| [adaptableStateKey](https://www.adaptabletools.com/docs/reference/basecontext.md#adaptablestatekey) | `string` | Current Adaptable State Key |
| [clientTimestamp](https://www.adaptabletools.com/docs/reference/basecontext.md#clienttimestamp) | `Date` | Time on user&#39;s computer |
| [userName](https://www.adaptabletools.com/docs/reference/basecontext.md#username) | `string` | Name of Current User |

- If this property is not provided, most Modules default to **Full**
- [State Management](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-management/index.md) defaults to **Hidden** and stays Hidden unless it is listed in `moduleEntitlements`
- Setting `defaultAccessLevel` to `Full` does **not** unhide State Management

## Hard Coded Value

This is a value that is set once at design time and doesn't require any run-time evaluation.

**Example: Entitlements: Default Access Level**

Providing a default Entitlement with a value

- In this example we set the Default Entitlement to `Hidden`, so most Modules are not available
- We override *Layout* and *FormatColumn* to be `ReadOnly` - so users can see the [Format Columns](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md) and can switch between [Layouts](https://www.adaptabletools.com/docs/handbook-layouts/index.md) - but **not** edit them
- We override *SettingsPanel* and *Dashboard* to `Full` - so they are fully viewable and usable
### See how the Default Entitlement is provided

```ts
entitlementOptions: {
  defaultAccessLevel: 'Hidden',
  moduleEntitlements: [
    {
      adaptableModule: 'FormatColumn',
      accessLevel: 'ReadOnly',
    },
    {
      adaptableModule: 'Layout',
      accessLevel: 'ReadOnly',
    },
    {
      adaptableModule: 'SettingsPanel',
      accessLevel: 'Full',
    },
    {
      adaptableModule: 'Dashboard',
      accessLevel: 'Full',
    },
  ],
},
```

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Default Entitlement By Value',

  entitlementOptions: {
    defaultAccessLevel: 'Hidden',
    moduleEntitlements: [
      {
        adaptableModule: 'FormatColumn',
        accessLevel: 'ReadOnly',
      },
      {
        adaptableModule: 'Layout',
        accessLevel: 'ReadOnly',
      },
      {
        adaptableModule: 'SettingsPanel',
        accessLevel: 'Full',
      },
      {
        adaptableModule: 'Dashboard',
        accessLevel: 'Full',
      },
    ],
  },

  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Demo',
          Toolbars: ['Layout'],
        },
      ],
      ModuleButtons: ['FormatColumn'],
    },
    Theme: {CurrentTheme: 'dark'},
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'formatColumn-week_issue_change-positive',
          Style: {
            ForeColor: 'var(--ab-color-palette-19)',
          },
          Scope: {
            ColumnIds: ['week_issue_change'],
          },
          Rule: '[week_issue_change] > 0',
        },
        {
          Name: 'formatColumn-week_issue_change-negative',
          Style: {
            ForeColor: 'var(--ab-color-palette-30)',
          },
          Scope: {
            ColumnIds: ['week_issue_change'],
          },
          Rule: '[week_issue_change] < 0',
        },
        {
          Name: 'formatColumn-all',
          Style: {
            BackColor: 'var(--ab-color-palette-26)',
            ForeColor: 'var(--ab-color-palette-17)',
          },
          Scope: {
            All: true,
          },
          Rule: '[language] = "HTML"',
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'week_issue_change',
            'github_stars',
            'topics',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
        {
          TableColumns: [
            'name',
            'week_issue_change',
            'license',
            'open_issues_count',
            'updated_at',
          ],
          Name: 'Grouped Layout',
          RowGroupedColumns: ['language'],
          TableAggregationColumns: [
            {
              ColumnId: 'open_issues_count',
              AggFunc: 'sum',
            },
            {
              ColumnId: 'week_issue_change',
              AggFunc: 'sum',
            },
          ],
        },
      ],
    },
  },
};
```

## JavaScript Function 

The other way to set the Default Access Level is via a Function.

This receives a [`DefaultAccessLevelContext`](https://www.adaptabletools.com/docs/reference/defaultaccesslevelcontext.md) object (which contains the username and the `adaptableId` of the current instance) and returns an AccessLevel.

This allows you to provide a different Default Access Level depending on the User's role.

```ts {5,6,7}
// Set default Module Entitlement as 'Full' for Admins and 'ReadOnly' for everyone else
const adaptableOptions: AdaptableOptions = {
  entitlementOptions: {
    defaultAccessLevel: (accessLevelContext: DefaultAccessLevelContext) => {
      return mockEntitlementService.isAdmin(accessLevelContext.userName) ? 'Full' : 'ReadOnly';
    },
  },
};
```

If `defaultAccessLevel` is set to `Hidden`, make sure to enable the [Settings Panel](https://www.adaptabletools.com/docs/ui-settings-panel/index.md) for access to AdapTable functionality
