* Add check api library name unique.

This commit is contained in:
liumengyi
2023-03-29 16:48:12 +08:00
parent 028b893345
commit 800cc712ae
6 changed files with 88 additions and 14 deletions
+5 -2
View File
@@ -431,8 +431,11 @@ class api extends control
return $this->sendSuccess(array('message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => "redirectParentWindow($id)"));
}
$type = !empty($lib->product) ? 'product' : 'project';
$this->lang->api->aclList['default'] = sprintf($this->lang->doclib->aclList['default'], $this->lang->{$type}->common);
$type = 'nolink';
if(!empty($lib->product)) $type = 'product';
if(!empty($lib->project)) $type = 'project';
if($type != 'nolink') $this->lang->api->aclList['default'] = sprintf($this->lang->doclib->aclList['default'], $this->lang->{$type}->common);
if($type == 'nolink') unset($this->lang->api->aclList['default']);
$this->view->lib = $lib;
$this->view->type = $type;
+5
View File
@@ -55,6 +55,11 @@ $lang->doclib->tabList['custom'] = 'Custom';
$lang->doclib->nameList['custom'] = 'Custom Name';
$lang->doclib->apiNameUnique = array();
$lang->doclib->apiNameUnique['product'] = 'In the api library of the same ' . $lang->productCommon . ', ';
$lang->doclib->apiNameUnique['project'] = 'In the api library of the same ' . $lang->projectCommon . ', ';
$lang->doclib->apiNameUnique['nolink'] = 'In the no linked api library, ';
/* Fields. */
$lang->doc->common = 'Dok';
$lang->doc->id = 'ID';
+5
View File
@@ -55,6 +55,11 @@ $lang->doclib->tabList['custom'] = 'Custom';
$lang->doclib->nameList['custom'] = 'Custom Name';
$lang->doclib->apiNameUnique = array();
$lang->doclib->apiNameUnique['product'] = 'In the api library of the same ' . $lang->productCommon . ', ';
$lang->doclib->apiNameUnique['project'] = 'In the api library of the same ' . $lang->projectCommon . ', ';
$lang->doclib->apiNameUnique['nolink'] = 'In the no linked api library, ';
/* Fields. */
$lang->doc->common = 'Document';
$lang->doc->id = 'ID';
+5
View File
@@ -55,6 +55,11 @@ $lang->doclib->tabList['custom'] = 'Personnelle';
$lang->doclib->nameList['custom'] = 'Nom personnalisé';
$lang->doclib->apiNameUnique = array();
$lang->doclib->apiNameUnique['product'] = 'In the api library of the same ' . $lang->productCommon . ', ';
$lang->doclib->apiNameUnique['project'] = 'In the api library of the same ' . $lang->projectCommon . ', ';
$lang->doclib->apiNameUnique['nolink'] = 'In the no linked api library, ';
/* Fields. */
$lang->doc->common = 'Gestion Documentaire';
$lang->doc->id = 'ID';
+5
View File
@@ -55,6 +55,11 @@ $lang->doclib->tabList['custom'] = '自定义';
$lang->doclib->nameList['custom'] = '自定义文档库名称';
$lang->doclib->apiNameUnique = array();
$lang->doclib->apiNameUnique['product'] = '同一' . $lang->productCommon . '下的接口库中';
$lang->doclib->apiNameUnique['project'] = '同一' . $lang->projectCommon . '下的接口库中';
$lang->doclib->apiNameUnique['nolink'] = '无关联接口库中';
/* 字段列表。*/
$lang->doc->common = '文档';
$lang->doc->id = 'ID';
+63 -12
View File
@@ -210,7 +210,11 @@ class docModel extends model
$execution = $this->loadModel('execution')->getByID($lib->execution);
$lib->project = $execution->project;
}
if($this->post->libType == 'api') $lib->type = 'api';
if($this->post->libType == 'api')
{
$lib->type = 'api';
$this->checkApiLibName($lib, $this->post->type);
}
$lib->name = trim($lib->name); //Temporary treatment: Code for bug #15528.
$this->dao->insert(TABLE_DOCLIB)->data($lib)->autoCheck()
@@ -228,13 +232,15 @@ class docModel extends model
*/
public function createApiLib()
{
$libType = $this->post->libType;
$data = fixer::input('post')
->trim('name')
->join('groups', ',')
->join('users', ',')
->setForce('product', $this->post->libType == 'product' ? $this->post->product : 0)
->setForce('project', $this->post->libType == 'project' ? $this->post->project : 0)
->setForce('execution', $this->post->libType == 'project' ? $this->post->execution : 0)
->setForce('product', $libType == 'product' ? $this->post->product : 0)
->setForce('project', $libType == 'project' ? $this->post->project : 0)
->setForce('execution', $libType == 'project' ? $this->post->execution : 0)
->add('addedBy', $this->app->user->account)
->add('addedDate', helper::now())
->remove('uid,contactListMenu,libType')
@@ -248,13 +254,16 @@ class docModel extends model
$this->lang->doclib->project = $this->lang->api->project;
$this->lang->doclib->product = $this->lang->api->product;
if($this->post->libType == 'product') $this->config->api->createlib->requiredFields .= ',product';
if($this->post->libType == 'project') $this->config->api->createlib->requiredFields .= ',project';
if($libType == 'product') $this->config->api->createlib->requiredFields .= ',product';
if($libType == 'project') $this->config->api->createlib->requiredFields .= ',project';
$this->checkApiLibName($data, $libType);
if(dao::isError()) return false;
$data->type = static::DOC_TYPE_API;
$this->dao->insert(TABLE_DOCLIB)->data($data)->autoCheck()
->batchCheck($this->config->api->createlib->requiredFields, 'notempty')
->check('name', 'unique', "`type` = '" . static::DOC_TYPE_API . "'")
->exec();
return $this->dao->lastInsertID();
@@ -269,14 +278,15 @@ class docModel extends model
*/
public function updateApiLib($id)
{
$oldLib = $this->getLibById($id);
$oldLib = $this->getLibById($id);
$libType = $this->post->libType;
$data = fixer::input('post')
->trim('name')
->join('groups', ',')
->join('users', ',')
->setForce('product', $this->post->libType == 'product' ? $this->post->product : 0)
->setForce('project', $this->post->libType == 'project' ? $this->post->project : 0)
->setForce('product', $libType == 'product' ? $this->post->product : 0)
->setForce('project', $libType == 'project' ? $this->post->project : 0)
->remove('uid,contactListMenu,libType')
->get();
@@ -288,8 +298,13 @@ class docModel extends model
$this->lang->doclib->project = $this->lang->api->project;
$this->lang->doclib->product = $this->lang->api->product;
if($this->post->libType == 'product') $this->config->api->createlib->requiredFields .= ',product';
if($this->post->libType == 'project') $this->config->api->createlib->requiredFields .= ',project';
if($libType == 'product') $this->config->api->createlib->requiredFields .= ',product';
if($libType == 'project') $this->config->api->createlib->requiredFields .= ',project';
$data->id = $id;
$this->checkApiLibName($data, $libType);
if(dao::isError()) return false;
$data->type = static::DOC_TYPE_API;
$this->dao->update(TABLE_DOCLIB)->data($data)->autoCheck()
@@ -336,6 +351,17 @@ class docModel extends model
}
if($oldLib->acl != $lib->acl and $lib->acl == 'open') $lib->users = '';
if($oldLib->type == 'api')
{
$type = 'nolink';
if(!empty($oldLib->product)) $type = 'product';
if(!empty($oldLib->project)) $type = 'project';
$lib->id = $libID;
$lib->product = $oldLib->product;
$lib->project = $oldLib->project;
$this->checkApiLibName($lib, $type);
}
$lib->name = trim($lib->name); //Temporary treatment: Code for bug #15528.
$this->dao->update(TABLE_DOCLIB)->data($lib)->autoCheck()
->batchCheck($this->config->doc->editlib->requiredFields, 'notempty')
@@ -2984,4 +3010,29 @@ class docModel extends model
}
return $modules;
}
/**
* Check api library name.
*
* @param object $lib
* @param string $libType
* @access public
* @return void
*/
public function checkApiLibName($lib, $libType)
{
$sameNames = $this->dao->select('*')
->from(TABLE_DOCLIB)
->where('`product`')->eq($lib->product)
->andWhere('`project`')->eq($lib->project)
->andWhere('`name`')->eq($lib->name)
->andWhere('`type`')->eq('api')
->beginIF(isset($lib->id))
->andWhere('`id`')->ne($lib->id)
->fi()
->fetchAll();
if(count($sameNames) > 0 and $libType == 'product') dao::$errors['name'] = $this->lang->doclib->apiNameUnique[$libType] . sprintf($this->lang->error->unique, $this->lang->doclib->name, $lib->name);
if(count($sameNames) > 0 and $libType == 'project') dao::$errors['name'] = $this->lang->doclib->apiNameUnique[$libType] . sprintf($this->lang->error->unique, $this->lang->doclib->name, $lib->name);
if(count($sameNames) > 0 and $libType == 'nolink') dao::$errors['name'] = $this->lang->doclib->apiNameUnique[$libType] . sprintf($this->lang->error->unique, $this->lang->doclib->name, $lib->name);
}
}