diff --git a/module/git/model.php b/module/git/model.php
index 29771f410c..5d5fca75e1 100644
--- a/module/git/model.php
+++ b/module/git/model.php
@@ -194,11 +194,17 @@ class gitModel extends model
$commits = $repo->commits;
$scm = strtolower($repo->SCM);
- $userList = $this->loadModel($scm)->apiGetUsers($repo->gitService);
- $acountIDPairs = $this->loadModel('pipeline')->getUserBindedPairs($repo->gitService, $scm, 'openID,account');
+ $acountIDPairs = $this->loadModel('pipeline')->getUserBindedPairs($repo->serviceHost, $scm, 'openID,account');
$accountPairs = array();
- foreach($userList as $user) $accountPairs[$user->realname] = zget($acountIDPairs, $user->id, '');
+ if($scm != 'git')
+ {
+ $userList = $this->loadModel($scm)->apiGetUsers($repo->serviceHost);
+ if(!empty($userList))
+ {
+ foreach($userList as $user) $accountPairs[$user->realname] = zget($acountIDPairs, $user->id, '');
+ }
+ }
/* Update code commit history. */
foreach($branches as $branch)
diff --git a/module/gitlab/control.php b/module/gitlab/control.php
index a49427af25..73750b070e 100644
--- a/module/gitlab/control.php
+++ b/module/gitlab/control.php
@@ -317,11 +317,7 @@ class gitlab extends control
*/
public function browseGroup(int $gitlabID, string $orderBy = 'name_asc')
{
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
- }
+ if(!$this->app->user->admin) $this->gitlabZen->checkBindedUser($gitlabID);
$fixOrderBy = str_replace('fullName', 'name', $orderBy);
$keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword');
@@ -351,11 +347,7 @@ class gitlab extends control
*/
public function createGroup(int $gitlabID)
{
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
- }
+ if(!$this->app->user->admin) $this->gitlabZen->checkBindedUser($gitlabID);
if($_POST)
{
@@ -387,8 +379,7 @@ class gitlab extends control
{
if(!$this->app->user->admin)
{
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('space', 'browse')));
+ $this->gitlabZen->checkBindedUser($gitlabID);
$members = $this->gitlab->apiGetGroupMembers($gitlabID, $groupID, $openID);
if(empty($members) or $members[0]->access_level < $this->config->gitlab->accessLevel['owner']) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('space', 'browse')));
@@ -522,8 +513,8 @@ class gitlab extends control
$isAdmin = true;
if(!$this->app->user->admin)
{
- $userID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- $user = $this->gitlab->apiGetSingleUser($gitlabID, $userID);
+ $userID = $this->loadModel('pipeline')->getOpenIdByAccount($gitlabID, 'gitlab', $this->app->user->account);
+ $user = $this->gitlab->apiGetSingleUser($gitlabID, (int)$userID);
if(!$user->is_admin) $isAdmin = false;
}
@@ -683,8 +674,7 @@ class gitlab extends control
$openID = 0;
if(!$this->app->user->admin)
{
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('space', 'browse')));
+ $this->gitlabZen->checkBindedUser($gitlabID);
}
$this->app->loadClass('pager', true);
@@ -927,11 +917,7 @@ class gitlab extends control
{
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
- if(!$this->app->user->admin)
- {
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
- }
+ if(!$this->app->user->admin) $this->gitlabZen->checkBindedUser($gitlabID);
$this->session->set('gitlabTagList', $this->app->getURI(true));
$keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword');
@@ -1308,8 +1294,7 @@ class gitlab extends control
{
if(!$this->app->user->admin)
{
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
+ $this->gitlabZen->checkBindedUser($gitlabID);
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
@@ -1354,8 +1339,7 @@ class gitlab extends control
{
if(!$this->app->user->admin)
{
- $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account);
- if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse')));
+ $this->gitlabZen->checkBindedUser($gitlabID);
$project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID);
if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse')));
diff --git a/module/gitlab/js/common.ui.js b/module/gitlab/js/common.ui.js
index 1958f91165..a086894e2b 100644
--- a/module/gitlab/js/common.ui.js
+++ b/module/gitlab/js/common.ui.js
@@ -26,3 +26,16 @@ function onAclChange(event)
if(visibility == 'public') $("#visibilitypublic").parent().append(publicTip);
if(visibility != 'public') $('#publicTip').remove();
}
+
+/**
+ * Alert error and jump page.
+ *
+ * @param string $error
+ * @param string $errorJump
+ * @access public
+ * @return viod
+ */
+function alertJump(error, errorJump)
+{
+ zui.Modal.alert(error).then((res) => {loadPage(errorJump)});
+}
diff --git a/module/gitlab/ui/browsegroup.html.php b/module/gitlab/ui/browsegroup.html.php
index 170620cbeb..b40a252d5d 100644
--- a/module/gitlab/ui/browsegroup.html.php
+++ b/module/gitlab/ui/browsegroup.html.php
@@ -10,6 +10,12 @@ declare(strict_types=1);
*/
namespace zin;
+if(!empty($permissionError))
+{
+ jsCall('alertJump', array($permissionError, $errorJump));
+ return;
+}
+
jsVar('gitlabUrl', $gitlab->url);
$canCreate = hasPriv('instance', 'manage');
diff --git a/module/gitlab/ui/browseproject.html.php b/module/gitlab/ui/browseproject.html.php
index 215c63c46c..972596da60 100644
--- a/module/gitlab/ui/browseproject.html.php
+++ b/module/gitlab/ui/browseproject.html.php
@@ -10,6 +10,12 @@ declare(strict_types=1);
*/
namespace zin;
+if(!empty($permissionError))
+{
+ jsCall('alertJump', array($permissionError, $errorJump));
+ return;
+}
+
jsVar('projectStar', $lang->gitlab->project->star);
jsVar('projectFork', $lang->gitlab->project->fork);
diff --git a/module/gitlab/ui/browsetag.html.php b/module/gitlab/ui/browsetag.html.php
index 4cd6761c82..5fa796ccb2 100644
--- a/module/gitlab/ui/browsetag.html.php
+++ b/module/gitlab/ui/browsetag.html.php
@@ -11,6 +11,12 @@ declare(strict_types=1);
namespace zin;
jsVar('protectedTag', $lang->gitlab->tag->protected);
+if(!empty($permissionError))
+{
+ jsCall('alertJump', array($permissionError, $errorJump));
+ return;
+}
+
featureBar
(
backBtn
diff --git a/module/gitlab/ui/creategroup.html.php b/module/gitlab/ui/creategroup.html.php
index ec49239b12..2002369a94 100644
--- a/module/gitlab/ui/creategroup.html.php
+++ b/module/gitlab/ui/creategroup.html.php
@@ -10,6 +10,12 @@ declare(strict_types=1);
*/
namespace zin;
+if(!empty($permissionError))
+{
+ jsCall('alertJump', array($permissionError, $errorJump));
+ return;
+}
+
$publicTip = "" . $lang->gitlab->group->publicTip . '';
jsVar('publicTip', $publicTip);
diff --git a/module/gitlab/ui/editgroup.html.php b/module/gitlab/ui/editgroup.html.php
index a26dea2525..5ae1c8f139 100644
--- a/module/gitlab/ui/editgroup.html.php
+++ b/module/gitlab/ui/editgroup.html.php
@@ -10,6 +10,12 @@ declare(strict_types=1);
*/
namespace zin;
+if(!empty($permissionError))
+{
+ jsCall('alertJump', array($permissionError, $errorJump));
+ return;
+}
+
$publicTip = "" . $lang->gitlab->group->publicTip . '';
jsVar('publicTip', $publicTip);
jsVar('visibility', $group->visibility);
diff --git a/module/gitlab/ui/managebranchpriv.html.php b/module/gitlab/ui/managebranchpriv.html.php
index 54e4792593..5ce8ec7593 100644
--- a/module/gitlab/ui/managebranchpriv.html.php
+++ b/module/gitlab/ui/managebranchpriv.html.php
@@ -10,6 +10,12 @@ declare(strict_types=1);
*/
namespace zin;
+if(!empty($permissionError))
+{
+ jsCall('alertJump', array($permissionError, $errorJump));
+ return;
+}
+
jsVar('hasAccessBranches', $hasAccessBranches);
formBatchPanel
(
diff --git a/module/gitlab/ui/managetagpriv.html.php b/module/gitlab/ui/managetagpriv.html.php
index a31b180935..40edf710d4 100644
--- a/module/gitlab/ui/managetagpriv.html.php
+++ b/module/gitlab/ui/managetagpriv.html.php
@@ -10,6 +10,12 @@ declare(strict_types=1);
*/
namespace zin;
+if(!empty($permissionError))
+{
+ jsCall('alertJump', array($permissionError, $errorJump));
+ return;
+}
+
jsVar('hasAccessTags', $hasAccessTags);
formBatchPanel
(
diff --git a/module/gitlab/zen.php b/module/gitlab/zen.php
index 101b081899..588e7b8380 100644
--- a/module/gitlab/zen.php
+++ b/module/gitlab/zen.php
@@ -229,4 +229,22 @@ class gitlabZen extends gitlab
return array($addedMembers, $deletedMembers, $updatedMembers);
}
+
+ /**
+ * 检查是否绑定用户。
+ * Check has binded user.
+ *
+ * @param int $gitlabID
+ * @access protected
+ * @return void
+ */
+ protected function checkBindedUser(int $gitlabID): void
+ {
+ $openID = $this->loadModel('pipeline')->getOpenIdByAccount($gitlabID, 'gitlab', $this->app->user->account);
+ if(!$openID)
+ {
+ $this->view->permissionError = $this->lang->gitlab->mustBindUser;
+ $this->view->errorJump = $this->createLink('space', 'browse');
+ }
+ }
}