1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
GroupCreateRule.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Permission\Rule;
6
7use Bitrix\Main\Access\AccessibleItem;
8use Bitrix\Main\Access\Rule\AbstractRule;
9use Bitrix\Main\Authentication\Internal\ModuleGroupTable;
10use Bitrix\Main\Config\Option;
11use Bitrix\Socialnetwork\Collab\Integration\Extranet\Extranet;
12use Bitrix\Socialnetwork\Permission\GroupAccessController;
13use Bitrix\Socialnetwork\Permission\Model\GroupModel;
14use Bitrix\Socialnetwork\Permission\User\UserModel;
15use COption;
16use CSocNetUser;
17use CUser;
18
20{
21 protected const MIN_RIGHT = 'D';
22 protected const ENOUGH_RIGHT = 'K';
23
25 protected $controller;
26
28 protected $user;
29
30 public function execute(AccessibleItem $item = null, $params = null): bool
31 {
32 if (!$item instanceof GroupModel)
33 {
34 $this->controller->addError(static::class, 'Wrong instance');
35
36 return false;
37 }
38
39 if (!$this->isAllowCreateByExtranetRule($item))
40 {
41 $this->controller->addError(static::class, 'Creating an extranet group is not possible');
42
43 return false;
44 }
45
46 if ($this->user->isCollaber())
47 {
48 $this->controller->addError(static::class, 'Access denied by collaber role');
49
50 return false;
51 }
52
53 if ($this->user->isAdmin())
54 {
55 return true;
56 }
57
58 if (CSocNetUser::IsUserModuleAdmin($this->user->getUserId(), $item->getSiteIds()))
59 {
60 return true;
61 }
62
63 if ($this->hasPermissions($item))
64 {
65 return true;
66 }
67
68 $this->controller->addError(static::class, 'Access denied by permissions');
69
70 return false;
71 }
72
73 private function isAllowCreateByExtranetRule(GroupModel $item): bool
74 {
75 $isExtranetForGroupsEnabled = (bool)Option::get('socialnetwork', 'enable_extranet_for_groups', 0);
76 if ($isExtranetForGroupsEnabled)
77 {
78 return true;
79 }
80
81 $existExtranetSiteId = in_array(Extranet::getSiteId(), $item->getSiteIds(), true);
82 if ($existExtranetSiteId)
83 {
84 return false;
85 }
86
87 return true;
88 }
89
93 protected function hasPermissions(GroupModel $item): bool
94 {
95 $siteIds = $item->getSiteIds();
96 $siteIds[] = false;
97
98 $groups = CUser::GetUserGroup($this->user->getUserId());
99
100 $modulePermissions = ModuleGroupTable::query()
101 ->setSelect(['*'])
102 ->where('MODULE_ID', 'socialnetwork')
103 ->where('GROUP.ACTIVE', 'Y')
104 ->setCacheTtl(86400)
105 ->cacheJoins(true)
106 ->fetchAll();
107
108 $right = '';
109 foreach ($modulePermissions as $permission)
110 {
111 // site filter
112 // group filter
113 // max
114 if (
115 in_array($permission['SITE_ID'], $siteIds)
116 && in_array($permission['GROUP_ID'], $groups)
117 && $permission['G_ACCESS'] > $right
118 )
119 {
120 $right = $permission['G_ACCESS'];
121 }
122 }
123
124 if ($right === '')
125 {
126 $right = COption::GetOptionString('socialnetwork', 'GROUP_DEFAULT_RIGHT', static::MIN_RIGHT);
127 }
128
129 return $right >= static::ENOUGH_RIGHT;
130 }
131}
execute(AccessibleItem $item=null, $params=null)
Определения GroupCreateRule.php:30
$right
Определения options.php:8
$groups
Определения options.php:30
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799