|
9 | 9 | namespace OCA\WorkflowEngine\Controller; |
10 | 10 |
|
11 | 11 | use OCA\WorkflowEngine\Helper\ScopeContext; |
| 12 | +use OCA\WorkflowEngine\ResponseDefinitions; |
| 13 | +use OCP\AppFramework\Http; |
| 14 | +use OCP\AppFramework\Http\Attribute\ApiRoute; |
| 15 | +use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired; |
| 16 | +use OCP\AppFramework\Http\DataResponse; |
| 17 | +use OCP\AppFramework\OCS\OCSBadRequestException; |
| 18 | +use OCP\AppFramework\OCS\OCSForbiddenException; |
| 19 | +use OCP\WorkflowEngine\IEntityEvent; |
12 | 20 | use OCP\WorkflowEngine\IManager; |
| 21 | +use OCP\WorkflowEngine\IOperation; |
13 | 22 |
|
14 | | -class GlobalWorkflowsController extends AWorkflowController { |
| 23 | +/** |
| 24 | + * @psalm-import-type WorkflowEngineCheck from ResponseDefinitions |
| 25 | + * @psalm-import-type WorkflowEngineRule from ResponseDefinitions |
| 26 | + */ |
| 27 | +class GlobalWorkflowsController extends AWorkflowOCSController { |
15 | 28 |
|
16 | 29 | private ?ScopeContext $scopeContext = null; |
17 | 30 |
|
| 31 | + /** |
| 32 | + * Retrieve all configured workflow rules |
| 33 | + * |
| 34 | + * @return DataResponse<Http::STATUS_OK, array<class-string<IOperation>, list<WorkflowEngineRule>>, array{}> |
| 35 | + * |
| 36 | + * 200: List of workflows returned |
| 37 | + */ |
| 38 | + #[ApiRoute(verb: 'GET', url: '/api/v1/workflows/global')] |
| 39 | + public function index(): DataResponse { |
| 40 | + return parent::index(); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Retrieve a specific workflow |
| 45 | + * |
| 46 | + * @param string $id Workflow ID to load |
| 47 | + * @return DataResponse<Http::STATUS_OK, WorkflowEngineRule|list<empty>, array{}> |
| 48 | + * |
| 49 | + * 200: Workflow returned or empty array if the ID is unknown in the scope |
| 50 | + */ |
| 51 | + #[ApiRoute(verb: 'GET', url: '/api/v1/workflows/global/{id}')] |
| 52 | + public function show(string $id): DataResponse { |
| 53 | + return parent::show($id); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Create a workflow |
| 58 | + * |
| 59 | + * @param class-string<IOperation> $class Operation class to execute |
| 60 | + * @param string $name Name of the workflow rule |
| 61 | + * @param list<WorkflowEngineCheck> $checks List of conditions that need to apply for the rule to match |
| 62 | + * @param string $operation Operation class to execute on match |
| 63 | + * @param string $entity The matched entity |
| 64 | + * @param list<class-string<IEntityEvent>> $events The list of events on which the rule should be validated |
| 65 | + * @return DataResponse<Http::STATUS_OK, WorkflowEngineRule, array{}> |
| 66 | + * |
| 67 | + * 200: Workflow created |
| 68 | + * |
| 69 | + * @throws OCSBadRequestException Thrown when a check or check value is invalid |
| 70 | + */ |
| 71 | + #[PasswordConfirmationRequired] |
| 72 | + #[ApiRoute(verb: 'POST', url: '/api/v1/workflows/global')] |
| 73 | + public function create(string $class, string $name, array $checks, string $operation, string $entity, array $events): DataResponse { |
| 74 | + return parent::create($class, $name, $checks, $operation, $entity, $events); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Modify a workflow |
| 79 | + * |
| 80 | + * @param int $id Workflow ID to delete |
| 81 | + * @param string $name Name of the workflow rule |
| 82 | + * @param list<WorkflowEngineCheck> $checks List of conditions that need to apply for the rule to match |
| 83 | + * @param string $operation Operation action to execute on match |
| 84 | + * @param string $entity The matched entity |
| 85 | + * @param list<class-string<IEntityEvent>> $events The list of events on which the rule should be validated |
| 86 | + * @return DataResponse<Http::STATUS_OK, WorkflowEngineRule, array{}> |
| 87 | + * |
| 88 | + * 200: Workflow updated |
| 89 | + * |
| 90 | + * @throws OCSBadRequestException Thrown when a check or check value is invalid |
| 91 | + * @throws OCSForbiddenException Thrown when workflow is from a different scope |
| 92 | + */ |
| 93 | + #[PasswordConfirmationRequired] |
| 94 | + #[ApiRoute(verb: 'PUT', url: '/api/v1/workflows/global/{id}')] |
| 95 | + public function update(int $id, string $name, array $checks, string $operation, string $entity, array $events): DataResponse { |
| 96 | + return parent::update($id, $name, $checks, $operation, $entity, $events); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Delete a workflow |
| 101 | + * |
| 102 | + * @param int $id Workflow ID to delete |
| 103 | + * @return DataResponse<Http::STATUS_OK, bool, array{}>|DataResponse<Http::STATUS_FORBIDDEN, list<empty>, array{}> |
| 104 | + * |
| 105 | + * 200: Workflow deleted |
| 106 | + * |
| 107 | + * @throws OCSForbiddenException Thrown when workflow is from a different scope |
| 108 | + */ |
| 109 | + #[PasswordConfirmationRequired] |
| 110 | + #[ApiRoute(verb: 'DELETE', url: '/api/v1/workflows/global/{id}')] |
| 111 | + public function destroy(int $id): DataResponse { |
| 112 | + return parent::destroy($id); |
| 113 | + } |
| 114 | + |
18 | 115 | protected function getScopeContext(): ScopeContext { |
19 | 116 | if ($this->scopeContext === null) { |
20 | 117 | $this->scopeContext = new ScopeContext(IManager::SCOPE_ADMIN); |
|
0 commit comments