diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 318d624d29..b24302a7fa 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -611,6 +611,7 @@ class gitlab extends control */ public function browseProject($gitlabID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1) { + $openID = 0; if(!$this->app->user->admin) { $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); @@ -623,6 +624,15 @@ class gitlab extends control $result = $this->gitlab->apiGetProjectsPager($gitlabID, $keyword, $orderBy, $pager); + foreach($result['projects'] as $key => $project) + { + $project->adminer = (bool)$this->app->user->admin; + if(!$project->adminer and isset($project->owner) and $project->owner->id == $openID) $project->adminer = true; + + $project->userAccess = 0; + if(isset($project->permissions) and $project->permissions->project_access) $project->userAccess = (int)$project->permissions->project_access->access_level; + } + $gitlab = $this->gitlab->getByID($gitlabID); $this->view->gitlab = $gitlab; @@ -823,10 +833,19 @@ class gitlab extends control */ public function browseBranchPriv($gitlabID, $projectID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1) { + $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'))); + } + $keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword'); $branches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, $keyword, $orderBy); $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'))); + /* Pager. */ $this->app->loadClass('pager', $static = true); $recTotal = count($branches); @@ -856,6 +875,16 @@ 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'))); + /* Fix error when request type is PATH_INFO and the branch name contains '-'.*/ if($branch) $branch = str_replace('*', '-', $branch); @@ -928,6 +957,16 @@ 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'))); + if($confirm != 'yes') { $branch = urlencode($branch); @@ -962,6 +1001,12 @@ class gitlab extends control */ public function browseTag($gitlabID, $projectID, $orderBy = 'updated_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { + 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->session->set('gitlabTagList', $this->app->getURI(true)); $keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword'); @@ -1008,6 +1053,16 @@ class gitlab extends control */ public function browseTagPriv($gitlabID, $projectID, $orderBy = 'name_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { + $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'))); + $this->session->set('gitlabTagPrivList', $this->app->getURI(true)); $keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword'); @@ -1058,7 +1113,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 = empty($tagList) ? $tagList: $tagList[$pageID - 1]; $this->view->orderBy = $orderBy; $this->display(); @@ -1074,6 +1129,16 @@ 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'))); + if($_POST) { $this->gitlab->createTagPriv($gitlabID, $projectID); @@ -1110,6 +1175,16 @@ 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'))); + /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ $tag = str_replace('*', '-', $tag); @@ -1143,6 +1218,16 @@ 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'))); + /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ $tag = str_replace('*', '-', $tag); $reponse = $this->gitlab->apiDeleteTagPriv($gitlabID, $projectID, $tag); diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 8fd68f46ca..f8ff8c6485 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -73,6 +73,7 @@ $lang->gitlab->tips = 'When using a password, please disable the "Preve $lang->gitlab->emptyError = " cannot be empty"; $lang->gitlab->createSuccess = "Create success"; $lang->gitlab->mustBindUser = 'You have not registered the GitLab account, please contact the administrator to register.'; +$lang->gitlab->noAccess = 'Permission denied'; $lang->gitlab->placeholder = new stdclass; $lang->gitlab->placeholder->name = ''; @@ -100,6 +101,7 @@ $lang->gitlab->apiError[2] = 'is too short (minimum is 8 characters)'; $lang->gitlab->apiError[3] = "can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom'"; $lang->gitlab->apiError[4] = 'Branch already exists'; $lang->gitlab->apiError[5] = 'Failed to save group {:path=>["has already been taken"]}'; +$lang->gitlab->apiError[6] = '403 Forbidden'; $lang->gitlab->errorLang[0] = 'You cannot set Internal as its Visibility Level, if it is private in GitLab.'; $lang->gitlab->errorLang[1] = 'You cannot set Public as its Visibility Level, if it is private in GitLab.'; @@ -107,6 +109,7 @@ $lang->gitlab->errorLang[2] = 'Password is too short (minimum is 8 characters)'; $lang->gitlab->errorLang[3] = 'It should contain only letters, digits, underscore, hyphen and period. It should not start with hypen, or end with .git or .atom.'; $lang->gitlab->errorLang[4] = 'Branch already exists.'; $lang->gitlab->errorLang[5] = 'Failed to save group, path has already been taken.'; +$lang->gitlab->errorLang[6] = $lang->gitlab->noAccess; $lang->gitlab->project = new stdclass; $lang->gitlab->project->id = "Project ID"; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 617f815aba..06bfb578ff 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -73,6 +73,7 @@ $lang->gitlab->tips = '使用密码时,请在GitLab全局安全设置 $lang->gitlab->emptyError = "不能为空"; $lang->gitlab->createSuccess = "创建成功"; $lang->gitlab->mustBindUser = '您还未绑定GitLab用户,请联系管理员进行绑定'; +$lang->gitlab->noAccess = '权限不足'; $lang->gitlab->placeholder = new stdclass; $lang->gitlab->placeholder->name = ''; @@ -100,6 +101,7 @@ $lang->gitlab->apiError[2] = 'is too short (minimum is 8 characters)'; $lang->gitlab->apiError[3] = "can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom'"; $lang->gitlab->apiError[4] = 'Branch already exists'; $lang->gitlab->apiError[5] = 'Failed to save group {:path=>["has already been taken"]}'; +$lang->gitlab->apiError[6] = '403 Forbidden'; $lang->gitlab->errorLang[0] = '私有分组的项目,可见性级别不能设为内部。'; $lang->gitlab->errorLang[1] = '私有分组的项目,可见性级别不能设为公开。'; @@ -107,6 +109,7 @@ $lang->gitlab->errorLang[2] = '密码太短(最少8个字符)'; $lang->gitlab->errorLang[3] = "只能包含字母、数字、'.'-'和'.'。不能以'-'开头、以'.git'结尾或以'.atom'结尾。"; $lang->gitlab->errorLang[4] = '分支名已存在。'; $lang->gitlab->errorLang[5] = '保存失败,群组URL路径已经被使用。'; +$lang->gitlab->errorLang[6] = $lang->gitlab->noAccess; $lang->gitlab->project = new stdclass; $lang->gitlab->project->id = "项目ID"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 164675e3d4..f502607c0f 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -651,7 +651,7 @@ class gitlabModel extends model /* Parse order string. */ $order = explode('_', $orderBy); - $result = commonModel::httpWithHeader($url . "&simple=true&&per_page={$pager->recPerPage}&order_by={$order[0]}&sort={$order[1]}&page={$pager->pageID}&search={$keyword}&search_namespaces=true"); + $result = commonModel::httpWithHeader($url . "&&per_page={$pager->recPerPage}&order_by={$order[0]}&sort={$order[1]}&page={$pager->pageID}&search={$keyword}&search_namespaces=true"); $header = $result['header']; $recTotal = $header['X-Total']; diff --git a/module/gitlab/view/browseproject.html.php b/module/gitlab/view/browseproject.html.php index 845778cc9a..d60a2d782c 100644 --- a/module/gitlab/view/browseproject.html.php +++ b/module/gitlab/view/browseproject.html.php @@ -67,12 +67,13 @@