2014-07-20 12:26:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require __DIR__.'/app/common.php';
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
use Symfony\Component\EventDispatcher\Event;
|
|
|
|
|
|
|
|
$container['dispatcher']->dispatch('api.bootstrap', new Event);
|
2014-12-22 19:15:38 +01:00
|
|
|
|
|
|
|
$server = new JsonRPC\Server;
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->authentication(array('jsonrpc' => $container['config']->get('api_token')));
|
2014-07-20 12:26:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Project procedures
|
|
|
|
*/
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->bind('getProjectById', $container['project'], 'getById');
|
|
|
|
$server->bind('getProjectByName', $container['project'], 'getByName');
|
|
|
|
$server->bind('getAllProjects', $container['project'], 'getAll');
|
|
|
|
$server->bind('removeProject', $container['project'], 'remove');
|
|
|
|
$server->bind('enableProject', $container['project'], 'enable');
|
|
|
|
$server->bind('disableProject', $container['project'], 'disable');
|
|
|
|
$server->bind('enableProjectPublicAccess', $container['project'], 'enablePublicAccess');
|
|
|
|
$server->bind('disableProjectPublicAccess', $container['project'], 'disablePublicAccess');
|
2015-02-25 17:29:06 +01:00
|
|
|
$server->bind('getProjectActivity', $container['projectActivity'], 'getProjects');
|
2015-01-16 14:23:05 +01:00
|
|
|
|
2015-04-21 17:56:16 +02:00
|
|
|
$server->register('createProject', function($name, $description = null) use ($container) {
|
|
|
|
$values = array(
|
|
|
|
'name' => $name,
|
|
|
|
'description' => $description
|
|
|
|
);
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['project']->validateCreation($values);
|
|
|
|
return $valid ? $container['project']->create($values) : false;
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
2015-04-21 17:56:16 +02:00
|
|
|
$server->register('updateProject', function($id, $name, $is_active = null, $is_public = null, $token = null, $description = null) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'id' => $id,
|
|
|
|
'name' => $name,
|
|
|
|
'is_active' => $is_active,
|
|
|
|
'is_public' => $is_public,
|
|
|
|
'token' => $token,
|
2015-04-21 17:56:16 +02:00
|
|
|
'description' => $description
|
2014-10-22 19:59:09 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
if (is_null($value)) {
|
|
|
|
unset($values[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['project']->validateModification($values);
|
|
|
|
return $valid && $container['project']->update($values);
|
2014-10-22 19:59:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Board procedures
|
|
|
|
*/
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->bind('getBoard', $container['board'], 'getBoard');
|
|
|
|
$server->bind('getColumns', $container['board'], 'getColumns');
|
|
|
|
$server->bind('getColumn', $container['board'], 'getColumn');
|
|
|
|
$server->bind('moveColumnUp', $container['board'], 'moveUp');
|
|
|
|
$server->bind('moveColumnDown', $container['board'], 'moveDown');
|
|
|
|
$server->bind('updateColumn', $container['board'], 'updateColumn');
|
|
|
|
$server->bind('addColumn', $container['board'], 'addColumn');
|
|
|
|
$server->bind('removeColumn', $container['board'], 'removeColumn');
|
2014-10-22 19:59:09 +02:00
|
|
|
|
2015-04-21 17:56:16 +02:00
|
|
|
/**
|
|
|
|
* Swimlane procedures
|
|
|
|
*/
|
|
|
|
$server->bind('getSwimlanes', $container['swimlane'], 'getSwimlanes');
|
|
|
|
$server->bind('getAllSwimlanes', $container['swimlane'], 'getAll');
|
|
|
|
$server->bind('getSwimlane', $container['swimlane'], 'getByName');
|
|
|
|
$server->bind('addSwimlane', $container['swimlane'], 'create');
|
|
|
|
$server->bind('updateSwimlane', $container['swimlane'], 'rename');
|
|
|
|
$server->bind('removeSwimlane', $container['swimlane'], 'remove');
|
|
|
|
$server->bind('disableSwimlane', $container['swimlane'], 'disable');
|
|
|
|
$server->bind('enableSwimlane', $container['swimlane'], 'enable');
|
|
|
|
$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->bind('removeAction', $container['action'], 'remove');
|
|
|
|
|
|
|
|
$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);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-10-22 19:59:09 +02:00
|
|
|
/**
|
|
|
|
* Project permissions procedures
|
|
|
|
*/
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->bind('getMembers', $container['projectPermission'], 'getMembers');
|
|
|
|
$server->bind('revokeUser', $container['projectPermission'], 'revokeMember');
|
|
|
|
$server->bind('allowUser', $container['projectPermission'], 'addMember');
|
2014-07-20 12:26:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Task procedures
|
|
|
|
*/
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->bind('getTask', $container['taskFinder'], 'getById');
|
|
|
|
$server->bind('getAllTasks', $container['taskFinder'], 'getAll');
|
2015-02-25 17:29:06 +01:00
|
|
|
$server->bind('getOverdueTasks', $container['taskFinder'], 'getOverdueTasks');
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->bind('openTask', $container['taskStatus'], 'open');
|
|
|
|
$server->bind('closeTask', $container['taskStatus'], 'close');
|
|
|
|
$server->bind('removeTask', $container['task'], 'remove');
|
|
|
|
$server->bind('moveTaskPosition', $container['taskPosition'], 'movePosition');
|
2014-12-22 19:15:38 +01:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('createTask', function($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, $date_due = '', $description = '', $category_id = 0, $score = 0, $swimlane_id = 0) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'title' => $title,
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'color_id' => $color_id,
|
|
|
|
'column_id' => $column_id,
|
|
|
|
'owner_id' => $owner_id,
|
|
|
|
'creator_id' => $creator_id,
|
|
|
|
'date_due' => $date_due,
|
|
|
|
'description' => $description,
|
|
|
|
'category_id' => $category_id,
|
|
|
|
'score' => $score,
|
2015-01-16 14:23:05 +01:00
|
|
|
'swimlane_id' => $swimlane_id,
|
2014-10-22 19:59:09 +02:00
|
|
|
);
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['taskValidator']->validateCreation($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
if (! $valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
return $container['taskCreation']->create($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('updateTask', function($id, $title = null, $project_id = null, $color_id = null, $column_id = null, $owner_id = null, $creator_id = null, $date_due = null, $description = null, $category_id = null, $score = null, $swimlane_id = null) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'id' => $id,
|
|
|
|
'title' => $title,
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'color_id' => $color_id,
|
|
|
|
'column_id' => $column_id,
|
|
|
|
'owner_id' => $owner_id,
|
|
|
|
'creator_id' => $creator_id,
|
|
|
|
'date_due' => $date_due,
|
|
|
|
'description' => $description,
|
|
|
|
'category_id' => $category_id,
|
|
|
|
'score' => $score,
|
2015-01-16 14:23:05 +01:00
|
|
|
'swimlane_id' => $swimlane_id,
|
2014-10-22 19:59:09 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
if (is_null($value)) {
|
|
|
|
unset($values[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid) = $container['taskValidator']->validateApiModification($values);
|
|
|
|
return $valid && $container['taskModification']->update($values);
|
2014-10-22 19:59:09 +02:00
|
|
|
});
|
|
|
|
|
2014-07-20 12:26:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User procedures
|
|
|
|
*/
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->bind('getUser', $container['user'], 'getById');
|
|
|
|
$server->bind('getAllUsers', $container['user'], 'getAll');
|
|
|
|
$server->bind('removeUser', $container['user'], 'remove');
|
2014-12-22 19:15:38 +01:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('createUser', function($username, $password, $name = '', $email = '', $is_admin = 0, $default_project_id = 0) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'username' => $username,
|
|
|
|
'password' => $password,
|
|
|
|
'confirmation' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
'email' => $email,
|
|
|
|
'is_admin' => $is_admin,
|
|
|
|
'default_project_id' => $default_project_id,
|
|
|
|
);
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['user']->validateCreation($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
if (! $valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
return $container['user']->create($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
2015-02-25 17:29:06 +01:00
|
|
|
$server->register('createLdapUser', function($username = '', $email = '', $is_admin = 0, $default_project_id = 0) use ($container) {
|
|
|
|
|
|
|
|
$ldap = new Auth\Ldap($container);
|
|
|
|
$user = $ldap->lookup($username, $email);
|
|
|
|
|
|
|
|
if (! $user) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'username' => $user['username'],
|
|
|
|
'name' => $user['name'],
|
|
|
|
'email' => $user['email'],
|
|
|
|
'is_ldap_user' => 1,
|
|
|
|
'is_admin' => $is_admin,
|
|
|
|
'default_project_id' => $default_project_id,
|
|
|
|
);
|
|
|
|
|
|
|
|
return $container['user']->create($values);
|
|
|
|
});
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('updateUser', function($id, $username = null, $name = null, $email = null, $is_admin = null, $default_project_id = null) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'id' => $id,
|
|
|
|
'username' => $username,
|
|
|
|
'name' => $name,
|
|
|
|
'email' => $email,
|
|
|
|
'is_admin' => $is_admin,
|
|
|
|
'default_project_id' => $default_project_id,
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
if (is_null($value)) {
|
|
|
|
unset($values[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['user']->validateApiModification($values);
|
|
|
|
return $valid && $container['user']->update($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Category procedures
|
|
|
|
*/
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->bind('getCategory', $container['category'], 'getById');
|
|
|
|
$server->bind('getAllCategories', $container['category'], 'getAll');
|
|
|
|
$server->bind('removeCategory', $container['category'], 'remove');
|
2014-12-22 19:15:38 +01:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('createCategory', function($project_id, $name) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $name,
|
|
|
|
);
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['category']->validateCreation($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
if (! $valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
return $container['category']->create($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('updateCategory', function($id, $name) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'id' => $id,
|
|
|
|
'name' => $name,
|
|
|
|
);
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['category']->validateModification($values);
|
|
|
|
return $valid && $container['category']->update($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comments procedures
|
|
|
|
*/
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->bind('getComment', $container['comment'], 'getById');
|
|
|
|
$server->bind('getAllComments', $container['comment'], 'getAll');
|
|
|
|
$server->bind('removeComment', $container['comment'], 'remove');
|
2014-12-22 19:15:38 +01:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('createComment', function($task_id, $user_id, $content) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'task_id' => $task_id,
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'comment' => $content,
|
|
|
|
);
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['comment']->validateCreation($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
if (! $valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
return $container['comment']->create($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('updateComment', function($id, $content) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'id' => $id,
|
|
|
|
'comment' => $content,
|
|
|
|
);
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
list($valid,) = $container['comment']->validateModification($values);
|
|
|
|
return $valid && $container['comment']->update($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtask procedures
|
|
|
|
*/
|
2015-02-25 17:29:06 +01:00
|
|
|
$server->bind('getSubtask', $container['subtask'], 'getById');
|
|
|
|
$server->bind('getAllSubtasks', $container['subtask'], 'getAll');
|
|
|
|
$server->bind('removeSubtask', $container['subtask'], 'remove');
|
2014-12-22 19:15:38 +01:00
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('createSubtask', function($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'title' => $title,
|
|
|
|
'task_id' => $task_id,
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'time_estimated' => $time_estimated,
|
|
|
|
'time_spent' => $time_spent,
|
|
|
|
'status' => $status,
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
if (is_null($value)) {
|
|
|
|
unset($values[$key]);
|
|
|
|
}
|
|
|
|
}
|
2015-02-25 17:29:06 +01:00
|
|
|
list($valid,) = $container['subtask']->validateCreation($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
if (! $valid) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-20 12:26:15 +02:00
|
|
|
|
2015-02-25 17:29:06 +01:00
|
|
|
return $container['subtask']->create($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('updateSubtask', function($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) use ($container) {
|
2014-10-22 19:59:09 +02:00
|
|
|
|
|
|
|
$values = array(
|
|
|
|
'id' => $id,
|
|
|
|
'task_id' => $task_id,
|
|
|
|
'title' => $title,
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'time_estimated' => $time_estimated,
|
|
|
|
'time_spent' => $time_spent,
|
|
|
|
'status' => $status,
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
if (is_null($value)) {
|
|
|
|
unset($values[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 17:29:06 +01:00
|
|
|
list($valid,) = $container['subtask']->validateApiModification($values);
|
|
|
|
return $valid && $container['subtask']->update($values);
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
2014-12-22 19:15:38 +01:00
|
|
|
/**
|
|
|
|
* Application procedures
|
|
|
|
*/
|
2015-01-16 14:23:05 +01:00
|
|
|
$server->register('getTimezone', function() use ($container) {
|
|
|
|
return $container['config']->get('application_timezone');
|
2014-07-20 12:26:15 +02:00
|
|
|
});
|
|
|
|
|
2015-04-21 17:56:16 +02:00
|
|
|
$server->register('getVersion', function() use ($container) {
|
|
|
|
return APP_VERSION;
|
|
|
|
});
|
|
|
|
|
2014-07-20 12:26:15 +02:00
|
|
|
/**
|
|
|
|
* Parse incoming requests
|
|
|
|
*/
|
|
|
|
echo $server->execute();
|