diff --git a/module/gitlab/control.php b/module/gitlab/control.php index b7ac6fdb0b..52fa0b9749 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -24,8 +24,6 @@ class gitlab extends control */ public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { - if(common::hasPriv('gitlab', 'create')) $this->lang->TRActions = html::a(helper::createLink('gitlab', 'create'), " " . $this->lang->gitlab->create, '', "class='btn btn-primary'"); - $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); @@ -50,12 +48,18 @@ class gitlab extends control { if($_POST) { - $tokenValid = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); - if($tokenValid['result'] == 'fail') $this->send($tokenValid); + if(strpos($host, 'http') !== 0) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); + if(!$this->post->token) $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); + + $user = $this->gitlab->apiGetCurrentUser($this->post->url, $this->post->token); + + if(!is_object($user)) $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); + if(isset($user->is_admin) and $user->is_admin == true) $this->send(array('result' => 'success')); + $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); $gitlabID = $this->gitlab->create(); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $gitlabID)); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } @@ -76,10 +80,11 @@ class gitlab extends control public function bindUser($id) { $gitlab = $this->gitlab->getByID($id); - $this->view->title = $this->lang->gitlab->bind; - $this->view->zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); - $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab); - $this->view->matchedInfo = $this->gitlab->getMatchedUsers($this->view->gitlabUsers); + $this->view->title = $this->lang->gitlab->bindUser; + $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); + $this->view->userPairs = $this->loadModel('user')->getPairs(); + $this->view->gitlabUsers = $this->gitlab->apiGetUsers($gitlab); + $this->view->matchedResult = $this->gitlab->getMatchedUsers($this->view->gitlabUsers, $zentaoUsers); $this->display(); } diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index dcd874762b..4389a02c38 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -4,9 +4,11 @@ $lang->gitlab->common = 'Gitlab'; $lang->gitlab->browse = '浏览gitlab'; $lang->gitlab->create = '添加gitlab'; $lang->gitlab->edit = '编辑gitlab'; -$lang->gitlab->bind = '绑定用户'; +$lang->gitlab->bindUser = '绑定用户'; $lang->gitlab->delete = '删除'; $lang->gitlab->confirmDelete = '确认删除该gitlab吗?'; +$lang->gitlab->gitlabAccount = 'gitlab用户'; +$lang->gitlab->zentaoAccount = '禅道用户'; $lang->gitlab->browseAction = 'gitlab列表'; $lang->gitlab->deleteAction = '删除gitlab'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 5b0b7cfbe7..e2280be116 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -80,14 +80,8 @@ class gitlabModel extends model */ public function apiGetCurrentUser($host, $token) { - if(strpos($host, 'http') !== 0) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))); - if(!$this->post->token) return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))); $api = rtrim($host, '/') . "/api/v4/user?private_token=$token"; - $response = json_decode(commonModel::http($api)); - - if(!is_object($response)) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))); - if(isset($response->is_admin) and $response->is_admin == true) return array('result' => 'success'); - return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))); + return json_decode(commonModel::http($api)); } /** @@ -114,17 +108,15 @@ class gitlabModel extends model $user->realname = $gitlabUser->name; $user->account = $gitlabUser->username; $user->email = $gitlabUser->email; + $user->avatar = $gitlabUser->avatar_url; $users[] = $user; } - a($users); return $users; } - public function getMatchedUsers($gitlabUsers) + public function getMatchedUsers($gitlabUsers, $zentaoUsers) { - $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); - $matches = new stdclass; foreach($gitlabUsers as $gitlabUser) { @@ -136,7 +128,8 @@ class gitlabModel extends model } } - foreach($gitlabUser as $gitlabUser) + $matchedUsers = array(); + foreach($gitlabUsers as $gitlabUser) { $matchedZentaoUsers = array(); if(isset($matches->accounts[$gitlabUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$gitlabUser->account]); @@ -146,15 +139,11 @@ class gitlabModel extends model $matchedZentaoUsers = array_unique($matchedZentaoUsers); if(count($matchedZentaoUsers) == 1) { - $matchedUsers[$gitlabUser->id] = current($matchedZentaoUsers); - } - else - { - $unmatchedUsers[$gitlabUser->id] = $gitlabUser; + $gitlabUser->zentaoAccount = current($matchedZentaoUsers); + $matchedUsers[] = $gitlabUser; } } - - return array('matched' => $matchedUsers, 'unmatched' => $unmatchedUsers); + return $matchedUsers; } /** diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php index dbf69d2414..2618efc9cf 100644 --- a/module/gitlab/view/binduser.html.php +++ b/module/gitlab/view/binduser.html.php @@ -17,20 +17,35 @@