1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
OperationService.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Permission;
6
7use Bitrix\Socialnetwork\Integration\Intranet\User;
8use Bitrix\Socialnetwork\UserToGroupTable;
9use Bitrix\Socialnetwork\WorkgroupTable;
10use COption;
11use CSocNetAllowed;
12use CSocNetFeaturesPerms;
13
15{
16 public function filterUsersWithAccess(
17 int $groupId,
18 array $users,
19 string $type,
20 string $feature,
21 string $operation,
22 bool $isAdmin = false
23 ): array
24 {
25 $result = [];
26 foreach ($users as $user)
27 {
28 $userId = array_key_first($user);
29 $role = $user[$userId];
30
31 if ($this->canPerform($groupId, $userId, $role, $type, $feature, $operation, $isAdmin))
32 {
33 $result[] = $userId;
34 }
35 }
36
37 return $result;
38 }
39
40 public function canPerform(
41 int $groupId,
42 int $userId,
43 bool|string $role,
44 string $type,
45 string $feature,
46 string $operation,
47 bool $isAdmin = false
48 ): bool
49 {
50 $permissions = $this->getPermissions($groupId, $type, $feature, $operation);
51
52 if ($permissions === false)
53 {
54 return false;
55 }
56
57 if ($role === SONET_ROLES_BAN)
58 {
59 return false;
60 }
61
62 $group = $this->getGroup($groupId);
63 if (empty($group))
64 {
65 return false;
66 }
67
68 if ($this->isClosedGroup($group, $feature, $operation))
69 {
70 if (!$this->isWorkWithClosedGroupEnabled())
71 {
72 return false;
73 }
74
75 $permissions = SONET_ROLES_OWNER;
76 }
77
78 if ($isAdmin)
79 {
80 return true;
81 }
82
83 if ($permissions === SONET_ROLES_ALL)
84 {
85 if (!$this->isHiddenGroup($group))
86 {
87 return true;
88 }
89
90 $permissions = SONET_ROLES_USER;
91 }
92
93 if ($permissions === SONET_ROLES_AUTHORIZED)
94 {
95 return $userId > 0;
96 }
97
98 if ($permissions === SONET_ROLES_EMPLOYEE)
99 {
100 return $this->checkIsEmployee($userId, $role);
101 }
102
103 if ($role === false)
104 {
105 return false;
106 }
107
108 if ($permissions === SONET_ROLES_MODERATOR)
109 {
110 return $this->checkIsModerator($role);
111 }
112
113 if ($permissions === SONET_ROLES_USER)
114 {
115 return $this->checkIsMember($role);
116 }
117
118 if ($permissions === SONET_ROLES_OWNER)
119 {
120 return ($role === SONET_ROLES_OWNER);
121 }
122
123 return false;
124 }
125
126 private function getGroup(int $groupId): array
127 {
128 $group = WorkgroupTable::getList([
129 'select' => ['CLOSED', 'VISIBLE'],
130 'filter' => ['ID' => $groupId],
131 ])->fetch();
132
133 if (!$group)
134 {
135 return [];
136 }
137
138 return $group;
139 }
140
141 private function isClosedGroup(array $group, string $feature, string $operation): bool
142 {
143 $featureSettings = CSocNetAllowed::GetAllowedFeatures();
144
145 return $group["CLOSED"] === "Y"
146 && !in_array($operation, $featureSettings[$feature]["minoperation"], true);
147 }
148
149 private function isHiddenGroup(array $group): bool
150 {
151 return $group["VISIBLE"] === "N";
152 }
153
154 private function isWorkWithClosedGroupEnabled(): bool
155 {
156 return COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") === "Y";
157 }
158
159 private function checkIsEmployee(int $userId, bool|string $role): bool
160 {
161 return in_array($role, UserToGroupTable::getRolesMember(), true)
163 }
164
165 private function checkIsModerator(string $role): bool
166 {
167 return in_array($role, [SONET_ROLES_MODERATOR, SONET_ROLES_OWNER], true);
168 }
169
170 private function checkIsMember(string $role): bool
171 {
172 return in_array($role, UserToGroupTable::getRolesMember(), true);
173 }
174
175 private function getPermissions(
176 int $groupId,
177 string $type,
178 string $feature,
179 string $operation,
180 ): array|string|false
181 {
182 return CSocNetFeaturesPerms::GetOperationPerm($type, $groupId, $feature, $operation);
183 }
184}
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
canPerform(int $groupId, int $userId, bool|string $role, string $type, string $feature, string $operation, bool $isAdmin=false)
Определения OperationService.php:40
filterUsersWithAccess(int $groupId, array $users, string $type, string $feature, string $operation, bool $isAdmin=false)
Определения OperationService.php:16
static GetOptionString($module_id, $name, $def="", $site=false, $bExactSite=false)
Определения option.php:8
static GetOperationPerm($type, $id, $feature, $operation)
Определения group_features_perms.php:815
</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
$user
Определения mysql_to_pgsql.php:33
return false
Определения prolog_main_admin.php:185
const SONET_ROLES_USER
Определения include.php:31
const SONET_ROLES_EMPLOYEE
Определения include.php:34
const SONET_ROLES_AUTHORIZED
Определения include.php:36
const SONET_ROLES_MODERATOR
Определения include.php:30
const SONET_ROLES_OWNER
Определения include.php:29
const SONET_ROLES_BAN
Определения include.php:32
const SONET_ROLES_ALL
Определения include.php:35