From e3ec91da2a9268dded73e2a5b542bccc0c4d9134 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Tue, 22 Mar 2022 09:54:35 +0800 Subject: [PATCH] + Add modules api. --- api/v1/entries/modules.php | 43 ++++++++++++++++++++++++++++++++++++++ config/routes.php | 2 ++ module/tree/control.php | 7 ++++++- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 api/v1/entries/modules.php diff --git a/api/v1/entries/modules.php b/api/v1/entries/modules.php new file mode 100644 index 0000000000..f38e90383a --- /dev/null +++ b/api/v1/entries/modules.php @@ -0,0 +1,43 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class modulesEntry extends Entry +{ + /** + * Get method. + * + * @access public + * @return void + */ + public function get() + { + $objectType = $this->param('type', ''); + $objectID = $this->param('id', ''); + + if(!$objectType or !$objectID) return $this->sendError(400, 'Need id and type.'); + if(!in_array($objectType, array('story', 'task', 'bug', 'case'))) return $this->sendError(400, 'Type is not allowed'); + + if($objectType == 'task') + { + $control = $this->loadController('tree', 'browsetask'); + $control->browseTask($objectID); + } + else + { + $control = $this->loadController('tree', 'browse'); + $control->browse($objectID, $objectType); + } + $data = $this->getData(); + if(isset($data->status) and $data->status == 'success') return $this->send(200, array('modules' => $data->data->tree)); + + return $this->send400(isset($data->message) ? $data->message: 'error'); + } +} diff --git a/config/routes.php b/config/routes.php index 324765ae4d..a484abdcda 100644 --- a/config/routes.php +++ b/config/routes.php @@ -140,6 +140,8 @@ $routes['/docs/:id'] = 'doc'; $routes['/repos'] = 'repos'; $routes['/repos/rules'] = 'reporules'; +$routes['/modules'] = 'modules'; + $routes['/reports'] = 'reports'; $routes['/z/folders'] = 'zfolders'; diff --git a/module/tree/control.php b/module/tree/control.php index 878886378a..330004dece 100644 --- a/module/tree/control.php +++ b/module/tree/control.php @@ -50,7 +50,12 @@ class tree extends control if(strpos('story|bug|case', $viewType) !== false) { $product = $this->loadModel('product')->getById($rootID); - if(empty($product)) $this->locate($this->createLink('product', 'create')); + if(empty($product)) + { + if($this->viewType == 'json' or (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'fail', 'message' => 'No product.')); + $this->locate($this->createLink('product', 'create')); + } + if(!empty($product->type) && $product->type != 'normal') { $branches = $this->loadModel('branch')->getPairs($product->id);