diff --git a/module/gitea/js/binduser.ui.js b/module/gitea/js/binduser.ui.js index 4bfcde782f..6969aa7757 100644 --- a/module/gitea/js/binduser.ui.js +++ b/module/gitea/js/binduser.ui.js @@ -15,7 +15,7 @@ window.renderGitlabUser = function(result, {row}) return result; } -window.bindUser = function() +window.bindUser = function(e) { const myDTable = $('#table-gitea-binduser').zui('dtable'); const formData = myDTable.$.getFormData(); @@ -25,10 +25,12 @@ window.bindUser = function() postData['giteaUserNames[]'] = []; for(i in bindData) { - postData['giteaUserNames[]'].push(bindData[i].giteaID); + postData['giteaUserNames[' + bindData[i].giteaID + ']'] = bindData[i].giteaUser; postData['zentaoUsers[' + bindData[i].giteaID + ']'] = formData['zentaoUsers[' + bindData[i].giteaID + ']']; } + e.preventDefault(); + e.stopPropagation(); $.ajaxSubmit({ url: $.createLink('gitea', 'bindUser', 'giteaID=' + giteaID + '&type=' + type), data: postData diff --git a/module/gitea/lang/zh-cn.php b/module/gitea/lang/zh-cn.php index 144da40f6c..7d97a58b62 100644 --- a/module/gitea/lang/zh-cn.php +++ b/module/gitea/lang/zh-cn.php @@ -41,3 +41,12 @@ $lang->gitea->server = "服务器列表"; $lang->gitea->lblCreate = '添加Gitea服务器'; $lang->gitea->emptyError = "不能为空"; $lang->gitea->createSuccess = "创建成功"; + +$lang->gitea->apiError = array(); +$lang->gitea->apiError[0] = 'The repository with the same name already exists.'; + +$lang->gitea->errorLang = array(); +$lang->gitea->errorLang[0] = '名称已存在。'; + +$lang->gitea->errorKey = array(); +$lang->gitea->errorKey[0] = 'name'; diff --git a/module/gitea/model.php b/module/gitea/model.php index b9a4d8605a..0e48069538 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -168,8 +168,7 @@ class giteaModel extends model { if(is_string($response->message)) { - $errorKey = array_search($response->message, $this->lang->gitea->apiError); - dao::$errors[] = $errorKey === false ? $response->message : zget($this->lang->gitea->errorLang, $errorKey); + $this->parseApiError($response->message); } else { @@ -177,15 +176,13 @@ class giteaModel extends model { if(is_string($fieldErrors)) { - $errorKey = array_search($fieldErrors, $this->lang->gitea->apiError); - if($fieldErrors) dao::$errors[$field][] = $errorKey === false ? $fieldErrors : zget($this->lang->gitea->errorLang, $errorKey); + $this->parseApiError($response->message); } else { foreach($fieldErrors as $error) { - $errorKey = array_search($error, $this->lang->gitea->apiError); - if($error) dao::$errors[$field][] = $errorKey === false ? $error : zget($this->lang->gitea->errorLang, $errorKey); + $this->parseApiError($response->message); } } } @@ -196,6 +193,27 @@ class giteaModel extends model return false; } + /** + * 解析api返回的错误信息。 + * + * @param string $message + * @access public + * @return void + */ + public function parseApiError($message) + { + $errorKey = array_search($message, $this->lang->gitea->apiError); + if($errorKey === false) + { + dao::$errors[] = $message; + } + else + { + $field = $this->lang->gitea->errorKey[$errorKey]; + dao::$errors[$field] = zget($this->lang->gitea->errorLang, $errorKey); + } + } + /** * Check user access. * @@ -409,6 +427,31 @@ class giteaModel extends model return $allResults; } + /** + * Get groups by api. + * + * @param int $giteaID + * @param int $sudo + * @access public + * @return array + */ + public function apiGetGroups($giteaID, $sudo = true) + { + $apiRoot = $this->getApiRoot($giteaID, $sudo); + if(!$apiRoot) return array(); + + $url = sprintf($apiRoot, "/orgs"); + $allResults = array(); + for($page = 1; true; $page++) + { + $results = json_decode(commonModel::http($url . "&page={$page}&limit=50")); + if(empty($results)) break; + $allResults = array_merge($allResults, $results); + if(count($results) < 50) break; + } + return $allResults; + } + /** * Get gitea user list. * @@ -594,4 +637,28 @@ class giteaModel extends model return $newBranches; } + + /** + * 创建代码库。 + * + * @param int $giteaID + * @param string $name + * @param string $org + * @param string $desc + * @access public + * @return void + */ + public function apiCreateRepository($giteaID, $name, $org, $desc) + { + $data = new stdclass(); + $data->name = $name; + $data->description = $desc; + $data->auto_init = true; + $data->template = false; + + $url = sprintf($this->getApiRoot($giteaID), "/orgs/{$org}/repos"); + $result = json_decode(commonModel::http($url, $data)); + + return $result; + } } diff --git a/module/gitea/ui/binduser.html.php b/module/gitea/ui/binduser.html.php index 9832051775..8d278e7f35 100644 --- a/module/gitea/ui/binduser.html.php +++ b/module/gitea/ui/binduser.html.php @@ -50,7 +50,7 @@ form array( 'text' => $lang->save, 'btnType' => 'primary', - 'onClick' => jsRaw("() => {bindUser()}") + 'onClick' => jsRaw("bindUser") ), array( 'text' => $lang->goback, diff --git a/module/gitlab/config/dtable.php b/module/gitlab/config/dtable.php index ad8bd65e85..555bf5bf63 100644 --- a/module/gitlab/config/dtable.php +++ b/module/gitlab/config/dtable.php @@ -74,63 +74,3 @@ $config->gitlab->dtable->bindUser->fieldList['status']['title'] = $lang->gitlab- $config->gitlab->dtable->bindUser->fieldList['status']['type'] = 'html'; $config->gitlab->dtable->bindUser->fieldList['status']['width'] = 100; $config->gitlab->dtable->bindUser->fieldList['status']['map'] = $lang->gitlab->bindStatus; - -$config->gitlab->dtable->project = new stdclass(); - -$config->gitlab->dtable->project->fieldList['id']['title'] = $lang->gitlab->id; -$config->gitlab->dtable->project->fieldList['id']['sortType'] = true; - -$config->gitlab->dtable->project->fieldList['name']['title'] = $lang->gitlab->project->name; -$config->gitlab->dtable->project->fieldList['name']['name'] = 'name_with_namespace'; -$config->gitlab->dtable->project->fieldList['name']['sortType'] = true; - -$config->gitlab->dtable->project->fieldList['star']['title'] = ''; - -$config->gitlab->dtable->project->fieldList['lastUpdate']['title'] = $lang->gitlab->lastUpdate; -$config->gitlab->dtable->project->fieldList['lastUpdate']['type'] = 'date'; -$config->gitlab->dtable->project->fieldList['lastUpdate']['sortType'] = false; - -$config->gitlab->dtable->project->fieldList['actions']['name'] = 'actions'; -$config->gitlab->dtable->project->fieldList['actions']['title'] = $lang->actions; -$config->gitlab->dtable->project->fieldList['actions']['type'] = 'actions'; -$config->gitlab->dtable->project->fieldList['actions']['menu'] = array('browseBranch', 'browseTag', 'manageBranchPriv', 'manageTagPriv', 'manageProjectMembers', 'createWebhook', 'importIssue', 'editProject', 'deleteProject'); - -$config->gitlab->dtable->project->fieldList['actions']['list']['browseBranch']['icon'] = 'treemap'; -$config->gitlab->dtable->project->fieldList['actions']['list']['browseBranch']['hint'] = $lang->gitlab->browseBranch; -$config->gitlab->dtable->project->fieldList['actions']['list']['browseBranch']['url'] = helper::createLink('gitlab', 'browseBranch', 'gitlabID={id}&projectID={projectID}'); - -$config->gitlab->dtable->project->fieldList['actions']['list']['browseTag']['icon'] = 'tag'; -$config->gitlab->dtable->project->fieldList['actions']['list']['browseTag']['hint'] = $lang->gitlab->browseTag; -$config->gitlab->dtable->project->fieldList['actions']['list']['browseTag']['url'] = array('module' => 'gitlab', 'method' => 'browseTag', 'params' => 'gitlabID={id}&projectID={projectID}'); -$config->gitlab->dtable->project->fieldList['actions']['list']['browseTag']['url'] = helper::createLink('gitlab', 'browseTag', 'gitlabID={id}&projectID={projectID}'); - -$config->gitlab->dtable->project->fieldList['actions']['list']['manageBranchPriv']['icon'] = 'tag'; -$config->gitlab->dtable->project->fieldList['actions']['list']['manageBranchPriv']['hint'] = $lang->gitlab->browseBranchPriv; -$config->gitlab->dtable->project->fieldList['actions']['list']['manageBranchPriv']['url'] = helper::createLink('gitlab', 'manageBranchPriv', 'gitlabID={id}&projectID={projectID}'); - -$config->gitlab->dtable->project->fieldList['actions']['list']['manageTagPriv']['icon'] = 'tag-lock'; -$config->gitlab->dtable->project->fieldList['actions']['list']['manageTagPriv']['hint'] = $lang->gitlab->browseTagPriv; -$config->gitlab->dtable->project->fieldList['actions']['list']['manageTagPriv']['url'] = helper::createLink('gitlab', 'manageTagPriv', 'gitlabID={id}&projectID={projectID}'); - -$config->gitlab->dtable->project->fieldList['actions']['list']['manageProjectMembers']['icon'] = 'team'; -$config->gitlab->dtable->project->fieldList['actions']['list']['manageProjectMembers']['hint'] = $lang->gitlab->manageProjectMembers; -$config->gitlab->dtable->project->fieldList['actions']['list']['manageProjectMembers']['url'] = helper::createLink('gitlab', 'manageProjectMembers', 'repoID={repoID}'); - -$config->gitlab->dtable->project->fieldList['actions']['list']['createWebhook']['icon'] = 'change'; -$config->gitlab->dtable->project->fieldList['actions']['list']['createWebhook']['hint'] = $lang->gitlab->createWebhook; -$config->gitlab->dtable->project->fieldList['actions']['list']['createWebhook']['url'] = helper::createLink('gitlab', 'createWebhook', 'repoID={repoID}'); -$config->gitlab->dtable->project->fieldList['actions']['list']['createWebhook']['className'] = 'ajax-submit'; - -$config->gitlab->dtable->project->fieldList['actions']['list']['importIssue']['icon'] = 'link'; -$config->gitlab->dtable->project->fieldList['actions']['list']['importIssue']['hint'] = $lang->gitlab->importIssue; -$config->gitlab->dtable->project->fieldList['actions']['list']['importIssue']['url'] = array('module' => 'gitlab', 'method' => 'importIssue', 'params' => 'gitlabID={id}&projectID={projectID}'); -$config->gitlab->dtable->project->fieldList['actions']['list']['importIssue']['url'] = helper::createLink('gitlab', 'importIssue', 'gitlabID={id}&projectID={projectID}'); - -$config->gitlab->dtable->project->fieldList['actions']['list']['editProject']['icon'] = 'edit'; -$config->gitlab->dtable->project->fieldList['actions']['list']['editProject']['hint'] = $lang->gitlab->editProject; -$config->gitlab->dtable->project->fieldList['actions']['list']['editProject']['url'] = helper::createLink('gitlab', 'editProject', 'gitlabID={id}&projectID={projectID}'); - -$config->gitlab->dtable->project->fieldList['actions']['list']['deleteProject']['icon'] = 'trash'; -$config->gitlab->dtable->project->fieldList['actions']['list']['deleteProject']['hint'] = $lang->gitlab->deleteProject; -$config->gitlab->dtable->project->fieldList['actions']['list']['deleteProject']['url'] = helper::createLink('gitlab', 'deleteProject', 'gitlabID={id}&projectID={projectID}'); -$config->gitlab->dtable->project->fieldList['actions']['list']['deleteProject']['className'] = 'ajax-submit'; diff --git a/module/gitlab/js/binduser.ui.js b/module/gitlab/js/binduser.ui.js index 0c8d821099..d25da5436f 100644 --- a/module/gitlab/js/binduser.ui.js +++ b/module/gitlab/js/binduser.ui.js @@ -15,7 +15,7 @@ window.renderGitlabUser = function(result, {row}) return result; } -window.bindUser = function() +window.bindUser = function(e) { const myDTable = $('#table-gitlab-binduser').zui('dtable'); const formData = myDTable.$.getFormData(); @@ -25,10 +25,12 @@ window.bindUser = function() postData['gitlabUserNames[]'] = []; for(i in bindData) { - postData['gitlabUserNames[]'].push(bindData[i].gitlabID); + postData['gitlabUserNames[' + bindData[i].gitlabID + ']'] = bindData[i].gitlabUser; postData['zentaoUsers[' + bindData[i].gitlabID + ']'] = formData['zentaoUsers[' + bindData[i].gitlabID + ']']; } + e.preventDefault(); + e.stopPropagation(); $.ajaxSubmit({ url: $.createLink('gitlab', 'bindUser', 'gitlabID=' + gitlabID + '&type=' + type), data: postData diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 4baa569967..c41b8eb58c 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -675,7 +675,8 @@ class gitlabModel extends model $allResults = array(); for($page = 1; true; $page++) { - $results = json_decode(commonModel::http($url . "&statistics=true&order_by={$order}&sort={$sort}&page={$page}&per_page=100&all_available=true")); + $pageUrl = $url . "&statistics=true&order_by={$order}&sort={$sort}&page={$page}&per_page=100&all_available=true"; + $results = json_decode(commonModel::http($pageUrl)); if(!is_array($results)) break; if(!empty($results)) $allResults = array_merge($allResults, $results); if(count($results) < 100) break; @@ -3000,25 +3001,14 @@ class gitlabModel extends model * 判断按钮是否可点击。 * Adjust the action clickable. * - * @param object $object + * @param object $instance * @param string $action * @access public * @return bool */ - public function isClickable(object $object, string $action): bool + public function isClickable(object $gitlab, string $action): bool { - if(!commonModel::hasPriv('space', 'browse')) return false; - - if($action == 'browseBranch') return $object->isDeveloper; - if($action == 'browseTag') return $object->isDeveloper; - if($action == 'manageProjectMembers') return $object->hasRepo; - if($action == 'createWebhook') return $object->hasRepo; - if($action == 'manageBranchPriv') return $object->defaultBranch; - if($action == 'manageTagPriv') return $object->defaultBranch; - if($action == 'editProject') return $object->defaultBranch; - if($action == 'deleteProject') return $object->defaultBranch; - - return true; + return commonModel::hasPriv('space', 'browse'); } /** diff --git a/module/gitlab/ui/binduser.html.php b/module/gitlab/ui/binduser.html.php index f1cbeeccc5..704e6bcc68 100644 --- a/module/gitlab/ui/binduser.html.php +++ b/module/gitlab/ui/binduser.html.php @@ -50,7 +50,7 @@ form array( 'text' => $lang->save, 'btnType' => 'primary', - 'onClick' => jsRaw("() => {bindUser()}") + 'onClick' => jsRaw("bindUser") ), array( 'text' => $lang->goback, diff --git a/module/gogs/js/binduser.ui.js b/module/gogs/js/binduser.ui.js index 02c5dd7afb..ef7fe61dc9 100644 --- a/module/gogs/js/binduser.ui.js +++ b/module/gogs/js/binduser.ui.js @@ -15,7 +15,7 @@ window.renderGitlabUser = function(result, {row}) return result; } -window.bindUser = function() +window.bindUser = function(e) { const myDTable = $('#table-gogs-binduser').zui('dtable'); const formData = myDTable.$.getFormData(); @@ -25,10 +25,12 @@ window.bindUser = function() postData['gogsUserNames[]'] = []; for(i in bindData) { - postData['gogsUserNames[]'].push(bindData[i].gogsID); + postData['gogsUserNames[' + bindData[i].gogsID + ']'] = bindData[i].gogsUser; postData['zentaoUsers[' + bindData[i].gogsID + ']'] = formData['zentaoUsers[' + bindData[i].gogsID + ']']; } + e.preventDefault(); + e.stopPropagation(); $.ajaxSubmit({ url: $.createLink('gogs', 'bindUser', 'gogsID=' + gogsID + '&type=' + type), data: postData diff --git a/module/gogs/ui/binduser.html.php b/module/gogs/ui/binduser.html.php index 3556164078..0e6e77314f 100644 --- a/module/gogs/ui/binduser.html.php +++ b/module/gogs/ui/binduser.html.php @@ -50,7 +50,7 @@ form array( 'text' => $lang->save, 'btnType' => 'primary', - 'onClick' => jsRaw("() => {bindUser()}") + 'onClick' => jsRaw("bindUser") ), array( 'text' => $lang->goback,