summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-02-27 19:15:23 -0500
committerFrederic Guillot <fred@kanboard.net>2015-02-27 19:15:23 -0500
commitdb59460da16bc607ae2e73838925bf3f6a95259d (patch)
tree0fa5fbfd43d95db1745f1a384e38931dbfa262cc
parentdd051feb8cd1d28244f701adffbe4b69ac9e161c (diff)
Improve pull-request
-rw-r--r--app/Model/Action.php2
-rw-r--r--docs/api-json-rpc.markdown1
-rw-r--r--jsonrpc.php32
3 files changed, 23 insertions, 12 deletions
diff --git a/app/Model/Action.php b/app/Model/Action.php
index 0ba889ba..99fb8b73 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -211,7 +211,7 @@ class Action extends Base
*
* @access public
* @param array $values Required parameters to save an action
- * @return bool Success or not
+ * @return integer
*/
public function create(array $values)
{
diff --git a/docs/api-json-rpc.markdown b/docs/api-json-rpc.markdown
index 0c303d2c..0440da0c 100644
--- a/docs/api-json-rpc.markdown
+++ b/docs/api-json-rpc.markdown
@@ -1451,7 +1451,6 @@ Response example:
"jsonrpc": "2.0",
"id": 1433237746,
"result": 14
- ]
}
```
diff --git a/jsonrpc.php b/jsonrpc.php
index 65d4405e..a2106010 100644
--- a/jsonrpc.php
+++ b/jsonrpc.php
@@ -82,58 +82,70 @@ $server->bind('moveSwimlaneDown', $container['swimlane'], 'moveDown');
$server->bind('getAvailableActions', $container['action'], 'getAvailableActions');
$server->bind('getAvailableEvents', $container['action'], 'getAvailableEvents');
$server->bind('getCompatibleEvents', $container['action'], 'getCompatibleEvents');
+$server->bind('removeAction', $container['action'], 'remove');
+
$server->register('getActions', function($project_id) use ($container) {
$actions = $container['action']->getAllByProject($project_id);
- foreach($actions as $index => $action) {
+
+ foreach ($actions as $index => $action) {
$params = array();
- foreach($action['params'] as $param)
+
+ foreach($action['params'] as $param) {
$params[$param['name']] = $param['value'];
+ }
+
$actions[$index]['params'] = $params;
}
+
return $actions;
});
+
$server->register('createAction', function($project_id, $event_name, $action_name, $params) use ($container) {
$values = array(
'project_id' => $project_id,
'event_name' => $event_name,
'action_name' => $action_name,
- 'params' => $params
+ 'params' => $params,
);
list($valid,) = $container['action']->validateCreation($values);
+
if (! $valid) {
return false;
}
- //Check the action exists
+ // Check the action exists
if (! isset($container['action']->getAvailableActions()[$action_name])) {
return false;
}
- //Check the event
+ // Check the event
$action = $container['action']->load($action_name, $project_id, $event_name);
+
if (! in_array($event_name, $action->getCompatibleEvents())) {
return false;
}
$required_params = $action->getActionRequiredParameters();
- //Check missing parameters
- foreach($required_params as $param => $value)
+ // Check missing parameters
+ foreach($required_params as $param => $value) {
if (! isset($params[$param])) {
return false;
}
+ }
- //Check extra parameters
- foreach($params as $param => $value)
+ // Check extra parameters
+ foreach($params as $param => $value) {
if (! isset($required_params[$param])) {
return false;
}
+ }
return $container['action']->create($values);
});
-$server->bind('removeAction', $container['action'], 'remove');
+
/**
* Project permissions procedures