UserWorkflowsController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\WorkflowEngine\Controller;
  8. use OCA\WorkflowEngine\Helper\ScopeContext;
  9. use OCA\WorkflowEngine\Manager;
  10. use OCP\AppFramework\Http\Attribute\NoAdminRequired;
  11. use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
  12. use OCP\AppFramework\Http\DataResponse;
  13. use OCP\AppFramework\OCS\OCSBadRequestException;
  14. use OCP\AppFramework\OCS\OCSForbiddenException;
  15. use OCP\IRequest;
  16. use OCP\IUserSession;
  17. use OCP\WorkflowEngine\IManager;
  18. use Psr\Log\LoggerInterface;
  19. class UserWorkflowsController extends AWorkflowController {
  20. /** @var ScopeContext */
  21. private $scopeContext;
  22. public function __construct(
  23. $appName,
  24. IRequest $request,
  25. Manager $manager,
  26. private IUserSession $session,
  27. LoggerInterface $logger,
  28. ) {
  29. parent::__construct($appName, $request, $manager, $logger);
  30. }
  31. /**
  32. * Retrieve all configured workflow rules
  33. *
  34. * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/user?format=json"
  35. *
  36. * @throws OCSForbiddenException
  37. */
  38. #[NoAdminRequired]
  39. public function index(): DataResponse {
  40. return parent::index();
  41. }
  42. /**
  43. * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/user/OCA\\Workflow_DocToPdf\\Operation?format=json"
  44. * @throws OCSForbiddenException
  45. */
  46. #[NoAdminRequired]
  47. public function show(string $id): DataResponse {
  48. return parent::show($id);
  49. }
  50. /**
  51. * @throws OCSBadRequestException
  52. * @throws OCSForbiddenException
  53. */
  54. #[NoAdminRequired]
  55. #[PasswordConfirmationRequired]
  56. public function create(string $class, string $name, array $checks, string $operation, string $entity, array $events): DataResponse {
  57. return parent::create($class, $name, $checks, $operation, $entity, $events);
  58. }
  59. /**
  60. * @throws OCSBadRequestException
  61. * @throws OCSForbiddenException
  62. */
  63. #[NoAdminRequired]
  64. #[PasswordConfirmationRequired]
  65. public function update(int $id, string $name, array $checks, string $operation, string $entity, array $events): DataResponse {
  66. return parent::update($id, $name, $checks, $operation, $entity, $events);
  67. }
  68. /**
  69. * @throws OCSForbiddenException
  70. */
  71. #[NoAdminRequired]
  72. #[PasswordConfirmationRequired]
  73. public function destroy(int $id): DataResponse {
  74. return parent::destroy($id);
  75. }
  76. /**
  77. * @throws OCSForbiddenException
  78. */
  79. protected function getScopeContext(): ScopeContext {
  80. if ($this->scopeContext === null) {
  81. $user = $this->session->getUser();
  82. if (!$user || !$this->manager->isUserScopeEnabled()) {
  83. throw new OCSForbiddenException('User not logged in');
  84. }
  85. $this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
  86. }
  87. return $this->scopeContext;
  88. }
  89. }