21 private const DB_ERROR_KEY =
"SENDER_CONFIG_PERMISSIONS_DB_ERROR";
26 private $roleRelationService;
42 foreach ($permissionSettings as &$setting)
45 $roleId = (int) $setting[
'id'];
46 $roleTitle = (string) $setting[
'title'];
48 $roleId = $this->
saveRole($roleTitle, $dealCategoryId, $roleId);
49 $setting[
'id'] = $roleId;
52 if(!isset($setting[
'accessRights']))
58 foreach ($setting[
'accessRights'] as $permission)
60 if((
int)$permission[
'id'] < 1)
64 $messageCodeByPermission = $adsAccessMap[(int)$permission[
'id']] ??
null;
66 if ($messageCodeByPermission !==
null && !Service::isAdVisibleInRegion($messageCodeByPermission))
73 'PERMISSION_ID' => $permission[
'id'],
74 'VALUE' => $permission[
'value'],
81 if (!PermissionTable::deleteList([
"=ROLE_ID" =>$roles]))
88 RoleUtil::insertPermissions($query);
89 if (\
Bitrix\Main\Loader::includeModule(
"intranet"))
91 \CIntranetUtils::clearMenuCache();
109 public function saveRole(
string $name,
int $dealCategoryId = -1,
int $roleId =
null): int
112 "NAME" => Encoding::convertEncodingToCurrent($name),
113 "DEAL_CATEGORY_ID" => $dealCategoryId
122 $role = RoleTable::getList(
124 '=NAME' => $nameField[
'NAME'],
125 '=DEAL_CATEGORY_ID' => $nameField[
'DEAL_CATEGORY_ID']
130 $role = RoleTable::add($nameField);
135 $role = RoleTable::update($roleId, $nameField);
142 return $role->getId();
156 if (!PermissionTable::deleteList([
"=ROLE_ID" => $roleId]))
161 $this->roleRelationService->deleteRoleRelations($roleId);
163 if (!RoleTable::delete($roleId))
179 return RoleTable::getList($parameters)->fetchAll();
187 return PermissionTable::getList($parameters)->fetchAll();
195 $userAccessCodes = \CAccess::getUserCodesArray($userId);
197 return $this->roleRelationService->getRolesByRelations($userAccessCodes);
209 "filter" => [
"=DEAL_CATEGORY_ID" => $dealCategoryId]
214 foreach ($res as $row)
216 $roleId = (int) $row[
'ID'];
220 'title' => $row[
'NAME'],
221 'accessRights' => $this->getRoleAccessRights($roleId),
222 'members' => $this->getRoleMembers($roleId)
240 foreach ($sections as $sectionId => $permissions)
244 foreach ($permissions as $permissionId)
246 $messageCodeByPermission = $adsAccessMap[$permissionId] ??
null;
248 $messageCodeByPermission !==
null
249 && !Service::isAdVisibleInRegion($adsAccessMap[$permissionId])
255 $messageCodeByPermission === iBase::CODE_MASTER_YANDEX
256 && !Service::isMasterYandexVisibleInRegion()
263 'id' => $permissionId,
264 'type' => PermissionDictionary::getType($permissionId),
265 'title' => PermissionDictionary::getTitle($permissionId)
277 private function getRoleAccessRights(
int $roleId): array
279 $settings = $this->getSettings();
282 if (array_key_exists($roleId, $settings))
284 foreach ($settings[$roleId] as $permissionId => $permission)
287 'id' => $permissionId,
288 'value' => $permission[
'VALUE']
293 return $accessRights;
296 private function getMemberInfo(
string $code)
298 $accessCode =
new AccessCode($code);
299 $member = (
new DataProvider())->getEntity($accessCode->getEntityType(), $accessCode->getEntityId());
300 return $member->getMetaData();
304 private function getRoleMembers(
int $roleId): array
309 ->roleRelationService
310 ->getRelationList([
"filter" =>[
"=ROLE_ID" => $roleId]]);
312 foreach ($relations as $row)
314 $accessCode = $row[
'RELATION'];
315 $members[$accessCode] = $this->getMemberInfo($accessCode);
321 private function getSettings()
326 foreach ($res as $row)
328 $settings[$row[
'ROLE_ID']][$row[
'PERMISSION_ID']] = $row;
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)