Documentation

BX.UI.AccessRights component

Bitrix24 Self-hosted provide content that allows rendering a table with access permission settings: BX.UI.AccessRights.

This component requires initialization of system component bitrix:main.ui.selector that ensures selection of employees and associates them to roles.

Component ensure the solution of two problems:

  1. Rendering existing settings;
  2. Saving updates in settings.

You need to pass two parameters for rendering:

  • userGroups - roles, permissions and associated users
[
    'id' => 1, // role id, for new - 0
    'title' => 'Manager', // role name
    'accessRights' => [ // list of permissions and values
        0 => [
            'id' => 1, // id, corresponds to constants in PermissionDictionary
            'value' => 0
        ]
    ],
    'members' => [ // list of participants in a role
        'U2' => [ // participant access code
            'type' => 'users', // type for JS. Available types are described in main/install/components/bitrix/main.ui.selector/templates/.default/script.js
            'id' => 2,
            'name' => 'Test User',
            'url' => '',
            'avatar' => null
        ]
    ]
]
  • accessRights - settings, split into sections
[
  0 => [
    'sectionTitle' => 'Tasks', // section name
    'rights' => [ // list of permissions
      0 => [
        'id' => 1, // id, corresponds to PermissionDictionary
        'type' => 'toggler', // type, currently only 'toggler' - switch
        'title' => 'Edit', // name
        'hint' => null // if specified, shows icon with a hint
      ]
    ]
  ]
]

For saving the changes, component generates standard AJAX query with data. Uses name for target component as an address and an action name (used save, delete, load by default).

Completely, component call will look as follows:

<?php

\Bitrix\Main\Loader::includeModule('ui');
\Bitrix\Main\UI\Extension::load(['ui.buttons', 'ui.icons', 'ui.notification', 'ui.accessrights']);
?>

<span id="bx-access-group"></span>

<?
$APPLICATION->IncludeComponent(
   "bitrix:main.ui.selector",
   ".default",
   [
      'API_VERSION' => 3,
      'ID' => 'bx-access-group', // replace with your own
      'BIND_ID' => 'bx-access-group', // replace with your own
      'ITEMS_SELECTED' => [],
      'CALLBACK' => [
         'select' => "AccessRights.onMemberSelect",
         'unSelect' => "AccessRights.onMemberUnselect",
         'openDialog' => 'function(){}',
         'closeDialog' => 'function(){}',
      ],
      'OPTIONS' => [
         'eventInit' => 'tasks:onComponentLoad', // replace with your own
         'eventOpen' => 'tasks:onComponentOpen', // replace with your own
         'useContainer' => 'Y',
         'lazyLoad' => 'Y',
         'context' => 'TASKS_PERMISSION',
         'contextCode' => '',
         'useSearch' => 'Y',
         'useClientDatabase' => 'Y',
         'allowEmailInvitation' => 'N',
         'enableAll' => 'N',
         'enableUsers' => 'Y',
         'enableDepartments' => 'Y',
         'enableGroups' => 'Y',
         'departmentSelectDisable' => 'N',
         'allowAddUser' => 'Y',
         'allowAddCrmContact' => 'N',
         'allowAddSocNetGroup' => 'N',
         'allowSearchEmailUsers' => 'N',
         'allowSearchCrmEmailUsers' => 'N',
         'allowSearchNetworkUsers' => 'N',
         'useNewCallback' => 'Y',
         'multiple' => 'Y',
         'enableSonetgroups' => 'Y',
         'showVacations' => 'Y',
      ]
   ],
   false,
   ["HIDE_ICONS" => "Y"]
);
?>

<div id="bx-config-permissions"></div>
<script>
   let AccessRights = new BX.UI.AccessRights({
      component: 'bitrix:tasks.config.permissions',
      actionSave: 'save',
      actionDelete: 'delete',
      renderTo: document.getElementById('bx-config-permissions'),
      userGroups: <?= CUtil::PhpToJSObject($arResult['USER_GROUPS']) ?>,
      accessRights: <?= CUtil::PhpToJSObject($arResult['ACCESS_RIGHTS']); ?>,
      initPopupEvent: '<?= $initPopupEvent ?>',
      openPopupEvent: '<?= $openPopupEvent ?>',
      popupContainer: '<?= $componentId ?>',
   });

   AccessRights.draw();
   setTimeout(function(){
      BX.onCustomEvent('<?= $initPopupEvent ?>', [{openDialogWhenInit: false}])
   }, 1000);
</script>

<?php
   $APPLICATION->IncludeComponent('bitrix:ui.button.panel', '', [
      'HIDE'    => true,
      'BUTTONS' => [
         [
            'TYPE'    => 'save',
            'ONCLICK' => 'AccessRights.sendActionRequest()',
         ],
         [
            'TYPE'    => 'cancel',
            'ONCLICK' => 'AccessRights.fireEventReset()'
         ],
      ],
   ]);
?>

Rendering icons applied to roles

Use the class \Bitrix\Main\UI\AccessRights\DataProvider to render user, group and etc. icons, associated to a specific role.

(new DataProvider())→getEntity($type, $id); - returns all information necessary for UI by specified entity type and ID.



© «Bitrix24», 2001-2024