+ Add user and bug api.

This commit is contained in:
zhujinyong
2021-07-19 11:58:25 +08:00
parent 7bb10b58db
commit 37f44fbbca
19 changed files with 390 additions and 22 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
/**
* 禅道API的bug资源类
* 版本V1
*
* The bug entry point of zentaopms
* Version 1
*/
class bugEntry extends entry
{
public function get($bugID)
{
$control = $this->loadController('bug', 'view');
$control->view($bugID);
$data = $this->getData();
$bug = $data->data->bug;
$this->send(200, $bug);
}
public function put($bugID)
{
$oldBug = $this->loadModel('bug')->getByID($bugID);
/* Set $_POST variables. */
$fields = 'title,project,execution,openedBuild,assignedTo,pri,severity,type,story,resolvedBy,closedBy,resolution,product,plan,task';
$this->batchSetPost($fields, $oldBug);
$control = $this->loadController('bug', 'edit');
$control->edit($bugID);
$data = $this->getData();
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
if(!isset($data->status)) return $this->sendError(400, 'error');
$bug = $this->bug->getByID($bugID);
$this->send(200, $bug);
}
public function delete($bugID)
{
$control = $this->loadController('bug', 'delete');
$control->delete($bugID, 'yes');
$this->getData();
$this->sendSuccess(200, 'success');
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* 禅道API的bugs资源类
* 版本V1
*
* The bugs entry point of zentaopms
* Version 1
*/
class bugsEntry extends entry
{
public function get($productID)
{
$control = $this->loadController('bug', 'browse');
$control->browse($productID);
$data = $this->getData();
if(isset($data->status) and $data->status == 'success')
{
$bugs = $data->data->bugs;
$result = array();
foreach($bugs as $bug)
{
$result[] = $bug;
}
return $this->send(200, $result);
}
if(isset($data->status) and $data->status == 'fail')
{
return $this->sendError(400, $data->message);
}
return $this->sendError(400, 'error');
}
public function post($productID)
{
$fields = 'title,project,execution,openedBuild,assignedTo,pri,severity,type,story';
$this->batchSetPost($fields);
$this->setPost('product', $productID);
$control = $this->loadController('bug', 'create');
$this->requireFields('title,pri,severity,type,openedBuild');
$control->create($productID);
$data = $this->getData();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
$bug = $this->loadModel('bug')->getByID($data->id);
$this->send(200, $bug);
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
/**
* 禅道API的execution资源类
* 版本V1
*
* The execution entry point of zentaopms
* Version 1
*/
class executionEntry extends Entry
{
public function get($executionID)
{
$control = $this->loadController('execution', 'view');
$control->view($executionID);
$data = $this->getData();
$execution = $data->data->execution;
$this->send(200, $execution);
}
public function put($executionID)
{
$oldExecution = $this->loadModel('execution')->getByID($executionID);
/* Set $_POST variables. */
$fields = 'project,code,name,begin,end,lifetime,desc,days,acl';
$this->batchSetPost($fields, $oldExecution);
$this->setPost('whitelist', $this->request('whitelist', explode(',', $oldExecution->whitelist)));
$control = $this->loadController('execution', 'edit');
$control->edit($executionID);
$data = $this->getData();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
if(!isset($data->result)) return $this->sendError(400, 'error');
$execution = $this->execution->getByID($executionID);
$this->sendSuccess(200, $execution);
}
public function delete($executionID)
{
$control = $this->loadController('execution', 'delete');
$control->delete($executionID, 'true');
$this->getData();
$this->sendSuccess(200, 'success');
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
/**
* 禅道API的executions资源类
* 版本V1
*
* The executions entry point of zentaopms
* Version 1
*/
class executionsEntry extends entry
{
public function get($projectID = 0)
{
$control = $this->loadController('execution', 'all');
$control->all($this->param('status', 'all'), $this->param('project', $projectID));
$data = $this->getData();
if(isset($data->status) and $data->status == 'success') return $this->send(200, $data->data->executionStats);
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
return $this->sendError(400, 'error');
}
public function post($projectID = 0)
{
$fields = 'project,code,name,begin,end,lifetime,desc,days';
$this->batchSetPost($fields);
$projectID = $this->param('project', $projectID);
$this->setPost('project', $projectID);
$this->setPost('acl', $this->request('acl', 'private'));
$this->setPost('whitelist', $this->request('whitelist', array()));
$this->setPost('products', $this->request('products', array()));
$this->setPost('plans', $this->request('plans', array()));
$control = $this->loadController('execution', 'create');
$this->requireFields('name,code,begin,end,days');
$control->create($projectID);
$data = $this->getData();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
$execution = $this->loadModel('execution')->getByID($data->id);
$this->send(200, $execution);
}
}
+2 -1
View File
@@ -30,7 +30,8 @@ class taskEntry extends Entry
$control->edit($taskID);
$this->getData();
$this->sendSuccess(200, 'success');
$task = $this->task->getByID($taskID);
$this->send(200, $task);
}
public function delete($taskID)
+1 -1
View File
@@ -23,7 +23,7 @@ class taskAssignToEntry extends Entry
$data = $this->getData();
if($data->result == 'fail') return $this->sendError(400, $data->message);
$task = $this->loadModel('task')->getByID($dataID);
$task = $this->loadModel('task')->getByID($taskID);
$this->send(200, $task);
}
+21 -3
View File
@@ -8,13 +8,31 @@
*/
class tasksEntry extends entry
{
public function get()
public function get($executionID)
{
$control = $this->loadController('execution', 'task');
$control->task($executionID);
$data = $this->getData();
if(isset($data->status) and $data->status == 'success')
{
$tasks = $data->data->tasks;
$result = array();
foreach($tasks as $task)
{
$result[] = $task;
}
return $this->send(200, $result);
}
if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
return $this->sendError(400, 'error');
}
public function post($executionID)
{
$fields = 'name,type,assignedTo,estimate,story,parent,execution,module';
$fields = 'name,type,assignedTo,estimate,story,parent,execution,module,pri,desc';
$this->batchSetPost($fields);
$control = $this->loadController('task', 'create');
@@ -27,6 +45,6 @@ class tasksEntry extends entry
$task = $this->loadModel('task')->getByID($data->id);
$this->send(200, $task);
$this->send(201, $task);
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ class taskStartEntry extends Entry
$data = $this->getData();
if($data->result == 'fail') return $this->sendError(400, $data->message);
$task = $this->loadModel('task')->getByID($dataID);
$task = $this->loadModel('task')->getByID($taskID);
$this->send(200, $task);
}
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* 禅道API的user资源类
* 版本V1
*
* The user entry point of zentaopms
* Version 1
*/
class userEntry extends Entry
{
public function get($userID = 0)
{
$control = $this->loadController('user', 'profile');
$control->profile($userID);
$data = $this->getData();
$user = $data->data->user;
unset($user->password);
$this->send(200, $user);
}
public function put($userID)
{
$oldUser = $this->loadModel('user')->getByID($userID, 'id');
/* Set $_POST variables. */
$fields = 'account,dept,realname,email,commiter,gender';
$this->batchSetPost($fields, $oldUser);
$this->setPost('password1', $this->request('password', ''));
$this->setPost('password2', $this->request('password', ''));
$this->setPost('verifyPassword', md5($this->app->user->password . $this->app->session->rand));
$control = $this->loadController('user', 'edit');
$control->edit($userID);
$this->getData();
$user = $this->user->getByID($userID, 'id');
unset($user->password);
$this->send(200, $user);
}
public function delete($userID)
{
$this->setPost('verifyPassword', md5($this->app->user->password . $this->app->session->rand));
$control = $this->loadController('user', 'delete');
$control->delete($userID);
$this->getData();
$this->sendSuccess(200, 'success');
}
}
+59
View File
@@ -0,0 +1,59 @@
<?php
/**
* 禅道API的users资源类
* 版本V1
*
* The users entry point of zentaopms
* Version 1
*/
class usersEntry extends entry
{
public function get()
{
$control = $this->loadController('company', 'browse');
$control->browse();
$data = $this->getData();
if(isset($data->status) and $data->status == 'success')
{
$users = $data->data->users;
$result = array();
foreach($users as $user)
{
$result[] = $user;
}
return $this->send(200, $result);
}
if(isset($data->status) and $data->status == 'fail')
{
return $this->sendError(400, $data->message);
}
return $this->sendError(400, 'error');
}
public function post()
{
$fields = 'account,dept,realname,email,commiter,gender';
$this->batchSetPost($fields);
$this->setPost('password1', $this->request('password'));
$this->setPost('password2', $this->request('password'));
$this->setPost('passwordStrength', 3);
$this->setPost('verifyPassword', md5($this->app->user->password . $this->app->session->rand));
$control = $this->loadController('user', 'create');
$this->requireFields('account,password1,realname');
$control->create();
$data = $this->getData();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
$user = $this->loadModel('user')->getByID($data->id, 'id');
unset($user->password);
$this->send(201, $user);
}
}
+17 -6
View File
@@ -6,12 +6,6 @@ $routes = array();
$routes['/tokens'] = 'tokens';
$routes['/programs'] = 'programs';
$routes['/programs/:id'] = 'program';
$routes['/projects'] = 'projects';
$routes['/projects/:id'] = 'project';
$routes['/products'] = 'products';
$routes['/products/:id'] = 'product';
$routes['/productlines'] = 'productLines';
@@ -21,10 +15,27 @@ $routes['/products/:id/stories'] = 'stories';
$routes['/stories/:id'] = 'story';
$routes['/stories/:id/change'] = 'storyChange';
$routes['/products/:id/bugs'] = 'bugs';
$routes['/bugs/:id'] = 'bug';
$routes['/projects'] = 'projects';
$routes['/projects/:id'] = 'project';
$routes['/projects/:project/executions'] = 'executions';
$routes['/executions'] = 'executions';
$routes['/executions/:id'] = 'execution';
$routes['/executions/:execution/tasks'] = 'tasks';
$routes['/tasks/:id'] = 'task';
$routes['/tasks/:id/assignto'] = 'taskAssignTo';
$routes['/tasks/:id/start'] = 'taskStart';
$routes['/tasks/:id/finish'] = 'taskFinish';
$routes['/users'] = 'users';
$routes['/users/:id'] = 'user';
$routes['/user'] = 'user';
$routes['/programs'] = 'programs';
$routes['/programs/:id'] = 'program';
$config->routes = $routes;
+17 -2
View File
@@ -54,8 +54,8 @@ class baseEntry
}
/**
* 获取请求数据(POST PUT)
* Get request data(POST or PUT).
* 获取请求数据(POST PUT)
* Get request data(POST or PUT)
*
* @param string $key
* @param mixed $defaultValue
@@ -68,6 +68,21 @@ class baseEntry
return $defaultValue;
}
/**
* 获取请求参数
* Get request params.
*
* @param string $key
* @param string $defaultValue
* @access public
* @return mixed
*/
public function param($key, $defaultValue = '')
{
if(isset($_GET[$key])) return $_GET[$key];
return $defaultValue;
}
/**
* 解析请求数据
* Parse body of request data.
+1
View File
@@ -832,6 +832,7 @@ class baseControl
* Parse the params, create the $module control object.
*/
$module = new $className($moduleName, $methodName, $appName);
$module->viewType = $this->viewType;
/**
* 调用对应方法,使用ob方法获取输出内容。
+2 -1
View File
@@ -783,7 +783,7 @@ class bug extends control
$files = array();
if($comment == false)
{
$changes = $this->bug->update($bugID);
$changes = $this->bug->update($bugID);
if(dao::isError())
{
if(defined('RUN_MODE') && RUN_MODE == 'api')
@@ -1579,6 +1579,7 @@ class bug extends control
$this->executeHooks($bugID);
if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess));
die(js::locate($this->session->bugList, 'parent'));
}
}
+2 -2
View File
@@ -656,8 +656,8 @@ class bugModel extends model
$this->dao->update(TABLE_BUG)->data($bug)
->autoCheck()
->batchCheck($this->config->bug->edit->requiredFields, 'notempty')
->checkIF($bug->resolvedBy, 'resolution', 'notempty')
->checkIF($bug->closedBy, 'resolution', 'notempty')
->checkIF($bug->resolvedBy, 'resolution', 'notempty')
->checkIF($bug->closedBy, 'resolution', 'notempty')
->checkIF($bug->resolution == 'duplicate', 'duplicateBug', 'notempty')
->checkIF($bug->resolution == 'fixed', 'resolvedBuild','notempty')
->where('id')->eq((int)$bugID)
+2
View File
@@ -2147,6 +2147,8 @@ class execution extends control
$this->session->set('execution', '');
$this->executeHooks($executionID);
if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess));
die(js::reload('parent'));
}
}
+7 -2
View File
@@ -564,14 +564,18 @@ class task extends control
$this->loadModel('action');
$changes = $this->task->assign($taskID);
if($this->viewType == 'json') return $this->send(array('result' => 'fail', 'message' => dao::getError()));
if(dao::isError()) die(js::error(dao::getError()));
if(dao::isError())
{
if($this->viewType == 'json') return $this->send(array('result' => 'fail', 'message' => dao::getError()));
die(js::error(dao::getError()));
}
$actionID = $this->action->create('task', $taskID, 'Assigned', $this->post->comment, $this->post->assignedTo);
$this->action->logHistory($actionID, $changes);
$this->executeHooks($taskID);
if($this->viewType == 'json') return $this->send(array('result' => 'success'));
if(isonlybody()) die(js::closeModal('parent.parent', 'this'));
die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent'));
}
@@ -787,6 +791,7 @@ class task extends control
}
}
if($this->viewType == 'json') return $this->send(array('result' => 'success'));
if(isonlybody()) die(js::closeModal('parent.parent', 'this'));
die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent'));
}
+1 -2
View File
@@ -1389,8 +1389,7 @@ class taskModel extends model
->where('id')->eq($taskID)->exec();
$task = $this->getById($taskID);
$this->loadModel('gitlab');
$relation = $this->gitlab->getRelationByObject('task', $taskID);
$relation = $this->loadModel('gitlab')->getRelationByObject('task', $taskID);
if(!empty($relation)) $this->gitlab->apiUpdateIssue($relation->gitlabID, $relation->projectID, $relation->issueID, 'task', $task, $taskID);
if(!dao::isError()) return common::createChanges($oldTask, $task);
+1 -1
View File
@@ -701,7 +701,7 @@ class user extends control
}
/* if ajax request, send result. */
if($this->server->ajax)
if($this->server->ajax or $this->viewType == 'json')
{
if(dao::isError())
{