1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/jsonrpc.php

315 lines
9.6 KiB
PHP
Raw Normal View History

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');
$server->register('createProject', function($name) use ($container) {
2014-07-20 12:26:15 +02:00
$values = array('name' => $name);
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-01-16 14:23:05 +01:00
$server->register('updateProject', function($id, $name, $is_active = null, $is_public = null, $token = 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,
);
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
/**
* 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');
$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-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-01-16 14:23:05 +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-01-16 14:23:05 +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-01-16 14:23:05 +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-01-16 14:23:05 +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
});
/**
* Parse incoming requests
*/
echo $server->execute();