-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathUserWorkflowsController.php
More file actions
158 lines (145 loc) · 5.24 KB
/
Copy pathUserWorkflowsController.php
File metadata and controls
158 lines (145 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\WorkflowEngine\Controller;
use OCA\WorkflowEngine\Helper\ScopeContext;
use OCA\WorkflowEngine\Manager;
use OCA\WorkflowEngine\ResponseDefinitions;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\WorkflowEngine\IEntityEvent;
use OCP\WorkflowEngine\IManager;
use OCP\WorkflowEngine\IOperation;
use Psr\Log\LoggerInterface;
/**
* @psalm-import-type WorkflowEngineCheck from ResponseDefinitions
* @psalm-import-type WorkflowEngineRule from ResponseDefinitions
*/
class UserWorkflowsController extends AWorkflowOCSController {
/** @var ScopeContext */
private $scopeContext;
public function __construct(
$appName,
IRequest $request,
Manager $manager,
private IUserSession $session,
LoggerInterface $logger,
) {
parent::__construct($appName, $request, $manager, $logger);
}
/**
* Retrieve all configured workflow rules
*
* @return DataResponse<Http::STATUS_OK, array<class-string<IOperation>, list<WorkflowEngineRule>>, array{}>
*
* 200: List of workflows returned
*/
#[\Override]
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/api/v1/workflows/user')]
public function index(): DataResponse {
return parent::index();
}
/**
* Retrieve a specific workflow
*
* @param string $id Workflow ID to load
* @return DataResponse<Http::STATUS_OK, WorkflowEngineRule|list<empty>, array{}>
*
* 200: Workflow returned or empty array if the ID is unknown in the scope
*/
#[\Override]
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/api/v1/workflows/user/{id}')]
public function show(string $id): DataResponse {
return parent::show($id);
}
/**
* Create a workflow
*
* @param class-string<IOperation> $class Operation class to execute
* @param string $name Name of the workflow rule
* @param list<WorkflowEngineCheck> $checks List of conditions that need to apply for the rule to match
* @param string $operation Operation class to execute on match
* @param string $entity The matched entity
* @param list<class-string<IEntityEvent>> $events The list of events on which the rule should be validated
* @param string $description Optional free-text description of the workflow rule
* @return DataResponse<Http::STATUS_OK, WorkflowEngineRule, array{}>
*
* 200: Workflow created
*
* @throws OCSBadRequestException Thrown when a check or check value is invalid
*/
#[\Override]
#[NoAdminRequired]
#[PasswordConfirmationRequired]
#[ApiRoute(verb: 'POST', url: '/api/v1/workflows/user')]
public function create(string $class, string $name, array $checks, string $operation, string $entity, array $events, string $description = ''): DataResponse {
return parent::create($class, $name, $checks, $operation, $entity, $events, $description);
}
/**
* Modify a workflow
*
* @param int $id Workflow ID to delete
* @param string $name Name of the workflow rule
* @param list<WorkflowEngineCheck> $checks List of conditions that need to apply for the rule to match
* @param string $operation Operation action to execute on match
* @param string $entity The matched entity
* @param list<class-string<IEntityEvent>> $events The list of events on which the rule should be validated
* @param string $description Optional free-text description of the workflow rule
* @return DataResponse<Http::STATUS_OK, WorkflowEngineRule, array{}>
*
* 200: Workflow updated
*
* @throws OCSBadRequestException Thrown when a check or check value is invalid
* @throws OCSForbiddenException Thrown when workflow is from a different scope
*/
#[\Override]
#[NoAdminRequired]
#[PasswordConfirmationRequired]
#[ApiRoute(verb: 'PUT', url: '/api/v1/workflows/user/{id}')]
public function update(int $id, string $name, array $checks, string $operation, string $entity, array $events, string $description = ''): DataResponse {
return parent::update($id, $name, $checks, $operation, $entity, $events, $description);
}
/**
* Delete a workflow
*
* @param int $id Workflow ID to delete
* @return DataResponse<Http::STATUS_OK, bool, array{}>|DataResponse<Http::STATUS_FORBIDDEN, list<empty>, array{}>
*
* 200: Workflow deleted
*
* @throws OCSForbiddenException Thrown when workflow is from a different scope
*/
#[\Override]
#[NoAdminRequired]
#[PasswordConfirmationRequired]
#[ApiRoute(verb: 'DELETE', url: '/api/v1/workflows/user/{id}')]
public function destroy(int $id): DataResponse {
return parent::destroy($id);
}
/**
* @throws OCSForbiddenException
*/
#[\Override]
protected function getScopeContext(): ScopeContext {
if ($this->scopeContext === null) {
$user = $this->session->getUser();
if (!$user || !$this->manager->isUserScopeEnabled()) {
throw new OCSForbiddenException('User not logged in');
}
$this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
}
return $this->scopeContext;
}
}