diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 2b064417b0..78d6844b92 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -42,18 +42,17 @@ class gitlab extends control $pager = new pager($recTotal, $recPerPage, $pageID); /* Admin user don't need bind. */ - $isBindUser = (int)$this->app->user->admin; $gitlabList = $this->gitlab->getList($orderBy, $pager); + $myGitLabs = $this->gitlab->getGitLabListByAccount(); + foreach($gitlabList as $gitlab) { $token = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token); $gitlab->isAdminToken = (isset($token->is_admin) and $token->is_admin); - - if(!$isBindUser) $isBindUser = (int)$this->gitlab->getUserIDByZentaoAccount($gitlab->id, $this->app->user->account); - $gitlab->isBindUser = $isBindUser; + $gitlab->isBindUser = true; + if(!$this->app->user->admin and !isset($myGitLabs[$gitlab->id])) $gitlab->isBindUser = false; } - $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browse; $this->view->gitlabList = $gitlabList; $this->view->orderBy = $orderBy; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 195e73c361..164675e3d4 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -144,6 +144,23 @@ class gitlabModel extends model ->fetch('openID'); } + /** + * Get GitLab id list by user account. + * + * @param string $account + * @access public + * @return array + */ + public function getGitLabListByAccount($account = '') + { + if(!$account) $account = $this->app->user->account; + + return $this->dao->select('providerID')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitlab') + ->andWhere('account')->eq($account) + ->fetchPairs('providerID'); + } + /** * Get project pairs of one gitlab. *