Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
access.php
1<?php
2
10
15
16class Access
17{
18 public static function canCreate(array $params = []): bool
19 {
20 $siteId = (string)($params['siteId'] ?? SITE_ID);
21 $checkAdminSession = (bool)($params['checkAdminSession'] ?? true);
22
23 return (
24 \CSocNetUser::isCurrentUserModuleAdmin(SITE_ID, $checkAdminSession)
25 || (\CMain::getGroupRight('socialnetwork', false, 'Y', 'Y', [ $siteId, false ]) >= 'K')
26 );
27 }
28
29 public static function canView(array $params = []): bool
30 {
31 $groupId = (int)($params['groupId'] ?? 0);
32 $currentUserId = (int)($params['userId'] ?? Helper\User::getCurrentUserId());
33 $checkAdminSession = (bool)($params['checkAdminSession'] ?? true);
34
35 if ($groupId <= 0)
36 {
37 return false;
38 }
39
40 if ($currentUserId <= 0)
41 {
42 return false;
43 }
44
45 $group = WorkgroupTable::getList([
46 'filter' => [
47 '=ID' => $groupId,
48 ],
49 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID', 'VISIBLE' ],
50 ])->fetchObject();
51 if (!$group)
52 {
53 return false;
54 }
55
56 $currentUserRelation = UserToGroupTable::getList([
57 'filter' => [
58 '=GROUP_ID' => $groupId,
59 '=USER_ID' => $currentUserId,
60 ],
61 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
62 ])->fetchObject();
63
64 $accessManager = new AccessManager(
65 $group,
66 $currentUserRelation,
67 $currentUserRelation,
68 [],
69 [
70 'checkAdminSession' => $checkAdminSession,
71 ]
72 );
73
74 return $accessManager->canView();
75 }
76
77 public static function canModify(array $params = []): bool
78 {
79 $groupId = (int)($params['groupId'] ?? 0);
80 $currentUserId = (int)($params['userId'] ?? Helper\User::getCurrentUserId());
81 $checkAdminSession = (bool)($params['checkAdminSession'] ?? true);
82
83 if ($groupId <= 0)
84 {
85 return false;
86 }
87
88 if ($currentUserId <= 0)
89 {
90 return false;
91 }
92
93 $group = WorkgroupTable::getList([
94 'filter' => [
95 '=ID' => $groupId,
96 ],
97 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID' ],
98 ])->fetchObject();
99 if (!$group)
100 {
101 return false;
102 }
103
104 $currentUserRelation = UserToGroupTable::getList([
105 'filter' => [
106 '=GROUP_ID' => $groupId,
107 '=USER_ID' => $currentUserId,
108 ],
109 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
110 ])->fetchObject();
111
112 $accessManager = new AccessManager(
113 $group,
114 $currentUserRelation,
115 $currentUserRelation,
116 [],
117 [
118 'checkAdminSession' => $checkAdminSession,
119 ]
120 );
121
122 return $accessManager->canModify();
123 }
124
125 public static function canUpdate(array $params = []): bool
126 {
127 return static::canModify($params);
128 }
129
130 public static function canSetOwner(array $params = []): bool
131 {
132 $groupId = (int)($params['groupId'] ?? 0);
133 $userId = (int)($params['userId'] ?? 0);
134 $currentUserId = Helper\User::getCurrentUserId();
135
136 if (
137 $groupId <= 0
138 || $userId <= 0
139 || $currentUserId <= 0
140 )
141 {
142 return false;
143 }
144
145 $group = WorkgroupTable::getList([
146 'filter' => [
147 '=ID' => $groupId,
148 ],
149 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID' ],
150 ])->fetchObject();
151 if (!$group)
152 {
153 return false;
154 }
155
156 $targetUserRelation = UserToGroupTable::getList([
157 'filter' => [
158 '=GROUP_ID' => $groupId,
159 '=USER_ID' => $userId,
160 ],
161 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
162 ])->fetchObject();
163
164 $currentUserRelation = UserToGroupTable::getList([
165 'filter' => [
166 '=GROUP_ID' => $groupId,
167 '=USER_ID' => $currentUserId,
168 ],
169 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
170 ])->fetchObject();
171
172 $accessManager = new AccessManager(
173 $group,
174 $targetUserRelation,
175 $currentUserRelation
176 );
177
178 return $accessManager->canSetOwner();
179 }
180
181 public static function canSetScrumMaster(array $params = []): bool
182 {
183 $groupId = (int)($params['groupId'] ?? 0);
184 $userId = ($params['userId'] ?? null);
185 $currentUserId = Helper\User::getCurrentUserId();
186
187 if (
188 $groupId <= 0
189 || $userId <= 0
190 || $currentUserId <= 0
191 )
192 {
193 return false;
194 }
195
196 $group = WorkgroupTable::getList([
197 'filter' => [
198 '=ID' => $groupId,
199 ],
200 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID' ],
201 ])->fetchObject();
202 if (!$group)
203 {
204 return false;
205 }
206
207 $targetUserRelation = UserToGroupTable::getList([
208 'filter' => [
209 '=GROUP_ID' => $groupId,
210 '=USER_ID' => $userId,
211 ],
212 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
213 ])->fetchObject();
214
215 $currentUserRelation = UserToGroupTable::getList([
216 'filter' => [
217 '=GROUP_ID' => $groupId,
218 '=USER_ID' => $currentUserId,
219 ],
220 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
221 ])->fetchObject();
222
223 $accessManager = new AccessManager(
224 $group,
225 $targetUserRelation,
226 $currentUserRelation
227 );
228
229 return $accessManager->canSetScrumMaster();
230 }
231
232 public static function canDeleteOutgoingRequest(array $params = []): bool
233 {
234 $groupId = (int)($params['groupId'] ?? 0);
235 $userId = ($params['userId'] ?? null);
236 $currentUserId = Helper\User::getCurrentUserId();
237
238 if (
239 $groupId <= 0
240 || $userId <= 0
241 || $currentUserId <= 0
242 )
243 {
244 return false;
245 }
246
247 $group = WorkgroupTable::getList([
248 'filter' => [
249 '=ID' => $groupId,
250 ],
251 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID', 'INITIATE_PERMS' ],
252 ])->fetchObject();
253 if (!$group)
254 {
255 return false;
256 }
257
258 $targetUserRelation = UserToGroupTable::getList([
259 'filter' => [
260 '=GROUP_ID' => $groupId,
261 '=USER_ID' => $userId,
262 ],
263 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID', 'INITIATED_BY_TYPE', 'INITIATED_BY_USER_ID' ],
264 ])->fetchObject();
265
266 $currentUserRelation = UserToGroupTable::getList([
267 'filter' => [
268 '=GROUP_ID' => $groupId,
269 '=USER_ID' => $currentUserId,
270 ],
271 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
272 ])->fetchObject();
273
274 $accessManager = new AccessManager(
275 $group,
276 $targetUserRelation,
277 $currentUserRelation
278 );
279
280 return $accessManager->canDeleteOutgoingRequest();
281 }
282
283 public static function canDeleteIncomingRequest(array $params = []): bool
284 {
285 $groupId = (int)($params['groupId'] ?? 0);
286 $userId = ($params['userId'] ?? null);
287 $currentUserId = Helper\User::getCurrentUserId();
288
289 if (
290 $groupId <= 0
291 || $userId <= 0
292 || $currentUserId <= 0
293 )
294 {
295 return false;
296 }
297
298 $group = WorkgroupTable::getList([
299 'filter' => [
300 '=ID' => $groupId,
301 ],
302 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID' ],
303 ])->fetchObject();
304 if (!$group)
305 {
306 return false;
307 }
308
309 $targetUserRelation = UserToGroupTable::getList([
310 'filter' => [
311 '=GROUP_ID' => $groupId,
312 '=USER_ID' => $userId,
313 ],
314 'select' => [ 'ID', 'ROLE', 'GROUP_ID', 'INITIATED_BY_TYPE', 'INITIATED_BY_USER_ID' ],
315 ])->fetchObject();
316
317 $currentUserRelation = UserToGroupTable::getList([
318 'filter' => [
319 '=GROUP_ID' => $groupId,
320 '=USER_ID' => $currentUserId,
321 ],
322 'select' => [ 'ID', 'GROUP_ID' ],
323 ])->fetchObject();
324
325 $accessManager = new AccessManager(
326 $group,
327 $targetUserRelation,
328 $currentUserRelation
329 );
330
331 return $accessManager->canDeleteIncomingRequest();
332 }
333
334 public static function canProcessIncomingRequest(array $params = []): bool
335 {
336 $groupId = (int)($params['groupId'] ?? 0);
337 $userId = ($params['userId'] ?? null);
338 $currentUserId = Helper\User::getCurrentUserId();
339
340 if (
341 $groupId <= 0
342 || $userId <= 0
343 || $currentUserId <= 0
344 )
345 {
346 return false;
347 }
348
349 $group = WorkgroupTable::getList([
350 'filter' => [
351 '=ID' => $groupId,
352 ],
353 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID', 'INITIATE_PERMS' ],
354 ])->fetchObject();
355 if (!$group)
356 {
357 return false;
358 }
359
360 $targetUserRelation = UserToGroupTable::getList([
361 'filter' => [
362 '=GROUP_ID' => $groupId,
363 '=USER_ID' => $userId,
364 ],
365 'select' => [ 'ID', 'ROLE', 'GROUP_ID', 'INITIATED_BY_TYPE' ],
366 ])->fetchObject();
367
368 $currentUserRelation = UserToGroupTable::getList([
369 'filter' => [
370 '=GROUP_ID' => $groupId,
371 '=USER_ID' => $currentUserId,
372 ],
373 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
374 ])->fetchObject();
375
376 $accessManager = new AccessManager(
377 $group,
378 $targetUserRelation,
379 $currentUserRelation
380 );
381
382 return $accessManager->canProcessIncomingRequest();
383 }
384
385 public static function canExclude(array $params = []): bool
386 {
387 $groupId = (int)($params['groupId'] ?? 0);
388 $userId = ($params['userId'] ?? null);
389 $currentUserId = Helper\User::getCurrentUserId();
390
391 $group = WorkgroupTable::getList([
392 'filter' => [
393 '=ID' => $groupId,
394 ],
395 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID', 'INITIATE_PERMS' ],
396 ])->fetchObject();
397 if (!$group)
398 {
399 return false;
400 }
401
402 $targetUserRelation = UserToGroupTable::getList([
403 'filter' => [
404 '=GROUP_ID' => $groupId,
405 '=USER_ID' => $userId,
406 ],
407 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID', 'AUTO_MEMBER' ],
408 ])->fetchObject();
409
410 $currentUserRelation = UserToGroupTable::getList([
411 'filter' => [
412 '=GROUP_ID' => $groupId,
413 '=USER_ID' => $currentUserId,
414 ],
415 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
416 ])->fetchObject();
417
418 $accessManager = new AccessManager(
419 $group,
420 $targetUserRelation,
421 $currentUserRelation
422 );
423
424 return $accessManager->canExclude();
425 }
426
427 public static function canJoin(array $params = []): bool
428 {
429 $groupId = (int)($params['groupId'] ?? 0);
430 $userId = ($params['userId'] ?? Helper\User::getCurrentUserId());
431
432 if (
433 $groupId <= 0
434 || $userId <= 0
435 )
436 {
437 return false;
438 }
439
440 $group = WorkgroupTable::getList([
441 'filter' => [
442 '=ID' => $groupId,
443 ],
444 'select' => [ 'ID', 'CLOSED', 'VISIBLE' ],
445 ])->fetchObject();
446 if (!$group)
447 {
448 return false;
449 }
450
451 $currentUserRelation = UserToGroupTable::getList([
452 'filter' => [
453 '=GROUP_ID' => $groupId,
454 '=USER_ID' => $userId,
455 ],
456 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID', 'INITIATED_BY_TYPE' ],
457 ])->fetchObject();
458
459 $accessManager = new AccessManager(
460 $group,
461 null,
462 $currentUserRelation
463 );
464
465 return $accessManager->canJoin();
466 }
467
468 public static function canLeave(array $params = []): bool
469 {
470 $groupId = (int)($params['groupId'] ?? 0);
471 $userId = ($params['userId'] ?? Helper\User::getCurrentUserId());
472
473 if (
474 $groupId <= 0
475 || $userId <= 0
476 )
477 {
478 return false;
479 }
480
481 $group = WorkgroupTable::getList([
482 'filter' => [
483 '=ID' => $groupId,
484 ],
485 'select' => [ 'ID', 'PROJECT', 'SCRUM_MASTER_ID' ],
486 ])->fetchObject();
487 if (!$group)
488 {
489 return false;
490 }
491
492 $currentUserRelation = UserToGroupTable::getList([
493 'filter' => [
494 '=GROUP_ID' => $groupId,
495 '=USER_ID' => $userId,
496 ],
497 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID', 'AUTO_MEMBER' ],
498 ])->fetchObject();
499
500 $accessManager = new AccessManager(
501 $group,
502 null,
503 $currentUserRelation
504 );
505
506 return $accessManager->canLeave();
507 }
508
509 public static function canSetModerator(array $params = []): bool
510 {
511 $groupId = (int)($params['groupId'] ?? 0);
512 $userId = ($params['userId'] ?? null);
513 $currentUserId = Helper\User::getCurrentUserId();
514
515 if (
516 $groupId <= 0
517 || $userId <= 0
518 || $currentUserId <= 0
519 )
520 {
521 return false;
522 }
523
524 $group = WorkgroupTable::getList([
525 'filter' => [
526 '=ID' => $groupId,
527 ],
528 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID' ],
529 ])->fetchObject();
530 if (!$group)
531 {
532 return false;
533 }
534
535 $targetUserRelation = UserToGroupTable::getList([
536 'filter' => [
537 '=GROUP_ID' => $groupId,
538 '=USER_ID' => $userId,
539 ],
540 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
541 ])->fetchObject();
542
543 $currentUserRelation = UserToGroupTable::getList([
544 'filter' => [
545 '=GROUP_ID' => $groupId,
546 '=USER_ID' => $currentUserId,
547 ],
548 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
549 ])->fetchObject();
550
551 $accessManager = new AccessManager(
552 $group,
553 $targetUserRelation,
554 $currentUserRelation
555 );
556
557 return $accessManager->canSetModerator();
558 }
559
560 public static function canRemoveModerator(array $params = []): bool
561 {
562 $groupId = (int)($params['groupId'] ?? 0);
563 $userId = ($params['userId'] ?? null);
564 $currentUserId = Helper\User::getCurrentUserId();
565
566 if (
567 $groupId <= 0
568 || $userId <= 0
569 || $currentUserId <= 0
570 )
571 {
572 return false;
573 }
574
575 $group = WorkgroupTable::getList([
576 'filter' => [
577 '=ID' => $groupId,
578 ],
579 'select' => [ 'ID', 'CLOSED', 'PROJECT', 'SCRUM_MASTER_ID' ],
580 ])->fetchObject();
581 if (!$group)
582 {
583 return false;
584 }
585
586 $targetUserRelation = UserToGroupTable::getList([
587 'filter' => [
588 '=GROUP_ID' => $groupId,
589 '=USER_ID' => $userId,
590 ],
591 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
592 ])->fetchObject();
593
594 $currentUserRelation = UserToGroupTable::getList([
595 'filter' => [
596 '=GROUP_ID' => $groupId,
597 '=USER_ID' => $currentUserId,
598 ],
599 'select' => [ 'ID', 'ROLE', 'USER_ID', 'GROUP_ID' ],
600 ])->fetchObject();
601
602 $accessManager = new AccessManager(
603 $group,
604 $targetUserRelation,
605 $currentUserRelation
606 );
607
608 return $accessManager->canRemoveModerator();
609 }
610}
static canSetModerator(array $params=[])
Definition access.php:509
static canCreate(array $params=[])
Definition access.php:18
static canRemoveModerator(array $params=[])
Definition access.php:560
static canSetOwner(array $params=[])
Definition access.php:130
static canDeleteIncomingRequest(array $params=[])
Definition access.php:283
static canSetScrumMaster(array $params=[])
Definition access.php:181
static canModify(array $params=[])
Definition access.php:77
static canExclude(array $params=[])
Definition access.php:385
static canDeleteOutgoingRequest(array $params=[])
Definition access.php:232
static canProcessIncomingRequest(array $params=[])
Definition access.php:334