UserWorkflowsController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. * @throws OCSBadRequestException
  74. * @throws OCSForbiddenException
  75. */
  76. public function create(string $class, string $name, array $checks, string $operation, string $entity, array $events): DataResponse {
  77. return parent::create($class, $name, $checks, $operation, $entity, $events);
  78. }
  79. /**
  80. * @NoAdminRequired
  81. * @throws OCSBadRequestException
  82. * @throws OCSForbiddenException
  83. */
  84. public function update(int $id, string $name, array $checks, string $operation, string $entity, array $events): DataResponse {
  85. return parent::update($id, $name, $checks, $operation, $entity, $events);
  86. }
  87. /**
  88. * @NoAdminRequired
  89. * @throws OCSForbiddenException
  90. */
  91. public function destroy(int $id): DataResponse {
  92. return parent::destroy($id);
  93. }
  94. /**
  95. * @throws OCSForbiddenException
  96. */
  97. protected function getScopeContext(): ScopeContext {
  98. if ($this->scopeContext === null) {
  99. $user = $this->session->getUser();
  100. if (!$user || !$this->manager->isUserScopeEnabled()) {
  101. throw new OCSForbiddenException('User not logged in');
  102. }
  103. $this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
  104. }
  105. return $this->scopeContext;
  106. }
  107. }