Merge pull request #969 from nextcloud/allow-to-validate-operations
Allow to validate operations
This commit is contained in:
commit
ede32a558a
|
@ -7,7 +7,7 @@
|
||||||
<licence>AGPL</licence>
|
<licence>AGPL</licence>
|
||||||
<author>Vincent Petry, Joas Schilling</author>
|
<author>Vincent Petry, Joas Schilling</author>
|
||||||
<default_enable/>
|
<default_enable/>
|
||||||
<version>1.1.1</version>
|
<version>1.1.2</version>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<owncloud min-version="9.2" max-version="9.2" />
|
<owncloud min-version="9.2" max-version="9.2" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Admin implements ISettings {
|
||||||
* @return string the section ID, e.g. 'sharing'
|
* @return string the section ID, e.g. 'sharing'
|
||||||
*/
|
*/
|
||||||
public function getSection() {
|
public function getSection() {
|
||||||
return 'sharing';
|
return 'additional';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,7 +43,7 @@ class AdminTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSection() {
|
public function testGetSection() {
|
||||||
$this->assertSame('sharing', $this->admin->getSection());
|
$this->assertSame('additional', $this->admin->getSection());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPriority() {
|
public function testGetPriority() {
|
||||||
|
|
|
@ -30,6 +30,7 @@ use OCP\IL10N;
|
||||||
use OCP\IServerContainer;
|
use OCP\IServerContainer;
|
||||||
use OCP\WorkflowEngine\ICheck;
|
use OCP\WorkflowEngine\ICheck;
|
||||||
use OCP\WorkflowEngine\IManager;
|
use OCP\WorkflowEngine\IManager;
|
||||||
|
use OCP\WorkflowEngine\IOperation;
|
||||||
|
|
||||||
class Manager implements IManager {
|
class Manager implements IManager {
|
||||||
|
|
||||||
|
@ -176,6 +177,8 @@ class Manager implements IManager {
|
||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function addOperation($class, $name, array $checks, $operation) {
|
public function addOperation($class, $name, array $checks, $operation) {
|
||||||
|
$this->validateOperation($class, $name, $checks, $operation);
|
||||||
|
|
||||||
$checkIds = [];
|
$checkIds = [];
|
||||||
foreach ($checks as $check) {
|
foreach ($checks as $check) {
|
||||||
$checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']);
|
$checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']);
|
||||||
|
@ -204,6 +207,9 @@ class Manager implements IManager {
|
||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function updateOperation($id, $name, array $checks, $operation) {
|
public function updateOperation($id, $name, array $checks, $operation) {
|
||||||
|
$row = $this->getOperation($id);
|
||||||
|
$this->validateOperation($row['class'], $name, $checks, $operation);
|
||||||
|
|
||||||
$checkIds = [];
|
$checkIds = [];
|
||||||
foreach ($checks as $check) {
|
foreach ($checks as $check) {
|
||||||
$checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']);
|
$checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']);
|
||||||
|
@ -232,6 +238,43 @@ class Manager implements IManager {
|
||||||
return (bool) $query->execute();
|
return (bool) $query->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
* @param int[] $checkIds
|
||||||
* @return array[]
|
* @return array[]
|
||||||
|
@ -279,13 +322,8 @@ class Manager implements IManager {
|
||||||
* @param string $operator
|
* @param string $operator
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return int Check unique ID
|
* @return int Check unique ID
|
||||||
* @throws \UnexpectedValueException
|
|
||||||
*/
|
*/
|
||||||
protected function addCheck($class, $operator, $value) {
|
protected function addCheck($class, $operator, $value) {
|
||||||
/** @var ICheck $check */
|
|
||||||
$check = $this->container->query($class);
|
|
||||||
$check->validateCheck($operator, $value);
|
|
||||||
|
|
||||||
$hash = md5($class . '::' . $operator . '::' . $value);
|
$hash = md5($class . '::' . $operator . '::' . $value);
|
||||||
|
|
||||||
$query = $this->connection->getQueryBuilder();
|
$query = $this->connection->getQueryBuilder();
|
||||||
|
|
|
@ -237,6 +237,7 @@ return array(
|
||||||
'OCP\\Util' => $baseDir . '/lib/public/Util.php',
|
'OCP\\Util' => $baseDir . '/lib/public/Util.php',
|
||||||
'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.php',
|
'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.php',
|
||||||
'OCP\\WorkflowEngine\\IManager' => $baseDir . '/lib/public/WorkflowEngine/IManager.php',
|
'OCP\\WorkflowEngine\\IManager' => $baseDir . '/lib/public/WorkflowEngine/IManager.php',
|
||||||
|
'OCP\\WorkflowEngine\\IOperation' => $baseDir . '/lib/public/WorkflowEngine/IOperation.php',
|
||||||
'OC\\Activity\\Event' => $baseDir . '/lib/private/Activity/Event.php',
|
'OC\\Activity\\Event' => $baseDir . '/lib/private/Activity/Event.php',
|
||||||
'OC\\Activity\\Manager' => $baseDir . '/lib/private/Activity/Manager.php',
|
'OC\\Activity\\Manager' => $baseDir . '/lib/private/Activity/Manager.php',
|
||||||
'OC\\AllConfig' => $baseDir . '/lib/private/AllConfig.php',
|
'OC\\AllConfig' => $baseDir . '/lib/private/AllConfig.php',
|
||||||
|
|
|
@ -267,6 +267,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php',
|
'OCP\\Util' => __DIR__ . '/../../..' . '/lib/public/Util.php',
|
||||||
'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.php',
|
'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.php',
|
||||||
'OCP\\WorkflowEngine\\IManager' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IManager.php',
|
'OCP\\WorkflowEngine\\IManager' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IManager.php',
|
||||||
|
'OCP\\WorkflowEngine\\IOperation' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IOperation.php',
|
||||||
'OC\\Activity\\Event' => __DIR__ . '/../../..' . '/lib/private/Activity/Event.php',
|
'OC\\Activity\\Event' => __DIR__ . '/../../..' . '/lib/private/Activity/Event.php',
|
||||||
'OC\\Activity\\Manager' => __DIR__ . '/../../..' . '/lib/private/Activity/Manager.php',
|
'OC\\Activity\\Manager' => __DIR__ . '/../../..' . '/lib/private/Activity/Manager.php',
|
||||||
'OC\\AllConfig' => __DIR__ . '/../../..' . '/lib/private/AllConfig.php',
|
'OC\\AllConfig' => __DIR__ . '/../../..' . '/lib/private/AllConfig.php',
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
||||||
|
*
|
||||||
|
* @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 OCP\WorkflowEngine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface IOperation
|
||||||
|
*
|
||||||
|
* @package OCP\WorkflowEngine
|
||||||
|
* @since 9.1
|
||||||
|
*/
|
||||||
|
interface IOperation {
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param array[] $checks
|
||||||
|
* @param string $operation
|
||||||
|
* @throws \UnexpectedValueException
|
||||||
|
* @since 9.1
|
||||||
|
*/
|
||||||
|
public function validateOperation($name, array $checks, $operation);
|
||||||
|
}
|
Loading…
Reference in New Issue