From bfde525f1349ecce65fdc16833d3497f3d17faf8 Mon Sep 17 00:00:00 2001 From: zenggang Date: Thu, 30 Dec 2021 03:08:42 +0000 Subject: [PATCH 1/2] * Finish task#46555 --- module/action/lang/en.php | 1 + module/action/lang/zh-cn.php | 1 + module/gitlab/control.php | 98 +++++++++++++++++++++++ module/gitlab/css/browsetagpriv.css | 7 ++ module/gitlab/js/browsetagpriv.js | 17 ++++ module/gitlab/lang/en.php | 5 ++ module/gitlab/lang/zh-cn.php | 5 ++ module/gitlab/model.php | 53 +++++++++++- module/gitlab/view/browsetagpriv.html.php | 80 ++++++++++++++++++ module/group/lang/resource.php | 2 + module/mr/view/link.html.php | 2 +- 11 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 module/gitlab/css/browsetagpriv.css create mode 100644 module/gitlab/js/browsetagpriv.js create mode 100644 module/gitlab/view/browsetagpriv.html.php diff --git a/module/action/lang/en.php b/module/action/lang/en.php index 445d378656..5577a82341 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -126,6 +126,7 @@ $lang->action->objectTypes['gitlabgroup'] = 'GitLab Group'; $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch'; $lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches'; $lang->action->objectTypes['gitlabtag'] = 'GitLab Tag'; +$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected'; $lang->action->objectTypes['kanbanspace'] = 'Kanban Space'; $lang->action->objectTypes['kanban'] = 'Kanban'; $lang->action->objectTypes['kanbanregion'] = 'Kanban Region'; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index 9285bf0bb9..264b9ef824 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -126,6 +126,7 @@ $lang->action->objectTypes['gitlabgroup'] = 'GitLab群组'; $lang->action->objectTypes['gitlabbranch'] = 'GitLab分支'; $lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab保护分支'; $lang->action->objectTypes['gitlabtag'] = 'GitLab标签'; +$lang->action->objectTypes['gitlabtagpriv'] = 'GitLab标签保护'; $lang->action->objectTypes['kanbanspace'] = '看板空间'; $lang->action->objectTypes['kanban'] = '看板'; $lang->action->objectTypes['kanbanregion'] = '看板区域'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index a56097db8f..23a991f8c1 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -974,6 +974,104 @@ class gitlab extends control $this->display(); } + /** + * Browse gitlab protect tag. + * + * @param int $gitlabID + * @param int $projectID + * @param string $orderBy + * @param int $recTotal + * @param int $recPerPage + * @param int $pageID + * @access public + * @return void + */ + public function browseTagPriv($gitlabID, $projectID, $orderBy = 'name_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) + { + $this->session->set('gitlabTagPrivList', $this->app->getURI(true)); + $keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword'); + + $gitlabTags = array(); + $allTags = $this->gitlab->apiGetTags($gitlabID, $projectID); + foreach($allTags as $tag) + { + $gitlabTags[$tag->name] = $tag; + } + + $tagList = array(); + $gitlabProtectTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID); + foreach($gitlabProtectTags as $gitlabProtectTag) + { + $tag = new stdClass(); + $tag->name = $gitlabProtectTag->name; + $tag->lastCommitter = isset($gitlabTags[$tag->name]) ? $gitlabTags[$tag->name]->commit->committer_name : ''; + $tag->accessLevels = $gitlabProtectTag->create_access_levels; + + $tagList[] = $tag; + } + + /* Data search. */ + if($keyword) + { + foreach($tagList as $key => $tag) + { + if(strpos($tag->name, $keyword) === false) unset($tagList[$key]); + } + $tagList = array_values($tagList); + } + + /* Data sort. */ + list($order, $sort) = explode('_', $orderBy); + $orderList = array(); + foreach($tagList as $tag) + { + $orderList[] = $tag->$order; + } + array_multisort($orderList, $sort == 'desc' ? SORT_DESC : SORT_ASC, $tagList); + + /* Pager. */ + $this->app->loadClass('pager', $static = true); + $recTotal = count($tagList); + $pager = new pager($recTotal, $recPerPage, $pageID); + $tagList = array_chunk($tagList, $pager->recPerPage); + + $this->view->gitlab = $this->gitlab->getByID($gitlabID); + $this->view->pager = $pager; + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseTagPriv; + $this->view->levelLang = $this->lang->gitlab->branch->branchCreationLevelList; + $this->view->gitlabID = $gitlabID; + $this->view->projectID = $projectID; + $this->view->keyword = $keyword; + $this->view->project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + $this->view->gitlabTagList = empty($tagList) ? $tagList: $tagList[$pageID - 1]; + $this->view->orderBy = $orderBy; + $this->display(); + } + + /** + * Delete a gitlab protect tag. + * + * @param int $gitlabID + * @param int $projectID + * @param string $tag + * @access public + * @return void + */ + public function deleteTagPriv($gitlabID, $projectID, $tag) + { + $tag = base64_decode($tag); + $reponse = $this->gitlab->apiDeleteTagPriv($gitlabID, $projectID, $tag); + + /* If the status code beginning with 20 is returned or empty is returned, it is successful. */ + if(!$reponse or substr($reponse->message, 0, 2) == '20') + { + $this->loadModel('action')->create('gitlabtagpriv', 0, 'deleted', '', $tag); + die(js::reload('parent')); + } + + die(js::alert($reponse->message)); + } + /** * Import gitlab issue to zentaopms. * diff --git a/module/gitlab/css/browsetagpriv.css b/module/gitlab/css/browsetagpriv.css new file mode 100644 index 0000000000..671f36d275 --- /dev/null +++ b/module/gitlab/css/browsetagpriv.css @@ -0,0 +1,7 @@ +.text-c-counts > span {margin-left: 5px;} +#mainMenu .pull-left {margin-right: 15px;} +.c-actions-1 {width: 60px;} + +#gitlabTagList .text-c-name .has-prefix{position: relative; display: flex; align-items: center;} +#gitlabTagList .text-c-name .label {flex: none;} +#gitlabTagList .text-c-name .tag-name {display: inline-block; max-width: calc(100% - 50px); padding-right: 10px;} diff --git a/module/gitlab/js/browsetagpriv.js b/module/gitlab/js/browsetagpriv.js new file mode 100644 index 0000000000..68a15f6a9f --- /dev/null +++ b/module/gitlab/js/browsetagpriv.js @@ -0,0 +1,17 @@ +$(document).ready(function() +{ + $('#tagSearch').click(function() + { + triggerSearch(); + }); + $('#keyword').keypress(function(event) + { + if(event.which == 13) triggerSearch(); + }) + +}); + +function triggerSearch() +{ + $("#tagForm").submit(); +} diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 48b3fadaec..836580879c 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -55,6 +55,9 @@ $lang->gitlab->editBranchPriv = 'Edit branch protected'; $lang->gitlab->deleteBranchPriv = 'Delete branch protected'; $lang->gitlab->createTag = 'Create Tag'; $lang->gitlab->deleteTag = 'Delete tag'; +$lang->gitlab->createTagPriv = 'Add tag protected'; +$lang->gitlab->editTagPriv = 'Edit tag protected'; +$lang->gitlab->deleteTagPriv = 'Delete tag protected'; $lang->gitlab->id = 'ID'; $lang->gitlab->name = "GitLab Name"; @@ -219,3 +222,5 @@ $lang->gitlab->tag->emptyRefError = "Create from cannot be empty."; $lang->gitlab->tag->issetNameError = "The tag already exists"; $lang->gitlab->tag->confirmDelete = 'Do you want to delete this GitLab tag?'; $lang->gitlab->tag->protected = 'Protected'; +$lang->gitlab->tag->accessLevel = 'Allow creation'; +$lang->gitlab->tag->protectConfirmDel = 'Do you want to delete this GitLab tag protected?'; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 4a147bb5bc..a5dc16191b 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -55,6 +55,9 @@ $lang->gitlab->editBranchPriv = '编辑分支保护'; $lang->gitlab->deleteBranchPriv = '删除分支保护'; $lang->gitlab->createTag = '创建标签'; $lang->gitlab->deleteTag = '删除标签'; +$lang->gitlab->createTagPriv = '添加标签保护'; +$lang->gitlab->editTagPriv = '编辑标签保护'; +$lang->gitlab->deleteTagPriv = '删除标签保护'; $lang->gitlab->id = 'ID'; $lang->gitlab->name = "{$lang->gitlab->common}名称"; @@ -219,3 +222,5 @@ $lang->gitlab->tag->emptyRefError = "创建自不能为空"; $lang->gitlab->tag->issetNameError = "已存在该标签"; $lang->gitlab->tag->confirmDelete = '确认删除该GitLab标签吗?'; $lang->gitlab->tag->protected = '受保护'; +$lang->gitlab->tag->accessLevel = '允许创建'; +$lang->gitlab->tag->protectConfirmDel = '确认删除该GitLab标签保护吗?'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 6878bbd7fa..de7d38d12a 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1485,8 +1485,16 @@ class gitlabModel extends model if(!$pager) { - $url = sprintf($apiRoot, "/projects/{$projectID}/repository/tags"); - return json_decode(commonModel::http($url)); + $allResults = array(); + $url = sprintf($apiRoot, "/projects/{$projectID}/repository/tags"); + for($page = 1; true; $page++) + { + $results = json_decode(commonModel::http($url . "&&page={$page}&per_page=100")); + if(!empty($results)) $allResults = array_merge($allResults, $results); + if(count($results)<100) break; + } + + return $allResults; } else { @@ -1521,6 +1529,47 @@ class gitlabModel extends model return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } + /** + * Get protect tags of one project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function apiGetTagPrivs($gitlabID, $projectID) + { + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/protected_tags"); + + $allResults = array(); + for($page = 1; true; $page++) + { + $results = json_decode(commonModel::http($url . "&&page={$page}&per_page=100")); + if(!empty($results)) $allResults = array_merge($allResults, $results); + if(count($results)<100) break; + } + + return $allResults; + } + + /** + * Delete a gitab protect tag by api. + * + * @param int $gitlabID + * @param int $projectID + * @param string $tag + * @access public + * @return object + */ + public function apiDeleteTagPriv($gitlabID, $projectID, $tag) + { + if(empty($gitlabID)) return false; + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}/protected_tags/{$tag}"); + return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); + } + /** * Check webhook token by HTTP_X_GITLAB_TOKEN. * diff --git a/module/gitlab/view/browsetagpriv.html.php b/module/gitlab/view/browsetagpriv.html.php new file mode 100644 index 0000000000..2422e598b9 --- /dev/null +++ b/module/gitlab/view/browsetagpriv.html.php @@ -0,0 +1,80 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +recTotal}&recPerPage={$pager->recPerPage}&pageID=1")?> + + + +
+

