1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
user.php
См. документацию.
1<?php
8namespace Bitrix\Sender\Security;
9
10use Bitrix\Main\Config\Option;
11use Bitrix\Main\Engine\CurrentUser;
12use Bitrix\Main\Loader;
13use Bitrix\Main\Localization\Loc;
14use Bitrix\Main\UserTable;
15
16use Bitrix\Sender\Integration;
17
18Loc::loadMessages(__FILE__);
19
24class User
25{
27 protected $id = null;
28
30 protected $object;
31
33 protected $access;
34
36 protected static $instanceCurrentUser;
37
39 protected static $instance;
40
41 protected static array $cache = [];
47 public static function current()
48 {
49 if (!static::$instanceCurrentUser)
50 {
51 static::$instanceCurrentUser = new static();
52 }
53
54 return static::$instanceCurrentUser;
55 }
56
63 public static function get($id)
64 {
65 if (!static::$instance || static::$instance->getId() != $id)
66 {
67 static::$instance = new static($id);
68 }
69
70 return static::$instance;
71 }
72
78 public function __construct($id = null)
79 {
80 $this->id = $id;
81 }
82
88 public function getId()
89 {
90 if ($this->isCurrent())
91 {
92 return $this->getObject()->getID();
93 }
94
95 return $this->id;
96 }
97
103 public function isAdmin()
104 {
105 if ($this->isCurrent())
106 {
107 return $this->getObject()->isAdmin();
108 }
109
110 return in_array(1, UserTable::getUserGroupIds($this->id));
111 }
112
118 public function hasAccess()
119 {
120 return $this->getAccess()->canViewAnything();
121 }
122
129 public function getAccess()
130 {
131 if (!$this->access)
132 {
133 $this->access = Access::getInstance($this);
134 }
135
136 return $this->access;
137 }
138
144 public function canView()
145 {
146 if (!$this->isModuleAccessibleOnPortal())
147 {
148 return false;
149 }
150
151 if ($this->isBroadAccess())
152 {
153 return true;
154 }
155
156 if ($this->isPortalAdmin())
157 {
158 return true;
159 }
160
161 if (is_object($GLOBALS['APPLICATION']) && $GLOBALS['APPLICATION']->getGroupRight('sender') !== "D")
162 {
163 return true;
164 }
165
166 return false;
167 }
168
169 private function isBroadAccess()
170 {
171 if ($this->isExtranet())
172 {
173 return false;
174 }
175
176 if (!Integration\Bitrix24\Service::isPortal())
177 {
178 return false;
179 }
180
181 return !Role\Manager::canUse();
182 }
183
184 private function isModuleAccessibleOnPortal()
185 {
186 if (!Integration\Bitrix24\Service::isCloud())
187 {
188 return true;
189 }
190
191 return Option::get('sender', '~is_accessible_on_portal', 'Y') === 'Y';
192 }
193
199 public function canEdit()
200 {
201 if (!$this->isModuleAccessibleOnPortal())
202 {
203 return false;
204 }
205
206 if ($this->isBroadAccess())
207 {
208 return true;
209 }
210
211 if ($this->isPortalAdmin())
212 {
213 return true;
214 }
215
216 if (is_object($GLOBALS['APPLICATION']) && $GLOBALS['APPLICATION']->getGroupRight('sender') === "W")
217 {
218 return true;
219 }
220
221 return false;
222 }
223
229 public function isPortalAdmin()
230 {
231 if (!Integration\Bitrix24\Service::isPortal() && !Integration\Bitrix24\Service::isCloud())
232 {
233 return $this->isAdmin();
234 }
235
236 return $this->getObject()->canDoOperation('bitrix24_config', $this->id);
237 }
238
239 public function isExtranet()
240 {
241 if(!$this->isConfigured())
242 {
243 return false;
244 }
245
246 if(array_key_exists($this->getId(), static::$cache))
247 {
248 return static::$cache[$this->getId()];
249 }
250
251 $result = !\CExtranet::IsIntranetUser(SITE_ID, $this->getId());
252
253 static::$cache[$this->getId()] = $result;
254
255 return $result;
256 }
257
258 private function isConfigured()
259 {
260 return Loader::includeModule('extranet') && $this->getExtranetSiteID();
261 }
262
263 private function getExtranetSiteID()
264 {
265 $extranet_site_id = \COption::GetOptionString("extranet", "extranet_site");
266 if (
267 ($extranet_site_id !== '')
268 && \CSite::GetArrayByID($extranet_site_id)
269 )
270 {
271 return $extranet_site_id;
272 }
273
274 return false;
275 }
276
282 public function isAgreementAccepted()
283 {
284 if (!Integration\Bitrix24\Service::isCloud())
285 {
286 return true;
287 }
288
289 return Agreement::isAcceptedByUser($this->getId());
290 }
291
297 public function canEditPhp()
298 {
299 if (Integration\Bitrix24\Service::isCloud())
300 {
301 return false;
302 }
303
304 return $this->getObject()->canDoOperation('edit_php', $this->id);
305 }
306
312 public function canUseLpa()
313 {
314 if (Integration\Bitrix24\Service::isCloud())
315 {
316 return false;
317 }
318
319 return $this->getObject()->canDoOperation('lpa_template_edit', $this->id);
320 }
321
327 public function getObject()
328 {
329 if ($this->object)
330 {
331 return $this->object;
332 }
333
334 if ($this->isCurrent())
335 {
336 $this->object = (is_object($GLOBALS['USER']) && ($GLOBALS['USER'] instanceof \CUser)) ? $GLOBALS['USER'] : null;
337 }
338
339 if (!$this->object)
340 {
341 $this->object = new \CUser();
342 }
343
344 return $this->object;
345 }
346
347 private function isCurrent(): bool
348 {
349 return !$this->id || ($this?->id == CurrentUser::get()->getId());
350 }
351}
static getInstance()
Определения application.php:98
static isAcceptedByUser($userId)
Определения agreement.php:22
getAccess()
Определения user.php:129
getId()
Определения user.php:88
isAgreementAccepted()
Определения user.php:282
canView()
Определения user.php:144
canUseLpa()
Определения user.php:312
static current()
Определения user.php:47
static array $cache
Определения user.php:41
canEditPhp()
Определения user.php:297
static $instanceCurrentUser
Определения user.php:36
isPortalAdmin()
Определения user.php:229
getObject()
Определения user.php:327
canEdit()
Определения user.php:199
isAdmin()
Определения user.php:103
isExtranet()
Определения user.php:239
__construct($id=null)
Определения user.php:78
hasAccess()
Определения user.php:118
static $instance
Определения user.php:39
</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
$GLOBALS['____1690880296']
Определения license.php:1
const SITE_ID
Определения sonet_set_content_view.php:12