From 6be518e93b2b497bdc1669d2354f4b0d76228eb3 Mon Sep 17 00:00:00 2001 From: "David.li" <1441836644@qq.com> Date: Mon, 7 Jun 2021 16:36:46 +0800 Subject: [PATCH] * gitlab for upgrade. --- module/common/lang/menu.php | 4 +- module/gitlab/control.php | 24 ++++++++--- module/gitlab/js/create.js | 24 +++++++++++ module/gitlab/lang/zh-cn.php | 8 ++-- module/gitlab/model.php | 67 +++++++++++++----------------- module/gitlab/view/bind.html.php | 49 ++++++++++++++++++++++ module/gitlab/view/browse.html.php | 1 + module/gitlab/view/create.html.php | 9 ---- module/gitlab/view/edit.html.php | 9 ---- 9 files changed, 127 insertions(+), 68 deletions(-) create mode 100644 module/gitlab/js/create.js create mode 100644 module/gitlab/view/bind.html.php diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index fdb26efab4..dcc63f3625 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -318,14 +318,14 @@ $lang->devops->menu = new stdclass(); $lang->devops->menu->code = array('link' => "{$lang->repo->common}|repo|browse|repoID=%s", 'alias' => 'diff,view,revision,log,blame,showsynccomment'); $lang->devops->menu->compile = array('link' => "{$lang->devops->compile}|job|browse", 'subModule' => 'compile,job'); $lang->devops->menu->jenkins = array('link' => "Jenkins|jenkins|browse", 'alias' => 'create,edit'); -$lang->devops->menu->gitlab = array('link' => "gitlab|gitlab|browse", 'alias' => 'create,edit'); +$lang->devops->menu->gitlab = array('link' => "Gitlab|gitlab|browse", 'alias' => 'create,edit'); $lang->devops->menu->maintain = array('link' => "{$lang->devops->repo}|repo|maintain", 'alias' => 'create,edit'); $lang->devops->menu->rules = array('link' => "{$lang->devops->rules}|repo|setrules"); $lang->devops->menuOrder[5] = 'code'; $lang->devops->menuOrder[10] = 'compile'; $lang->devops->menuOrder[15] = 'jenkins'; -$lang->devops->menuOrder[16] = 'gitlab'; +$lang->devops->menuOrder[14] = 'gitlab'; $lang->devops->menuOrder[20] = 'maintain'; $lang->devops->menuOrder[25] = 'rules'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 69953d6795..f00cc8b081 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -64,6 +64,18 @@ class gitlab extends control $this->display(); } + /** + * bind a gitlab. + * + * @access public + * @return void + */ + public function bind() + { + echo 123;die; + $this->display(); + } + /** * Edit a gitlab. * @@ -106,17 +118,17 @@ class gitlab extends control } /** - * Ajax get tasks. + * Ajax get gitlab token permissions. * - * @param int $id + * @param string $host + * @param string $token * @access public * @return void */ - public function ajaxGetTasks($id) + public function ajaxCheckToken($host, $token) { - if(empty($id)) die(json_encode(array('' => ''))); + $host = helper::safe64Decode($host); + $permissions = $this->gitlab->getPermissionsByToken($host, $token); - $tasks = $this->gitlab->getTasks($id); - die(json_encode($tasks)); } } diff --git a/module/gitlab/js/create.js b/module/gitlab/js/create.js new file mode 100644 index 0000000000..6410b0fdc0 --- /dev/null +++ b/module/gitlab/js/create.js @@ -0,0 +1,24 @@ +$(function () { + $('#token, #url').change(function () { + //取用户名 + var uid = $("#uid").val(); + + //调ajax + $.ajax({ + url: "uidchuli.php", + data: {u: uid}, + type: "POST", + dataType: "TEXT", + success: function (data) { + if (data > 0) { + $("#ts").html("该应户名已存在"); + $("#ts").css("color", "red"); + } else { + $("#ts").html("该应户名可用"); + $("#ts").css("color", "green"); + } + } + + }); + }) +}); diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 1e64004c55..1a5c554701 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -1,8 +1,9 @@ gitlab->common = 'gitlab'; +$lang->gitlab->common = 'Gitlab'; $lang->gitlab->browse = '浏览gitlab'; $lang->gitlab->create = '添加gitlab'; $lang->gitlab->edit = '编辑gitlab'; +$lang->gitlab->bind = '绑定用户'; $lang->gitlab->delete = '删除'; $lang->gitlab->confirmDelete = '确认删除该gitlab吗?'; @@ -13,10 +14,11 @@ $lang->gitlab->id = 'ID'; $lang->gitlab->name = '名称'; $lang->gitlab->url = '服务地址'; $lang->gitlab->token = 'Token'; -$lang->gitlab->account = '用户名'; -$lang->gitlab->password = '密码'; $lang->gitlab->lblCreate = '添加gitlab服务器'; $lang->gitlab->desc = '描述'; $lang->gitlab->tokenFirst = 'Token不为空时,优先使用Token。'; $lang->gitlab->tips = '使用密码时,请在gitlab全局安全设置中禁用"防止跨站点请求伪造"选项。'; + +/* 交互提示。*/ +$lang->gitlab->tokenPermissions = "当前token非root权限。"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index f0bc79d668..51d296384a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -21,7 +21,7 @@ class gitlabModel extends model */ public function getByID($id) { - $gitlab = $this->dao->select('*')->from(TABLE_GITLAB)->where('id')->eq($id)->fetch(); + $gitlab = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch(); $gitlab->password = base64_decode($gitlab->password); return $gitlab; @@ -37,8 +37,9 @@ class gitlabModel extends model */ public function getList($orderBy = 'id_desc', $pager = null) { - return $this->dao->select('*')->from(TABLE_GITLAB) + return $this->dao->select('*')->from(TABLE_JENKINS) ->where('deleted')->eq('0') + ->andwhere('type')->eq('1') ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); @@ -51,41 +52,13 @@ class gitlabModel extends model */ public function getPairs() { - $gitlab = $this->dao->select('id,name')->from(TABLE_GITLAB) + $gitlab = $this->dao->select('id,name')->from(TABLE_JENKINS) ->where('deleted')->eq('0') ->orderBy('id')->fetchPairs('id', 'name'); $gitlab = array('' => '') + $gitlab; return $gitlab; } - /** - * Get gitlab tasks. - * - * @param int $id - * @access public - * @return array - */ - public function getTasks($id) - { - $gitlab = $this->getById($id); - - $gitlabServer = $gitlab->url; - $gitlabUser = $gitlab->account; - $gitlabPassword = $gitlab->token ? $gitlab->token : $gitlab->password; - - $userPWD = "$gitlabUser:$gitlabPassword"; - $response = common::http($gitlabServer . '/api/json/items/list', '', array(CURLOPT_USERPWD => $userPWD)); - $response = json_decode($response); - - $tasks = array(); - if(isset($response->jobs)) - { - foreach($response->jobs as $job) $tasks[basename($job->url)] = $job->name; - } - return $tasks; - - } - /** * Create a gitlab. * @@ -97,12 +70,11 @@ class gitlabModel extends model $gitlab = fixer::input('post') ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) - ->skipSpecial('url,token,account,password') + ->add('type', 1) + ->skipSpecial('url,token') ->get(); - $gitlab->password = base64_encode($gitlab->password); - - $this->dao->insert(TABLE_GITLAB)->data($gitlab) + $this->dao->insert(TABLE_JENKINS)->data($gitlab) ->batchCheck($this->config->gitlab->create->requiredFields, 'notempty') ->batchCheck("url", 'URL') ->autoCheck() @@ -123,12 +95,10 @@ class gitlabModel extends model $gitlab = fixer::input('post') ->add('editedBy', $this->app->user->account) ->add('editedDate', helper::now()) - ->skipSpecial('url,token,account,password') + ->skipSpecial('url,token') ->get(); - $gitlab->password = base64_encode($gitlab->password); - - $this->dao->update(TABLE_GITLAB)->data($gitlab) + $this->dao->update(TABLE_JENKINS)->data($gitlab) ->batchCheck($this->config->gitlab->edit->requiredFields, 'notempty') ->batchCheck("url", 'URL') ->autoCheck() @@ -136,4 +106,23 @@ class gitlabModel extends model ->exec(); return !dao::isError(); } + + /** + * Get gitlab token permissions. + * + * @param string $host + * @param string $token + * @access public + * @return array + */ + public function getPermissionsByToken($host, $token) + { + $host = rtrim($host, '/'); + $host .= '/api/v4/activities'; + + $results = json_decode(file_get_contents($host . "?private_token=$token")); + + return $results; + } + } diff --git a/module/gitlab/view/bind.html.php b/module/gitlab/view/bind.html.php new file mode 100644 index 0000000000..d9af48a455 --- /dev/null +++ b/module/gitlab/view/bind.html.php @@ -0,0 +1,49 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +