Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/workflowengine/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

return [
'routes' => [
['name' => 'flowOperations#getChecks', 'url' => '/checks', 'verb' => 'GET'], // TODO rm and do via js?
['name' => 'flowOperations#getOperations', 'url' => '/operations', 'verb' => 'GET'],
['name' => 'flowOperations#addOperation', 'url' => '/operations', 'verb' => 'POST'],
['name' => 'flowOperations#updateOperation', 'url' => '/operations/{id}', 'verb' => 'PUT'],
Expand Down
73 changes: 37 additions & 36 deletions apps/workflowengine/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,27 @@
});

Handlebars.registerHelper('getOperators', function(classname) {
return OCA.WorkflowEngine.availableChecks
.getOperatorsByClassName(classname);
var check = OCA.WorkflowEngine.getCheckByClass(classname);
if (!_.isUndefined(check)) {
return check['operators'];
}
return [];
});

OCA.WorkflowEngine = OCA.WorkflowEngine || {};
OCA.WorkflowEngine = _.extend(OCA.WorkflowEngine || {}, {
availablePlugins: [],
availableChecks: [],

getCheckByClass: function(className) {
var length = OCA.WorkflowEngine.availableChecks.length;
for (var i = 0; i < length; i++) {
if (OCA.WorkflowEngine.availableChecks[i]['class'] === className) {
return OCA.WorkflowEngine.availableChecks[i];
}
}
return undefined;
}
});

/**
* 888b d888 888 888
Expand Down Expand Up @@ -86,22 +102,6 @@
url: OC.generateUrl('apps/workflowengine/operations')
});

/**
* @class OCA.WorkflowEngine.AvailableChecksCollection
*
* collection for all available checks
*/
OCA.WorkflowEngine.AvailableChecksCollection =
OC.Backbone.Collection.extend({
model: OCA.WorkflowEngine.AvailableCheck,
url: OC.generateUrl('apps/workflowengine/checks'),
getOperatorsByClassName: function(classname) {
return OCA.WorkflowEngine.availableChecks
.findWhere({'class': classname})
.get('operators');
}
});

/**
* 888 888 d8b
* 888 888 Y8P
Expand Down Expand Up @@ -154,7 +154,6 @@
message: '',
errorMessage: '',
saving: false,
plugins: [],
initialize: function() {
// this creates a new copy of the object to definitely have a new reference and being able to reset the model
this.originalModel = JSON.parse(JSON.stringify(this.model));
Expand All @@ -167,13 +166,6 @@
if (this.model.get('id') === undefined) {
this.hasChanged = true;
}

this.plugins = OC.Plugins.getPlugins('OCA.WorkflowEngine.CheckPlugins');
_.each(this.plugins, function(plugin) {
if (_.isFunction(plugin.initialize)) {
plugin.initialize();
}
});
},
delete: function() {
this.model.destroy();
Expand Down Expand Up @@ -209,13 +201,12 @@
},
add: function() {
var checks = _.clone(this.model.get('checks')),
classname = OCA.WorkflowEngine.availableChecks.at(0).get('class'),
operators = OCA.WorkflowEngine.availableChecks
.getOperatorsByClassName(classname);
classname = OCA.WorkflowEngine.availableChecks[0]['class'],
operators = OCA.WorkflowEngine.availableChecks[0]['operators'];

checks.push({
'class': classname,
'operator': operators[0],
'operator': operators[0]['operator'],
'value': ''
});
this.model.set({'checks': checks});
Expand Down Expand Up @@ -249,9 +240,10 @@
// if the class is changed most likely also the operators have changed
// with this we set the operator to the first possible operator
if (key === 'class') {
var operators = OCA.WorkflowEngine.availableChecks
.getOperatorsByClassName(value);
checks[id]['operator'] = operators[0];
var check = OCA.WorkflowEngine.getCheckByClass(value);
if (!_.isUndefined(check)) {
checks[id]['operator'] = check['operators'][0]['operator'];
}
}
// model change will trigger render
this.model.set({'checks': checks});
Expand Down Expand Up @@ -294,7 +286,7 @@
render: function() {
this.$el.html(this.template({
operation: this.model.toJSON(),
classes: OCA.WorkflowEngine.availableChecks.toJSON(),
classes: OCA.WorkflowEngine.availableChecks,
hasChanged: this.hasChanged,
message: this.message,
errorMessage: this.errorMessage,
Expand All @@ -308,7 +300,7 @@
check = checks[id],
valueElement = $element.find('.check-value').first();

_.each(this.plugins, function(plugin) {
_.each(OCA.WorkflowEngine.availablePlugins, function(plugin) {
if (_.isFunction(plugin.render)) {
plugin.render(valueElement, check['class'], check['value']);
}
Expand All @@ -334,13 +326,22 @@
OCA.WorkflowEngine.OperationsView =
OCA.WorkflowEngine.TemplateView.extend({
templateId: '#operations-template',
collection: null,
$el: null,
events: {
'click .button-add-operation': 'add'
},
initialize: function() {
this._initialize('OCA\\WorkflowEngine\\Operation');
},
_initialize: function(classname) {
OCA.WorkflowEngine.availablePlugins = OC.Plugins.getPlugins('OCA.WorkflowEngine.CheckPlugins');
_.each(OCA.WorkflowEngine.availablePlugins, function(plugin) {
if (_.isFunction(plugin.getCheck)) {
OCA.WorkflowEngine.availableChecks.push(plugin.getCheck());
}
});

this.collection.fetch({data: {
'class': classname
}});
Expand Down
10 changes: 10 additions & 0 deletions apps/workflowengine/js/usergroupmembershipplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
OCA.WorkflowEngine.Plugins = OCA.WorkflowEngine.Plugins || {};

OCA.WorkflowEngine.Plugins.UserGroupMembershipPlugin = {
getCheck: function() {
return {
'class': 'OCA\\WorkflowEngine\\Check\\UserGroupMembership',
'name': t('workflowengine', 'User group membership'),
'operators': [
{'operator': 'is', 'name': t('workflowengine', 'is member of')},
{'operator': '!is', 'name': t('workflowengine', 'is not member of')}
]
};
},
render: function(element, classname, value) {
if (classname !== 'OCA\\WorkflowEngine\\Check\\UserGroupMembership') {
return;
Expand Down
12 changes: 0 additions & 12 deletions apps/workflowengine/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ public function __construct() {
*/
public function registerHooksAndListeners() {
$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(
'OCP\WorkflowEngine::loadAdditionalSettingScripts',
function() {
Expand Down
21 changes: 1 addition & 20 deletions apps/workflowengine/lib/Controller/FlowOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,19 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\WorkflowEngine\RegisterCheckEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class FlowOperations extends Controller {

/** @var Manager */
protected $manager;

/** @var EventDispatcherInterface */
protected $dispatcher;

/**
* @param IRequest $request
* @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);
$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());
}

/**
Expand Down
14 changes: 8 additions & 6 deletions apps/workflowengine/lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ protected function check(array $check) {
$checkInstance->setFileInfo($this->storage, $this->path);
return $checkInstance->executeCheck($check['operator'], $check['value']);
} else {
// Check is invalid, assume it matches.
return true;
// Check is invalid
throw new \RuntimeException('Check ' . htmlspecialchars($check['class']) . ' is invalid or does not exist');
}
}

Expand Down Expand Up @@ -258,10 +258,12 @@ public function getChecks(array $checkIds) {
}
$result->closeCursor();

// TODO What if a check is missing? Should we throw?
// 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
// access. So better save than sorry.
$checkIds = array_diff($checkIds, array_keys($checks));

if (!empty($checkIds)) {
$missingCheck = array_pop($checkIds);
throw new \RuntimeException('Check #' . htmlspecialchars($missingCheck) . ' is invalid or does not exist');
}

return $checks;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/workflowengine/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/** @var array $_ */
/** @var OC_L10N $l */
?>
<div id="workflowengine" class="section workflowengine">
<div id="<?php p($_['appid']); ?>" class="section workflowengine">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<h2 class="inlineblock"><?php p($_['heading']); ?></h2>
<script type="text/template" id="operations-template">
<div class="operations"></div>
Expand All @@ -48,7 +48,7 @@
</select>
<select class="check-operator">
{{#each (getOperators class)}}
<option value="{{this}}" {{selectItem this ../operator}}>{{this}}</option>
<option value="{{operator}}" {{selectItem operator ../operator}}>{{name}}</option>
{{/each}}
</select>
<input type="text" class="check-value" value="{{value}}">
Expand Down
79 changes: 0 additions & 79 deletions lib/public/WorkflowEngine/RegisterCheckEvent.php

This file was deleted.