From c047d2b4228fa17f67eaf5cd6cd9d3c820949a03 Mon Sep 17 00:00:00 2001 From: zhengrunyu Date: Tue, 29 Mar 2022 09:41:17 +0800 Subject: [PATCH] * Add api for close bug and confirm bug. --- api/v1/entries/bugclose.php | 40 ++++++++++++++++++++++++++++++++ api/v1/entries/bugconfirm.php | 40 ++++++++++++++++++++++++++++++++ api/v1/entries/story.php | 2 +- api/v1/entries/storyassignto.php | 2 +- config/routes.php | 3 +++ module/bug/control.php | 11 +++++++-- 6 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 api/v1/entries/bugclose.php create mode 100644 api/v1/entries/bugconfirm.php diff --git a/api/v1/entries/bugclose.php b/api/v1/entries/bugclose.php new file mode 100644 index 0000000000..17644f0afa --- /dev/null +++ b/api/v1/entries/bugclose.php @@ -0,0 +1,40 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + **/ +class bugCloseEntry extends Entry +{ + /** + * POST method. + * + * @param int $bugID + * @access public + * @return void + */ + public function post($bugID) + { + $story = $this->loadModel('bug')->getByID($bugID); + + $fields = 'comment'; + $this->batchSetPost($fields); + + $control = $this->loadController('bug', 'close'); + $control->close($bugID); + + $data = $this->getData(); + if(!$data) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $bug = $this->bug->getByID($bugID); + + $this->send(200, $this->format($bug, 'openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,reviewedBy:user,reviewedDate:time,lastEditedBy:user,lastEditedDate:time,closedBy:user,closedDate:time,deleted:bool,mailto:userList')); + } +} + diff --git a/api/v1/entries/bugconfirm.php b/api/v1/entries/bugconfirm.php new file mode 100644 index 0000000000..0324eed50f --- /dev/null +++ b/api/v1/entries/bugconfirm.php @@ -0,0 +1,40 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class bugConfirmEntry extends Entry +{ + /** + * POST method. + * + * @param int $bugID + * @access public + * @return void + **/ + public function post($bugID) + { + $bug = $this->loadModel('bug')->getById($bugID); + + $fields = 'assignedTo,mailto,comment,pri,type'; + $this->batchSetPost($fields); + + $control = $this->loadController('bug', 'confirmBug'); + $control->confirmBug($bugID); + + $data = $this->getData(); + if(!$data) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $bug = $this->bug->getById($bugID); + + $this->send(200, $this->format($story, 'openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,reviewedBy:user,reviewedDate:time,lastEditedBy:user,lastEditedDate:time,closedBy:user,closedDate:time,deleted:bool,mailto:userList')); + } +} + diff --git a/api/v1/entries/story.php b/api/v1/entries/story.php index 33d471c20c..b80ecc571c 100644 --- a/api/v1/entries/story.php +++ b/api/v1/entries/story.php @@ -61,7 +61,7 @@ class storyEntry extends Entry foreach($executionTasks as $task) { if(!isset($data->data->executions->{$task->execution})) continue; - $storyTasks[] = $this->filterFields($task, 'id,name,type,status'); + $storyTasks[] = $this->filterFields($task, 'id,name,type,status,assignedTo'); } } $story->tasks = $storyTasks; diff --git a/api/v1/entries/storyassignto.php b/api/v1/entries/storyassignto.php index 0b3477a1ee..66e6f089f8 100644 --- a/api/v1/entries/storyassignto.php +++ b/api/v1/entries/storyassignto.php @@ -20,7 +20,7 @@ class storyAssignToEntry extends Entry */ public function post($storyID) { - $task = $this->loadModel('story')->getByID($storyID); + $story = $this->loadModel('story')->getByID($storyID); $fields = 'assignedTo'; $this->batchSetPost($fields); diff --git a/config/routes.php b/config/routes.php index 0b12c61896..c7af65ffab 100644 --- a/config/routes.php +++ b/config/routes.php @@ -60,6 +60,9 @@ $routes['/projects/:id/bugs'] = 'projectBugs'; $routes['/executions/:id/bugs'] = 'executionBugs'; $routes['/bugs'] = 'bugs'; $routes['/bugs/:id'] = 'bug'; +$routes['/bugs/:id/close'] = 'bugClose'; +$routes['/bugs/:id/assign'] = 'bugAssign'; +$routes['/bugs/:id/confirm'] = 'bugConfirm'; $routes['/programs/:id/projects'] = 'projects'; $routes['/products/:id/projects'] = 'productProjects'; diff --git a/module/bug/control.php b/module/bug/control.php index 101995c396..4da3a367ff 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -1259,7 +1259,14 @@ class bug extends control return print(js::closeModal('parent.parent')); } } - return print(js::locate($this->createLink('bug', 'view', "bugID=$bugID"), 'parent')); + if(defined('RUN_MODE') && RUN_MODE == 'api') + { + return $this->send(array('status' => 'success', 'data' => $bugID)); + } + else + { + return print(js::locate($this->createLink('bug', 'view', "bugID=$bugID"), 'parent')); + } } if($this->app->tab == 'project') @@ -1710,7 +1717,7 @@ class bug extends control } if(defined('RUN_MODE') && RUN_MODE == 'api') { - return print(array('status' => 'success', 'data' => $bugID)); + return $this->send(array('status' => 'success', 'data' => $bugID)); } else {