diff --git a/api/v1/entries/gitlabWebhook.php b/api/v1/entries/gitlabwebhook.php similarity index 93% rename from api/v1/entries/gitlabWebhook.php rename to api/v1/entries/gitlabwebhook.php index 2a416234d8..148a679abd 100644 --- a/api/v1/entries/gitlabWebhook.php +++ b/api/v1/entries/gitlabwebhook.php @@ -20,8 +20,8 @@ class gitlabWebhookEntry extends baseEntry */ public function post() { - $repoID= $this->param('repoID'); - if(empty($id)) return; + $repoID = $this->param('repoID'); + if(empty($repoID)) return; $this->loadModel('repo'); diff --git a/module/gitlab/control.php b/module/gitlab/control.php index c506b45f9c..9bdf308131 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -845,6 +845,7 @@ class gitlab extends control */ public function createBranchPriv($gitlabID, $projectID, $branch = '') { + if($branch) $branch = base64_decode($branch); if($_POST) { $this->gitlab->createBranchPriv($gitlabID, $projectID, $branch); @@ -916,6 +917,7 @@ class gitlab extends control { if($confirm != 'yes') die(js::confirm($this->lang->gitlab->branch->confirmDelete , inlink('deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch&confirm=yes"))); + $branch = base64_decode($branch); $reponse = $this->gitlab->apiDeleteBranchPriv($gitlabID, $projectID, $branch); /* If the status code beginning with 20 is returned or empty is returned, it is successful. */ @@ -1044,6 +1046,73 @@ class gitlab extends control $this->display(); } + /** + * Set a gitlab protect tag. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function createTagPriv($gitlabID, $projectID) + { + if($_POST) + { + $this->gitlab->createTagPriv($gitlabID, $projectID); + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseTagPriv', "gitlabID=$gitlabID&projectID=$projectID"))); + } + + $gitlabTags = $this->gitlab->apiGetTags($gitlabID, $projectID); + $protectTags = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, '', 'name_asc'); + $protectNames = array_keys($protectBranches); + + $tags = array(); + foreach($gitlabTags as $tag) + { + if(!in_array($tag->name, $protectNames)) $tags[$tag->name] = $tag->name; + } + + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->createTagPriv; + $this->view->gitlabID = $gitlabID; + $this->view->projectID = $projectID; + $this->view->tags = $tags; + $this->display(); + } + + /** + * Edit a gitlab protect tag. + * + * @param int $gitlabID + * @param int $projectID + * @param string $tag + * @access public + * @return void + */ + public function editTagPriv($gitlabID, $projectID, $tag = '') + { + $tag = base64_decode($tag); + + if($_POST) + { + $this->gitlab->createTagPriv($gitlabID, $projectID, $tag); + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseTagPriv', "gitlabID=$gitlabID&projectID=$projectID"))); + } + + $tagPriv = $this->gitlab->apiGetSingleTagPriv($gitlabID, $projectID, $tag); + $tagPriv->createAccessLevel = $this->gitlab->checkAccessLevel($tagPriv->create_access_levels); + + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->editTagPriv; + $this->view->gitlabID = $gitlabID; + $this->view->projectID = $projectID; + $this->view->tagPriv = $tagPriv; + $this->view->tag = $tag; + $this->display(); + } + /** * Delete a gitlab protect tag. * @@ -1466,6 +1535,7 @@ class gitlab extends control { if($confirm != 'yes') die(js::confirm($this->lang->gitlab->tag->confirmDelete , inlink('deleteTag', "gitlabID=$gitlabID&projectID=$projectID&tagName=$tagName&confirm=yes"))); + $tagName = base64_decode($tagName); $reponse = $this->gitlab->apiDeleteTag($gitlabID, $projectID, $tagName); /* If the status code beginning with 20 is returned or empty is returned, it is successful. */ diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 836580879c..dda54c7e78 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -55,7 +55,7 @@ $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->createTagPriv = 'Create tag protected'; $lang->gitlab->editTagPriv = 'Edit tag protected'; $lang->gitlab->deleteTagPriv = 'Delete tag protected'; @@ -211,16 +211,18 @@ $lang->gitlab->branch->emptyPrivNameError = "Branch cannot be empty."; $lang->gitlab->branch->issetPrivNameError = "The protection branch already exists"; $lang->gitlab->tag = new stdclass(); -$lang->gitlab->tag->name = 'Tag name'; -$lang->gitlab->tag->ref = 'Create from'; -$lang->gitlab->tag->lastCommitter = 'Last Committer'; -$lang->gitlab->tag->lastCommittedDate = 'Last Committed Date'; -$lang->gitlab->tag->placeholderSearch = "Enter branch tag"; -$lang->gitlab->tag->message = 'Message'; -$lang->gitlab->tag->emptyNameError = "Name cannot be empty."; -$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?'; +$lang->gitlab->tag->name = 'Tag name'; +$lang->gitlab->tag->ref = 'Create from'; +$lang->gitlab->tag->lastCommitter = 'Last Committer'; +$lang->gitlab->tag->lastCommittedDate = 'Last Committed Date'; +$lang->gitlab->tag->placeholderSearch = "Enter branch tag"; +$lang->gitlab->tag->message = 'Message'; +$lang->gitlab->tag->emptyNameError = "Name cannot be empty."; +$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?'; +$lang->gitlab->tag->emptyPrivNameError = 'Tag cannot be empty.'; +$lang->gitlab->tag->issetPrivNameError = 'The protection tag already exists.'; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index a5dc16191b..82da87fc2c 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -55,7 +55,7 @@ $lang->gitlab->editBranchPriv = '编辑分支保护'; $lang->gitlab->deleteBranchPriv = '删除分支保护'; $lang->gitlab->createTag = '创建标签'; $lang->gitlab->deleteTag = '删除标签'; -$lang->gitlab->createTagPriv = '添加标签保护'; +$lang->gitlab->createTagPriv = '创建标签保护'; $lang->gitlab->editTagPriv = '编辑标签保护'; $lang->gitlab->deleteTagPriv = '删除标签保护'; @@ -211,16 +211,18 @@ $lang->gitlab->branch->emptyPrivNameError = "分支不能为空"; $lang->gitlab->branch->issetPrivNameError = "已存在该保护分支"; $lang->gitlab->tag = new stdclass(); -$lang->gitlab->tag->name = '标签名'; -$lang->gitlab->tag->ref = '创建自'; -$lang->gitlab->tag->lastCommitter = '最后提交'; -$lang->gitlab->tag->lastCommittedDate = '最后修改时间'; -$lang->gitlab->tag->placeholderSearch = "请输入标签名称"; -$lang->gitlab->tag->message = '信息'; -$lang->gitlab->tag->emptyNameError = "标签名不能为空"; -$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标签保护吗?'; +$lang->gitlab->tag->name = '标签名'; +$lang->gitlab->tag->ref = '创建自'; +$lang->gitlab->tag->lastCommitter = '最后提交'; +$lang->gitlab->tag->lastCommittedDate = '最后修改时间'; +$lang->gitlab->tag->placeholderSearch = "请输入标签名称"; +$lang->gitlab->tag->message = '信息'; +$lang->gitlab->tag->emptyNameError = "标签名不能为空"; +$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标签保护吗?'; +$lang->gitlab->tag->emptyPrivNameError = "标签不能为空"; +$lang->gitlab->tag->issetPrivNameError = "已存在该保护标签"; diff --git a/module/gitlab/lang/zh-tw.php b/module/gitlab/lang/zh-tw.php index b183b01247..cb886aeab1 100644 --- a/module/gitlab/lang/zh-tw.php +++ b/module/gitlab/lang/zh-tw.php @@ -54,6 +54,8 @@ $lang->gitlab->editBranchPriv = '編輯分支保護'; $lang->gitlab->deleteBranchPriv = '刪除分支保護'; $lang->gitlab->createTag = '創建標籤'; $lang->gitlab->deleteTag = '刪除標籤'; +$lang->gitlab->createTagPriv = '創建標簽保護'; +$lang->gitlab->editTagPriv = '編輯標簽保護'; $lang->gitlab->id = 'ID'; $lang->gitlab->name = "{$lang->gitlab->common}名稱"; @@ -207,14 +209,17 @@ $lang->gitlab->branch->emptyPrivNameError = "分支不能為空"; $lang->gitlab->branch->issetPrivNameError = "已存在該保護分支"; $lang->gitlab->tag = new stdclass(); -$lang->gitlab->tag->name = '標籤名'; -$lang->gitlab->tag->ref = '創建自'; -$lang->gitlab->tag->lastCommitter = '最後提交'; -$lang->gitlab->tag->lastCommittedDate = '最後修改時間'; -$lang->gitlab->tag->placeholderSearch = "請輸入標籤名稱"; -$lang->gitlab->tag->message = '信息'; -$lang->gitlab->tag->emptyNameError = "標籤名不能為空"; -$lang->gitlab->tag->emptyRefError = "創建自不能為空"; -$lang->gitlab->tag->issetNameError = "已存在該標籤"; -$lang->gitlab->tag->confirmDelete = '確認刪除該GitLab標籤嗎?'; -$lang->gitlab->tag->protected = '受保護'; +$lang->gitlab->tag->name = '標籤名'; +$lang->gitlab->tag->ref = '創建自'; +$lang->gitlab->tag->lastCommitter = '最後提交'; +$lang->gitlab->tag->lastCommittedDate = '最後修改時間'; +$lang->gitlab->tag->placeholderSearch = "請輸入標籤名稱"; +$lang->gitlab->tag->message = '信息'; +$lang->gitlab->tag->emptyNameError = "標籤名不能為空"; +$lang->gitlab->tag->emptyRefError = "創建自不能為空"; +$lang->gitlab->tag->issetNameError = "已存在該標籤"; +$lang->gitlab->tag->confirmDelete = '確認刪除該GitLab標籤嗎?'; +$lang->gitlab->tag->protected = '受保護'; +$lang->gitlab->tag->accessLevel = '允許創建'; +$lang->gitlab->tag->emptyPrivNameError = '標簽不能爲空'; +$lang->gitlab->tag->issetPrivNameError = '已存在該保護標簽'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 16e301c74d..e5098ae215 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2403,10 +2403,18 @@ class gitlabModel extends model { foreach($response->message as $field => $fieldErrors) { - foreach($fieldErrors as $error) + if(is_string($fieldErrors)) { - $errorKey = array_search($error, $this->lang->gitlab->apiError); - if($error) dao::$errors[$field][] = $errorKey === false ? $error : zget($this->lang->gitlab->errorLang, $errorKey); + $errorKey = array_search($fieldErrors, $this->lang->gitlab->apiError); + if($fieldErrors) dao::$errors[$field][] = $errorKey === false ? $fieldErrors : zget($this->lang->gitlab->errorLang, $errorKey); + } + else + { + foreach($fieldErrors as $error) + { + $errorKey = array_search($error, $this->lang->gitlab->apiError); + if($error) dao::$errors[$field][] = $errorKey === false ? $error : zget($this->lang->gitlab->errorLang, $errorKey); + } } } } @@ -2542,6 +2550,69 @@ class gitlabModel extends model return json_decode(commonModel::http($url, array(), $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); } + /** + * Create gitlab protect tag. + * + * @param int $gitlabID + * @param int $projectID + * @param string $tag + * @access public + * @return bool + */ + public function createTagPriv($gitlabID, $projectID, $tag = '') + { + $priv = fixer::input('post')->get(); + if(empty($priv->name)) dao::$errors['name'][] = $this->lang->gitlab->branch->emptyPrivNameError; + $singleTag = $this->apiGetSingleTagPriv($gitlabID, $projectID, $priv->name); + if(empty($tag) && !empty($singleTag->id)) dao::$errors['name'][] = $this->lang->gitlab->tag->issetPrivNameError; + if(dao::isError()) return false; + if(!empty($tag) && !empty($singleTag->name)) $this->apiDeleteTagPriv($gitlabID, $projectID, $tag); + + $response = $this->apiCreateTagPriv($gitlabID, $projectID, $priv); + + if(!empty($response->id)) + { + $action = empty($tag) ? 'created' : 'edited'; + $this->loadModel('action')->create('gitlabtagpriv', $response->id, $action, '', $response->name); + return true; + } + + return $this->apiErrorHandling($response); + } + + /** + * Get single protct tag by API. + * + * @param int $gitlabID + * @param int $projectID + * @param string $tag + * @access public + * @return object + */ + public function apiGetSingleTagPriv($gitlabID, $projectID, $tag) + { + if(empty($gitlabID)) return false; + $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/protected_tags/$tag"); + return json_decode(commonModel::http($url)); + } + + /** + * Create a gitab protect tag by api. + * + * @param int $gitlabID + * @param int $projectID + * @param object $priv + * @access public + * @return object + */ + public function apiCreateTagPriv($gitlabID, $projectID, $priv) + { + if(empty($gitlabID)) return false; + if(empty($priv->name)) return false; + $url = sprintf($this->getApiRoot($gitlabID), "/projects/" . $projectID . '/protected_tags'); + return json_decode(commonModel::http($url, $priv)); + } + /** * Check access level. * diff --git a/module/gitlab/view/browsebranchpriv.html.php b/module/gitlab/view/browsebranchpriv.html.php index 7023020575..88b606cd8f 100644 --- a/module/gitlab/view/browsebranchpriv.html.php +++ b/module/gitlab/view/browsebranchpriv.html.php @@ -62,8 +62,8 @@ push_access_level];?> name", " ", '', "title={$lang->gitlab->editBranchPriv} class='btn btn-primary'"); - if(common::hasPriv('gitlab', 'deleteBranchPriv')) echo html::a($this->createLink('gitlab', 'deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch->name"), '', 'hiddenwin', "title='{$lang->gitlab->deleteBranchPriv}' class='btn'"); + if(common::hasPriv('gitlab', 'editBranchPriv')) common::printLink('gitlab', 'editBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=" . urlencode(base64_encode($branch->name)), " ", '', "title={$lang->gitlab->editBranchPriv} class='btn btn-primary'"); + if(common::hasPriv('gitlab', 'deleteBranchPriv')) echo html::a($this->createLink('gitlab', 'deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=" . urlencode(base64_encode($branch->name))), '', 'hiddenwin', "title='{$lang->gitlab->deleteBranchPriv}' class='btn'"); ?> diff --git a/module/gitlab/view/browsetag.html.php b/module/gitlab/view/browsetag.html.php index 18e5a82442..233089a065 100644 --- a/module/gitlab/view/browsetag.html.php +++ b/module/gitlab/view/browsetag.html.php @@ -68,7 +68,7 @@ protected ? 'disabled' : ''; - common::printLink('gitlab', 'deleteTag', "gitlabID=$gitlabID&projectID={$projectID}&tag_name={$gitlabTag->name}", " ", '', "title='{$lang->gitlab->deleteTag}' class='btn btn-primary' target='hiddenwin' $isDisabled"); + common::printLink('gitlab', 'deleteTag', "gitlabID=$gitlabID&projectID={$projectID}&tag_name=" . urlencode(base64_encode($gitlabTag->name)), " ", '', "title='{$lang->gitlab->deleteTag}' class='btn btn-primary' target='hiddenwin' $isDisabled"); ?> diff --git a/module/gitlab/view/browsetagpriv.html.php b/module/gitlab/view/browsetagpriv.html.php index ec8a5bd065..228633c24f 100644 --- a/module/gitlab/view/browsetagpriv.html.php +++ b/module/gitlab/view/browsetagpriv.html.php @@ -63,7 +63,7 @@ gitlab->branch->branchCreationLevelList, $gitlabTag->accessLevel);?> name}", " ", '', "title={$lang->gitlab->editTagPriv} class='btn btn-primary'"); + common::printLink('gitlab', 'editTagPriv', "gitlabID=$gitlabID&projectID=$projectID&tag_name=" . urlencode(base64_encode($gitlabTag->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/gitlab/view/createtagpriv.html.php b/module/gitlab/view/createtagpriv.html.php new file mode 100644 index 0000000000..44296d5d22 --- /dev/null +++ b/module/gitlab/view/createtagpriv.html.php @@ -0,0 +1,43 @@ + + * @package gitlab + * @version $Id$ + * @link https://www.zentao.net + */ +?> + +
+
+
+
+

gitlab->createTagPriv;?>

+
+
+ + + + + + + + + + + + + + +
gitlab->tag->name;?>
gitlab->tag->accessLevel;?>gitlab->branch->branchCreationLevelList, '40', "class='form-control chosen'");?>
+ + goback, '', 'class="btn btn-wide"');?> +
+
+
+
+
+ diff --git a/module/gitlab/view/edittagpriv.html.php b/module/gitlab/view/edittagpriv.html.php new file mode 100644 index 0000000000..5074c304eb --- /dev/null +++ b/module/gitlab/view/edittagpriv.html.php @@ -0,0 +1,44 @@ + + * @package gitlab + * @version $Id$ + * @link https://www.zentao.net + */ +?> + +
+
+
+
+

gitlab->editTagPriv;?>

+
+
+ + + + + + + + + + + + + + + +
gitlab->tag->name;?>
gitlab->tag->accessLevel;?>gitlab->branch->branchCreationLevelList, $tagPriv->createAccessLevel, "class='form-control chosen'");?>
+ + goback, '', 'class="btn btn-wide"');?> +
+
+
+
+
+