From 66dc0e1cb6fe5943afa5c17a8c78cda2053c92f1 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Wed, 11 Dec 2019 14:51:26 +0800 Subject: [PATCH 001/164] jenkins GRUD --- config/zentaopms.php | 14 +- module/ci/config.php | 12 ++ module/ci/control.php | 234 +++++++++++++++++++++++ module/ci/css/index.css | 1 + module/ci/js/browsecredential.js | 4 + module/ci/js/browsejenkins.js | 4 + module/ci/js/createcredential.js | 27 +++ module/ci/js/createjenkins.js | 23 +++ module/ci/js/editcredential.js | 27 +++ module/ci/js/editjenkins.js | 23 +++ module/ci/js/menu.js | 4 + module/ci/lang/en.php | 1 + module/ci/lang/zh-cn.php | 48 +++++ module/ci/model.php | 166 ++++++++++++++++ module/ci/view/browsecredential.html.php | 57 ++++++ module/ci/view/browsejenkins.html.php | 57 ++++++ module/ci/view/createcredential.html.php | 79 ++++++++ module/ci/view/createjenkins.html.php | 74 +++++++ module/ci/view/editcredential.html.php | 79 ++++++++ module/ci/view/editjenkins.html.php | 74 +++++++ module/ci/view/header.html.php | 28 +++ module/ci/view/index.html.php | 15 ++ module/ci/view/menu.html.php | 11 ++ module/common/lang/menuOrder.php | 2 + module/common/lang/zh-cn.php | 11 +- module/custom/view/set.html.php | 4 +- 26 files changed, 1070 insertions(+), 9 deletions(-) create mode 100644 module/ci/config.php create mode 100644 module/ci/control.php create mode 100644 module/ci/css/index.css create mode 100644 module/ci/js/browsecredential.js create mode 100644 module/ci/js/browsejenkins.js create mode 100644 module/ci/js/createcredential.js create mode 100644 module/ci/js/createjenkins.js create mode 100644 module/ci/js/editcredential.js create mode 100644 module/ci/js/editjenkins.js create mode 100644 module/ci/js/menu.js create mode 100644 module/ci/lang/en.php create mode 100644 module/ci/lang/zh-cn.php create mode 100644 module/ci/model.php create mode 100644 module/ci/view/browsecredential.html.php create mode 100644 module/ci/view/browsejenkins.html.php create mode 100644 module/ci/view/createcredential.html.php create mode 100644 module/ci/view/createjenkins.html.php create mode 100644 module/ci/view/editcredential.html.php create mode 100644 module/ci/view/editjenkins.html.php create mode 100644 module/ci/view/header.html.php create mode 100644 module/ci/view/index.html.php create mode 100644 module/ci/view/menu.html.php diff --git a/config/zentaopms.php b/config/zentaopms.php index 61d3d5e986..0efdf433a4 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -163,12 +163,14 @@ define('TABLE_TESTSUITE', '`' . $config->db->prefix . 'testsuite`'); define('TABLE_SUITECASE', '`' . $config->db->prefix . 'suitecase`'); define('TABLE_TESTREPORT', '`' . $config->db->prefix . 'testreport`'); -define('TABLE_ENTRY', '`' . $config->db->prefix . 'entry`'); -define('TABLE_WEBHOOK', '`' . $config->db->prefix . 'webhook`'); -define('TABLE_LOG', '`' . $config->db->prefix . 'log`'); -define('TABLE_SCORE', '`' . $config->db->prefix . 'score`'); -define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`'); -define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`'); +define('TABLE_ENTRY', '`' . $config->db->prefix . 'entry`'); +define('TABLE_WEBHOOK', '`' . $config->db->prefix . 'webhook`'); +define('TABLE_LOG', '`' . $config->db->prefix . 'log`'); +define('TABLE_SCORE', '`' . $config->db->prefix . 'score`'); +define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`'); +define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`'); +define('TABLE_CREDENTIAL', '`' . $config->db->prefix . 'credential`'); +define('TABLE_JENKINS', '`' . $config->db->prefix . 'jenkins`'); define('TABLE_REPO', '`' . $config->db->prefix . 'repo`'); define('TABLE_REPOHISTORY', '`' . $config->db->prefix . 'repohistory`'); diff --git a/module/ci/config.php b/module/ci/config.php new file mode 100644 index 0000000000..f003bd71b8 --- /dev/null +++ b/module/ci/config.php @@ -0,0 +1,12 @@ +credential->create = new stdclass(); +$config->credential->create->requiredFields = 'name'; + +$config->credential->edit = new stdclass(); +$config->credential->edit->requiredFields = 'name'; + +$config->jenkins->create = new stdclass(); +$config->jenkins->create->requiredFields = 'name'; + +$config->jenkins->edit = new stdclass(); +$config->jenkins->edit->requiredFields = 'name'; \ No newline at end of file diff --git a/module/ci/control.php b/module/ci/control.php new file mode 100644 index 0000000000..6e47655129 --- /dev/null +++ b/module/ci/control.php @@ -0,0 +1,234 @@ + + * @package product + * @version $Id: control.php 5144 2019-12-11 06:37:03Z chenqi@cnezsoft.com $ + * @link http://www.zentao.net + */ +class ci extends control +{ + /** + * Construct function. + * + * @access public + * @return void + */ + public function __construct($moduleName = '', $methodName = '') + { + parent::__construct($moduleName, $methodName); + + /* Load need modules. */ + $this->loadModel('credential'); + $this->loadModel('user'); + } + + /** + * CI index page. + * + * @access public + * @return void + */ + public function index() + { + $this->display(); + } + + /** + * Browse credentials. + * + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * @access public + * @return void + */ + public function browseCredential($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + { + $this->app->loadClass('pager', $static = true); + $pager = new pager($recTotal, $recPerPage, $pageID); + + $this->view->title = $this->lang->credential->common . $this->lang->colon . $this->lang->credential->list; + $this->view->credentialList = $this->ci->listCredential($orderBy, $pager); + + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = $this->lang->credential->common; + + $this->view->orderBy = $orderBy; + $this->view->pager = $pager; + $this->view->module = 'credential'; + $this->display(); + } + + /** + * Create a credential. + * + * @access public + * @return void + */ + public function createCredential() + { + if($_POST) + { + $this->ci->createCredential(); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseCredential'))); + } + + $this->app->loadLang('action'); + $this->view->title = $this->lang->credential->create . $this->lang->colon . $this->lang->credential->common; + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = html::a(inlink('browseCredential'), $this->lang->credential->common); + $this->view->position[] = $this->lang->credential->create; + + $this->view->module = 'credential'; + $this->display(); + } + + /** + * Edit a credential. + * + * @param int $id + * @access public + * @return void + */ + public function editCredential($id) + { + $credential = $this->ci->getCredentialByID($id); + if($_POST) + { + $this->ci->updateCredential($id); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseCredential'))); + } + + $this->app->loadLang('action'); + $this->view->title = $this->lang->credential->edit . $this->lang->colon . $credential->name; + + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = html::a(inlink('browseCredential'), $this->lang->credential->common); + $this->view->position[] = $this->lang->credential->edit; + + $this->view->credential = $credential; + + $this->view->module = 'credential'; + $this->display(); + } + + /** + * Delete a credential. + * + * @param int $id + * @access public + * @return void + */ + public function deleteCredential($id) + { + $this->ci->delete(TABLE_CREDENTIAL, $id); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $this->send(array('result' => 'success')); + } + + + /** + * Browse jenkinss. + * + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * @access public + * @return void + */ + public function browseJenkins($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + { + $this->app->loadClass('pager', $static = true); + $pager = new pager($recTotal, $recPerPage, $pageID); + + $this->view->title = $this->lang->jenkins->common . $this->lang->colon . $this->lang->jenkins->list; + $this->view->jenkinsList = $this->ci->listJenkins($orderBy, $pager); + + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = $this->lang->jenkins->common; + + $this->view->orderBy = $orderBy; + $this->view->pager = $pager; + $this->view->module = 'jenkins'; + $this->display(); + } + + /** + * Create a jenkins. + * + * @access public + * @return void + */ + public function createJenkins() + { + if($_POST) + { + $this->ci->createJenkins(); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseJenkins'))); + } + + $this->app->loadLang('action'); + $this->view->title = $this->lang->jenkins->create . $this->lang->colon . $this->lang->jenkins->common; + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = html::a(inlink('browseJenkins'), $this->lang->jenkins->common); + $this->view->position[] = $this->lang->jenkins->create; + + $this->view->module = 'jenkins'; + $this->display(); + } + + /** + * Edit a jenkins. + * + * @param int $id + * @access public + * @return void + */ + public function editJenkins($id) + { + $jenkins = $this->ci->getJenkinsByID($id); + if($_POST) + { + $this->ci->updateJenkins($id); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseJenkins'))); + } + + $this->app->loadLang('action'); + $this->view->title = $this->lang->jenkins->edit . $this->lang->colon . $jenkins->name; + + $this->view->position[] = $this->lang->ci->common; + $this->view->position[] = html::a(inlink('browseJenkins'), $this->lang->jenkins->common); + $this->view->position[] = $this->lang->jenkins->edit; + + $this->view->jenkins = $jenkins; + + $this->view->module = 'jenkins'; + $this->display(); + } + + /** + * Delete a jenkins. + * + * @param int $id + * @access public + * @return void + */ + public function deleteJenkins($id) + { + $this->ci->delete(TABLE_JENKINS, $id); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $this->send(array('result' => 'success')); + } +} diff --git a/module/ci/css/index.css b/module/ci/css/index.css new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/module/ci/css/index.css @@ -0,0 +1 @@ + diff --git a/module/ci/js/browsecredential.js b/module/ci/js/browsecredential.js new file mode 100644 index 0000000000..6126dd22b2 --- /dev/null +++ b/module/ci/js/browsecredential.js @@ -0,0 +1,4 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); +}) \ No newline at end of file diff --git a/module/ci/js/browsejenkins.js b/module/ci/js/browsejenkins.js new file mode 100644 index 0000000000..6126dd22b2 --- /dev/null +++ b/module/ci/js/browsejenkins.js @@ -0,0 +1,4 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); +}) \ No newline at end of file diff --git a/module/ci/js/createcredential.js b/module/ci/js/createcredential.js new file mode 100644 index 0000000000..499e5986ce --- /dev/null +++ b/module/ci/js/createcredential.js @@ -0,0 +1,27 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); + + showByType(type); + $('#type').on('change', function() + { + showByType($(this).val()); + }); +}); + +function showByType(type) { + if(type == 'account') + { + $('#password-field').show(); + + $('#privateKey-field').hide(); + $('#passphrase-field').hide(); + } + else + { + $('#privateKey-field').show(); + $('#passphrase-field').show(); + + $('#password-field').hide(); + } +} \ No newline at end of file diff --git a/module/ci/js/createjenkins.js b/module/ci/js/createjenkins.js new file mode 100644 index 0000000000..675534f51e --- /dev/null +++ b/module/ci/js/createjenkins.js @@ -0,0 +1,23 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); + + showByType(type); + $('#type').on('change', function() + { + showByType($(this).val()); + }); +}); + +function showByType(type) { + if(type == 'account') + { + $('#password-field').show(); + $('#token-field').hide(); + } + else + { + $('#token-field').show(); + $('#password-field').hide(); + } +} \ No newline at end of file diff --git a/module/ci/js/editcredential.js b/module/ci/js/editcredential.js new file mode 100644 index 0000000000..9a8b9cd05c --- /dev/null +++ b/module/ci/js/editcredential.js @@ -0,0 +1,27 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); + + showByType(type); + $('#type').on('change', function() + { + showByType($(this).val()); + }); +}) + +function showByType(type) { + if(type == 'account') + { + $('#password-field').show(); + + $('#privateKey-field').hide(); + $('#passphrase-field').hide(); + } + else + { + $('#privateKey-field').show(); + $('#passphrase-field').show(); + + $('#password-field').hide(); + } +} \ No newline at end of file diff --git a/module/ci/js/editjenkins.js b/module/ci/js/editjenkins.js new file mode 100644 index 0000000000..675534f51e --- /dev/null +++ b/module/ci/js/editjenkins.js @@ -0,0 +1,23 @@ +$(function() +{ + $('#' + module + 'Tab').addClass('btn-active-text'); + + showByType(type); + $('#type').on('change', function() + { + showByType($(this).val()); + }); +}); + +function showByType(type) { + if(type == 'account') + { + $('#password-field').show(); + $('#token-field').hide(); + } + else + { + $('#token-field').show(); + $('#password-field').hide(); + } +} \ No newline at end of file diff --git a/module/ci/js/menu.js b/module/ci/js/menu.js new file mode 100644 index 0000000000..0a12f8df4f --- /dev/null +++ b/module/ci/js/menu.js @@ -0,0 +1,4 @@ +$(function() +{ + +}) \ No newline at end of file diff --git a/module/ci/lang/en.php b/module/ci/lang/en.php new file mode 100644 index 0000000000..b3d9bbc7f3 --- /dev/null +++ b/module/ci/lang/en.php @@ -0,0 +1 @@ +ci->common = '持续集成'; +$lang->ci->list = '列表'; +$lang->ci->create = '添加'; + +$lang->ci->subModules['credential'] = '凭证'; +$lang->ci->subModules['jenkins'] = 'Jenkins'; + +// credential +$lang->credential->common = '凭证'; +$lang->credential->browse = '浏览凭证'; +$lang->credential->create = '添加凭证'; +$lang->credential->edit = '编辑凭证'; +$lang->credential->delete = '删除凭证'; +$lang->credential->confirmDelete = '确认删除该凭证吗?'; + +$lang->credential->id = 'ID'; +$lang->credential->name = '名称'; +$lang->credential->type = '类型'; +$lang->credential->username = '用户名'; +$lang->credential->password = '密码'; +$lang->credential->privateKey = '私钥'; +$lang->credential->passphrase = '私钥密码'; +$lang->credential->desc = '描述'; + +$lang->credential->typeList[''] = ''; +$lang->credential->typeList['account'] = '用户名密码'; +$lang->credential->typeList['sshKey '] = '密钥'; + +// jenkins +$lang->jenkins->common = 'Jenkins'; +$lang->jenkins->browse = '浏览Jenkins'; +$lang->jenkins->create = '添加Jenkins'; +$lang->jenkins->edit = '编辑Jenkins'; +$lang->jenkins->delete = '删除Jenkins'; +$lang->jenkins->confirmDelete = '确认删除该Jenkins吗?'; + +$lang->jenkins->id = 'ID'; +$lang->jenkins->name = '名称'; +$lang->jenkins->type = '类型'; +$lang->jenkins->username = '用户名'; +$lang->jenkins->password = '密码'; +$lang->jenkins->token = 'Token'; +$lang->jenkins->desc = '描述'; + +$lang->jenkins->typeList[''] = ''; +$lang->jenkins->typeList['token '] = '用户Token'; +$lang->jenkins->typeList['account'] = '用户名密码'; diff --git a/module/ci/model.php b/module/ci/model.php new file mode 100644 index 0000000000..ceb1a49242 --- /dev/null +++ b/module/ci/model.php @@ -0,0 +1,166 @@ + + * @package product + * @version $Id: control.php 5144 2019-12-11 06:37:03Z chenqi@cnezsoft.com $ + * @link http://www.zentao.net + */ +?> +dao->select('*')->from(TABLE_CREDENTIAL)->where('id')->eq($id)->fetch(); + return $credential; + } + + /** + * Get credential list. + * + * @param string $orderBy + * @param object $pager + * @param bool $decode + * @access public + * @return array + */ + public function listCredential($orderBy = 'id_desc', $pager = null, $decode = true) + { + $credentials = $this->dao->select('*')->from(TABLE_CREDENTIAL) + ->where('deleted')->eq('0') + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + return $credentials; + } + + /** + * Create a credential. + * + * @access public + * @return bool + */ + public function createCredential() + { + $credential = fixer::input('post') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) +// ->remove('') + ->get(); + + $this->dao->insert(TABLE_CREDENTIAL)->data($credential) + ->batchCheck($this->config->credential->create->requiredFields, 'notempty') + ->autoCheck() + ->exec(); + return !dao::isError(); + } + + /** + * Update a credential. + * + * @param int $id + * @access public + * @return bool + */ + public function updateCredential($id) + { + $credential = fixer::input('post') + ->add('editedBy', $this->app->user->account) + ->add('editedDate', helper::now()) + ->get(); + + $this->dao->update(TABLE_CREDENTIAL)->data($credential) + ->batchCheck($this->config->credential->edit->requiredFields, 'notempty') + ->autoCheck() + ->where('id')->eq($id) + ->exec(); + return !dao::isError(); + } + + + /** + * Get a jenkins by id. + * + * @param int $id + * @access public + * @return object + */ + public function getJenkinsByID($id) + { + $jenkins = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch(); + return $jenkins; + } + + /** + * Get jenkins list. + * + * @param string $orderBy + * @param object $pager + * @param bool $decode + * @access public + * @return array + */ + public function listJenkins($orderBy = 'id_desc', $pager = null, $decode = true) + { + $jenkinsList = $this->dao->select('*')->from(TABLE_JENKINS) + ->where('deleted')->eq('0') + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + return $jenkinsList; + } + + /** + * Create a jenkins. + * + * @access public + * @return bool + */ + public function createJenkins() + { + $jenkins = fixer::input('post') + ->add('createdBy', $this->app->user->account) + ->add('createdDate', helper::now()) +// ->remove('') + ->get(); + + $this->dao->insert(TABLE_JENKINS)->data($jenkins) + ->batchCheck($this->config->jenkins->create->requiredFields, 'notempty') + ->autoCheck() + ->exec(); + return !dao::isError(); + } + + /** + * Update a jenkins. + * + * @param int $id + * @access public + * @return bool + */ + public function updateJenkins($id) + { + $jenkins = fixer::input('post') + ->add('editedBy', $this->app->user->account) + ->add('editedDate', helper::now()) + ->get(); + + $this->dao->update(TABLE_JENKINS)->data($jenkins) + ->batchCheck($this->config->jenkins->edit->requiredFields, 'notempty') + ->autoCheck() + ->where('id')->eq($id) + ->exec(); + return !dao::isError(); + } +} diff --git a/module/ci/view/browsecredential.html.php b/module/ci/view/browsecredential.html.php new file mode 100644 index 0000000000..c8ef56d0c9 --- /dev/null +++ b/module/ci/view/browsecredential.html.php @@ -0,0 +1,57 @@ + + * @package credential + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +credential->confirmDelete); ?> + +