1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
group_features_perms.php
См. документацию.
1<?php
2
6
8
9$GLOBALS["arSonetFeaturesPermsCache"] = array();
10
12{
13 /***************************************/
14 /******** DATA MODIFICATION **********/
15 /***************************************/
16 public static function CheckFields($ACTION, &$arFields, $ID = 0)
17 {
19
20 $arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
21
22 if ($ACTION !== 'ADD' && (int)$ID <= 0)
23 {
24 $APPLICATION->ThrowException("System error 870164", "ERROR");
25 return false;
26 }
27
28 if ((is_set($arFields, "FEATURE_ID") || $ACTION === "ADD") && (int)$arFields["FEATURE_ID"] <= 0)
29 {
30 $APPLICATION->ThrowException(GetMessage("SONET_GFP_EMPTY_GROUP_FEATURE_ID"), "EMPTY_FEATURE_ID");
31 return false;
32 }
33
34 if (is_set($arFields, "FEATURE_ID"))
35 {
36 $arResult = CSocNetFeatures::GetByID($arFields["FEATURE_ID"]);
37 if ($arResult == false)
38 {
39 $APPLICATION->ThrowException(str_replace("#ID#", $arFields["FEATURE_ID"], GetMessage("SONET_GFP_ERROR_NO_GROUP_FEATURE_ID")), "ERROR_NO_FEATURE_ID");
40 return false;
41 }
42 }
43
44 $groupFeature = "";
45 $groupFeatureType = "";
46
47 if ((is_set($arFields, "OPERATION_ID") || $ACTION === "ADD") && $arFields["OPERATION_ID"] == '')
48 {
49 $APPLICATION->ThrowException(GetMessage("SONET_GFP_EMPTY_OPERATION_ID"), "EMPTY_OPERATION_ID");
50 return false;
51 }
52
53 if (is_set($arFields, "OPERATION_ID"))
54 {
55 $arFields["OPERATION_ID"] = mb_strtolower($arFields["OPERATION_ID"]);
56
57 if (is_set($arFields, "FEATURE_ID"))
58 {
59 $arGroupFeature = CSocNetFeatures::GetByID($arFields["FEATURE_ID"]);
60 if ($arGroupFeature != false)
61 {
62 $groupFeature = $arGroupFeature["FEATURE"];
63 $groupFeatureType = $arGroupFeature["ENTITY_TYPE"];
64 }
65 }
66 elseif ($ACTION !== "ADD" && (int)$ID > 0)
67 {
68 $dbGroupFeature = CSocNetFeaturesPerms::GetList(
69 array(),
70 array("ID" => $ID),
71 false,
72 false,
73 array("FEATURE_FEATURE", "FEATURE_ENTITY_TYPE")
74 );
75 if ($arGroupFeature = $dbGroupFeature->Fetch())
76 {
77 $groupFeature = $arGroupFeature["FEATURE_FEATURE"];
78 $groupFeatureType = $arGroupFeature["FEATURE_ENTITY_TYPE"];
79 }
80 }
81 if (
82 $groupFeature == ''
83 || !array_key_exists($groupFeature, $arSocNetFeaturesSettings)
84 )
85 {
86 $APPLICATION->ThrowException(GetMessage("SONET_GFP_BAD_OPERATION_ID"), "BAD_OPERATION_ID");
87 return false;
88 }
89
90 if (!array_key_exists($arFields["OPERATION_ID"], $arSocNetFeaturesSettings[$groupFeature]["operations"]))
91 {
92 $APPLICATION->ThrowException(GetMessage("SONET_GFP_NO_OPERATION_ID"), "NO_OPERATION_ID");
93 return false;
94 }
95 }
96
97 if ((is_set($arFields, "ROLE") || $ACTION === "ADD") && $arFields["ROLE"] == '')
98 {
99 $APPLICATION->ThrowException(GetMessage("SONET_GFP_EMPTY_ROLE"), "EMPTY_ROLE");
100 return false;
101 }
102
103 if (is_set($arFields, "ROLE"))
104 {
105 if ($groupFeatureType == '')
106 {
107 if (is_set($arFields, "FEATURE_ID"))
108 {
109 $arGroupFeature = CSocNetFeatures::GetByID($arFields["FEATURE_ID"]);
110 if ($arGroupFeature != false)
111 {
112 $groupFeatureType = $arGroupFeature["ENTITY_TYPE"];
113 }
114 }
115 elseif ($ACTION !== "ADD" && (int)$ID > 0)
116 {
117 $dbGroupFeature = CSocNetFeaturesPerms::GetList(
118 array(),
119 array("ID" => $ID),
120 false,
121 false,
122 array("FEATURE_FEATURE", "FEATURE_ENTITY_TYPE")
123 );
124 if ($arGroupFeature = $dbGroupFeature->Fetch())
125 {
126 $groupFeatureType = $arGroupFeature["FEATURE_ENTITY_TYPE"];
127 }
128 }
129 }
130 if ($groupFeatureType == '' || !in_array($groupFeatureType, $arSocNetAllowedEntityTypes))
131 {
132 $APPLICATION->ThrowException(GetMessage("SONET_GF_EMPTY_ENTITY_TYPE"), "BAD_TYPE");
133 return false;
134 }
135 if ($groupFeatureType == SONET_ENTITY_GROUP)
136 {
137 if (!in_array($arFields["ROLE"], $arSocNetAllowedRolesForFeaturesPerms))
138 {
139 $APPLICATION->ThrowException(str_replace("#ID#", $arFields["ROLE"], GetMessage("SONET_GFP_ERROR_NO_ROLE")), "ERROR_NO_SITE");
140 return false;
141 }
142 }
143 else
144 {
145 if (!in_array($arFields["ROLE"], $arSocNetAllowedRelationsType))
146 {
147 $APPLICATION->ThrowException(str_replace("#ID#", $arFields["ROLE"], GetMessage("SONET_GFP_ERROR_NO_ROLE")), "ERROR_NO_SITE");
148 return false;
149 }
150
152 {
154 }
155 }
156 }
157
158 return True;
159 }
160
161 public static function Delete($ID)
162 {
163 global $DB, $CACHE_MANAGER;
164
165 if (!CSocNetGroup::__ValidateID($ID))
166 return false;
167
168 $ID = intval($ID);
169 $bSuccess = True;
170
171 $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetFeaturesPermsDelete");
172 while ($arEvent = $db_events->Fetch())
173 if (ExecuteModuleEventEx($arEvent, array($ID))===false)
174 return false;
175
176 $events = GetModuleEvents("socialnetwork", "OnSocNetFeaturesPermsDelete");
177 while ($arEvent = $events->Fetch())
178 ExecuteModuleEventEx($arEvent, array($ID));
179
180 if ($bSuccess)
181 {
182 $bSuccess = $DB->Query("DELETE FROM b_sonet_features2perms WHERE ID = ".$ID."", true);
183 if ($bSuccess)
184 {
185 if (defined("BX_COMP_MANAGED_CACHE"))
186 {
187 $CACHE_MANAGER->ClearByTag('sonet_features2perms');
188 $CACHE_MANAGER->ClearByTag("sonet_features2perms_".$ID);
189 }
190 else
191 {
192 $dbGroupFeaturePerm = CSocNetFeaturesPerms::GetList(
193 array(),
194 array("ID" => $ID),
195 false,
196 false,
197 array("FEATURE_ENTITY_TYPE", "FEATURE_ENTITY_ID")
198 );
199 if ($arGroupFeaturePerm = $dbGroupFeaturePerm->Fetch())
200 {
201 $cache = new CPHPCache;
202 $cache->CleanDir(self::getCachePath($arGroupFeaturePerm['FEATURE_ENTITY_TYPE'], $arGroupFeaturePerm['FEATURE_ENTITY_ID']));
203 }
204 }
205 }
206 }
207
208 return $bSuccess;
209 }
210
211 public static function Update($ID, $arFields)
212 {
213 global $DB, $CACHE_MANAGER;
214
215 if (!CSocNetGroup::__ValidateID($ID))
216 return false;
217
218 $ID = intval($ID);
219
221
223 return false;
224
225 $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetFeaturesPermsUpdate");
226 while ($arEvent = $db_events->Fetch())
227 {
228 if (ExecuteModuleEventEx($arEvent, array($ID, $arFields)) === false)
229 {
230 return false;
231 }
232 }
233
234 $strUpdate = $DB->PrepareUpdate("b_sonet_features2perms", $arFields);
236
237 if ($strUpdate <> '')
238 {
239 $strSql =
240 "UPDATE b_sonet_features2perms SET ".
241 " ".$strUpdate." ".
242 "WHERE ID = ".$ID." ";
243 $DB->Query($strSql);
244
245 $events = GetModuleEvents("socialnetwork", "OnSocNetFeaturesPermsUpdate");
246 while ($arEvent = $events->Fetch())
247 {
249 }
250
251 if (defined("BX_COMP_MANAGED_CACHE"))
252 {
253 $CACHE_MANAGER->ClearByTag('sonet_features2perms');
254 $CACHE_MANAGER->ClearByTag("sonet_features2perms_".$ID);
255 }
256 else
257 {
258 $dbGroupFeaturePerm = CSocNetFeaturesPerms::GetList(
259 array(),
260 array("ID" => $ID),
261 false,
262 false,
263 array("FEATURE_ENTITY_TYPE", "FEATURE_ENTITY_ID")
264 );
265 if ($arGroupFeaturePerm = $dbGroupFeaturePerm->Fetch())
266 {
267 $cache = new CPHPCache;
268 $cache->CleanDir(self::getCachePath($arGroupFeaturePerm['FEATURE_ENTITY_TYPE'], $arGroupFeaturePerm['FEATURE_ENTITY_ID']));
269 }
270 }
271 }
272 else
273 {
274 $ID = False;
275 }
276
277 return $ID;
278 }
279
280 public static function SetPerm($featureID, $operation, $perm)
281 {
282 global $APPLICATION;
283
284 $arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
285
286 $featureID = intval($featureID);
287 $operation = Trim($operation);
288 $perm = Trim($perm);
289
290 $dbResult = CSocNetFeaturesPerms::GetList(
291 array(),
292 array(
293 "FEATURE_ID" => $featureID,
294 "OPERATION_ID" => $operation,
295 ),
296 false,
297 false,
298 array("ID", "FEATURE_ENTITY_TYPE", "FEATURE_ENTITY_ID", "FEATURE_FEATURE", "OPERATION_ID", "ROLE")
299 );
300
301 if ($arResult = $dbResult->Fetch())
302 {
303 $r = CSocNetFeaturesPerms::Update($arResult["ID"], array("ROLE" => $perm));
304 }
305 else
306 {
307 $r = CSocNetFeaturesPerms::Add(array("FEATURE_ID" => $featureID, "OPERATION_ID" => $operation, "ROLE" => $perm));
308 }
309
310 if (!$r)
311 {
312 $errorMessage = "";
313 if ($e = $APPLICATION->GetException())
314 {
315 $errorMessage = $e->GetString();
316 }
317
318 if ($errorMessage == '')
319 {
320 $errorMessage = GetMessage("SONET_GF_ERROR_SET").".";
321 }
322
323 $APPLICATION->ThrowException($errorMessage, "ERROR_SET_RECORD");
324 return false;
325 }
326
327 if (!$arResult)
328 {
329 $arFeature = CSocNetFeatures::GetByID($featureID);
330 $entity_type = $arFeature["ENTITY_TYPE"];
331 $entity_id = $arFeature["ENTITY_ID"];
332 $feature = $arFeature["FEATURE"];
333 }
334 else
335 {
336 $entity_type = $arResult["FEATURE_ENTITY_TYPE"];
337 $entity_id = $arResult["FEATURE_ENTITY_ID"];
338 $feature = $arResult["FEATURE_FEATURE"];
339 }
340
341 if(empty($arResult) || $arResult["ROLE"] != $perm)
342 {
344 $entity_type,
345 $entity_id,
346 $feature,
347 (
349 && $arResult["ROLE"] != $perm
350 ? $arResult["OPERATION_ID"]
351 : $operation
352 ),
353 $perm
354 );
355 }
356
357 if (
358 !in_array($feature, array("tasks", "files", "blog"))
359 && is_array($arSocNetFeaturesSettings[$feature]["subscribe_events"] ?? null))
360 {
361 $arEventsTmp = array_keys($arSocNetFeaturesSettings[$feature]["subscribe_events"]);
362 $rsLog = CSocNetLog::GetList(
363 array(),
364 array(
365 "ENTITY_TYPE" => $entity_type,
366 "ENTITY_ID" => $entity_id,
367 "EVENT_ID" => $arEventsTmp
368 ),
369 false,
370 false,
371 array("ID", "EVENT_ID")
372 );
373 while($arLog = $rsLog->Fetch())
374 {
377 $arLog["ID"],
378 $entity_type,
379 $entity_id,
380 $feature,
381 $arSocNetFeaturesSettings[$feature]["subscribe_events"][$arLog["EVENT_ID"]]["OPERATION"]
382 );
383 }
384 }
385
386
387 return $r;
388 }
389
390 /***************************************/
391 /********** DATA SELECTION ***********/
392 /***************************************/
393 public static function GetByID($ID)
394 {
395 if (!CSocNetGroup::__ValidateID($ID))
396 return false;
397
398 $ID = intval($ID);
399
400 $dbResult = CSocNetFeaturesPerms::GetList(Array(), Array("ID" => $ID));
401 if ($arResult = $dbResult->GetNext())
402 {
403 return $arResult;
404 }
405
406 return False;
407 }
408
409 /***************************************/
410 /********** COMMON METHODS ***********/
411 /***************************************/
412 public static function CurrentUserCanPerformOperation($type, $id, $feature, $operation, $site_id = SITE_ID)
413 {
414 global $USER;
415
416 $userID = 0;
417 if (is_object($USER) && $USER->IsAuthorized())
418 {
419 $userID = (int)$USER->getId();
420 }
421
422 $bCurrentUserIsAdmin = CSocNetUser::IsCurrentUserModuleAdmin($site_id);
423
424 return CSocNetFeaturesPerms::CanPerformOperation($userID, $type, $id, $feature, $operation, $bCurrentUserIsAdmin);
425 }
426
427 public static function CanPerformOperation($userID, $type, $id, $feature, $operation, $bCurrentUserIsAdmin = false)
428 {
430
431 $arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
432
433 $userID = (int)$userID;
434
435 if ((is_array($id) && count($id) <= 0) || (!is_array($id) && $id <= 0))
436 {
437 $APPLICATION->ThrowException(GetMessage("SONET_GF_EMPTY_ENTITY_ID"), "ERROR_EMPTY_ENTITY_ID");
438 return false;
439 }
440
441 $type = Trim($type);
442 if (($type == '') || !in_array($type, $arSocNetAllowedEntityTypes))
443 {
444 $APPLICATION->ThrowException(GetMessage("SONET_GF_ERROR_NO_ENTITY_TYPE"), "ERROR_EMPTY_TYPE");
445 return false;
446 }
447
448 $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm($type, $id, $feature, $operation);
449
451 {
452 $bWorkWithClosedGroups = (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") === "Y");
453 if (is_array($id))
454 {
455 $arGroupToGet = array();
456 foreach($id as $group_id)
457 {
458 if ($featureOperationPerms[$group_id] == false)
459 {
460 $arReturn[$group_id] = false;
461 }
462 else
463 {
464 $arGroupToGet[] = $group_id;
465 }
466 }
467
468 $arGroupToGet = array_unique($arGroupToGet);
469
470 $userRoleInGroup = CSocNetUserToGroup::GetUserRole($userID, $arGroupToGet);
471 $arGroupToGet = array();
472 if (is_array($userRoleInGroup))
473 {
474 foreach($userRoleInGroup as $group_id => $role)
475 {
476 if ($userRoleInGroup[$group_id] == SONET_ROLES_BAN)
477 {
478 $arReturn[$group_id] = false;
479 }
480 else
481 {
482 $arGroupToGet[] = $group_id;
483 }
484 }
485 }
486
487 $arGroupToGet = array_unique($arGroupToGet);
488
489 if (
490 (is_array($arGroupToGet) && count($arGroupToGet) <= 0)
491 || (!is_array($arGroupToGet) && intval($arGroupToGet) <= 0)
492 )
493 {
494 $arReturn = array();
495 foreach($id as $group_id)
496 {
497 $arReturn[$group_id] = false;
498 }
499 return $arReturn;
500 }
501
502 $resGroupTmp = CSocNetGroup::GetList(
503 array("ID" => "ASC"),
504 array("@ID" => $arGroupToGet),
505 false,
506 false,
507 array('ID', 'VISIBLE', 'CLOSED')
508 );
509 while ($arGroupTmp = $resGroupTmp->Fetch())
510 {
511 if (
512 $arGroupTmp["CLOSED"] === "Y"
513 && !in_array($operation, $arSocNetFeaturesSettings[$feature]["minoperation"])
514 )
515 {
516 if (!$bWorkWithClosedGroups)
517 {
518 $arReturn[$arGroupTmp["ID"]] = false;
519 continue;
520 }
521
522 $featureOperationPerms[$arGroupTmp["ID"]] = SONET_ROLES_OWNER;
523 }
524
525 if ($bCurrentUserIsAdmin)
526 {
527 $arReturn[$arGroupTmp["ID"]] = true;
528 continue;
529 }
530
531 if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_ALL)
532 {
533 if ($arGroupTmp["VISIBLE"] === "N")
534 {
535 $featureOperationPerms[$arGroupTmp["ID"]] = SONET_ROLES_USER;
536 }
537 else
538 {
539 $arReturn[$arGroupTmp["ID"]] = true;
540 continue;
541 }
542 }
543
544 if ($featureOperationPerms[$arGroupTmp['ID']] === SONET_ROLES_EMPLOYEE)
545 {
546 $arReturn[$arGroupTmp['ID']] =
547 in_array($userRoleInGroup[$arGroupTmp["ID"]], UserToGroupTable::getRolesMember(), true)
548 && User::isIntranet($userID);
549
550 continue;
551 }
552
553 if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_AUTHORIZED)
554 {
555 if ($userID > 0)
556 {
557 $arReturn[$arGroupTmp["ID"]] = true;
558 continue;
559 }
560
561 $arReturn[$arGroupTmp["ID"]] = false;
562 continue;
563 }
564
565 if ($userRoleInGroup[$arGroupTmp["ID"]] == false)
566 {
567 $arReturn[$arGroupTmp["ID"]] = false;
568 continue;
569 }
570
571 if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_MODERATOR)
572 {
573 if (in_array($userRoleInGroup[$arGroupTmp["ID"]], [SONET_ROLES_MODERATOR, SONET_ROLES_OWNER], true))
574 {
575 $arReturn[$arGroupTmp["ID"]] = true;
576 continue;
577 }
578
579 $arReturn[$arGroupTmp["ID"]] = false;
580 continue;
581 }
582
583 if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_USER)
584 {
585 if (in_array($userRoleInGroup[$arGroupTmp["ID"]], UserToGroupTable::getRolesMember(), true))
586 {
587 $arReturn[$arGroupTmp["ID"]] = true;
588 continue;
589 }
590
591 $arReturn[$arGroupTmp["ID"]] = false;
592 continue;
593 }
594
595 if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_OWNER)
596 {
597 if ($userRoleInGroup[$arGroupTmp["ID"]] === SONET_ROLES_OWNER)
598 {
599 $arReturn[$arGroupTmp["ID"]] = true;
600 continue;
601 }
602
603 $arReturn[$arGroupTmp["ID"]] = false;
604 continue;
605 }
606 }
607
608 return $arReturn ?? false;
609 }
610
611 // not array of groups
612 $id = (int)$id;
613
614 if ($featureOperationPerms == false)
615 {
616 return false;
617 }
618
619 $userRoleInGroup = CSocNetUserToGroup::GetUserRole($userID, $id);
620 if ($userRoleInGroup === SONET_ROLES_BAN)
621 {
622 return false;
623 }
624
625 $arGroupTmp = WorkgroupTable::getList([
626 'select' => ['CLOSED', 'VISIBLE'],
627 'filter' => ['ID' => $id],
628 ])->fetch();
629
630 if (
631 ($arGroupTmp["CLOSED"] ?? null) === "Y"
632 && !in_array($operation, $arSocNetFeaturesSettings[$feature]["minoperation"])
633 )
634 {
635 if (!$bWorkWithClosedGroups)
636 {
637 return false;
638 }
639
640 $featureOperationPerms = SONET_ROLES_OWNER;
641 }
642
643 if ($bCurrentUserIsAdmin)
644 {
645 return true;
646 }
647
648 if ($featureOperationPerms === SONET_ROLES_ALL)
649 {
650 if ($arGroupTmp["VISIBLE"] === "N")
651 {
652 $featureOperationPerms = SONET_ROLES_USER;
653 }
654 else
655 {
656 return true;
657 }
658 }
659
660 if ($featureOperationPerms === SONET_ROLES_AUTHORIZED)
661 {
662 return ($userID > 0);
663 }
664
665 if ($featureOperationPerms === SONET_ROLES_EMPLOYEE)
666 {
667 return
668 in_array($userRoleInGroup, UserToGroupTable::getRolesMember(), true)
669 && User::isIntranet($userID);
670 }
671
672 if ($userRoleInGroup == false)
673 {
674 return false;
675 }
676
677 if ($featureOperationPerms === SONET_ROLES_MODERATOR)
678 {
679 return (in_array($userRoleInGroup, array(SONET_ROLES_MODERATOR, SONET_ROLES_OWNER)));
680 }
681
682 if ($featureOperationPerms === SONET_ROLES_USER)
683 {
684 return (in_array($userRoleInGroup, UserToGroupTable::getRolesMember()));
685 }
686
687 if ($featureOperationPerms === SONET_ROLES_OWNER)
688 {
689 return ($userRoleInGroup === SONET_ROLES_OWNER);
690 }
691 }
692 else // user
693 {
694 if (is_array($id))
695 {
696
697 foreach($id as $entity_id)
698 {
699
700 if ($featureOperationPerms[$entity_id] == false)
701 {
702 $arReturn[$entity_id] = false;
703 continue;
704 }
705
706 $usersRelation = CSocNetUserRelations::GetRelation($userID, $entity_id);
707
708 if ($type == SONET_ENTITY_USER && $userID == $entity_id)
709 {
710 $arReturn[$entity_id] = true;
711 continue;
712 }
713
714 if ($bCurrentUserIsAdmin)
715 {
716 $arReturn[$entity_id] = true;
717 continue;
718 }
719
720 if ($userID == $entity_id)
721 {
722 $arReturn[$entity_id] = true;
723 continue;
724 }
725
726 if ($usersRelation == SONET_RELATIONS_BAN)
727 {
728 if (!IsModuleInstalled("im"))
729 {
730 $arReturn[$entity_id] = false;
731 continue;
732 }
733 }
734
735 if ($featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_NONE)
736 {
737 $arReturn[$entity_id] = false;
738 continue;
739 }
740
741 if ($featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_ALL)
742 {
743 $arReturn[$entity_id] = true;
744 continue;
745 }
746
747 if ($featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_AUTHORIZED)
748 {
749 $arReturn[$entity_id] = ($userID > 0);
750 continue;
751 }
752
753 if (
754 $featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_FRIENDS
755 || $featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_FRIENDS2
756 )
757 {
758 $arReturn[$entity_id] = CSocNetUserRelations::IsFriends($userID, $entity_id);
759 continue;
760 }
761 }
762
763 return $arReturn;
764 }
765
766 // not array
767 if ($featureOperationPerms == false)
768 {
769 return false;
770 }
771
772 if ($type === SONET_ENTITY_USER && $userID == $id)
773 {
774 return true;
775 }
776
777 if ($bCurrentUserIsAdmin)
778 {
779 return true;
780 }
781
782 $usersRelation = CSocNetUserRelations::GetRelation($userID, $id);
783 if ($usersRelation == SONET_RELATIONS_BAN && !IsModuleInstalled("im"))
784 {
785 return false;
786 }
787
788 if ($featureOperationPerms == SONET_RELATIONS_TYPE_NONE)
789 {
790 return false;
791 }
792
793 if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL)
794 {
795 return true;
796 }
797
798 if ($featureOperationPerms === SONET_RELATIONS_TYPE_AUTHORIZED)
799 {
800 return ($userID > 0);
801 }
802
803 if (
804 $featureOperationPerms === SONET_RELATIONS_TYPE_FRIENDS
805 || $featureOperationPerms === SONET_RELATIONS_TYPE_FRIENDS2
806 )
807 {
808 return CSocNetUserRelations::IsFriends($userID, $id);
809 }
810 }
811
812 return false;
813 }
814
815 public static function GetOperationPerm($type, $id, $feature, $operation)
816 {
818
819 static $arSonetGroupCache = array();
820
821 $arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
822
823 $type = Trim($type);
824 if (
825 ($type == '')
827 )
828 {
829 $APPLICATION->ThrowException(GetMessage("SONET_GF_ERROR_NO_ENTITY_TYPE"), "ERROR_EMPTY_TYPE");
830 if (is_array($id))
831 {
832 $arReturn = array();
833 foreach($id as $TmpGroupID)
834 {
835 $arReturn[$TmpGroupID] = false;
836 }
837
838 return $arReturn;
839 }
840
841 return false;
842 }
843
844 $feature = mb_strtolower(trim($feature));
845 if ($feature == '')
846 {
847 $APPLICATION->ThrowException(GetMessage("SONET_GF_EMPTY_FEATURE_ID"), "ERROR_EMPTY_FEATURE_ID");
848 if (is_array($id))
849 {
850 $arReturn = array();
851 foreach($id as $TmpGroupID)
852 {
853 $arReturn[$TmpGroupID] = false;
854 }
855
856 return $arReturn;
857 }
858
859 return false;
860 }
861
862 if (
863 !array_key_exists($feature, $arSocNetFeaturesSettings)
864 || !array_key_exists("allowed", $arSocNetFeaturesSettings[$feature])
865 || !in_array($type, $arSocNetFeaturesSettings[$feature]["allowed"])
866 )
867 {
868 $APPLICATION->ThrowException(GetMessage("SONET_GF_ERROR_NO_FEATURE_ID"), "ERROR_NO_FEATURE_ID");
869 if (is_array($id))
870 {
871 $arReturn = array();
872 foreach($id as $TmpGroupID)
873 {
874 $arReturn[$TmpGroupID] = false;
875 }
876
877 return $arReturn;
878 }
879
880 return false;
881 }
882
883 $operation = mb_strtolower(Trim($operation));
884 if (
885 !array_key_exists("operations", $arSocNetFeaturesSettings[$feature])
886 || !array_key_exists($operation, $arSocNetFeaturesSettings[$feature]["operations"])
887 )
888 {
889 if (is_array($id))
890 {
891 $arReturn = array();
892 foreach($id as $TmpGroupID)
893 {
894 $arReturn[$TmpGroupID] = false;
895 }
896
897 return $arReturn;
898 }
899
900 return false;
901 }
902
903 global $arSonetFeaturesPermsCache;
904 if (!isset($arSonetFeaturesPermsCache) || !is_array($arSonetFeaturesPermsCache))
905 {
906 $arSonetFeaturesPermsCache = array();
907 }
908
909 if (is_array($id))
910 {
911 $arFeaturesPerms = array();
912 $arGroupToGet = array();
913 foreach($id as $TmpGroupID)
914 {
915 $arFeaturesPerms[$TmpGroupID] = array();
916
917 if (!array_key_exists($type."_".$TmpGroupID, $arSonetFeaturesPermsCache))
918 {
919 $arGroupToGet[] = $TmpGroupID;
920 }
921 else
922 {
923 $arFeaturesPerms[$TmpGroupID] = $arSonetFeaturesPermsCache[$type."_".$TmpGroupID];
924 }
925 }
926
927 $arGroupToGet = array_unique($arGroupToGet);
928
929 if (!empty($arGroupToGet))
930 {
931 $rsSonetGroup = CSocNetGroup::GetList(
932 array(),
933 array('@ID' => $arGroupToGet),
934 false,
935 false,
936 array('ID', 'VISIBLE', 'OPENED')
937 );
938 while ($arSonetGroup = $rsSonetGroup->Fetch())
939 {
940 if (!isset($arSonetGroupCache[$arSonetGroup['ID']]))
941 {
942 $arSonetGroupCache[$arSonetGroup['ID']] = array(
943 'VISIBLE' => $arSonetGroup['VISIBLE'],
944 'OPENED' => $arSonetGroup['OPENED']
945 );
946 }
947 }
948
949 $dbResult = CSocNetFeaturesPerms::GetList(
950 Array(),
951 Array(
952 "@FEATURE_ENTITY_ID" => $arGroupToGet,
953 "FEATURE_ENTITY_TYPE" => $type,
954 "FEATURE_ACTIVE" => "Y"
955 ),
956 false,
957 false,
958 array("OPERATION_ID", "FEATURE_ENTITY_ID", "FEATURE_FEATURE", "ROLE")
959 );
960 while ($arResult = $dbResult->Fetch())
961 {
962 if (
963 !array_key_exists($arResult["FEATURE_ENTITY_ID"], $arFeaturesPerms)
964 || !array_key_exists($arResult["FEATURE_FEATURE"], $arFeaturesPerms[$arResult["FEATURE_ENTITY_ID"]])
965 )
966 {
967 $arFeaturesPerms[$arResult["FEATURE_ENTITY_ID"]][$arResult["FEATURE_FEATURE"]] = array();
968 }
969 $arFeaturesPerms[$arResult["FEATURE_ENTITY_ID"]][$arResult["FEATURE_FEATURE"]][$arResult["OPERATION_ID"]] = $arResult["ROLE"];
970 }
971 }
972
973 $arReturn = array();
974
975 foreach ($id as $TmpEntityID)
976 {
977 $arSonetFeaturesPermsCache[$type."_".$TmpEntityID] = $arFeaturesPerms[$TmpEntityID];
978
980 {
981 if (
982 !array_key_exists($feature, $arFeaturesPerms[$TmpEntityID])
983 || !array_key_exists($operation, $arFeaturesPerms[$TmpEntityID][$feature])
984 )
985 {
986 $perm = $arSocNetFeaturesSettings[$feature]["operations"][$operation][SONET_ENTITY_GROUP];
987
988 if (
989 isset($arSonetGroupCache[$TmpEntityID])
990 && $arSonetGroupCache[$TmpEntityID]['OPENED'] === 'Y'
991 && $arSonetGroupCache[$TmpEntityID]['VISIBLE'] === 'Y'
992 && $feature === "blog"
993 && ($perm === SONET_ROLES_USER)
994 && !empty($arSocNetFeaturesSettings[$feature]["minoperation"])
995 && (
996 (
997 is_array($arSocNetFeaturesSettings[$feature]["minoperation"])
998 && in_array($operation, $arSocNetFeaturesSettings[$feature]["minoperation"])
999 )
1000 || (
1001 !is_array($arSocNetFeaturesSettings[$feature]["minoperation"])
1002 && $operation == $arSocNetFeaturesSettings[$feature]["minoperation"]
1003 )
1004 )
1005 )
1006 {
1007 $featureOperationPerms = SONET_ROLES_AUTHORIZED;
1008 }
1009 else
1010 {
1011 $featureOperationPerms = $perm;
1012 }
1013 }
1014 else
1015 {
1016 $featureOperationPerms = $arFeaturesPerms[$TmpEntityID][$feature][$operation];
1017 }
1018 }
1019 else
1020 {
1021 if (!array_key_exists($feature, $arFeaturesPerms[$TmpEntityID]))
1022 {
1023 $featureOperationPerms = $arSocNetFeaturesSettings[$feature]["operations"][$operation][SONET_ENTITY_USER];
1024 }
1025 elseif (!array_key_exists($operation, $arFeaturesPerms[$TmpEntityID][$feature]))
1026 {
1027 $featureOperationPerms = $arSocNetFeaturesSettings[$feature]["operations"][$operation][SONET_ENTITY_USER];
1028 }
1029 else
1030 {
1031 $featureOperationPerms = $arFeaturesPerms[$TmpEntityID][$feature][$operation];
1032 }
1033
1034 if ($featureOperationPerms == SONET_RELATIONS_TYPE_FRIENDS2)
1035 {
1036 $featureOperationPerms = SONET_RELATIONS_TYPE_FRIENDS;
1037 }
1038 }
1039
1040 $arReturn[$TmpEntityID] = $featureOperationPerms;
1041 }
1042
1043 return $arReturn;
1044 }
1045
1046 // not array
1047 $id = (int)$id;
1048 if ($id <= 0)
1049 {
1050 $APPLICATION->ThrowException(GetMessage("SONET_GF_EMPTY_ENTITY_ID"), "ERROR_EMPTY_ENTITY_ID");
1051 return false;
1052 }
1053
1054 $arFeaturesPerms = array();
1055 if (array_key_exists($type."_".$id, $arSonetFeaturesPermsCache))
1056 {
1057 $arFeaturesPerms = $arSonetFeaturesPermsCache[$type."_".$id];
1058 }
1059 else
1060 {
1061 $cache = new CPHPCache;
1062 $cache_time = 31536000;
1063 $cache_id = "entity_"."_".$type."_".$id;
1064 $cache_path = self::getCachePath($type, $id);
1065
1066 $arTmp = array();
1067
1068 if ($cache->InitCache($cache_time, $cache_id, $cache_path))
1069 {
1070 $arCacheVars = $cache->GetVars();
1071 $arTmp = $arCacheVars["RESULT"];
1072 }
1073 else
1074 {
1075 $cache->StartDataCache($cache_time, $cache_id, $cache_path);
1076 if (defined("BX_COMP_MANAGED_CACHE"))
1077 {
1078 $CACHE_MANAGER->StartTagCache($cache_path);
1079 }
1080
1081 $dbResult = CSocNetFeaturesPerms::GetList(
1082 Array(),
1083 Array(
1084 "FEATURE_ENTITY_ID" => $id,
1085 "FEATURE_ENTITY_TYPE" => $type,
1086 "FEATURE_ACTIVE" => "Y"
1087 ),
1088 false,
1089 false,
1090 array("ID", "OPERATION_ID", "FEATURE_ID", "FEATURE_FEATURE", "ROLE")
1091 );
1092 while ($arResult = $dbResult->Fetch())
1093 {
1094 if (defined("BX_COMP_MANAGED_CACHE"))
1095 {
1096 $CACHE_MANAGER->RegisterTag("sonet_features2perms_".$arResult["ID"]);
1097 }
1098 $arTmp[] = $arResult;
1099 }
1100
1101 if (defined("BX_COMP_MANAGED_CACHE"))
1102 {
1103 $dbResult = CSocNetFeatures::GetList(
1104 Array(),
1105 Array("ENTITY_ID" => $id, "ENTITY_TYPE" => $type),
1106 false,
1107 false,
1108 array("ID")
1109 );
1110 while ($arResult = $dbResult->Fetch())
1111 {
1112 $CACHE_MANAGER->RegisterTag("sonet_feature_".$arResult["ID"]);
1113 }
1114 }
1115
1116 if (defined("BX_COMP_MANAGED_CACHE"))
1117 {
1119 {
1120 $CACHE_MANAGER->RegisterTag("sonet_group_".$id);
1121 $CACHE_MANAGER->RegisterTag("sonet_group");
1122 }
1124 {
1125 $CACHE_MANAGER->RegisterTag("USER_CARD_".intval($id / TAGGED_user_card_size));
1126 }
1127
1128 $CACHE_MANAGER->RegisterTag("sonet_features_".$type."_".$id);
1129 }
1130
1131 $arCacheData = Array(
1132 "RESULT" => $arTmp
1133 );
1134
1135 if(defined("BX_COMP_MANAGED_CACHE"))
1136 {
1137 $CACHE_MANAGER->EndTagCache();
1138 }
1139
1140 $cache->EndDataCache($arCacheData);
1141 }
1142
1143 foreach($arTmp as $arResult)
1144 {
1145 if (!array_key_exists($arResult["FEATURE_FEATURE"], $arFeaturesPerms))
1146 {
1147 $arFeaturesPerms[$arResult["FEATURE_FEATURE"]] = array();
1148 }
1149 $arFeaturesPerms[$arResult["FEATURE_FEATURE"]][$arResult["OPERATION_ID"]] = $arResult["ROLE"];
1150 }
1151 $arSonetFeaturesPermsCache[$type."_".$id] = $arFeaturesPerms;
1152 }
1153
1155 {
1156 if (
1157 !array_key_exists($feature, $arFeaturesPerms)
1158 || !array_key_exists($operation, $arFeaturesPerms[$feature])
1159 )
1160 {
1161 if (!isset($arSonetGroupCache[$id]))
1162 {
1163 $sonetGroup = WorkgroupTable::getList([
1164 'select' => ['OPENED', 'VISIBLE'],
1165 'filter' => ['ID' => $id],
1166 ])->fetch();
1167
1168 $arSonetGroupCache[$id] = [
1169 'OPENED' => $sonetGroup['OPENED'] ?? null,
1170 'VISIBLE' => $sonetGroup['VISIBLE'] ?? null,
1171 ];
1172 }
1173
1174 $perm = $arSocNetFeaturesSettings[$feature]["operations"][$operation][SONET_ENTITY_GROUP];
1175
1176 if (
1177 isset($arSonetGroupCache[$id])
1178 && $arSonetGroupCache[$id]['OPENED'] === 'Y'
1179 && $arSonetGroupCache[$id]['VISIBLE'] === 'Y'
1180 && $feature === "blog"
1181 && ($perm === SONET_ROLES_USER)
1182 && !empty($arSocNetFeaturesSettings[$feature]["minoperation"])
1183 && (
1184 (
1185 is_array($arSocNetFeaturesSettings[$feature]["minoperation"])
1186 && in_array($operation, $arSocNetFeaturesSettings[$feature]["minoperation"])
1187 )
1188 || (
1189 !is_array($arSocNetFeaturesSettings[$feature]["minoperation"])
1190 && $operation == $arSocNetFeaturesSettings[$feature]["minoperation"]
1191 )
1192 )
1193 )
1194 {
1195 $featureOperationPerms = SONET_ROLES_AUTHORIZED;
1196 }
1197 else
1198 {
1199 $featureOperationPerms = $perm;
1200 }
1201 }
1202 else
1203 {
1204 $featureOperationPerms = $arFeaturesPerms[$feature][$operation];
1205 }
1206 }
1207 else
1208 {
1209 if (!array_key_exists($feature, $arFeaturesPerms))
1210 {
1211 $featureOperationPerms = $arSocNetFeaturesSettings[$feature]["operations"][$operation][SONET_ENTITY_USER];
1212 }
1213 elseif (!array_key_exists($operation, $arFeaturesPerms[$feature]))
1214 {
1215 $featureOperationPerms = $arSocNetFeaturesSettings[$feature]["operations"][$operation][SONET_ENTITY_USER];
1216 }
1217 else
1218 {
1219 $featureOperationPerms = $arFeaturesPerms[$feature][$operation];
1220 }
1221
1222 if ($featureOperationPerms == SONET_RELATIONS_TYPE_FRIENDS2)
1223 {
1224 $featureOperationPerms = SONET_RELATIONS_TYPE_FRIENDS;
1225 }
1226 }
1227
1228 return $featureOperationPerms;
1229
1230 }
1231
1232 private static function getCachePath($type, $id): string
1233 {
1234 $id = (int)$id;
1235 return '/sonet/features_perms/' . (string)$type . '/' . (int)($id / 1000) . '/' . $id . '/';
1236 }
1237}
$type
Определения options.php:106
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
static processEqualityFieldsToUpdate($fields1, &$update)
Определения util.php:239
static getEqualityFields(&$fields)
Определения util.php:207
static CurrentUserCanPerformOperation($type, $id, $feature, $operation, $site_id=SITE_ID)
Определения group_features_perms.php:412
static Delete($ID)
Определения group_features_perms.php:161
static GetByID($ID)
Определения group_features_perms.php:393
static CheckFields($ACTION, &$arFields, $ID=0)
Определения group_features_perms.php:16
static SetPerm($featureID, $operation, $perm)
Определения group_features_perms.php:280
static GetOperationPerm($type, $id, $feature, $operation)
Определения group_features_perms.php:815
static CanPerformOperation($userID, $type, $id, $feature, $operation, $bCurrentUserIsAdmin=false)
Определения group_features_perms.php:427
static Update($ID, $arFields)
Определения group_features_perms.php:211
static GetRelation($firstUserID, $secondUserID)
Определения user_relations.php:256
static IsFriends($firstUserID, $secondUserID)
Определения user_relations.php:355
Определения cache.php:11
CleanDir($initdir=false, $basedir="cache")
Определения cache.php:25
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array(), $arParams=array())
Определения log.php:338
static SetForSonet($logID, $entity_type, $entity_id, $feature, $operation, $bNew=false)
Определения log_rights.php:320
static DeleteByLogID($LOG_ID)
Определения log_rights.php:232
static SetFeaturePermissions($entity_type, $entity_id, $feature, $operation, $new_perm)
Определения search.php:68
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$perm
Определения options.php:169
if($ajaxMode) $ID
Определения get_user.php:27
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
$ACTION
Определения csv_new_setup.php:27
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
IsModuleInstalled($module_id)
Определения tools.php:5301
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if(intval($iTestTransaction) > 0) $arTmp
Определения payment.php:22
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</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
const SONET_ROLES_USER
Определения include.php:31
const SONET_ENTITY_GROUP
Определения include.php:117
const SONET_ROLES_EMPLOYEE
Определения include.php:34
global $arSocNetAllowedRolesForFeaturesPerms
Определения include.php:99
const SONET_ROLES_AUTHORIZED
Определения include.php:36
const SONET_ENTITY_USER
Определения include.php:118
const SONET_ROLES_MODERATOR
Определения include.php:30
const SONET_ROLES_OWNER
Определения include.php:29
const SONET_ROLES_BAN
Определения include.php:32
const SONET_RELATIONS_TYPE_FRIENDS
Определения include.php:41
const SONET_ROLES_ALL
Определения include.php:35
const SONET_RELATIONS_TYPE_FRIENDS2
Определения include.php:40
const SONET_RELATIONS_TYPE_ALL
Определения include.php:38
const SONET_RELATIONS_TYPE_AUTHORIZED
Определения include.php:39
const SONET_RELATIONS_TYPE_NONE
Определения include.php:42
global $arSocNetAllowedEntityTypes
Определения include.php:123
global $arSocNetAllowedRelationsType
Определения include.php:111
const SONET_RELATIONS_BAN
Определения include.php:26
if( $_SERVER $arSocNetFeaturesSettings['REQUEST_METHOD']=="GET" &&($RestoreDefaults ?? null)<> '' && $SONET_RIGHT=="W" &&check_bitrix_sessid())
Определения options.php:35
$site_id
Определения sonet_set_content_view.php:9
const SITE_ID
Определения sonet_set_content_view.php:12
$GLOBALS['_____370096793']
Определения update_client.php:1
$dbResult
Определения updtr957.php:3