* Finish task#46555

This commit is contained in:
zenggang
2021-12-30 03:08:42 +00:00
parent 6bbb031a07
commit bfde525f13
11 changed files with 268 additions and 3 deletions
+98
View File
@@ -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.
*