From 7945a8c8cbf63c73e2f05bf7b1e0b35dd0c7da53 Mon Sep 17 00:00:00 2001 From: zenggang Date: Fri, 5 Nov 2021 05:13:36 +0000 Subject: [PATCH] * Finish task#43841,43842,43843 --- module/gitlab/control.php | 81 ++++++++++++++++ module/gitlab/lang/en.php | 23 +++++ module/gitlab/lang/zh-cn.php | 23 +++++ module/gitlab/model.php | 108 ++++++++++++++++++++++ module/gitlab/view/browse.html.php | 3 +- module/gitlab/view/createproject.html.php | 56 +++++++++++ module/gitlab/view/editproject.html.php | 56 +++++++++++ module/gitlab/view/projectBrowse.html.php | 65 +++++++++++++ 8 files changed, 414 insertions(+), 1 deletion(-) create mode 100644 module/gitlab/view/createproject.html.php create mode 100644 module/gitlab/view/editproject.html.php create mode 100644 module/gitlab/view/projectBrowse.html.php diff --git a/module/gitlab/control.php b/module/gitlab/control.php index d2ef1b4cc0..998261ab9a 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -292,6 +292,87 @@ class gitlab extends control $this->display(); } + /** + * Browse gitlab project. + * + * @param int $gitlabID + * @access public + * @return void + */ + public function projectbrowse($gitlabID) + { + $this->view->gitlabID = $gitlabID; + $this->view->gitlabProjectList = $this->gitlab->apiGetProjects($gitlabID); + $this->display(); + } + + /** + * Creat a gitlab project. + * + * @param int $gitlabID + * @access public + * @return void + */ + public function createProject($gitlabID) + { + if($_POST) + { + $this->gitlab->createProject($gitlabID); + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('projectbrowse', "gitlabID=$gitlabID"))); + } + + $gitlab = $this->gitlab->getByID($gitlabID); + $user = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token); + + $this->view->gitlab = $gitlab; + $this->view->user = $user; + $this->view->gitlabID = $gitlabID; + $this->display(); + } + + /** + * Edit a gitlab project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function editProject($gitlabID, $projectID) + { + if($_POST) + { + $this->gitlab->editProject($gitlabID); + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('projectbrowse', "gitlabID=$gitlabID"))); + } + + $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); + $this->view->project = $project; + $this->view->gitlabID = $gitlabID; + $this->display(); + } + + /** + * Delete a gitlab project. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return void + */ + public function deleteProject($gitlabID, $projectID, $confirm = 'no') + { + if($confirm != 'yes') die(js::confirm($this->lang->gitlab->project->confirmDelete , inlink('deleteProject', "gitlabID=$gitlabID&projectID=$projectID&confirm=yes"))); + + $reponse = $this->gitlab->apiDeleteProject($gitlabID, $projectID); + if(substr($reponse->message, 0, 2) == '20') die(js::reload('parent')); + die(js::alert($reponse->message)); + } + /** * Import gitlab issue to zentaopms. * diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 454f6fa584..dc61ff4306 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -16,10 +16,12 @@ $lang->gitlab->zentaoAccount = 'Zentao Account'; $lang->gitlab->bindingStatus = 'Binding Status'; $lang->gitlab->binded = 'Binded'; $lang->gitlab->serverFail = 'Connect to GitLab server failed, please check the GitLab server.'; +$lang->gitlab->lastUpdate = 'Last Update'; $lang->gitlab->browseAction = 'GitLab List'; $lang->gitlab->deleteAction = 'Delete GitLab'; $lang->gitlab->gitlabProject = "GitLab Project"; +$lang->gitlab->browseProject = "GitLab Project List"; $lang->gitlab->gitlabIssue = "GitLab Issue"; $lang->gitlab->zentaoProduct = 'Zentao Product'; $lang->gitlab->objectType = 'Type'; // task, bug, story @@ -48,3 +50,24 @@ $lang->gitlab->hostError = "Invalid GitLab service address."; $lang->gitlab->bindUserError = "Can not bind users repeatedly %s"; $lang->gitlab->importIssueError = "The execution to which this issue belongs is not selected."; $lang->gitlab->importIssueWarn = "There is a problem of import failure, you can try to import again."; + +$lang->gitlab->project = new stdclass; +$lang->gitlab->project->id = "Project ID"; +$lang->gitlab->project->name = "Project name"; +$lang->gitlab->project->create = "Create {$lang->gitlab->gitlabProject}"; +$lang->gitlab->project->edit = "Edit {$lang->gitlab->gitlabProject}"; +$lang->gitlab->project->url = "Project URL"; +$lang->gitlab->project->path = "Project slug"; +$lang->gitlab->project->description = "Project description"; +$lang->gitlab->project->visibility = "Visibility Level"; +$lang->gitlab->project->visibilityList['private'] = "Private(Project access must be granted explicitly to each user. If this project is part of a group, access will be granted to members of the group)"; +$lang->gitlab->project->visibilityList['internal'] = "Internal(The project can be accessed by any logged in user except external users)"; +$lang->gitlab->project->visibilityList['public'] = "Public(The project can be accessed without any authentication)"; +$lang->gitlab->project->star = "Stars"; +$lang->gitlab->project->fork = "Forks"; +$lang->gitlab->project->mergeRequests = "Merge Requests"; +$lang->gitlab->project->issues = "Issues"; +$lang->gitlab->project->tagList = "Topics"; +$lang->gitlab->project->tagListTips = "Separate topics with commas."; +$lang->gitlab->project->emptyError = "Project name or slug cannot be empty"; +$lang->gitlab->project->confirmDelete = 'Do you want to delete this GitLab project?'; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 8df7c03543..f4cd473cb3 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -16,10 +16,12 @@ $lang->gitlab->zentaoAccount = '禅道用户'; $lang->gitlab->bindingStatus = '绑定状态'; $lang->gitlab->binded = '已绑定'; $lang->gitlab->serverFail = '连接GitLab服务器异常,请检查GitLab服务器。'; +$lang->gitlab->lastUpdate = '最后更新'; $lang->gitlab->browseAction = 'GitLab列表'; $lang->gitlab->deleteAction = '删除GitLab'; $lang->gitlab->gitlabProject = "{$lang->gitlab->common}项目"; +$lang->gitlab->browseProject = "{$lang->gitlab->common}项目列表"; $lang->gitlab->gitlabIssue = "{$lang->gitlab->common} issue"; $lang->gitlab->zentaoProduct = '禅道产品'; $lang->gitlab->objectType = '类型'; // task, bug, story @@ -48,3 +50,24 @@ $lang->gitlab->hostError = "无效的GitLab服务地址。"; $lang->gitlab->bindUserError = "不能重复绑定用户 %s"; $lang->gitlab->importIssueError = "未选择该issue所属的执行。"; $lang->gitlab->importIssueWarn = "存在导入失败的issue,可再次尝试导入。"; + +$lang->gitlab->project = new stdclass; +$lang->gitlab->project->id = "项目ID"; +$lang->gitlab->project->name = "项目名称"; +$lang->gitlab->project->create = "添加{$lang->gitlab->gitlabProject}"; +$lang->gitlab->project->edit = "编辑{$lang->gitlab->gitlabProject}"; +$lang->gitlab->project->url = "项目 URL"; +$lang->gitlab->project->path = "项目标识串"; +$lang->gitlab->project->description = "项目描述"; +$lang->gitlab->project->visibility = "可见性级别"; +$lang->gitlab->project->visibilityList['private'] = "私有(项目访问必须明确授予每个用户。 如果此项目是在一个群组中,群组成员将会获得访问权限)"; +$lang->gitlab->project->visibilityList['internal'] = "内部(除外部用户外,任何登录用户均可访问该项目)"; +$lang->gitlab->project->visibilityList['public'] = "公开(该项目允许任何人访问)"; +$lang->gitlab->project->star = "星标"; +$lang->gitlab->project->fork = "派生"; +$lang->gitlab->project->mergeRequests = "合并请求"; +$lang->gitlab->project->issues = "议题"; +$lang->gitlab->project->tagList = "主题"; +$lang->gitlab->project->tagListTips = "用逗号分隔主题。"; +$lang->gitlab->project->emptyError = "项目名称或标识符不能为空"; +$lang->gitlab->project->confirmDelete = '确认删除该GitLab项目吗?'; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 87d00e6bd4..b377305f84 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -495,6 +495,57 @@ class gitlabModel extends model return $allResults; } + /** + * Create a gitab project by api. + * + * @param int $gitlabID + * @param object $project + * @access public + * @return object + */ + public function apiCreateProject($gitlabID, $project) + { + if(empty($project->name) and empty($project->path)) return false; + + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects"); + return json_decode(commonModel::http($url, $project)); + } + + /** + * Update a gitab project by api. + * + * @param int $gitlabID + * @param object $project + * @access public + * @return object + */ + public function apiUpdateProject($gitlabID, $project) + { + if(empty($project->id)) return false; + + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$project->id}"); + return json_decode(commonModel::http($url, $project, $options = array(CURLOPT_CUSTOMREQUEST => 'PUT'))); + } + + /** + * Delete a gitab project by api. + * + * @param int $gitlabID + * @param int $projectID + * @access public + * @return object + */ + public function apiDeleteProject($gitlabID, $projectID) + { + if(empty($projectID)) return false; + + $apiRoot = $this->getApiRoot($gitlabID); + $url = sprintf($apiRoot, "/projects/{$projectID}"); + return json_decode(commonModel::http($url, $project, $options = array(CURLOPT_CUSTOMREQUEST => 'DELETE'))); + } + /** * Get single project by API. * @@ -1550,4 +1601,61 @@ class gitlabModel extends model } return $object; } + + /** + * Create gitlab project. + * + * @param int $gitlabID + * @access public + * @return bool + */ + public function createProject($gitlabID) + { + $project = fixer::input('post')->get(); + if(empty($project->name) and empty($project->path)) dao::$errors['name'][] = $this->lang->gitlab->project->emptyError; + if(dao::isError()) return false; + + $reponse = $this->apiCreateProject($gitlabID, $project); + + if($reponse->id) return TRUE; + foreach($reponse->message as $field => $fieldErrors) + { + foreach($fieldErrors as $error) + { + if($error) dao::$errors[$field][] = $error; + } + } + if(!$reponse) dao::$errors[] = false; + } + + /** + * Edit gitlab project. + * + * @param int $gitlabID + * @access public + * @return bool + */ + public function editProject($gitlabID) + { + $project = fixer::input('post')->get(); + if(empty($project->name)) dao::$errors['name'][] = $this->lang->gitlab->project->emptyError; + if(dao::isError()) return false; + + $reponse = $this->apiUpdateProject($gitlabID, $project); + + if($reponse->id) return TRUE; + if(is_string($reponse->message)) dao::$errors[] = $reponse->message; + else + { + foreach($reponse->message as $field => $fieldErrors) + { + foreach($fieldErrors as $error) + { + if($error) dao::$errors[$field][] = $error; + } + } + } + + if(!$reponse) dao::$errors[] = false; + } } diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index 07ebd9f40d..0e18af3bf9 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -35,7 +35,7 @@ gitlab->id);?> gitlab->name);?> gitlab->url);?> - actions;?> + actions;?> @@ -47,6 +47,7 @@ isAdminToken) ? '' : 'disabled'; + common::printLink('gitlab', 'projectBrowse', "gitlabID=$id", " ", '',"title={$lang->gitlab->browseProject} class='btn btn-primary'"); common::printLink('gitlab', 'edit', "gitlabID=$id", " ", '',"title={$lang->gitlab->edit} class='btn btn-primary'"); common::printLink('gitlab', 'bindUser', "id=$id", " ", '', "title={$lang->gitlab->bindUser} class='btn {$disabled}' ,'disabled'"); if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'delete', "gitlabID=$id"), '', 'hiddenwin', "title='{$lang->gitlab->delete}' class='btn'"); diff --git a/module/gitlab/view/createproject.html.php b/module/gitlab/view/createproject.html.php new file mode 100644 index 0000000000..ce15a9dd0e --- /dev/null +++ b/module/gitlab/view/createproject.html.php @@ -0,0 +1,56 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + +
+
+
+
+

