+ " . $lang->gitlab->group->create, '', "class='btn btn-primary'");?>
+
+diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 5c2862594f..1455e13b24 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -292,6 +292,24 @@ class gitlab extends control $this->display(); } + /** + * Browse gitlab group. + * + * @param int $gitlabID + * @param string $orderBy + * @access public + * @return void + */ + public function groupBrowse($gitlabID, $orderBy = 'name_asc') + { + $gitlabGroupList = $this->gitlab->apiGetGroups($gitlabID, $orderBy); + + $this->view->gitlabID = $gitlabID; + $this->view->gitlabGroupList = $gitlabGroupList; + $this->view->orderBy = $orderBy; + $this->display(); + } + /** * Browse gitlab project. * @@ -334,7 +352,7 @@ class gitlab extends control * Edit a gitlab user. * * @param int $gitlabID - * @param int $projectID + * @param int $userID * @access public * @return void */ @@ -350,7 +368,7 @@ class gitlab extends control $userPairs = $this->loadModel('user')->getPairs('noclosed|noletter'); $user = $this->gitlab->apiGetSingleUser($gitlabID, $userID); - $zentaoBindAccount = $this->dao->select('account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlabID)->andWhere('openID')->eq($user->id)->fetch(); + $zentaoBindAccount = $this->dao->select('account')->from(TABLE_OAUTH)->where('providerType')->eq('gitlab')->andWhere('providerID')->eq($gitlabID)->andWhere('openID')->eq($user->id)->fetch('account'); $this->view->user = $user; $this->view->userPairs = $userPairs; @@ -359,6 +377,23 @@ class gitlab extends control $this->display(); } + /** + * Delete a gitlab user. + * + * @param int $gitlabID + * @param int $userID + * @access public + * @return void + */ + public function deleteUser($gitlabID, $userID, $confirm = 'no') + { + if($confirm != 'yes') die(js::confirm($this->lang->gitlab->user->confirmDelete , inlink('deleteUser', "gitlabID=$gitlabID&userID=$userID&confirm=yes"))); + + $reponse = $this->gitlab->apiDeleteUser($gitlabID, $userID); + if(!$reponse or substr($reponse->message, 0, 2) == '20') die(js::reload('parent')); + die(js::alert($reponse->message)); + } + /** * Browse gitlab project. * diff --git a/module/gitlab/css/groupbrowse.css b/module/gitlab/css/groupbrowse.css new file mode 100644 index 0000000000..de56d7deb6 --- /dev/null +++ b/module/gitlab/css/groupbrowse.css @@ -0,0 +1,2 @@ +.text-c-name > .avatar {vertical-align: middle;display: inline-block;margin-right: 5px;} +.text-c-name > span {vertical-align: middle;} \ No newline at end of file diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 3ef8062003..4c8e2c4663 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -23,6 +23,7 @@ $lang->gitlab->deleteAction = 'Delete GitLab'; $lang->gitlab->gitlabProject = "GitLab Project"; $lang->gitlab->browseProject = "GitLab Project List"; $lang->gitlab->browseUser = "User List"; +$lang->gitlab->browseGroup = "Group List"; $lang->gitlab->gitlabIssue = "GitLab Issue"; $lang->gitlab->zentaoProduct = 'Zentao Product'; $lang->gitlab->objectType = 'Type'; // task, bug, story @@ -98,3 +99,19 @@ $lang->gitlab->user->edit = "Edit {$lang->gitlab->gitlabAccount}"; $lang->gitlab->user->emptyError = "cannot be empty"; $lang->gitlab->user->passwordError = "The second password is inconsistent!"; $lang->gitlab->user->bindError = "The user has been bound!"; +$lang->gitlab->user->confirmDelete = 'Do you want to delete this GitLab user?'; + +$lang->gitlab->group = new stdclass; +$lang->gitlab->group->id = "Group ID"; +$lang->gitlab->group->name = "Group name"; +$lang->gitlab->group->path = "Group URL"; +$lang->gitlab->group->description = "Group description"; +$lang->gitlab->group->avatar = "Group avatar"; +$lang->gitlab->group->visibility = "Visibility level"; +$lang->gitlab->group->requestAccessEnabledTip = "Allow users to request access (if visibility is public or internal)"; +$lang->gitlab->group->lfsEnabledTip = "Allow projects within this group to use Git LFS(This setting can be overridden in each project)"; +$lang->gitlab->group->create = "Create Group"; +$lang->gitlab->group->edit = "Edit Group"; +$lang->gitlab->group->createOn = "Created on"; +$lang->gitlab->group->members = "Group Members"; +$lang->gitlab->group->confirmDelete = 'Do you want to delete this GitLab group?'; \ No newline at end of file diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 525f36b6bb..f3e12a4e83 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -23,6 +23,7 @@ $lang->gitlab->deleteAction = '删除GitLab'; $lang->gitlab->gitlabProject = "{$lang->gitlab->common}项目"; $lang->gitlab->browseProject = "{$lang->gitlab->common}项目列表"; $lang->gitlab->browseUser = "用户列表"; +$lang->gitlab->browseGroup = "群组列表"; $lang->gitlab->gitlabIssue = "{$lang->gitlab->common} issue"; $lang->gitlab->zentaoProduct = '禅道产品'; $lang->gitlab->objectType = '类型'; // task, bug, story @@ -98,3 +99,19 @@ $lang->gitlab->user->edit = "编辑{$lang->gitlab->gitlabAccount}"; $lang->gitlab->user->emptyError = "不能为空"; $lang->gitlab->user->passwordError = "二次密码不一致!"; $lang->gitlab->user->bindError = "该用户已经被绑定!"; +$lang->gitlab->user->confirmDelete = '确认删除该GitLab用户吗?'; + +$lang->gitlab->group = new stdclass; +$lang->gitlab->group->id = "群组ID"; +$lang->gitlab->group->name = "群组名称"; +$lang->gitlab->group->path = "群组URL"; +$lang->gitlab->group->description = "群组描述"; +$lang->gitlab->group->avatar = "群组头像"; +$lang->gitlab->group->visibility = "可见性级别"; +$lang->gitlab->group->requestAccessEnabledTip = "允许用户请求访问(如果可见性是公开或内部的)"; +$lang->gitlab->group->lfsEnabledTip = "允许该组内的项目使用 Git LFS(可以在每个项目中覆盖此设置)"; +$lang->gitlab->group->create = "添加群组"; +$lang->gitlab->group->edit = "编辑群组"; +$lang->gitlab->group->createOn = "创建于"; +$lang->gitlab->group->members = "群组成员"; +$lang->gitlab->group->confirmDelete = '确认删除该GitLab群组吗?'; \ No newline at end of file diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 5803cf19b2..a86a1ecc0f 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -471,6 +471,31 @@ class gitlabModel extends model return $users; } + /** + * Get groups of one gitlab. + * + * @param int $gitlabID + * @param string $orderBy + * @access public + * @return object + */ + public function apiGetGroups($gitlabID, $orderBy) + { + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/groups"); + list($order, $sort) = explode('_', $orderBy); + + $allResults = array(); + for($page = 1; true; $page++) + { + $results = json_decode(commonModel::http($url . "&statistics=true&order_by={$order}&sort={$sort}&page={$page}&per_page=100")); + if(!empty($results)) $allResults = array_merge($allResults, $results); + if(count($results)<100 or $page > 10) break; + } + + return $allResults; + } + /** * Get projects of one gitlab. * @@ -490,8 +515,8 @@ class gitlabModel extends model for($page = 1; true; $page++) { $results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&page={$page}&per_page=100")); - if(empty($results) or $page > 10) break; - $allResults = array_merge($allResults, $results); + if(!empty($results)) $allResults = array_merge($allResults, $results); + if(count($results)<100 or $page > 10) break; } return $allResults; @@ -579,7 +604,24 @@ class gitlabModel extends model $apiRoot = $this->getApiRoot($gitlabID); $url = sprintf($apiRoot, "/projects/{$projectID}"); - return json_decode(commonModel::http($url, $project, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); + return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); + } + + /** + * Delete a gitab user by api. + * + * @param int $gitlabID + * @param int $userID + * @access public + * @return object + */ + public function apiDeleteUser($gitlabID, $userID) + { + if(empty($userID)) return false; + + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/users/{$userID}"); + return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } /** diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 13e8707a29..5bfcea49e1 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -35,7 +35,7 @@
+ noData;?> + + createLink('gitlab', 'createProject', "gitlabID=$gitlabID"), " " . $lang->gitlab->group->create, '', "class='btn btn-info'");?> + +
+