Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
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;
19 $this->isUserAdmin = in_array(1, \CUser::GetUserGroup($userId), false);
20 }
21
22 public function checkDelegateTask(int $toUserId, int $fromUserId): CheckDelegateTasksResponse
23 {
24 $response = new CheckDelegateTasksResponse();
25
26 if (Loader::includeModule('intranet'))
27 {
28 if (
29 !\Bitrix\Intranet\Util::isIntranetUser($toUserId)
30 || !\Bitrix\Intranet\Util::isIntranetUser($this->userId)
31 )
32 {
33 return $response->addError(
34 new Error(Loc::getMessage('BIZPROC_LIB_API_TASK_ACCESS_SERVICE_DELEGATE_ERROR_ONLY_INTRANET_USER'))
35 );
36 }
37 }
38
39 $isHead = \CBPHelper::checkUserSubordination($this->userId, $toUserId);
40 $allowedDelegationTypes = [\CBPTaskDelegationType::AllEmployees];
41 if ($isHead)
42 {
43 $allowedDelegationTypes[] = \CBPTaskDelegationType::Subordinate;
44 }
45
46 $response->setData([
47 'allowedDelegationTypes' => $this->isUserAdmin ? null : $allowedDelegationTypes,
48 ]);
49
50 return $response;
51 }
52
53 public function checkViewTasks(int $targetUserId): Result
54 {
55 $result = new Result();
56
57 if (Loader::includeModule('intranet') && !\Bitrix\Intranet\Util::isIntranetUser($this->userId))
58 {
59 // todo: message
60 return $result->addError(new Error('only intranet'));
61 }
62
63 $isHead = \CBPHelper::checkUserSubordination($this->userId, $targetUserId);
64 if ($this->userId !== $targetUserId && !$this->isUserAdmin && !$isHead)
65 {
66 return $result->addError(new Error(Loc::getMessage('BIZPROC_LIB_API_TASK_ACCESS_SERVICE_ERROR_SUBORDINATION')));
67 }
68
69 return $result;
70 }
71}
checkDelegateTask(int $toUserId, int $fromUserId)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29