From 2f28bb8c85a745cc70ed367d457e25114f7051b5 Mon Sep 17 00:00:00 2001 From: xiawenlong Date: Tue, 19 Oct 2021 17:49:39 +0800 Subject: [PATCH] fix all level 1 and 3 bugs. --- config/zentaopms.php | 1 + module/action/config.php | 1 + module/action/lang/zh-cn.php | 1 + module/action/view/trash.html.php | 5 + module/api/control.php | 52 ++++++--- module/api/js/common.js | 9 ++ module/api/lang/en.php | 9 +- module/api/lang/zh-cn.php | 8 +- module/api/model.php | 175 +++++++++++++++--------------- module/api/view/content.html.php | 3 +- module/api/view/create.html.php | 9 +- module/api/view/edit.html.php | 2 +- module/api/view/index.html.php | 2 +- module/api/view/struct.html.php | 2 +- module/group/lang/resource.php | 3 +- 15 files changed, 168 insertions(+), 114 deletions(-) diff --git a/config/zentaopms.php b/config/zentaopms.php index f034ff71e2..8508db61cd 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -251,6 +251,7 @@ $config->objectTables['testtask'] = TABLE_TESTTASK; $config->objectTables['testsuite'] = TABLE_TESTSUITE; $config->objectTables['testreport'] = TABLE_TESTREPORT; $config->objectTables['user'] = TABLE_USER; +$config->objectTables['api'] = TABLE_API; $config->objectTables['doc'] = TABLE_DOC; $config->objectTables['doclib'] = TABLE_DOCLIB; $config->objectTables['todo'] = TABLE_TODO; diff --git a/module/action/config.php b/module/action/config.php index 568e426ba1..58d0f4a69c 100755 --- a/module/action/config.php +++ b/module/action/config.php @@ -13,6 +13,7 @@ $config->action->objectNameFields['testcase'] = 'title'; $config->action->objectNameFields['case'] = 'title'; $config->action->objectNameFields['testtask'] = 'name'; $config->action->objectNameFields['user'] = 'account'; +$config->action->objectNameFields['api'] = 'title'; $config->action->objectNameFields['doc'] = 'title'; $config->action->objectNameFields['doclib'] = 'name'; $config->action->objectNameFields['todo'] = 'name'; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index 2f1e82893b..87bf8b3a2d 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -97,6 +97,7 @@ $lang->action->objectTypes['testsuite'] = '套件'; $lang->action->objectTypes['testtask'] = '测试单'; $lang->action->objectTypes['testreport'] = '报告'; $lang->action->objectTypes['doc'] = '文档'; +$lang->action->objectTypes['api'] = '接口'; $lang->action->objectTypes['doclib'] = '文档库'; $lang->action->objectTypes['todo'] = '待办'; $lang->action->objectTypes['risk'] = '风险'; diff --git a/module/action/view/trash.html.php b/module/action/view/trash.html.php index 4e8bdae124..e7825bb503 100755 --- a/module/action/view/trash.html.php +++ b/module/action/view/trash.html.php @@ -57,6 +57,11 @@ $methodName = 'view'; $module = 'caselib'; } + if ($action->objectType == 'api') + { + $params = "libID=0&moduelID=0&apiID={$action->objectID}"; + $methodName = 'index'; + } if(isset($config->action->customFlows[$action->objectType])) { $flow = $config->action->customFlows[$action->objectType]; diff --git a/module/api/control.php b/module/api/control.php index 5b2da11eea..2b2aabe4df 100755 --- a/module/api/control.php +++ b/module/api/control.php @@ -32,16 +32,6 @@ class api extends control */ public function index($libID = 0, $moduleID = 0, $apiID = 0, $version = 0, $release = 0) { - /* Get all api doc libraries. */ - $libs = $this->doc->getApiLibs(); - - /* Generate bread crumbs dropMenu. */ - if($libs) - { - if($libID == 0) $libID = key($libs); - $this->lang->modulePageNav = $this->generateLibsDropMenu($libs, $libID, $release); - } - $this->setMenu($libID); /* Get an api doc. */ if($apiID > 0) @@ -67,9 +57,20 @@ class api extends control $this->view->apiList = $apiList; } + /* Get all api doc libraries. */ + $libs = $this->doc->getApiLibs(); + + /* Generate bread crumbs dropMenu. */ + if($libs) + { + if($libID == 0) $libID = key($libs); + $this->lang->modulePageNav = $this->generateLibsDropMenu($libs, $libID, $release); + } + $this->setMenu($libID); + $this->view->isRelease = $release > 0; $this->view->release = $release; - $this->view->title = $this->lang->api->title; + $this->view->title = $this->lang->api->pageTitle; $this->view->libID = $libID; $this->view->apiID = $apiID; $this->view->libs = $libs; @@ -208,6 +209,7 @@ class api extends control $userId = $this->app->user->account; $data = fixer::input('post') ->add('lib', $libID) + ->skipSpecial('attribute') ->add('addedBy', $userId) ->add('addedDate', $now) ->add('editedBy', $userId) @@ -219,7 +221,7 @@ class api extends control $this->action->create('apistruct', $id, 'Created'); if(dao::isError()) return $this->sendError(dao::getError()); - return $this->sendSuccess(array('locate' => helper::createLink('api', 'editStruct', "libID=$libID&structID=$id"))); + return $this->sendSuccess(array('locate' => helper::createLink('api', 'struct', "libID=$libID"))); } $options = array(); @@ -229,6 +231,7 @@ class api extends control } $this->view->typeOptions = $options; $this->view->title = $this->lang->api->createStruct; + $this->view->gobackLink = $this->createLink('api', 'struct', "libID=$libID"); $this->display(); } @@ -251,6 +254,7 @@ class api extends control $now = helper::now(); $userId = $this->app->user->account; $data = fixer::input('post') + ->skipSpecial('attribute') ->add('lib', $struct->lib) ->add('editedBy', $userId) ->add('editedDate', $now) @@ -381,7 +385,7 @@ class api extends control { if($confirm == 'no') { - die(js::confirm($this->lang->doc->confirmDeleteLib, $this->createLink('api', 'deleteLib', "libID=$libID&confirm=yes"))); + die(js::confirm($this->lang->api->confirmDeleteLib, $this->createLink('api', 'deleteLib', "libID=$libID&confirm=yes"))); } else { @@ -413,6 +417,7 @@ class api extends control $userId = $this->app->user->account; $params = fixer::input('post') ->remove('type') + ->skipSpecial('params,response') ->add('addedBy', $userId) ->add('addedDate', $now) ->add('editedBy', $userId) @@ -447,6 +452,7 @@ class api extends control $options[] = array('label' => $item, 'value' => $key); } $this->view->typeOptions = $options; + $this->view->gobackLink = $this->createLink('api', 'index', "libID={$api->lib}&moduleID={$api->module}"); $this->view->user = $this->app->user->account; $this->view->allUsers = $this->loadModel('user')->getPairs('devfirst|noclosed');; $this->view->moduleOptionMenu = $this->loadModel('tree')->getOptionMenu($api->lib, 'api', $startModuleID = 0); @@ -472,6 +478,7 @@ class api extends control $now = helper::now(); $params = fixer::input('post') ->remove('type') + ->skipSpecial('params,response') ->add('addedBy', $this->app->user->account) ->add('addedDate', $now) ->add('editedBy', $this->app->user->account) @@ -499,6 +506,7 @@ class api extends control $example = json_encode($example, JSON_PRETTY_PRINT); $this->getTypeOptions($libID); + $this->view->gobackLink = $this->createLink('api', 'index', "libID=$libID&moduleID=$moduleID"); $this->view->user = $this->app->user->account; $this->view->allUsers = $this->loadModel('user')->getPairs('devfirst|noclosed'); $this->view->libID = $libID; @@ -593,6 +601,21 @@ class api extends control $this->sendSuccess(array('info' => $info)); } + /** + * Ajax get all child module. + * + * @access public + * @return void + */ + public function ajaxGetChild($libID, $type = 'module') + { + $this->loadModel('tree'); + $childModules = $this->tree->getOptionMenu($libID, 'api'); + $select = ($type == 'module') ? html::select('module', $childModules, '', "class='form-control chosen'") : html::select('parent', $childModules, '', "class='form-control chosen'"); + die($select); + } + + /** * Set doc menu by method name. * @@ -600,8 +623,7 @@ class api extends control * @access public * @return void */ - private - function setMenu($libID = 0) + private function setMenu($libID = 0) { common::setMenuVars('doc', $libID); diff --git a/module/api/js/common.js b/module/api/js/common.js index d44b37b284..6f915d1af2 100644 --- a/module/api/js/common.js +++ b/module/api/js/common.js @@ -1,3 +1,11 @@ +function loadDocModule(libID) +{ + var link = createLink('api', 'ajaxGetChild', 'libID=' + libID + '&type=parent'); + $.post(link, function(data) + { + $('#module').empty().append($(data).children()).trigger('chosen:updated'); + }); +} /** * Toggle acl. * @@ -378,6 +386,7 @@ try { data.push(field); }, del(data, index) { + if(data.length <= 1) return; data.splice(index, 1) }, changeType() { diff --git a/module/api/lang/en.php b/module/api/lang/en.php index 6156c5140a..e66c6d86b7 100644 --- a/module/api/lang/en.php +++ b/module/api/lang/en.php @@ -43,7 +43,8 @@ $lang->api->createStruct = 'Create Data Structure'; $lang->api->editStruct = 'Edit Data Structure'; $lang->api->deleteStruct = 'Delete Data Structure'; $lang->api->create = 'Ceate Doc'; -$lang->api->title = 'Api Library'; +$lang->api->title = 'Interface Name'; +$lang->api->pageTitle = 'Api Library'; $lang->api->module = 'Directory'; $lang->api->apiDoc = 'Interface'; $lang->api->manageType = 'Manage Directory'; @@ -195,6 +196,12 @@ $lang->api->requiredOptions = array(0 => 'No', 1 => 'Yes'); $lang->doclib = new stdclass(); $lang->doclib->name = 'Interface Library Name'; +$lang->apistruct = new stdClass(); +$lang->apistruct->name = 'Structure Name'; + +$lang->api_lib_release = new stdClass(); +$lang->api_lib_release->version = 'Version'; + $lang->api->error = new stdclass(); $lang->api->error->onlySelect = 'SQL interface only allow SELECT query.'; $lang->api->error->disabled = 'For security reasons, this feature is disabled. You can go to the config directory and modify the configuration item %s to open this function.'; diff --git a/module/api/lang/zh-cn.php b/module/api/lang/zh-cn.php index 3bea024dc5..0f589675e5 100755 --- a/module/api/lang/zh-cn.php +++ b/module/api/lang/zh-cn.php @@ -16,7 +16,7 @@ $lang->api->sql = 'SQL查询接口'; $lang->api->index = '接口库主页'; $lang->api->editLib = '编辑接口库'; -$lang->api->editPublish = '编辑版本'; +$lang->api->editPublish = '版本管理'; $lang->api->deleteLib = '删除接口库'; $lang->api->publish = '发布接口'; $lang->api->createLib = '创建接口库'; @@ -43,7 +43,8 @@ $lang->api->createStruct = '创建数据结构'; $lang->api->editStruct = '修改数据结构'; $lang->api->deleteStruct = '删除数据结构'; $lang->api->create = '创建接口'; -$lang->api->title = '接口库'; +$lang->api->title = '接口名称'; +$lang->api->pageTitle = '接口库'; $lang->api->module = '目录'; $lang->api->apiDoc = '接口'; $lang->api->manageType = '维护目录'; @@ -198,6 +199,9 @@ $lang->doclib->name = '接口库名称'; $lang->apistruct = new stdClass(); $lang->apistruct->name = '结构名'; +$lang->api_lib_release = new stdClass(); +$lang->api_lib_release->version = '版本'; + $lang->api->error = new stdclass(); $lang->api->error->onlySelect = 'SQL查询接口只允许SELECT查询'; $lang->api->error->disabled = '因为安全原因,该功能被禁用。可以到config目录,修改配置项 %s,打开此功能。'; diff --git a/module/api/model.php b/module/api/model.php index d769e8c3a4..e4b4fc8ce0 100644 --- a/module/api/model.php +++ b/module/api/model.php @@ -1,4 +1,5 @@ where('id')->eq($id) ->exec(); - if(dao::isError()) return false; + if (dao::isError()) return false; /* Create a struct version */ $version = array( @@ -176,7 +177,7 @@ class apiModel extends model /** * Delete a struct. * - * @param int $id + * @param int $id * @access public * @return void */ @@ -191,8 +192,8 @@ class apiModel extends model /** * Update an api doc. * - * @param int $id - * @param object $data + * @param int $id + * @param object $data * @access public * @return void */ @@ -218,7 +219,7 @@ class apiModel extends model /** * Get struct list by api doc id. * - * @param int $id + * @param int $id * @access public * @return array */ @@ -230,7 +231,7 @@ class apiModel extends model ->fetchAll(); array_map(function ($item) { - $item->attribute = json_decode(htmlspecialchars_decode($item->attribute), true); + $item->attribute = json_decode($item->attribute, true); return $item; }, $res); return $res; @@ -239,7 +240,7 @@ class apiModel extends model /** * Get a struct info. * - * @param int $id + * @param int $id * @access public * @return object */ @@ -250,7 +251,7 @@ class apiModel extends model ->where('id')->eq($id) ->fetch(); - if($model) $model->attribute = json_decode(htmlspecialchars_decode($model->attribute), true); + if ($model) $model->attribute = json_decode($model->attribute, true); return $model; } @@ -258,8 +259,8 @@ class apiModel extends model /** * Get release by version. * - * @param int $libID - * @param string $version + * @param int $libID + * @param string $version * @return object * @access public */ @@ -270,14 +271,14 @@ class apiModel extends model ->where('version')->eq($version) ->andWhere('lib')->eq($libID) ->fetch(); - if($model) $model->snap = json_decode(htmlspecialchars_decode($model->snap), true); + if ($model) $model->snap = json_decode($model->snap, true); return $model; } /** * Get release by id. * - * @param int $id + * @param int $id * @access public * @return array */ @@ -287,14 +288,14 @@ class apiModel extends model ->from(TABLE_API_LIB_RELEASE) ->where('id')->eq($id) ->fetch(); - if($model) $model->snap = json_decode(htmlspecialchars_decode($model->snap), true); + if ($model) $model->snap = json_decode($model->snap, true); return $model; } /** * Get Versions by api id * - * @param int $libID + * @param int $libID * @access public * @return array */ @@ -310,22 +311,23 @@ class apiModel extends model /** * Get api doc by id. * - * @param int $id - * @param int $version - * @param int $release + * @param int $id + * @param int $version + * @param int $release * @access public * @return object */ public function getLibById($id, $version = 0, $release = 0) { - if ($release) { + if ($release) + { $rel = $this->getReleaseById($release); foreach ($rel->snap['apis'] as $api) { if ($api['id'] == $id) $version = $api['version']; } } - if($version) + if ($version) { $fields = 'spec.*,api.id,api.product,api.lib,api.version,doc.name as libName,module.name as moduleName,api.editedBy,api.editedDate'; } @@ -344,10 +346,10 @@ class apiModel extends model ->beginIF($version)->andWhere('spec.version')->eq($version)->fi() ->fetch(); - if($model) + if ($model) { - $model->params = json_decode(htmlspecialchars_decode($model->params), true); - $model->response = json_decode(htmlspecialchars_decode($model->response), true); + $model->params = json_decode($model->params, true); + $model->response = json_decode($model->response, true); } return $model; } @@ -355,20 +357,20 @@ class apiModel extends model /** * Get api list by release. * - * @param object $release - * @param string $where + * @param object $release + * @param string $where * @return array */ public function getApiListByRelease($release, $where = '') { $strJoin = array(); - foreach($release->snap['apis'] as $api) + foreach ($release->snap['apis'] as $api) { $strJoin[] = "(spec.doc = {$api['id']} and spec.version = {$api['version']} )"; } - if($strJoin) $where .= 'and (' . implode(' or ', $strJoin) . ')'; - $list = $this->dao->select('api.lib,spec.*,api.id')->from(TABLE_API)->alias('api') + if ($strJoin) $where .= 'and (' . implode(' or ', $strJoin) . ')'; + $list = $this->dao->select('api.lib,spec.*,api.id')->from(TABLE_API)->alias('api') ->leftJoin(TABLE_API_SPEC)->alias('spec')->on('api.id = spec.doc') ->where($where) ->fetchAll(); @@ -378,27 +380,27 @@ class apiModel extends model /** * Get api doc list by module id * - * @param int $libID - * @param int $moduleID - * @param int $release + * @param int $libID + * @param int $moduleID + * @param int $release * @return array $list * @author thanatos thanatos915@163.com */ public function getListByModuleId($libID = 0, $moduleID = 0, $release = 0) { /* Get release info. */ - if($release > 0) + if ($release > 0) { $rel = $this->getReleaseById($release); $where = "1=1 and lib = $libID "; - if($moduleID > 0) + if ($moduleID > 0) { $sub = array(); - foreach($rel->snap['modules'] as $module) + foreach ($rel->snap['modules'] as $module) { $tmp = explode(',', $module['path']); - if(in_array($moduleID, $tmp)) + if (in_array($moduleID, $tmp)) { $sub[] = $module['id']; } @@ -410,7 +412,7 @@ class apiModel extends model else { - if($moduleID > 0) + if ($moduleID > 0) { $sub = $this->dao->select('id')->from(TABLE_MODULE)->where('FIND_IN_SET(' . $moduleID . ', path)')->processSQL(); $where = 'module in (' . $sub . ')'; @@ -426,7 +428,8 @@ class apiModel extends model ->fetchAll(); } array_map(function ($item) { - $item->params = json_decode(htmlspecialchars_decode($item->params), true); + $item->params = json_decode($item->params, true); + $item->response = json_decode($item->response, true); return $item; }, $list); return $list; @@ -435,7 +438,7 @@ class apiModel extends model /** * Get status text by status. * - * @param string $status + * @param string $status * @access public * @return string */ @@ -456,26 +459,27 @@ class apiModel extends model } /** - * @param int $libID - * @param string $pager - * @param string $orderBy + * @param int $libID + * @param string $pager + * @param string $orderBy * @access public * @return array */ public function getStructByQuery($libID, $pager = '', $orderBy = '') { - return $this->dao->select('*')->from(TABLE_APISTRUCT) - ->where('deleted')->eq(0) - ->andWhere('lib')->eq($libID) + return $this->dao->select('s.*,user.realname as addedName')->from(TABLE_APISTRUCT)->alias('s') + ->leftJoin(TABLE_USER)->alias('user')->on('user.account = s.addedBy') + ->where('s.deleted')->eq(0) + ->andWhere('s.lib')->eq($libID) ->orderBy($orderBy) ->page($pager) ->fetchAll(); } /** - * @param int $libID - * @param string $pager - * @param string $orderBy + * @param int $libID + * @param string $pager + * @param string $orderBy * @access public * @return array */ @@ -491,8 +495,8 @@ class apiModel extends model /** * Get struct tree by lib id * - * @param int $libID - * @param int $structID + * @param int $libID + * @param int $structID * @access public * @return string */ @@ -501,10 +505,10 @@ class apiModel extends model $list = $this->getStructListByLibID($libID); $html = "