42 self::EVENT_ON_BEFORE_SAVE,
50 $catalogStoreDocumentPermissions = PermissionDictionary::getStoreDocumentPermissionRules(
52 PermissionDictionary::CATALOG_STORE_DOCUMENT_VIEW,
53 PermissionDictionary::CATALOG_STORE_DOCUMENT_MODIFY,
54 PermissionDictionary::CATALOG_STORE_DOCUMENT_CANCEL,
55 PermissionDictionary::CATALOG_STORE_DOCUMENT_CONDUCT,
56 PermissionDictionary::CATALOG_STORE_DOCUMENT_DELETE,
57 PermissionDictionary::CATALOG_STORE_DOCUMENT_ALLOW_NEGATION_PRODUCT_QUANTITY,
61 foreach ($permissionSettings as &$setting)
63 $roleId = (int)$setting[
'id'];
64 $roleTitle = (string)$setting[
'title'];
66 $roleId = $this->
saveRole($roleTitle, $roleId);
67 $setting[
'id'] = $roleId;
70 if(!isset($setting[
'accessRights']))
75 foreach ($setting[
'accessRights'] as $permission)
78 in_array($permission[
'id'], $catalogStoreDocumentPermissions,
true)
80 : (int)$permission[
'id']
83 if ($permissionId < 1)
103 $db->startTransaction();
105 if (!PermissionTable::deleteList([
"=ROLE_ID" => $roles]))
110 RoleUtil::insertPermissions($query);
111 if (\
Bitrix\Main\Loader::includeModule(
"intranet"))
113 \CIntranetUtils::clearMenuCache();
116 $this->roleRelationService->saveRoleRelation($permissionSettings);
118 $db->commitTransaction();
120 IblockCatalogPermissionStepper::bind(1);
124 $db->rollbackTransaction();
132 self::EVENT_ON_AFTER_SAVE,
137 return $permissionSettings;
148 public function saveRole(
string $name,
int $roleId =
null): int
151 "NAME" => Encoding::convertEncodingToCurrent($name),
160 $role = RoleTable::getList(
162 '=NAME' => $nameField[
'NAME'],
167 $role = RoleTable::add($nameField);
172 $role = RoleTable::update($roleId, $nameField);
179 return $role->getId();
260 $inventoryManagementPermissions = (
new PermissionConfig)->getInventoryManagementPermissions();
262 foreach ($permissionSettings as &$setting)
264 $roleId = (int)$setting[
'id'];
270 $newRights = $setting[
'accessRights'] ?? [];
271 if (!is_array($newRights))
276 $inventoryManagementRights = array_map(
277 static function (array $item) {
279 'id' => $item[
'PERMISSION_ID'],
280 'value' => $item[
'VALUE'],
285 '=ROLE_ID' => $roleId,
286 '=PERMISSION_ID' => $inventoryManagementPermissions,
291 $diffRights = array_udiff($inventoryManagementRights, $newRights,
static function ($a, $b) {
292 $a = (string)$a[
'id'];
293 $b = (string)$b[
'id'];
297 if (empty($diffRights))
302 array_push($newRights, ... $diffRights);
304 $setting[
'accessRights'] = $newRights;
307 return $permissionSettings;