Improve pull-request
This commit is contained in:
@@ -211,7 +211,7 @@ class Action extends Base
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param array $values Required parameters to save an action
|
* @param array $values Required parameters to save an action
|
||||||
* @return bool Success or not
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function create(array $values)
|
public function create(array $values)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1451,7 +1451,6 @@ Response example:
|
|||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": 1433237746,
|
"id": 1433237746,
|
||||||
"result": 14
|
"result": 14
|
||||||
]
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
32
jsonrpc.php
32
jsonrpc.php
@@ -82,58 +82,70 @@ $server->bind('moveSwimlaneDown', $container['swimlane'], 'moveDown');
|
|||||||
$server->bind('getAvailableActions', $container['action'], 'getAvailableActions');
|
$server->bind('getAvailableActions', $container['action'], 'getAvailableActions');
|
||||||
$server->bind('getAvailableEvents', $container['action'], 'getAvailableEvents');
|
$server->bind('getAvailableEvents', $container['action'], 'getAvailableEvents');
|
||||||
$server->bind('getCompatibleEvents', $container['action'], 'getCompatibleEvents');
|
$server->bind('getCompatibleEvents', $container['action'], 'getCompatibleEvents');
|
||||||
|
$server->bind('removeAction', $container['action'], 'remove');
|
||||||
|
|
||||||
$server->register('getActions', function($project_id) use ($container) {
|
$server->register('getActions', function($project_id) use ($container) {
|
||||||
$actions = $container['action']->getAllByProject($project_id);
|
$actions = $container['action']->getAllByProject($project_id);
|
||||||
foreach($actions as $index => $action) {
|
|
||||||
|
foreach ($actions as $index => $action) {
|
||||||
$params = array();
|
$params = array();
|
||||||
foreach($action['params'] as $param)
|
|
||||||
|
foreach($action['params'] as $param) {
|
||||||
$params[$param['name']] = $param['value'];
|
$params[$param['name']] = $param['value'];
|
||||||
|
}
|
||||||
|
|
||||||
$actions[$index]['params'] = $params;
|
$actions[$index]['params'] = $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $actions;
|
return $actions;
|
||||||
});
|
});
|
||||||
|
|
||||||
$server->register('createAction', function($project_id, $event_name, $action_name, $params) use ($container) {
|
$server->register('createAction', function($project_id, $event_name, $action_name, $params) use ($container) {
|
||||||
|
|
||||||
$values = array(
|
$values = array(
|
||||||
'project_id' => $project_id,
|
'project_id' => $project_id,
|
||||||
'event_name' => $event_name,
|
'event_name' => $event_name,
|
||||||
'action_name' => $action_name,
|
'action_name' => $action_name,
|
||||||
'params' => $params
|
'params' => $params,
|
||||||
);
|
);
|
||||||
|
|
||||||
list($valid,) = $container['action']->validateCreation($values);
|
list($valid,) = $container['action']->validateCreation($values);
|
||||||
|
|
||||||
if (! $valid) {
|
if (! $valid) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check the action exists
|
// Check the action exists
|
||||||
if (! isset($container['action']->getAvailableActions()[$action_name])) {
|
if (! isset($container['action']->getAvailableActions()[$action_name])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check the event
|
// Check the event
|
||||||
$action = $container['action']->load($action_name, $project_id, $event_name);
|
$action = $container['action']->load($action_name, $project_id, $event_name);
|
||||||
|
|
||||||
if (! in_array($event_name, $action->getCompatibleEvents())) {
|
if (! in_array($event_name, $action->getCompatibleEvents())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$required_params = $action->getActionRequiredParameters();
|
$required_params = $action->getActionRequiredParameters();
|
||||||
|
|
||||||
//Check missing parameters
|
// Check missing parameters
|
||||||
foreach($required_params as $param => $value)
|
foreach($required_params as $param => $value) {
|
||||||
if (! isset($params[$param])) {
|
if (! isset($params[$param])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Check extra parameters
|
// Check extra parameters
|
||||||
foreach($params as $param => $value)
|
foreach($params as $param => $value) {
|
||||||
if (! isset($required_params[$param])) {
|
if (! isset($required_params[$param])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $container['action']->create($values);
|
return $container['action']->create($values);
|
||||||
});
|
});
|
||||||
$server->bind('removeAction', $container['action'], 'remove');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Project permissions procedures
|
* Project permissions procedures
|
||||||
|
|||||||
Reference in New Issue
Block a user