Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
permission.php
1<?php
2
3namespace Bitrix\Translate;
4
7
8
10{
11 const SOURCE = 'X';
12 const WRITE = 'W';
13 const READ = 'R';
14 const DENY = 'D';
15
23 public static function isAllowPath(string $path): bool
24 {
25 static $initFolders;
26 if (empty($initFolders))
27 {
28 $initFolders = Translate\Config::getInitPath();
29 if (empty($initFolders))
30 {
31 $initFolders = array(Translate\Config::getDefaultPath());
32 }
33 }
34
35 $path = (string)$path;
36 $allowPath = false;
37 foreach ($initFolders as $oneFolder)
38 {
39 if (\mb_strpos($path, $oneFolder) === 0)
40 {
41 $allowPath = true;
42 break;
43 }
44 }
45
46 return $allowPath;
47 }
48
56 public static function canEditSource($checkUser): bool
57 {
58 if ($checkUser instanceof \CUser || $checkUser instanceof Main\Engine\CurrentUser)
59 {
60 return $checkUser->canDoOperation('edit_php');
61 }
62
63 return false;
64 }
65
66
74 public static function isAdmin($checkUser): bool
75 {
76 if (!($checkUser instanceof \CUser) && !($checkUser instanceof Main\Engine\CurrentUser))
77 {
78 return false;
79 }
80
81 return $checkUser->isAdmin();
82 }
83
84
92 public static function canView($checkUser): bool
93 {
94 if (!($checkUser instanceof \CUser) && !($checkUser instanceof Main\Engine\CurrentUser))
95 {
96 return false;
97 }
98
99 if (self::isAdmin($checkUser))
100 {
101 return true;
102 }
103
104 if ($checkUser instanceof Main\Engine\CurrentUser)
105 {
106 $userRights = \CMain::getUserRight('translate', $checkUser->getUserGroups());
107 }
108 elseif ($checkUser instanceof \CUser)
109 {
110 $userRights = \CMain::getUserRight('translate', $checkUser->getUserGroupArray());
111 }
112
113 return ($userRights >= self::READ);
114 }
115
123 public static function canEdit($checkUser): bool
124 {
125 if (!($checkUser instanceof \CUser) && !($checkUser instanceof Main\Engine\CurrentUser))
126 {
127 return false;
128 }
129
130 if (self::isAdmin($checkUser))
131 {
132 return true;
133 }
134
135 if ($checkUser instanceof Main\Engine\CurrentUser)
136 {
137 $userRights = \CMain::getUserRight('translate', $checkUser->getUserGroups());
138 }
139 elseif ($checkUser instanceof \CUser)
140 {
141 $userRights = \CMain::getUserRight('translate', $checkUser->getUserGroupArray());
142 }
143
144 return ($userRights >= self::WRITE);
145 }
146}
static canView($checkUser)
static isAllowPath(string $path)
static canEdit($checkUser)
static isAdmin($checkUser)
static canEditSource($checkUser)