summaryrefslogtreecommitdiffstats
path: root/apps/workflowengine
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-08-07 11:01:09 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-09-09 22:55:56 +0200
commitd015cd9c55b9e5b1e7899fbf7ae79fb5ab4c0beb (patch)
treea31cca6420a5200980adf3884b08d38a987db04d /apps/workflowengine
parentbf6082e119d1c2420286dbcdbbfda1b1e196d9a0 (diff)
downloadnextcloud-server-d015cd9c55b9e5b1e7899fbf7ae79fb5ab4c0beb.tar.gz
nextcloud-server-d015cd9c55b9e5b1e7899fbf7ae79fb5ab4c0beb.zip
provides an OCS workflow controller for admins
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/workflowengine')
-rw-r--r--apps/workflowengine/appinfo/routes.php5
-rw-r--r--apps/workflowengine/composer/composer/autoload_classmap.php1
-rw-r--r--apps/workflowengine/composer/composer/autoload_static.php1
-rw-r--r--apps/workflowengine/lib/Controller/GlobalWorkflowsController.php111
-rw-r--r--apps/workflowengine/lib/Manager.php35
5 files changed, 152 insertions, 1 deletions
diff --git a/apps/workflowengine/appinfo/routes.php b/apps/workflowengine/appinfo/routes.php
index 5ae74bcafc3..c650bee4cf2 100644
--- a/apps/workflowengine/appinfo/routes.php
+++ b/apps/workflowengine/appinfo/routes.php
@@ -26,5 +26,8 @@ return [
['name' => 'flowOperations#updateOperation', 'url' => '/operations/{id}', 'verb' => 'PUT'],
['name' => 'flowOperations#deleteOperation', 'url' => '/operations/{id}', 'verb' => 'DELETE'],
['name' => 'requestTime#getTimezones', 'url' => '/timezones', 'verb' => 'GET'],
- ]
+ ],
+ 'ocs-resources' => [
+ 'global_workflows' => ['url' => '/api/v1/workflows/global'],
+ ],
];
diff --git a/apps/workflowengine/composer/composer/autoload_classmap.php b/apps/workflowengine/composer/composer/autoload_classmap.php
index 583213eb853..7d73b3a6241 100644
--- a/apps/workflowengine/composer/composer/autoload_classmap.php
+++ b/apps/workflowengine/composer/composer/autoload_classmap.php
@@ -18,6 +18,7 @@ return array(
'OCA\\WorkflowEngine\\Check\\RequestUserAgent' => $baseDir . '/../lib/Check/RequestUserAgent.php',
'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => $baseDir . '/../lib/Check/UserGroupMembership.php',
'OCA\\WorkflowEngine\\Controller\\FlowOperations' => $baseDir . '/../lib/Controller/FlowOperations.php',
+ 'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => $baseDir . '/../lib/Controller/GlobalWorkflowsController.php',
'OCA\\WorkflowEngine\\Controller\\RequestTime' => $baseDir . '/../lib/Controller/RequestTime.php',
'OCA\\WorkflowEngine\\Manager' => $baseDir . '/../lib/Manager.php',
'OCA\\WorkflowEngine\\Settings\\Section' => $baseDir . '/../lib/Settings/Section.php',
diff --git a/apps/workflowengine/composer/composer/autoload_static.php b/apps/workflowengine/composer/composer/autoload_static.php
index 01988161ce4..8d54000260c 100644
--- a/apps/workflowengine/composer/composer/autoload_static.php
+++ b/apps/workflowengine/composer/composer/autoload_static.php
@@ -33,6 +33,7 @@ class ComposerStaticInitWorkflowEngine
'OCA\\WorkflowEngine\\Check\\RequestUserAgent' => __DIR__ . '/..' . '/../lib/Check/RequestUserAgent.php',
'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => __DIR__ . '/..' . '/../lib/Check/UserGroupMembership.php',
'OCA\\WorkflowEngine\\Controller\\FlowOperations' => __DIR__ . '/..' . '/../lib/Controller/FlowOperations.php',
+ 'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => __DIR__ . '/..' . '/../lib/Controller/GlobalWorkflowsController.php',
'OCA\\WorkflowEngine\\Controller\\RequestTime' => __DIR__ . '/..' . '/../lib/Controller/RequestTime.php',
'OCA\\WorkflowEngine\\Manager' => __DIR__ . '/..' . '/../lib/Manager.php',
'OCA\\WorkflowEngine\\Settings\\Section' => __DIR__ . '/..' . '/../lib/Settings/Section.php',
diff --git a/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php b/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php
new file mode 100644
index 00000000000..e4321b9c0b6
--- /dev/null
+++ b/apps/workflowengine/lib/Controller/GlobalWorkflowsController.php
@@ -0,0 +1,111 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\WorkflowEngine\Controller;
+
+use OCA\WorkflowEngine\Manager;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSBadRequestException;
+use OCP\AppFramework\OCSController;
+use OCP\IRequest;
+
+class GlobalWorkflowsController extends OCSController {
+
+ /** @var Manager */
+ private $manager;
+
+ public function __construct(
+ $appName,
+ IRequest $request,
+ Manager $manager
+ ) {
+ parent::__construct($appName, $request);
+
+ $this->manager = $manager;
+ }
+
+ /**
+ * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/global?format=json"
+ */
+ public function index(): DataResponse {
+ $operationsByClass = $this->manager->getAllOperations();
+
+ foreach ($operationsByClass as &$operations) {
+ foreach ($operations as &$operation) {
+ $operation = $this->manager->formatOperation($operation);
+ }
+ }
+
+ return new DataResponse($operationsByClass);
+ }
+
+ /**
+ * @throws OCSBadRequestException
+ *
+ * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/global/OCA\\Workflow_DocToPdf\\Operation?format=json"
+ */
+ public function show(string $id): DataResponse {
+ // The ID corresponds to a class name
+ $operations = $this->manager->getOperations($id);
+
+ foreach ($operations as &$operation) {
+ $operation = $this->manager->formatOperation($operation);
+ }
+
+ return new DataResponse($operations);
+ }
+
+ /**
+ * @throws OCSBadRequestException
+ */
+ public function create(string $class, string $name, array $checks, string $operation): DataResponse {
+ try {
+ $operation = $this->manager->addOperation($class, $name, $checks, $operation);
+ $operation = $this->manager->formatOperation($operation);
+ return new DataResponse($operation);
+ } catch (\UnexpectedValueException $e) {
+ throw new OCSBadRequestException($e->getMessage(), $e);
+ }
+ }
+
+ /**
+ * @throws OCSBadRequestException
+ */
+ public function update(int $id, string $name, array $checks, string $operation): DataResponse {
+ try {
+ $operation = $this->manager->updateOperation($id, $name, $checks, $operation);
+ $operation = $this->manager->formatOperation($operation);
+ return new DataResponse($operation);
+ } catch (\UnexpectedValueException $e) {
+ throw new OCSBadRequestException($e->getMessage(), $e);
+ }
+ }
+
+ /**
+ */
+ public function destroy(int $id): DataResponse {
+ $deleted = $this->manager->deleteOperation((int) $id);
+ return new DataResponse($deleted);
+ }
+}
diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php
index 080faa6bfc1..32b04c1021d 100644
--- a/apps/workflowengine/lib/Manager.php
+++ b/apps/workflowengine/lib/Manager.php
@@ -127,6 +127,25 @@ class Manager implements IManager {
}
}
+ public function getAllOperations(): array {
+ $this->operations = [];
+
+ $query = $this->connection->getQueryBuilder();
+
+ $query->select('*')
+ ->from('flow_operations');
+ $result = $query->execute();
+
+ while ($row = $result->fetch()) {
+ if(!isset($this->operations[$row['class']])) {
+ $this->operations[$row['class']] = [];
+ }
+ $this->operations[$row['class']][] = $row;
+ }
+
+ return $this->operations;
+ }
+
/**
* @param string $class
* @return array[]
@@ -353,4 +372,20 @@ class Manager implements IManager {
return $query->getLastInsertId();
}
+
+ public function formatOperation(array $operation): array {
+ $checkIds = json_decode($operation['checks'], true);
+ $checks = $this->getChecks($checkIds);
+
+ $operation['checks'] = [];
+ foreach ($checks as $check) {
+ // Remove internal values
+ unset($check['id']);
+ unset($check['hash']);
+
+ $operation['checks'][] = $check;
+ }
+
+ return $operation;
+ }
}