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

351 lines
9.6 KiB
PHP
Raw Normal View History

2014-07-20 12:26:15 +02:00
<?php
require __DIR__.'/app/common.php';
2014-12-22 19:15:38 +01:00
$models = array(
'Config',
'Project',
'ProjectPermission',
'Task',
'TaskCreation',
'TaskModification',
'TaskFinder',
'TaskPosition',
'TaskStatus',
'TaskValidator',
'User',
'Category',
'Comment',
'SubTask',
'Board',
'Action',
'Webhook',
'Notification',
);
$events = array(
'actionModel',
'projectModel',
'webhookModel',
'notificationModel',
);
foreach ($models as $model) {
$variable = lcfirst($model).'Model';
$class = '\Model\\'.$model;
$$variable = new $class($container);
}
foreach ($events as $class) {
$$class->attachEvents();
}
$configModel->setupTranslations();
$configModel->setupTimezone();
$server = new JsonRPC\Server;
$server->authentication(array('jsonrpc' => $configModel->get('api_token')));
2014-07-20 12:26:15 +02:00
/**
* Project procedures
*/
2014-12-22 19:15:38 +01:00
$server->bind('getProjectById', $projectModel, 'getById');
$server->bind('getProjectByName', $projectModel, 'getByName');
$server->bind('getAllProjects', $projectModel, 'getAll');
$server->bind('removeProject', $projectModel, 'remove');
$server->bind('enableProject', $projectModel, 'enable');
$server->bind('disableProject', $projectModel, 'disable');
$server->bind('enableProjectPublicAccess', $projectModel, 'enablePublicAccess');
$server->bind('disableProjectPublicAccess', $projectModel, 'disablePublicAccess');
$server->register('createProject', function($name) use ($projectModel) {
2014-07-20 12:26:15 +02:00
$values = array('name' => $name);
2014-12-22 19:15:38 +01:00
list($valid,) = $projectModel->validateCreation($values);
return $valid && $projectModel->create($values);
2014-07-20 12:26:15 +02:00
});
2014-12-22 19:15:38 +01:00
$server->register('updateProject', function($id, $name, $is_active = null, $is_public = null, $token = null) use ($projectModel) {
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]);
}
}
2014-12-22 19:15:38 +01:00
list($valid,) = $projectModel->validateModification($values);
return $valid && $projectModel->update($values);
2014-10-22 19:59:09 +02:00
});
/**
* Board procedures
*/
2014-12-22 19:15:38 +01:00
$server->bind('getBoard', $boardModel, 'get');
$server->bind('getColumns', $boardModel, 'getColumns');
$server->bind('getColumn', $boardModel, 'getColumn');
$server->bind('moveColumnUp', $boardModel, 'moveUp');
$server->bind('moveColumnDown', $boardModel, 'moveDown');
$server->bind('updateColumn', $boardModel, 'updateColumn');
$server->bind('addColumn', $boardModel, 'addColumn');
$server->bind('removeColumn', $boardModel, 'removeColumn');
2014-10-22 19:59:09 +02:00
/**
* Project permissions procedures
*/
2014-12-22 19:15:38 +01:00
$server->bind('getMembers', $projectPermissionModel, 'getMembers');
$server->bind('revokeUser', $projectPermissionModel, 'revokeUser');
$server->bind('allowUser', $projectPermissionModel, 'allowUser');
2014-07-20 12:26:15 +02:00
/**
* Task procedures
*/
2014-12-22 19:15:38 +01:00
$server->bind('getTask', $taskFinderModel, 'getById');
$server->bind('getAllTasks', $taskFinderModel, 'getAll');
$server->bind('openTask', $taskStatusModel, 'open');
$server->bind('closeTask', $taskStatusModel, 'close');
$server->bind('removeTask', $taskModel, 'remove');
$server->bind('moveTaskPosition', $taskPositionModel, 'movePosition');
$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) use ($taskCreationModel, $taskValidatorModel) {
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,
);
2014-12-22 19:15:38 +01:00
list($valid,) = $taskValidatorModel->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
2014-12-22 19:15:38 +01:00
return $taskCreationModel->create($values);
2014-07-20 12:26:15 +02:00
});
2014-12-22 19:15:38 +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) use ($taskModificationModel, $taskValidatorModel) {
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,
);
foreach ($values as $key => $value) {
if (is_null($value)) {
unset($values[$key]);
}
}
2014-12-22 19:15:38 +01:00
list($valid) = $taskValidatorModel->validateApiModification($values);
return $valid && $taskModificationModel->update($values);
2014-10-22 19:59:09 +02:00
});
2014-07-20 12:26:15 +02:00
/**
* User procedures
*/
2014-12-22 19:15:38 +01:00
$server->bind('getUser', $userModel, 'getById');
$server->bind('getAllUsers', $userModel, 'getAll');
$server->bind('removeUser', $userModel, 'remove');
$server->register('createUser', function($username, $password, $name = '', $email = '', $is_admin = 0, $default_project_id = 0) use ($userModel) {
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,
);
2014-12-22 19:15:38 +01:00
list($valid,) = $userModel->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
2014-12-22 19:15:38 +01:00
return $userModel->create($values);
2014-07-20 12:26:15 +02:00
});
2014-12-22 19:15:38 +01:00
$server->register('updateUser', function($id, $username = null, $name = null, $email = null, $is_admin = null, $default_project_id = null) use ($userModel) {
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]);
}
}
2014-12-22 19:15:38 +01:00
list($valid,) = $userModel->validateApiModification($values);
return $valid && $userModel->update($values);
2014-07-20 12:26:15 +02:00
});
/**
* Category procedures
*/
2014-12-22 19:15:38 +01:00
$server->bind('getCategory', $categoryModel, 'getById');
$server->bind('getAllCategories', $categoryModel, 'getAll');
$server->bind('removeCategory', $categoryModel, 'remove');
$server->register('createCategory', function($project_id, $name) use ($categoryModel) {
2014-10-22 19:59:09 +02:00
$values = array(
'project_id' => $project_id,
'name' => $name,
);
2014-12-22 19:15:38 +01:00
list($valid,) = $categoryModel->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
2014-12-22 19:15:38 +01:00
return $categoryModel->create($values);
2014-07-20 12:26:15 +02:00
});
2014-12-22 19:15:38 +01:00
$server->register('updateCategory', function($id, $name) use ($categoryModel) {
2014-10-22 19:59:09 +02:00
$values = array(
'id' => $id,
'name' => $name,
);
2014-12-22 19:15:38 +01:00
list($valid,) = $categoryModel->validateModification($values);
return $valid && $categoryModel->update($values);
2014-07-20 12:26:15 +02:00
});
/**
* Comments procedures
*/
2014-12-22 19:15:38 +01:00
$server->bind('getComment', $commentModel, 'getById');
$server->bind('getAllComments', $commentModel, 'getAll');
$server->bind('removeComment', $commentModel, 'remove');
$server->register('createComment', function($task_id, $user_id, $content) use ($commentModel) {
2014-10-22 19:59:09 +02:00
$values = array(
'task_id' => $task_id,
'user_id' => $user_id,
'comment' => $content,
);
2014-12-22 19:15:38 +01:00
list($valid,) = $commentModel->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
2014-12-22 19:15:38 +01:00
return $commentModel->create($values);
2014-07-20 12:26:15 +02:00
});
2014-12-22 19:15:38 +01:00
$server->register('updateComment', function($id, $content) use ($commentModel) {
2014-10-22 19:59:09 +02:00
$values = array(
'id' => $id,
'comment' => $content,
);
2014-12-22 19:15:38 +01:00
list($valid,) = $commentModel->validateModification($values);
return $valid && $commentModel->update($values);
2014-07-20 12:26:15 +02:00
});
/**
* Subtask procedures
*/
2014-12-22 19:15:38 +01:00
$server->bind('getSubtask', $subTaskModel, 'getById');
$server->bind('getAllSubtasks', $subTaskModel, 'getAll');
$server->bind('removeSubtask', $subTaskModel, 'remove');
$server->register('createSubtask', function($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) use ($subTaskModel) {
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]);
}
}
2014-12-22 19:15:38 +01:00
list($valid,) = $subTaskModel->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
2014-12-22 19:15:38 +01:00
return $subTaskModel->create($values);
2014-07-20 12:26:15 +02:00
});
2014-12-22 19:15:38 +01:00
$server->register('updateSubtask', function($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) use ($subTaskModel) {
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]);
}
}
2014-12-22 19:15:38 +01:00
list($valid,) = $subTaskModel->validateApiModification($values);
return $valid && $subTaskModel->update($values);
2014-07-20 12:26:15 +02:00
});
2014-12-22 19:15:38 +01:00
/**
* Application procedures
*/
$server->register('getTimezone', function() use($configModel) {
return $configModel->get('application_timezone');
2014-07-20 12:26:15 +02:00
});
/**
* Parse incoming requests
*/
echo $server->execute();