17 private const STEP_LIMIT = 200;
20 private static $accessCodes = [];
21 private static $userGroups = [];
40 !array_key_exists(
'CHECK_RIGHTS', $param)
41 || $param[
'CHECK_RIGHTS'] !==
'Y'
49 if (array_key_exists(
'CURRENT_USER_ID', $param))
51 $userId = (int) $param[
'CURRENT_USER_ID'];
56 $userId = (int) $USER->getId();
59 $userIds = array_column($items,
'ID');
61 $controller =
new self($userId);
62 $filtered = $controller->filterUsers($userIds);
71 foreach ($items as $k => $item)
73 if (!in_array($item[
'ID'], $filtered))
88 public static function checkEvent(array $info = []): array
97 !array_key_exists(
'CHECK_RIGHTS', $info)
98 || $info[
'CHECK_RIGHTS'] !==
'Y'
101 return $result->toArray();
104 if (array_key_exists(
'CURRENT_USER_ID', $info))
106 $userId = (int) $info[
'CURRENT_USER_ID'];
111 $userId = (int) $USER->getId();
114 if (!array_key_exists(
'ENTITY_TYPE_ID', $info))
116 return $result->toArray();
118 $entityTypeId = (string) $info[
'ENTITY_TYPE_ID'];
120 if (!array_key_exists(
'ENTITY_ID', $info))
122 return $result->toArray();
124 $entityId = (int) $info[
'ENTITY_ID'];
126 $controller =
new self($userId);
127 if (!$controller->check($entityTypeId, $entityId))
132 return $result->toArray();
137 $this->userId = $userId;
148 public function check(
string $typeId,
int $entityId): bool
157 $logId = $this->getLogId($typeId, $entityId);
172 $logRights = $this->getLogRights($logId);
173 if (empty($logRights))
179 if ($this->isExtranetUser($this->userId))
181 $extranetSiteId = \CExtranet::GetExtranetSiteID();
182 $logSites = $this->getLogSites($logId);
184 if (!in_array($extranetSiteId, $logSites))
190 if (in_array(
"UA", $logRights))
196 in_array(
"AU", $logRights)
203 $accessCodes = $this->getAccessCodes();
204 $isAccess = !empty(array_intersect($accessCodes, $logRights));
208 && Loader::includeModule(
'tasks')
211 $isAccess = $isAccess || TaskAccessController::can($this->userId, ActionDictionary::ACTION_TASK_READ, $entityId);
226 if (!$this->isExtranetUser($this->userId))
231 $userIds = array_map(
function($el) {
235 $userGroups = $this->getUserGroups();
236 if (empty($userGroups))
241 $chunks = array_chunk($userIds, self::STEP_LIMIT);
244 foreach ($chunks as $chunk)
246 $groupUsers = UserToGroupTable::getList([
247 'select' => [
'USER_ID'],
249 '@USER_ID' => $chunk,
250 '@GROUP_ID' => $userGroups,
254 $groupUsers = array_column($groupUsers,
'USER_ID');
255 $groupUsers = array_intersect($userIds, $groupUsers);
257 $result = array_merge($result, $groupUsers);
260 return array_unique($result);
269 private function getUserGroups(): array
271 if (array_key_exists($this->userId, self::$userGroups))
273 return self::$userGroups[$this->userId];
276 self::$userGroups[$this->userId] = [];
278 $groups = UserToGroupTable::getList([
279 'select' => [
'GROUP_ID'],
281 '=USER_ID' => $this->userId,
286 self::$userGroups[$this->userId] = array_column($groups,
'GROUP_ID');
288 return self::$userGroups[$this->userId];
298 private function getLogRights(
int $logId): array
300 $rights = LogRightTable::getList([
301 'select' => [
'GROUP_CODE'],
307 $rights = array_column($rights,
'GROUP_CODE');
320 private function getLogSites(
int $logId): array
323 'select' => [
'SITE_ID'],
329 $sites = array_column($sites,
'SITE_ID');
337 private function getAccessCodes()
339 if (array_key_exists($this->userId, self::$accessCodes))
341 return self::$accessCodes[$this->userId];
344 self::$accessCodes[$this->userId] = [];
346 $accessCodes = \CAccess::GetUserCodesArray($this->userId);
347 foreach ($accessCodes as $code)
349 self::$accessCodes[$this->userId][] = $code;
350 $signature = (
new AccessCode($code))->getSignature();
353 && $signature !== $code
356 self::$accessCodes[$this->userId][] = $signature;
360 return self::$accessCodes[$this->userId];
371 private function getLogId(
string $typeId,
int $entityId): ?int
376 '=RATING_ENTITY_ID' => $entityId,
377 '=RATING_TYPE_ID' => $typeId,
387 return (
int) $log[
'ID'];
395 private function isExtranetUser(
int $userId): bool
397 if (!Loader::includeModule(
'extranet'))
402 return !\CExtranet::IsIntranetUser(SITE_ID, $userId);
static getList(array $parameters=array())