From 775f065069b97cbdb09f2d4da02bb1095dea27bb Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 7 Nov 2023 13:49:47 +0800 Subject: [PATCH] + Add managetagpriv page for gitlab. --- module/gitlab/control.php | 16 +++----- module/gitlab/js/managetagpriv.ui.js | 26 +++++++++++++ module/gitlab/model.php | 6 ++- module/gitlab/ui/managetagpriv.html.php | 50 +++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 module/gitlab/js/managetagpriv.ui.js create mode 100644 module/gitlab/ui/managetagpriv.html.php diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 67553c630a..128d74e31d 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -1486,10 +1486,7 @@ class gitlab extends control } $hasAccessTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID, '', 'name_asc'); - foreach($hasAccessTags as $tag) - { - $tag->createAccess = $this->gitlab->checkAccessLevel($tag->create_access_levels); - } + foreach($hasAccessTags as $tag) $tag->createAccess = $this->gitlab->checkAccessLevel($tag->create_access_levels); if(!empty($_POST)) { @@ -1498,18 +1495,15 @@ class gitlab extends control return $this->send(array('message' => $this->lang->saveSuccess, 'result' => 'success', 'locate' => inlink('browseProject', "gitlabID=$gitlabID"))); } - $allTags = $this->gitlab->apiGetTags($gitlabID, $projectID); - $noAccessTags = array(); - foreach($allTags as $tag) - { - if(!isset($hasAccessTags[$tag->name])) $noAccessTags[$tag->name] = $tag->name; - } + $allTags = $this->gitlab->apiGetTags($gitlabID, $projectID); + $tagPairs = array(); + foreach($allTags as $tag) $tagPairs[$tag->name] = $tag->name; $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseTagPriv; $this->view->gitlabID = $gitlabID; $this->view->projectID = $projectID; $this->view->hasAccessTags = $hasAccessTags; - $this->view->noAccessTags = $noAccessTags; + $this->view->tagPairs = $tagPairs; $this->display(); } } diff --git a/module/gitlab/js/managetagpriv.ui.js b/module/gitlab/js/managetagpriv.ui.js new file mode 100644 index 0000000000..3890e7f875 --- /dev/null +++ b/module/gitlab/js/managetagpriv.ui.js @@ -0,0 +1,26 @@ +window.getMenu = function(item) +{ + const selectedTags = []; + $('.pick-value[name^=name]').each(function() + { + const name = $(this).val(); + if(name) selectedTags.push(name); + }); + + item.disabled = selectedTags.includes(item.text); + return item; +} + +window.onRenderRow = function(row, rowIdx, data) +{ + if(!data) return; + + row.find('[data-name="name"]').find('.picker-box').on('inited', function(_, info) + { + if(hasAccessTags[data.name]) + { + const tags = [{text: data.name, value: data.name}]; + info[0].render({disabled: true, required: true, items: tags, defaultValue: data.name}); + } + }); +} diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0f3e38df24..9dfa7f46c1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2721,8 +2721,10 @@ class gitlabModel extends model */ public function manageTagPrivs($gitlabID, $projectID, $protected = array()) { - $data = (array)fixer::input('post')->get(); - extract($data); + $data = fixer::input('post')->get(); + $tags = $data->name; + $createLevels = $data->createAccess; + $failure = array(); /* Remove privs. */ diff --git a/module/gitlab/ui/managetagpriv.html.php b/module/gitlab/ui/managetagpriv.html.php new file mode 100644 index 0000000000..91de38fb92 --- /dev/null +++ b/module/gitlab/ui/managetagpriv.html.php @@ -0,0 +1,50 @@ + + * @package gitlab + * @link https://www.zentao.net + */ +namespace zin; + +jsVar('hasAccessTags', $hasAccessTags); +formBatchPanel +( + set::data(array_values($hasAccessTags)), + set::onRenderRow(jsRaw('onRenderRow')), + formBatchItem + ( + set::name('id'), + set::label('ID'), + set::control('index'), + set::width('50px'), + ), + formBatchItem + ( + set::label($lang->gitlab->tag->name), + set::width('1/3'), + set::name('name'), + set::control + ( + array( + 'type' => 'picker', + 'name' => 'name', + 'cache' => false, + 'items' => $tagPairs, + 'menu' => jsRaw('{getItem(item) {return getMenu(item)}}'), + ) + ) + ), + formBatchItem + ( + set::name('createAccess'), + set::label($lang->gitlab->tag->accessLevel), + set::control('picker'), + set::width('1/2'), + set::required(true), + set::items($lang->gitlab->branch->branchCreationLevelList) + ) +);