UserWorkflowsController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\DataResponse;
  30. use OCP\AppFramework\OCS\OCSBadRequestException;
  31. use OCP\AppFramework\OCS\OCSForbiddenException;
  32. use OCP\IRequest;
  33. use OCP\IUserSession;
  34. use OCP\WorkflowEngine\IManager;
  35. use Psr\Log\LoggerInterface;
  36. class UserWorkflowsController extends AWorkflowController {
  37. /** @var IUserSession */
  38. private $session;
  39. /** @var ScopeContext */
  40. private $scopeContext;
  41. public function __construct(
  42. $appName,
  43. IRequest $request,
  44. Manager $manager,
  45. IUserSession $session,
  46. LoggerInterface $logger
  47. ) {
  48. parent::__construct($appName, $request, $manager, $logger);
  49. $this->session = $session;
  50. }
  51. /**
  52. * Retrieve all configured workflow rules
  53. *
  54. * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/user?format=json"
  55. *
  56. * @NoAdminRequired
  57. * @throws OCSForbiddenException
  58. */
  59. public function index(): DataResponse {
  60. return parent::index();
  61. }
  62. /**
  63. * @NoAdminRequired
  64. *
  65. * 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"
  66. * @throws OCSForbiddenException
  67. */
  68. public function show(string $id): DataResponse {
  69. return parent::show($id);
  70. }
  71. /**
  72. * @NoAdminRequired
  73. * @PasswordConfirmationRequired
  74. * @throws OCSBadRequestException
  75. * @throws OCSForbiddenException
  76. */
  77. public function create(string $class, string $name, array $checks, string $operation, string $entity, array $events): DataResponse {
  78. return parent::create($class, $name, $checks, $operation, $entity, $events);
  79. }
  80. /**
  81. * @NoAdminRequired
  82. * @PasswordConfirmationRequired
  83. * @throws OCSBadRequestException
  84. * @throws OCSForbiddenException
  85. */
  86. public function update(int $id, string $name, array $checks, string $operation, string $entity, array $events): DataResponse {
  87. return parent::update($id, $name, $checks, $operation, $entity, $events);
  88. }
  89. /**
  90. * @NoAdminRequired
  91. * @PasswordConfirmationRequired
  92. * @throws OCSForbiddenException
  93. */
  94. public function destroy(int $id): DataResponse {
  95. return parent::destroy($id);
  96. }
  97. /**
  98. * @throws OCSForbiddenException
  99. */
  100. protected function getScopeContext(): ScopeContext {
  101. if ($this->scopeContext === null) {
  102. $user = $this->session->getUser();
  103. if (!$user || !$this->manager->isUserScopeEnabled()) {
  104. throw new OCSForbiddenException('User not logged in');
  105. }
  106. $this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
  107. }
  108. return $this->scopeContext;
  109. }
  110. }