Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
TaskAccessService.php
1
<?php
2
3
namespace
Bitrix\Bizproc\Api\Service
;
4
5
use
Bitrix\Bizproc\Api\Response\TaskAccessService\CheckDelegateTasksResponse
;
6
use
Bitrix\Main\Error
;
7
use
Bitrix\Main\Loader
;
8
use
Bitrix\Main\Localization\Loc
;
9
use
Bitrix\Main\Result
;
10
11
class
TaskAccessService
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
}
Bitrix\Bizproc\Api\Response\Error
Definition
Error.php:8
Bitrix\Bizproc\Api\Response\TaskAccessService\CheckDelegateTasksResponse
Definition
CheckDelegateTasksResponse.php:8
Bitrix\Bizproc\Api\Service\TaskAccessService
Definition
TaskAccessService.php:12
Bitrix\Bizproc\Api\Service\TaskAccessService\checkViewTasks
checkViewTasks(int $targetUserId)
Definition
TaskAccessService.php:53
Bitrix\Bizproc\Api\Service\TaskAccessService\checkDelegateTask
checkDelegateTask(int $toUserId, int $fromUserId)
Definition
TaskAccessService.php:22
Bitrix\Bizproc\Api\Service\TaskAccessService\__construct
__construct(int $userId)
Definition
TaskAccessService.php:16
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Bizproc\Api\Service
Definition
TaskAccessService.php:3
Bitrix
modules
bizproc
lib
Api
Service
TaskAccessService.php
Создано системой
1.10.0