diff --git a/api/v1/entries/bug.php b/api/v1/entries/bug.php new file mode 100644 index 0000000000..13d872ddf4 --- /dev/null +++ b/api/v1/entries/bug.php @@ -0,0 +1,49 @@ +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'); + } +} diff --git a/api/v1/entries/bugs.php b/api/v1/entries/bugs.php new file mode 100644 index 0000000000..a227cbf2a1 --- /dev/null +++ b/api/v1/entries/bugs.php @@ -0,0 +1,55 @@ +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); + } +} diff --git a/api/v1/entries/execution.php b/api/v1/entries/execution.php new file mode 100644 index 0000000000..a382de3ad1 --- /dev/null +++ b/api/v1/entries/execution.php @@ -0,0 +1,50 @@ +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'); + } +} diff --git a/api/v1/entries/executions.php b/api/v1/entries/executions.php new file mode 100644 index 0000000000..45c7730f7c --- /dev/null +++ b/api/v1/entries/executions.php @@ -0,0 +1,47 @@ +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); + } +} diff --git a/api/v1/entries/task.php b/api/v1/entries/task.php index 00496ea8ef..1ee0f8daf9 100644 --- a/api/v1/entries/task.php +++ b/api/v1/entries/task.php @@ -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) diff --git a/api/v1/entries/taskassignto.php b/api/v1/entries/taskassignto.php index 77feefa35c..42452a2fd6 100644 --- a/api/v1/entries/taskassignto.php +++ b/api/v1/entries/taskassignto.php @@ -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); } diff --git a/api/v1/entries/tasks.php b/api/v1/entries/tasks.php index de9a5a33c4..64f2678ead 100644 --- a/api/v1/entries/tasks.php +++ b/api/v1/entries/tasks.php @@ -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); } } diff --git a/api/v1/entries/taskstart.php b/api/v1/entries/taskstart.php index d81e69874e..3990c3f9a0 100644 --- a/api/v1/entries/taskstart.php +++ b/api/v1/entries/taskstart.php @@ -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); } diff --git a/api/v1/entries/user.php b/api/v1/entries/user.php new file mode 100644 index 0000000000..84a0081960 --- /dev/null +++ b/api/v1/entries/user.php @@ -0,0 +1,55 @@ +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'); + } +} diff --git a/api/v1/entries/users.php b/api/v1/entries/users.php new file mode 100644 index 0000000000..e5ab96cfbc --- /dev/null +++ b/api/v1/entries/users.php @@ -0,0 +1,59 @@ +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); + } +} diff --git a/config/routes.php b/config/routes.php index f3fcee5dc2..5440427857 100644 --- a/config/routes.php +++ b/config/routes.php @@ -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; diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index 03aac91b8f..07e5c37881 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -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. diff --git a/framework/base/control.class.php b/framework/base/control.class.php index f0d4a82df5..b8f74d3b5e 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -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方法获取输出内容。 diff --git a/module/bug/control.php b/module/bug/control.php index 41e4ea680b..21078719ee 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -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')); } } diff --git a/module/bug/model.php b/module/bug/model.php index 04176bfd6b..d1af2087d0 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -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) diff --git a/module/execution/control.php b/module/execution/control.php index 6d37712eb2..5b5eca29ff 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -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')); } } diff --git a/module/task/control.php b/module/task/control.php index 8b02e7295f..729b727f3a 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -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')); } diff --git a/module/task/model.php b/module/task/model.php index 08927d7543..be768f75df 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -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); diff --git a/module/user/control.php b/module/user/control.php index bc229a44c0..b92ca18702 100644 --- a/module/user/control.php +++ b/module/user/control.php @@ -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()) {