1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
TaskAccessService.php
См. документацию.
1<?php
2
4
10
12{
13 private int $userId;
14 private bool $isUserAdmin;
15
16 public function __construct(int $userId)
17 {
18 $this->userId = $userId;
20 $userGroups =
21 !is_null($currentUser) && $currentUser->getId() === $userId
22 ? $currentUser->getUserGroups()
23 : \CUser::GetUserGroup($userId);
24 $this->isUserAdmin = in_array(1, $userGroups, false);
25 }
26
27 public function isCurrentUser(int $userId): bool
28 {
29 return $this->userId === $userId;
30 }
31
32 public function checkDelegateTask(int $toUserId, int $fromUserId): CheckDelegateTasksResponse
33 {
35
36 if (Loader::includeModule('intranet'))
37 {
38 if (
39 !\Bitrix\Intranet\Util::isIntranetUser($toUserId)
40 || !\Bitrix\Intranet\Util::isIntranetUser($this->userId)
41 )
42 {
43 return $response->addError(
44 new Error(Loc::getMessage('BIZPROC_LIB_API_TASK_ACCESS_SERVICE_DELEGATE_ERROR_ONLY_INTRANET_USER'))
45 );
46 }
47 }
48
49 if (!$this->canUserViewTasks($fromUserId))
50 {
51 return $response->addError(new Error(Loc::getMessage('BIZPROC_LIB_API_TASK_ACCESS_SERVICE_DELEGATE_ERROR_SUBORDINATION')));
52 }
53
54 $isHead = \CBPHelper::checkUserSubordination($this->userId, $toUserId);
55 $allowedDelegationTypes = [\CBPTaskDelegationType::AllEmployees];
56 if ($isHead)
57 {
58 $allowedDelegationTypes[] = \CBPTaskDelegationType::Subordinate;
59 }
60
61 $response->setData([
62 'allowedDelegationTypes' => $this->isUserAdmin ? null : $allowedDelegationTypes,
63 ]);
64
65 return $response;
66 }
67
68 public function checkViewTasks(int $targetUserId): Result
69 {
70 $result = new Result();
71
72 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser($this->userId))
73 {
74 return $result->addError(new Error(Loc::getMessage('BIZPROC_LIB_API_TASK_ACCESS_SERVICE_VIEW_TASKS_ERROR_ONLY_INTRANET_USER')));
75 }
76
77 if (!$this->canUserViewTasks($targetUserId))
78 {
79 return $result->addError(new Error(Loc::getMessage('BIZPROC_LIB_API_TASK_ACCESS_SERVICE_ERROR_SUBORDINATION_MSGVER_1')));
80 }
81
82 return $result;
83 }
84
85 public function checkDoTasks(int $targetUserId): Result
86 {
87 $result = new Result();
88
89 if (!$this->canUserViewTasks($targetUserId))
90 {
91 return $result->addError(new Error(Loc::getMessage('BIZPROC_LIB_API_TASK_ACCESS_SERVICE_ERROR_SUBORDINATION_MSGVER_1')));
92 }
93
94 return $result;
95 }
96
97 private function canUserViewTasks(int $targetUserId): bool
98 {
99 if ($this->isCurrentUser($targetUserId))
100 {
101 return true;
102 }
103
104 if ($this->isUserAdmin)
105 {
106 return true;
107 }
108
109 return \CBPHelper::checkUserSubordination($this->userId, $targetUserId);
110 }
111}
checkViewTasks(int $targetUserId)
Определения TaskAccessService.php:68
checkDelegateTask(int $toUserId, int $fromUserId)
Определения TaskAccessService.php:32
checkDoTasks(int $targetUserId)
Определения TaskAccessService.php:85
static get()
Определения currentuser.php:33
Определения error.php:15
Определения loader.php:13
const AllEmployees
Определения constants.php:324
const Subordinate
Определения constants.php:323
$result
Определения get_property_values.php:14
$response
Определения result.php:21