Remove php side of check registration
This commit is contained in:
parent
155e4ced3f
commit
6a21289378
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'routes' => [
|
'routes' => [
|
||||||
['name' => 'flowOperations#getChecks', 'url' => '/checks', 'verb' => 'GET'], // TODO rm and do via js?
|
|
||||||
['name' => 'flowOperations#getOperations', 'url' => '/operations', 'verb' => 'GET'],
|
['name' => 'flowOperations#getOperations', 'url' => '/operations', 'verb' => 'GET'],
|
||||||
['name' => 'flowOperations#addOperation', 'url' => '/operations', 'verb' => 'POST'],
|
['name' => 'flowOperations#addOperation', 'url' => '/operations', 'verb' => 'POST'],
|
||||||
['name' => 'flowOperations#updateOperation', 'url' => '/operations/{id}', 'verb' => 'PUT'],
|
['name' => 'flowOperations#updateOperation', 'url' => '/operations/{id}', 'verb' => 'PUT'],
|
||||||
|
|
|
@ -37,18 +37,6 @@ class Application extends \OCP\AppFramework\App {
|
||||||
*/
|
*/
|
||||||
public function registerHooksAndListeners() {
|
public function registerHooksAndListeners() {
|
||||||
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
|
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
|
||||||
$dispatcher->addListener(
|
|
||||||
'OCP\WorkflowEngine\RegisterCheckEvent',
|
|
||||||
function(RegisterCheckEvent $event) {
|
|
||||||
$event->addCheck(
|
|
||||||
'OCA\WorkflowEngine\Check\UserGroupMembership',
|
|
||||||
'User group membership',
|
|
||||||
['is', '!is']
|
|
||||||
);
|
|
||||||
},
|
|
||||||
-100
|
|
||||||
);
|
|
||||||
|
|
||||||
$dispatcher->addListener(
|
$dispatcher->addListener(
|
||||||
'OCP\WorkflowEngine::loadAdditionalSettingScripts',
|
'OCP\WorkflowEngine::loadAdditionalSettingScripts',
|
||||||
function() {
|
function() {
|
||||||
|
|
|
@ -26,38 +26,19 @@ use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\JSONResponse;
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\WorkflowEngine\RegisterCheckEvent;
|
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
||||||
|
|
||||||
class FlowOperations extends Controller {
|
class FlowOperations extends Controller {
|
||||||
|
|
||||||
/** @var Manager */
|
/** @var Manager */
|
||||||
protected $manager;
|
protected $manager;
|
||||||
|
|
||||||
/** @var EventDispatcherInterface */
|
|
||||||
protected $dispatcher;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IRequest $request
|
* @param IRequest $request
|
||||||
* @param Manager $manager
|
* @param Manager $manager
|
||||||
* @param EventDispatcherInterface $dispatcher
|
|
||||||
*/
|
*/
|
||||||
public function __construct(IRequest $request, Manager $manager, EventDispatcherInterface $dispatcher) {
|
public function __construct(IRequest $request, Manager $manager) {
|
||||||
parent::__construct('workflowengine', $request);
|
parent::__construct('workflowengine', $request);
|
||||||
$this->manager = $manager;
|
$this->manager = $manager;
|
||||||
$this->dispatcher = $dispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @NoCSRFRequired
|
|
||||||
*
|
|
||||||
* @return JSONResponse
|
|
||||||
*/
|
|
||||||
public function getChecks() {
|
|
||||||
$event = new RegisterCheckEvent();
|
|
||||||
$this->dispatcher->dispatch('OCP\WorkflowEngine\RegisterCheckEvent', $event);
|
|
||||||
|
|
||||||
return new JSONResponse($event->getChecks());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -110,8 +110,8 @@ class Manager implements IManager {
|
||||||
$checkInstance->setFileInfo($this->storage, $this->path);
|
$checkInstance->setFileInfo($this->storage, $this->path);
|
||||||
return $checkInstance->executeCheck($check['operator'], $check['value']);
|
return $checkInstance->executeCheck($check['operator'], $check['value']);
|
||||||
} else {
|
} else {
|
||||||
// Check is invalid, assume it matches.
|
// Check is invalid
|
||||||
return true;
|
throw new \RuntimeException('Check ' . htmlspecialchars($check['class']) . ' is invalid or does not exist');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,10 +258,12 @@ class Manager implements IManager {
|
||||||
}
|
}
|
||||||
$result->closeCursor();
|
$result->closeCursor();
|
||||||
|
|
||||||
// TODO What if a check is missing? Should we throw?
|
$checkIds = array_diff($checkIds, array_keys($checks));
|
||||||
// As long as we only allow AND-concatenation of checks, a missing check
|
|
||||||
// is like a matching check, so it evaluates to true and therefor blocks
|
if (!empty($checkIds)) {
|
||||||
// access. So better save than sorry.
|
$missingCheck = array_pop($checkIds);
|
||||||
|
throw new \RuntimeException('Check #' . htmlspecialchars($missingCheck) . ' is invalid or does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
return $checks;
|
return $checks;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.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 OCP\WorkflowEngine;
|
|
||||||
|
|
||||||
|
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class RegisterCheckEvent
|
|
||||||
*
|
|
||||||
* @package OCP\WorkflowEngine
|
|
||||||
* @since 9.1
|
|
||||||
*/
|
|
||||||
class RegisterCheckEvent extends Event {
|
|
||||||
|
|
||||||
/** @var array[] */
|
|
||||||
protected $checks = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $class
|
|
||||||
* @param string $name
|
|
||||||
* @param string[] $operators
|
|
||||||
* @throws \OutOfBoundsException when the check class is already registered
|
|
||||||
* @throws \OutOfBoundsException when the provided information is invalid
|
|
||||||
* @since 9.1
|
|
||||||
*/
|
|
||||||
public function addCheck($class, $name, array $operators) {
|
|
||||||
if (!is_string($class)) {
|
|
||||||
throw new \OutOfBoundsException('Given class name is not a string');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->checks[$class])) {
|
|
||||||
throw new \OutOfBoundsException('Duplicate check class "' . $class . '"');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_string($name)) {
|
|
||||||
throw new \OutOfBoundsException('Given check name is not a string');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($operators as $operator) {
|
|
||||||
if (!is_string($operator)) {
|
|
||||||
throw new \OutOfBoundsException('At least one of the operators is not a string');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->checks[$class] = [
|
|
||||||
'class' => $class,
|
|
||||||
'name' => $name,
|
|
||||||
'operators' => $operators,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array[]
|
|
||||||
* @since 9.1
|
|
||||||
*/
|
|
||||||
public function getChecks() {
|
|
||||||
return array_values($this->checks);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue