1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
manager.php
См. документацию.
1<?php
2
4
8use Bitrix\Main\Entity\AddResult;
12
13use Bitrix\Bitrix24\Feature;
14
15Loc::loadMessages(__FILE__);
16
23{
25 protected static $userRoles = []; // 'USER_ID' => 'ROLE_ID'
26
32 public static function clearMenuCache()
33 {
34 Application::getInstance()->getTaggedCache()->clearByTag('bitrix:menu');
35 }
36
42 public static function canUse()
43 {
44 if(!Loader::includeModule('bitrix24'))
45 {
46 return true;
47 }
48
49 return Feature::isFeatureEnabled('sender_security');
50 }
51
57 public static function getTrialText()
58 {
59 return Loc::getMessage('SENDER_SECURITY_ROLE_MANAGER_TRIAL_TEXT_NEW');
60 }
61
68 public static function getRoleList(array $parameters = [])
69 {
70 return RoleTable::getList($parameters);
71 }
72
79 public static function getAccessList(array $parameters = [])
80 {
81 return Model\Role\AccessTable::getList($parameters);
82 }
83
90 public static function setAccessCodes(array $list = [])
91 {
92 self::clearMenuCache();
94 foreach ($list as $item)
95 {
96 $result = Model\Role\AccessTable::add(array(
97 'ROLE_ID' => $item['ROLE_ID'],
98 'ACCESS_CODE' => $item['ACCESS_CODE']
99 ));
100 if(!$result->isSuccess())
101 {
102 return $result;
103 }
104 }
105
106 return new AddResult();
107 }
108
117 public static function getRolesByUserId($userId)
118 {
119 if(isset(self::$userRoles[$userId]))
120 return self::$userRoles[$userId];
121
122 $result = [];
123 $userAccessCodes = \CAccess::getUserCodesArray($userId);
124
125 if(!is_array($userAccessCodes) || count($userAccessCodes) === 0)
126 return [];
127
128 $cursor = Model\Role\AccessTable::getList([
129 'filter' => [
130 '=ACCESS_CODE' => $userAccessCodes
131 ]
132 ]);
133
134 while($row = $cursor->fetch())
135 {
136 $result[] = $row['ROLE_ID'];
137 }
138
139 self::$userRoles[$userId] = $result;
140 return $result;
141 }
142
149 public static function getRolePermissions($roleId)
150 {
151 $result = [];
152 $list = Model\Role\PermissionTable::getList(['filter' => ['=ROLE_ID' => $roleId]]);
153 foreach ($list as $row)
154 {
155 $result[$row['ENTITY']][$row['ACTION']] = $row['PERMISSION'];
156 }
157
159 }
160
170 public static function setRolePermissions($roleId = null, array $roleFields = [], array $permissions)
171 {
172 $roleId = (int) $roleId;
173 if ($roleId <= 0 && empty($roleFields))
174 {
175 throw new ArgumentException('Role id should be greater than zero', 'roleId');
176 }
177
178 if(RoleTable::getRowById($roleId))
179 {
180 if (!empty($roleFields))
181 {
182 $result = RoleTable::update($roleId, $roleFields);
183 if (!$result->isSuccess())
184 {
185 return $result;
186 }
187 }
188 }
189 else
190 {
191 $result = RoleTable::add($roleFields);
192 if (!$result->isSuccess())
193 {
194 return $result;
195 }
196
197 $roleId = $result->getId();
198 }
199
200 $normalizedPermissions = Permission::normalize($permissions);
202 foreach ($normalizedPermissions as $entity => $actions)
203 {
204 foreach ($actions as $action => $permission)
205 {
206 $result = Model\Role\PermissionTable::add(array(
207 'ROLE_ID' => $roleId,
208 'ENTITY' => $entity,
209 'ACTION' => $action,
210 'PERMISSION' => $permission
211 ));
212 if (!$result->isSuccess())
213 {
214 return $result;
215 }
216 }
217 }
218
219 self::clearMenuCache();
220 $result = new AddResult();
221 $result->setId($roleId);
222 return $result;
223 }
224
231 public static function deleteRole($roleId)
232 {
235 RoleTable::delete($roleId);
236 self::clearMenuCache();
237 }
238
244 public static function installRolesAgent()
245 {
246 self::installRoles();
247 return '';
248 }
249
255 public static function installRoles()
256 {
257 $roleRow = RoleTable::getRow([]);
258 if($roleRow)
259 {
260 return;
261 }
262
263
264 $defaultRoles = array(
265 'ADMIN' => array(
266 'NAME' => Loc::getMessage('SENDER_SECURITY_ROLE_MANAGER_INSTALLER_ADMIN'),
267 'PERMISSIONS' => array(
271 ),
275 ),
279 ),
283 ),
287 ),
290 ),
291 )
292 ),
293 'MANAGER' => array(
294 'NAME' => Loc::getMessage('SENDER_SECURITY_ROLE_MANAGER_INSTALLER_MANAGER'),
295 'PERMISSIONS' => array(
299 ),
303 ),
307 ),
311 ),
315 ),
318 ),
319 )
320 )
321 );
322
323 $roleIds = array();
324 foreach ($defaultRoles as $roleCode => $role)
325 {
326 $addResult = RoleTable::add(array(
327 'NAME' => $role['NAME'],
328 'XML_ID' => $roleCode,
329 ));
330
331 $roleId = $addResult->getId();
332 if ($roleId)
333 {
334 $roleIds[$roleCode] = $roleId;
335 Manager::setRolePermissions($roleId, [], $role['PERMISSIONS']);
336 }
337 }
338
339 if (isset($roleIds['ADMIN']))
340 {
341 Model\Role\AccessTable::add(array(
342 'ROLE_ID' => $roleIds['ADMIN'],
343 'ACCESS_CODE' => 'G1'
344 ));
345 }
346 if (isset($roleIds['MANAGER']) && Loader::includeModule('intranet'))
347 {
348 $departmentTree = \CIntranetUtils::getDeparmentsTree();
349 $rootDepartment = (int)$departmentTree[0][0];
350
351 if ($rootDepartment > 0)
352 {
353 Model\Role\AccessTable::add(array(
354 'ROLE_ID' => $roleIds['MANAGER'],
355 'ACCESS_CODE' => 'DR'.$rootDepartment
356 ));
357 }
358 }
359 }
360}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения loader.php:13
static deleteByRoleId($roleId)
Определения access.php:88
static getRolesByUserId($userId)
Определения manager.php:117
static deleteRole($roleId)
Определения manager.php:231
static installRoles()
Определения manager.php:255
static getTrialText()
Определения manager.php:57
static canUse()
Определения manager.php:42
static $userRoles
Определения manager.php:25
static getRolePermissions($roleId)
Определения manager.php:149
static getRoleList(array $parameters=[])
Определения manager.php:68
static clearMenuCache()
Определения manager.php:32
static getAccessList(array $parameters=[])
Определения manager.php:79
static setAccessCodes(array $list=[])
Определения manager.php:90
static setRolePermissions($roleId=null, array $roleFields=[], array $permissions)
Определения manager.php:170
static installRolesAgent()
Определения manager.php:244
static normalize(array $source)
Определения permission.php:212
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entity
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$action
Определения file_dialog.php:21