UserWorkflowsController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\WorkflowEngine\Controller;
  27. use OCA\WorkflowEngine\Helper\ScopeContext;
  28. use OCA\WorkflowEngine\Manager;
  29. use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
  30. use OCP\AppFramework\Http\DataResponse;
  31. use OCP\AppFramework\OCS\OCSBadRequestException;
  32. use OCP\AppFramework\OCS\OCSForbiddenException;
  33. use OCP\IRequest;
  34. use OCP\IUserSession;
  35. use OCP\WorkflowEngine\IManager;
  36. use Psr\Log\LoggerInterface;
  37. class UserWorkflowsController extends AWorkflowController {
  38. /** @var IUserSession */
  39. private $session;
  40. /** @var ScopeContext */
  41. private $scopeContext;
  42. public function __construct(
  43. $appName,
  44. IRequest $request,
  45. Manager $manager,
  46. IUserSession $session,
  47. LoggerInterface $logger
  48. ) {
  49. parent::__construct($appName, $request, $manager, $logger);
  50. $this->session = $session;
  51. }
  52. /**
  53. * Retrieve all configured workflow rules
  54. *
  55. * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/user?format=json"
  56. *
  57. * @NoAdminRequired
  58. * @throws OCSForbiddenException
  59. */
  60. public function index(): DataResponse {
  61. return parent::index();
  62. }
  63. /**
  64. * @NoAdminRequired
  65. *
  66. * 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"
  67. * @throws OCSForbiddenException
  68. */
  69. public function show(string $id): DataResponse {
  70. return parent::show($id);
  71. }
  72. /**
  73. * @NoAdminRequired
  74. * @throws OCSBadRequestException
  75. * @throws OCSForbiddenException
  76. */
  77. #[PasswordConfirmationRequired]
  78. public function create(string $class, string $name, array $checks, string $operation, string $entity, array $events): DataResponse {
  79. return parent::create($class, $name, $checks, $operation, $entity, $events);
  80. }
  81. /**
  82. * @NoAdminRequired
  83. * @throws OCSBadRequestException
  84. * @throws OCSForbiddenException
  85. */
  86. #[PasswordConfirmationRequired]
  87. public function update(int $id, string $name, array $checks, string $operation, string $entity, array $events): DataResponse {
  88. return parent::update($id, $name, $checks, $operation, $entity, $events);
  89. }
  90. /**
  91. * @NoAdminRequired
  92. * @throws OCSForbiddenException
  93. */
  94. #[PasswordConfirmationRequired]
  95. public function destroy(int $id): DataResponse {
  96. return parent::destroy($id);
  97. }
  98. /**
  99. * @throws OCSForbiddenException
  100. */
  101. protected function getScopeContext(): ScopeContext {
  102. if ($this->scopeContext === null) {
  103. $user = $this->session->getUser();
  104. if (!$user || !$this->manager->isUserScopeEnabled()) {
  105. throw new OCSForbiddenException('User not logged in');
  106. }
  107. $this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
  108. }
  109. return $this->scopeContext;
  110. }
  111. }