Adaptable

#Permissioning

Permissioning decides which Adaptable features a user sees. It works on two levels:

  • modules — which feature modules are available in the app at all (a design time choice, the same for every user);
  • user permissions — what the current user may do with the available modules, based on roles and permissions.
Warning

Permissions only change what the UI offers. They do not affect how state is evaluated, and API calls are not checked.

#Choosing the modules

By default every module is available. Use the modules prop of the Adaptable.Provider to narrow that down — either list the module objects to register:

Registering only some modules
import { viewModule, themeModule, exportModule } from '@adaptabletools/datagrid-react/modules';

<Adaptable.Provider {...props} modules={[viewModule, themeModule, exportModule]}>
  <Adaptable.Workspace />
</Adaptable.Provider>;

or filter the built-in catalog by module id, with include (only these) or exclude (everything but these):

Filtering the modules by id
<Adaptable.Provider
  {...props}
  modules={{ include: ['theme', 'calculatedColumn', 'styledCell'] }}
/>;

<Adaptable.Provider {...props} modules={{ exclude: ['flashingCell', 'styledCell'] }} />;

The module ids are alert, calculatedColumn, cellNote, cell-summary, contextMenu, customSort, dashboard, export, flashingCell, namedQuery, quickSearch, settingsPanel, styledCell, theme, view, grid, state and config.

A module that is not available contributes no dashboard widget, no column menu items and no context menu items. You can re-render the Provider with a new modules value at any time, and the UI follows.

#
Excluding modules

The quickSearch, styledCell and flashingCell modules are excluded. The top dashboard lists four widgets but shows only the view and theme ones, and the column menus have no Add Styled Cell or Add Flashing Cell items.

open
loading demo…

Module availability always wins over user permissions: a user with permissions for an excluded module still doesn't see it.

#User permissions

Pass the current user via the userInfo prop — an object, or a function that returns one:

The shape of userInfo
type UserInformation = {
  userId: string;
  userName: string;
  auth?: {
    // roles, or a function returning roles
    roles?: string[] | ((context: AuthContext) => string[]);
    // permissions (also negated ones, like '!styledCell_delete'), or a function returning them
    permissions?: string[] | ((context: AuthContext) => string[]);
    // optional — has the final say on every permission check
    checkPermission?: (context: CheckPermissionContext) => boolean;
  };
};
Note

Without userInfo.auth, the user has every permission of the available modules. As soon as you provide auth, the user has only the permissions granted by its roles and permissions.

A user with a role and an extra permission
<Adaptable.Provider
  {...props}
  userInfo={{
    userId: 'jdoe',
    userName: 'John Doe',
    auth: {
      roles: ['exportViewer'],
      permissions: ['styledCell_create'],
    },
  }}
>
  <Adaptable.UI />
</Adaptable.Provider>;

A module that defines permissions is only available to a user who has at least one of them. Modules without permissions (such as view, theme or quickSearch) are always available.

#
Roles and permissions

The user has the exportViewer role and the styledCell_create permission. The export widget lets them pick and run a report, without the edit, delete and new buttons. The styled cells widget is shown and the column menus offer Add Styled Cell; the flashing cells widget and Add Flashing Cell are hidden, because the user has no flashing cell permissions.

open
loading demo…

#Available permissions

ModulePermissions
Alertalert_create, alert_delete, alert_edit, alert_add_to_view, alert_remove_from_view
Cell NotecellNote_view, cellNote_create, cellNote_edit, cellNote_delete, cellNote_admin
Calculated ColumncalculatedColumn_create, calculatedColumn_delete, calculatedColumn_edit, calculatedColumn_add_to_view, calculatedColumn_remove_from_view
Exportexport_create, export_delete, export_edit, export_run
Flashing CellflashingCell_create, flashingCell_delete, flashingCell_edit, flashingCell_add_to_view, flashingCell_remove_from_view
Named QuerynamedQuery_create, namedQuery_edit, namedQuery_delete
Styled CellstyledCell_create, styledCell_delete, styledCell_edit, styledCell_add_to_view, styledCell_remove_from_view

The other modules don't define permissions.

#Available roles

A role is a named set of permissions, granted together.

RolePermissions
alertAdminall alert permissions
cellNoteViewercellNote_view
cellNoteAdminall cell note permissions
calculatedColumnViewercalculatedColumn_add_to_view, calculatedColumn_remove_from_view
calculatedColumnAdminall calculated column permissions
exportViewerexport_run
exportAdminall export permissions
flashingCellViewerflashingCell_add_to_view, flashingCell_remove_from_view
flashingCellAdminall flashing cell permissions
namedQueryAdminall named query permissions
styledCellViewerstyledCell_add_to_view, styledCell_remove_from_view
styledCellAdminall styled cell permissions

#Custom roles

Define your own roles — or redefine the built-in ones — with the authRoles prop, a map of role name to permissions:

A custom role
<Adaptable.Provider
  authRoles={{
    calculatedColumnEditor: ['calculatedColumn_edit'],
  }}
  userInfo={{
    userId: 'jdoe',
    userName: 'John Doe',
    auth: {
      roles: ['calculatedColumnEditor'],
    },
  }}
  {...props}
/>;

#Negated permissions

Prefix a permission with ! to take it away from what the roles grant. This user has every styled cell permission except deleting:

auth: {
  roles: ['styledCellAdmin'],
  permissions: ['!styledCell_delete'],
},

#How a permission is checked

Every check goes through three levels, the later ones overriding the earlier:

  1. Roles and permissions from userInfo.auth (or everything, without auth).
  2. Object flags — Adaptable objects in state (styled cells, flashing cells, reports, views, …) accept permissions: { editable, deletable }. When a check is made for a specific object and the flag is set, the flag decides its _edit or _delete permission, whatever the user's roles.
  3. checkPermission — when provided, it's called for every check with the result of the first two levels as defaultPermissionCheckResult, and its return value is final.
A custom permission check
userInfo={{
  userId: 'jdoe',
  userName: 'John Doe',
  auth: {
    roles: ['calculatedColumnAdmin'],
    checkPermission: (context) => {
      if (context.permission === 'calculatedColumn_delete') {
        return isAllowedToDelete(context.userId);
      }
      return context.defaultPermissionCheckResult;
    },
  },
}}

The checkPermission context carries permission, defaultPermissionCheckResult, userId, userName, userPermissions (the resolved permission list), adaptableObject (when the check is about a specific object), adaptableId and adaptableApi. The roles and permissions functions receive userId, userName, adaptableId and adaptableApi.

#Where permissions apply

These parts of the UI check permissions today:

  • Dashboard — module widgets are hidden when their module is not available to the user (see Dashboard).
  • Column menu — Add Styled Cell needs styledCell_create, Add Flashing Cell needs flashingCell_create, Edit Calculated Column needs calculatedColumn_edit.
  • Export — running a report (from the export widget or the context menu) needs export_run; the export widget's edit, delete and new buttons need export_edit, export_delete and export_create.
  • Context menu — module items only appear for available modules (see Context Menu).
Note

The settings panel pages don't check modules or user permissions yet — every page is shown to every user.