+ noData;?> + + createLink('gitlab', 'createTagPriv', "gitlabID=$gitlabID&projectID=$projectID"), " " . $lang->gitlab->createTagPriv, '', "class='btn btn-info'");?> + +

+
+ +
+
+ + recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?> + + + + + + + + + + $gitlabTag): ?> + accessLevel = $this->gitlab->checkAccessLevel($gitlabTag->accessLevels); ?> + + + + + + + + +
gitlab->tag->name);?>gitlab->tag->lastCommitter;?>gitlab->tag->accessLevel);?>actions;?>
name;?>lastCommitter;?>accessLevel];?> + name}", " ", '', "title={$lang->gitlab->editTagPriv} class='btn btn-primary'"); + common::printLink('gitlab', 'deleteTagPriv', "gitlabID=$gitlabID&projectID={$projectID}&tag_name=" . urlencode(base64_encode($gitlabTag->name)), " ", '', "title='{$lang->gitlab->deleteTagPriv}' class='btn btn-primary' target='hiddenwin' onclick='if(confirm(\"{$lang->gitlab->tag->protectConfirmDel}\")==false) return false;'"); + ?> +
+ + + +
+
+ + diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 6f33dc7a05..d7b741b1aa 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -1341,6 +1341,7 @@ $lang->resource->gitlab->browseTag = 'browseTag'; $lang->resource->gitlab->createTag = 'createTag'; $lang->resource->gitlab->deleteTag = 'deleteTag'; $lang->resource->gitlab->browseTagPriv = 'browseTagPriv'; +$lang->resource->gitlab->deleteTagPriv = 'deleteTagPriv'; $lang->gitlab->methodOrder[5] = 'browse'; $lang->gitlab->methodOrder[10] = 'create'; @@ -1369,6 +1370,7 @@ $lang->gitlab->methodOrder[125] = 'createWebhook'; $lang->gitlab->methodOrder[130] = 'manageProjectMembers'; $lang->gitlab->methodOrder[135] = 'browseTag'; $lang->gitlab->methodOrder[140] = 'browseTagPriv'; +$lang->gitlab->methodOrder[145] = 'deleteTagPriv'; /* merge request. */ $lang->resource->mr = new stdclass(); diff --git a/module/mr/view/link.html.php b/module/mr/view/link.html.php index ca9c0c33bf..b62ff14399 100644 --- a/module/mr/view/link.html.php +++ b/module/mr/view/link.html.php @@ -230,7 +230,7 @@ id);?> task->priList, $task->pri, $task->pri);?> - createLink('task', 'view', "taskID=$task->id"), $task->name, '', 'data-app="product"');?> + createLink('task', 'view', "taskID=$task->id"), $task->name);?> finishedBy);?> assignedTo);?> From 3bfc8e04c19f5485af0aa161d361e8973d660395 Mon Sep 17 00:00:00 2001 From: zenggang Date: Thu, 30 Dec 2021 05:24:37 +0000 Subject: [PATCH 2/2] * Adjust code --- module/gitlab/control.php | 24 ++++++++++------------- module/gitlab/model.php | 2 +- module/gitlab/view/browsetagpriv.html.php | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 23a991f8c1..c506b45f9c 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -1023,10 +1023,7 @@ class gitlab extends control /* Data sort. */ list($order, $sort) = explode('_', $orderBy); $orderList = array(); - foreach($tagList as $tag) - { - $orderList[] = $tag->$order; - } + foreach($tagList as $tag) $orderList[] = $tag->$order; array_multisort($orderList, $sort == 'desc' ? SORT_DESC : SORT_ASC, $tagList); /* Pager. */ @@ -1035,16 +1032,15 @@ class gitlab extends control $pager = new pager($recTotal, $recPerPage, $pageID); $tagList = array_chunk($tagList, $pager->recPerPage); - $this->view->gitlab = $this->gitlab->getByID($gitlabID); - $this->view->pager = $pager; - $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseTagPriv; - $this->view->levelLang = $this->lang->gitlab->branch->branchCreationLevelList; - $this->view->gitlabID = $gitlabID; - $this->view->projectID = $projectID; - $this->view->keyword = $keyword; - $this->view->project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - $this->view->gitlabTagList = empty($tagList) ? $tagList: $tagList[$pageID - 1]; - $this->view->orderBy = $orderBy; + $this->view->gitlab = $this->gitlab->getByID($gitlabID); + $this->view->pager = $pager; + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseTagPriv; + $this->view->gitlabID = $gitlabID; + $this->view->projectID = $projectID; + $this->view->keyword = $keyword; + $this->view->project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + $this->view->gitlabTagList = empty($tagList) ? $tagList: $tagList[$pageID - 1]; + $this->view->orderBy = $orderBy; $this->display(); } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index de7d38d12a..16e301c74d 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -1535,7 +1535,7 @@ class gitlabModel extends model * @param int $gitlabID * @param int $projectID * @access public - * @return void + * @return array */ public function apiGetTagPrivs($gitlabID, $projectID) { diff --git a/module/gitlab/view/browsetagpriv.html.php b/module/gitlab/view/browsetagpriv.html.php index 2422e598b9..ec8a5bd065 100644 --- a/module/gitlab/view/browsetagpriv.html.php +++ b/module/gitlab/view/browsetagpriv.html.php @@ -60,7 +60,7 @@ name;?> lastCommitter;?> - accessLevel];?> + gitlab->branch->branchCreationLevelList, $gitlabTag->accessLevel);?> name}", " ", '', "title={$lang->gitlab->editTagPriv} class='btn btn-primary'");