summaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-08-19 10:34:45 +0200
committerJoas Schilling <coding@schilljs.com>2016-08-19 12:23:05 +0200
commita111181eb32750d9701df3d6025cfe97960ba9f3 (patch)
tree6c624464db7dfa93d357985fcdcc5a9eeead779c /apps/workflowengine/lib
parent6d4ede3e84a95340f3a2c51c57384d30d8467f8a (diff)
downloadnextcloud-server-a111181eb32750d9701df3d6025cfe97960ba9f3.tar.gz
nextcloud-server-a111181eb32750d9701df3d6025cfe97960ba9f3.zip
Validate the operation
Diffstat (limited to 'apps/workflowengine/lib')
-rw-r--r--apps/workflowengine/lib/Manager.php48
1 files changed, 43 insertions, 5 deletions
diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php
index b72836a919c..9140ef73ea7 100644
--- a/apps/workflowengine/lib/Manager.php
+++ b/apps/workflowengine/lib/Manager.php
@@ -30,6 +30,7 @@ use OCP\IL10N;
use OCP\IServerContainer;
use OCP\WorkflowEngine\ICheck;
use OCP\WorkflowEngine\IManager;
+use OCP\WorkflowEngine\IOperation;
class Manager implements IManager {
@@ -176,6 +177,8 @@ class Manager implements IManager {
* @throws \UnexpectedValueException
*/
public function addOperation($class, $name, array $checks, $operation) {
+ $this->validateOperation($class, $name, $checks, $operation);
+
$checkIds = [];
foreach ($checks as $check) {
$checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']);
@@ -204,6 +207,9 @@ class Manager implements IManager {
* @throws \UnexpectedValueException
*/
public function updateOperation($id, $name, array $checks, $operation) {
+ $row = $this->getOperation($id);
+ $this->validateOperation($row['class'], $name, $checks, $operation);
+
$checkIds = [];
foreach ($checks as $check) {
$checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']);
@@ -233,6 +239,43 @@ class Manager implements IManager {
}
/**
+ * @param string $class
+ * @param string $name
+ * @param array[] $checks
+ * @param string $operation
+ * @throws \UnexpectedValueException
+ */
+ protected function validateOperation($class, $name, array $checks, $operation) {
+ try {
+ /** @var IOperation $instance */
+ $instance = $this->container->query($class);
+ } catch (QueryException $e) {
+ throw new \UnexpectedValueException($this->l->t('Operation %s does not exist', $class));
+ }
+
+ if (!($instance instanceof IOperation)) {
+ throw new \UnexpectedValueException($this->l->t('Operation %s is invalid', $class));
+ }
+
+ $instance->validateOperation($name, $checks, $operation);
+
+ foreach ($checks as $check) {
+ try {
+ /** @var ICheck $instance */
+ $instance = $this->container->query($check['class']);
+ } catch (QueryException $e) {
+ throw new \UnexpectedValueException($this->l->t('Check %s does not exist', $class));
+ }
+
+ if (!($instance instanceof ICheck)) {
+ throw new \UnexpectedValueException($this->l->t('Check %s is invalid', $class));
+ }
+
+ $instance->validateCheck($check['operator'], $check['value']);
+ }
+ }
+
+ /**
* @param int[] $checkIds
* @return array[]
*/
@@ -279,13 +322,8 @@ class Manager implements IManager {
* @param string $operator
* @param string $value
* @return int Check unique ID
- * @throws \UnexpectedValueException
*/
protected function addCheck($class, $operator, $value) {
- /** @var ICheck $check */
- $check = $this->container->query($class);
- $check->validateCheck($operator, $value);
-
$hash = md5($class . '::' . $operator . '::' . $value);
$query = $this->connection->getQueryBuilder();