gitlab->project->create;?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
gitlab->project->name;?>gitlab->project->name}'");?>
gitlab->project->url;?>url . '/' . $user->username . '/', "class='form-control' disabled");?>
gitlab->project->path;?>gitlab->project->path}'");?>
gitlab->project->description;?>gitlab->project->description}'");?>
gitlab->project->visibility;?>gitlab->project->visibilityList, 'private', "", 'block'));?>
+ + goback, '', 'class="btn btn-wide"');?> +
+
+
+
+
+ diff --git a/module/gitlab/view/editproject.html.php b/module/gitlab/view/editproject.html.php new file mode 100644 index 0000000000..6bc13f3a5c --- /dev/null +++ b/module/gitlab/view/editproject.html.php @@ -0,0 +1,56 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + +
+
+
+
+

gitlab->project->edit;?>

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
gitlab->project->id;?>id, "class='form-control' readonly placeholder='{$lang->gitlab->project->id}'");?>
gitlab->project->name;?>name, "class='form-control' placeholder='{$lang->gitlab->project->name}'");?>
gitlab->project->tagList;?>tag_list), "class='form-control'");?>gitlab->project->tagListTips;?>
gitlab->project->description;?>description, "rows='10' class='form-control' placeholder='{$lang->gitlab->project->description}'");?>
gitlab->project->visibility;?>gitlab->project->visibilityList, $project->visibility, "", 'block'));?>
+ + goback, '', 'class="btn btn-wide"');?> +
+
+
+
+
+ diff --git a/module/gitlab/view/projectBrowse.html.php b/module/gitlab/view/projectBrowse.html.php new file mode 100644 index 0000000000..9c904456a8 --- /dev/null +++ b/module/gitlab/view/projectBrowse.html.php @@ -0,0 +1,65 @@ + + * @package gitlab + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + +
+

+ noData;?> + + createLink('gitlab', 'createProject', "gitlabID=$gitlabID"), " " . $lang->gitlab->project->create, '', "class='btn btn-info'");?> + +

+
+ +
+
+ + + + recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?> + + + + + + + + + $gitlabProject): ?> + + + + + + + + + +
gitlab->project->id;?>gitlab->project->name;?>gitlab->lastUpdate;?>actions;?>
id;?>name;?> + star_count;?> + forks_count;?> + last_activity_at, 0, 10);?> + id", " ", '', "title={$lang->gitlab->edit} class='btn btn-primary'"); + if(common::hasPriv('gitlab', 'delete')) echo html::a($this->createLink('gitlab', 'deleteProject', "gitlabID=$gitlabID&projectID=$gitlabProject->id"), '', 'hiddenwin', "title='{$lang->gitlab->project->confirmDelete}' class='btn'"); + ?> +
+
+
+ +