170 public static function setRolePermissions($roleId =
null, array $roleFields = [], array $permissions)
172 $roleId = (int) $roleId;
173 if ($roleId <= 0 && empty($roleFields))
178 if(RoleTable::getRowById($roleId))
180 if (!empty($roleFields))
182 $result = RoleTable::update($roleId, $roleFields);
183 if (!$result->isSuccess())
191 $result = RoleTable::add($roleFields);
192 if (!$result->isSuccess())
197 $roleId = $result->getId();
200 $normalizedPermissions = Permission::normalize($permissions);
201 Model\Role\PermissionTable::deleteByRoleId($roleId);
202 foreach ($normalizedPermissions as $entity => $actions)
204 foreach ($actions as $action => $permission)
206 $result = Model\Role\PermissionTable::add(array(
207 'ROLE_ID' => $roleId,
210 'PERMISSION' => $permission
212 if (!$result->isSuccess())
219 self::clearMenuCache();
221 $result->setId($roleId);
257 $roleRow = RoleTable::getRow([]);
264 $defaultRoles = array(
266 'NAME' =>
Loc::getMessage(
'SENDER_SECURITY_ROLE_MANAGER_INSTALLER_ADMIN'),
267 'PERMISSIONS' => array(
268 Permission::ENTITY_AD => array(
269 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
270 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
272 Permission::ENTITY_RC => array(
273 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
274 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
276 Permission::ENTITY_LETTER => array(
277 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
278 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
280 Permission::ENTITY_SEGMENT => array(
281 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
282 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
284 Permission::ENTITY_BLACKLIST => array(
285 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
286 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
288 Permission::ENTITY_SETTINGS => array(
289 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
294 'NAME' =>
Loc::getMessage(
'SENDER_SECURITY_ROLE_MANAGER_INSTALLER_MANAGER'),
295 'PERMISSIONS' => array(
296 Permission::ENTITY_AD => array(
297 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
298 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
300 Permission::ENTITY_RC => array(
301 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
302 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
304 Permission::ENTITY_LETTER => array(
305 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
306 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
308 Permission::ENTITY_SEGMENT => array(
309 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
310 Permission::ACTION_MODIFY => Permission::PERMISSION_NONE,
312 Permission::ENTITY_BLACKLIST => array(
313 Permission::ACTION_VIEW => Permission::PERMISSION_ANY,
314 Permission::ACTION_MODIFY => Permission::PERMISSION_ANY,
316 Permission::ENTITY_SETTINGS => array(
317 Permission::ACTION_MODIFY => Permission::PERMISSION_NONE,
324 foreach ($defaultRoles as $roleCode => $role)
326 $addResult = RoleTable::add(array(
327 'NAME' => $role[
'NAME'],
328 'XML_ID' => $roleCode,
331 $roleId = $addResult->getId();
334 $roleIds[$roleCode] = $roleId;
335 Manager::setRolePermissions($roleId, [], $role[
'PERMISSIONS']);
339 if (isset($roleIds[
'ADMIN']))
341 Model\Role\AccessTable::add(array(
342 'ROLE_ID' => $roleIds[
'ADMIN'],
343 'ACCESS_CODE' =>
'G1'
346 if (isset($roleIds[
'MANAGER']) && Loader::includeModule(
'intranet'))
348 $departmentTree = \CIntranetUtils::getDeparmentsTree();
349 $rootDepartment = (int)$departmentTree[0][0];
351 if ($rootDepartment > 0)
353 Model\Role\AccessTable::add(array(
354 'ROLE_ID' => $roleIds[
'MANAGER'],
355 'ACCESS_CODE' =>
'DR'.$rootDepartment