diff options
author | Francois Ferrand <thetypz@gmail.com> | 2015-02-25 11:18:04 +0100 |
---|---|---|
committer | Francois Ferrand <thetypz@gmail.com> | 2015-02-25 11:35:31 +0100 |
commit | 34a0216ca74b52472f8e717c78e927672c0dd4cf (patch) | |
tree | d8d1ec5ceed03290767eea914007d05f1acc20bd /jsonrpc.php | |
parent | 11d1314fbe96c8f19d898cf18dc615a49a89fd0d (diff) |
Add REST api to manage actions.
Diffstat (limited to 'jsonrpc.php')
-rw-r--r-- | jsonrpc.php | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/jsonrpc.php b/jsonrpc.php index 03f007c2..65d4405e 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -77,6 +77,65 @@ $server->bind('moveSwimlaneUp', $container['swimlane'], 'moveUp'); $server->bind('moveSwimlaneDown', $container['swimlane'], 'moveDown'); /** + * Actions procedures + */ +$server->bind('getAvailableActions', $container['action'], 'getAvailableActions'); +$server->bind('getAvailableEvents', $container['action'], 'getAvailableEvents'); +$server->bind('getCompatibleEvents', $container['action'], 'getCompatibleEvents'); +$server->register('getActions', function($project_id) use ($container) { + $actions = $container['action']->getAllByProject($project_id); + foreach($actions as $index => $action) { + $params = array(); + 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 + ); + + list($valid,) = $container['action']->validateCreation($values); + if (! $valid) { + return false; + } + + //Check the action exists + if (! isset($container['action']->getAvailableActions()[$action_name])) { + return false; + } + + //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) + if (! isset($params[$param])) { + return false; + } + + //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 */ $server->bind('getMembers', $container['projectPermission'], 'getMembers'); |