diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 8cd64af9d5..c8ce7f34ba 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -307,10 +307,23 @@ class gitlab extends control */ public function browseGroup($gitlabID, $orderBy = 'name_asc') { - $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseGroup; - $this->view->gitlabID = $gitlabID; - $this->view->gitlabGroupList = $this->gitlab->apiGetGroups($gitlabID, $orderBy); - $this->view->orderBy = $orderBy; + 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'))); + } + + $groups = $this->gitlab->apiGetGroups($gitlabID, $orderBy); + $adminGroups = $this->gitlab->apiGetGroups($gitlabID, $orderBy, $this->gitlab->config->accessLevel['owner']); + + $adminGropuIDList = array(); + foreach($adminGroups as $group) $adminGropuIDList[] = $group->id; + + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseGroup; + $this->view->gitlabID = $gitlabID; + $this->view->gitlabGroupList = $groups; + $this->view->adminGropuIDList = $adminGropuIDList; + $this->view->orderBy = $orderBy; $this->display(); } @@ -323,6 +336,12 @@ class gitlab extends control */ public function createGroup($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($_POST) { $this->gitlab->createGroup($gitlabID); @@ -349,6 +368,15 @@ class gitlab extends control */ public function editGroup($gitlabID, $groupID) { + 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'))); + + $members = $this->gitlab->apiGetGroupMembers($gitlabID, $groupID, $openID); + if(empty($members)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + } + if($_POST) { $this->gitlab->editGroup($gitlabID); @@ -837,7 +865,6 @@ class gitlab extends control */ public function browseBranchPriv($gitlabID, $projectID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1) { - $openID = 0; $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); if(!$this->app->user->admin) @@ -879,15 +906,14 @@ class gitlab extends control */ public function createBranchPriv($gitlabID, $projectID, $branch = '') { - $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('gitlab', 'browse'))); - } - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + } /* Fix error when request type is PATH_INFO and the branch name contains '-'.*/ if($branch) $branch = str_replace('*', '-', $branch); @@ -961,15 +987,14 @@ class gitlab extends control */ public function deleteBranchPriv($gitlabID, $projectID, $branch, $confirm = 'no') { - $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('gitlab', 'browse'))); - } - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + } if($confirm != 'yes') { @@ -1005,10 +1030,14 @@ class gitlab extends control */ public function browseTag($gitlabID, $projectID, $orderBy = 'updated_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { + $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->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); } $this->session->set('gitlabTagList', $this->app->getURI(true)); @@ -1037,7 +1066,7 @@ class gitlab extends control $this->view->gitlabID = $gitlabID; $this->view->projectID = $projectID; $this->view->keyword = $keyword; - $this->view->project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + $this->view->project = $project; $this->view->gitlabTagList = $tagList; $this->view->orderBy = $orderBy; $this->display(); @@ -1057,14 +1086,14 @@ class gitlab extends control */ public function browseTagPriv($gitlabID, $projectID, $orderBy = 'name_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { - $openID = 0; $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(!isset($project->owner) or $project->owner->id != $openID) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + + if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); } $this->session->set('gitlabTagPrivList', $this->app->getURI(true)); @@ -1133,15 +1162,14 @@ class gitlab extends control */ public function createTagPriv($gitlabID, $projectID) { - $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('gitlab', 'browse'))); - } - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + } if($_POST) { @@ -1179,15 +1207,14 @@ class gitlab extends control */ public function editTagPriv($gitlabID, $projectID, $tag = '') { - $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('gitlab', 'browse'))); - } - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + } /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ $tag = str_replace('*', '-', $tag); @@ -1222,15 +1249,14 @@ class gitlab extends control */ public function deleteTagPriv($gitlabID, $projectID, $tag) { - $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('gitlab', 'browse'))); - } - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->app->user->admin and (!isset($project->owner) or $project->owner->id != $openID)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + if(!$this->gitlab->checkUserAccess($gitlabID, $openID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + } /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ $tag = str_replace('*', '-', $tag); diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index f8ff8c6485..28569ea795 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -15,6 +15,7 @@ $lang->gitlab->confirmDelete = 'Do you want to delete this GitLab server?'; $lang->gitlab->gitlabAccount = 'GitLab Account'; $lang->gitlab->zentaoAccount = 'Zentao Account'; $lang->gitlab->bindingStatus = 'Binding Status'; +$lang->gitlab->notBind = 'Not bind'; $lang->gitlab->binded = 'Binded'; $lang->gitlab->bindedError = 'The bound user has been deleted or modified. Please bind again.'; $lang->gitlab->serverFail = 'Connect to GitLab server failed, please check the GitLab server.'; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 06bfb578ff..78c9dc6dbc 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -15,6 +15,7 @@ $lang->gitlab->confirmDelete = '确认删除该GitLab吗?'; $lang->gitlab->gitlabAccount = 'GitLab用户'; $lang->gitlab->zentaoAccount = '禅道用户'; $lang->gitlab->bindingStatus = '绑定状态'; +$lang->gitlab->notBind = '未绑定'; $lang->gitlab->binded = '已绑定'; $lang->gitlab->bindedError = '绑定的用户已删除或者已修改,请重新绑定'; $lang->gitlab->serverFail = '连接GitLab服务器异常,请检查GitLab服务器。'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 98b78615ef..68afc2c66a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -544,13 +544,15 @@ class gitlabModel extends model * * @param int $gitlabID * @param int $groupID + * @param int $userID * @access public * @return object */ - public function apiGetGroupMembers($gitlabID, $groupID) + public function apiGetGroupMembers($gitlabID, $groupID, $userID = 0) { $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/groups/$groupID/members/all"); + if($userID) $url .= "&user_ids=$userID"; $allResults = array(); for($page = 1; true; $page++) diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php index c83bea3e6e..8129b6769e 100644 --- a/module/gitlab/view/binduser.html.php +++ b/module/gitlab/view/binduser.html.php @@ -37,7 +37,7 @@ email) echo " <" . $gitlabUser->email . ">";?> id]", $userPairs, '', "class='form-control select chosen'" );?> - + gitlab->notBind;?> diff --git a/module/gitlab/view/browsegroup.html.php b/module/gitlab/view/browsegroup.html.php index d52fb66dd9..c0d515f526 100644 --- a/module/gitlab/view/browsegroup.html.php +++ b/module/gitlab/view/browsegroup.html.php @@ -55,9 +55,10 @@ created_at, 0, 10);?> id, $adminGropuIDList) ? '' : 'disabled'; common::printLink('gitlab', 'manageGroupMembers', "gitlabID=$gitlabID&groupID=$gitlabGroup->id", " ", '',"title='{$lang->gitlab->group->manageMembers}' class='btn btn-primary'"); - common::printLink('gitlab', 'editGroup', "gitlabID=$gitlabID&groupID=$gitlabGroup->id", " ", '', "title='{$lang->gitlab->group->edit}' class='btn btn-primary'"); - if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'deleteGroup', "gitlabID=$gitlabID&groupID=$gitlabGroup->id"), '', 'hiddenwin', "title='{$lang->gitlab->deleteGroup}' class='btn'"); + common::printLink('gitlab', 'editGroup', "gitlabID=$gitlabID&groupID=$gitlabGroup->id", " ", '', "title='{$lang->gitlab->group->edit}' class='btn btn-primary {$adminClass}'"); + if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'deleteGroup', "gitlabID=$gitlabID&groupID=$gitlabGroup->id"), '', 'hiddenwin', "title='{$lang->gitlab->deleteGroup}' class='btn {$adminClass}'"); ?>