From 23de383c838f6d0f3c98304435bda43c7820749b Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Mon, 11 Jul 2022 08:57:24 +0000 Subject: [PATCH 01/85] * Finish task #60452. --- lib/scm/gitea.class.php | 837 +++++++++++++++++++++++++++++++ module/gitea/model.php | 36 ++ module/repo/config.php | 2 + module/repo/control.php | 96 +++- module/repo/js/create.js | 41 +- module/repo/js/edit.js | 46 +- module/repo/lang/de.php | 4 + module/repo/lang/en.php | 4 + module/repo/lang/fr.php | 4 + module/repo/lang/vi.php | 9 + module/repo/lang/zh-cn.php | 4 + module/repo/lang/zh-tw.php | 4 + module/repo/model.php | 88 ++-- module/repo/view/create.html.php | 20 +- module/repo/view/edit.html.php | 20 +- 15 files changed, 1117 insertions(+), 98 deletions(-) create mode 100644 lib/scm/gitea.class.php diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php new file mode 100644 index 0000000000..c0f5150779 --- /dev/null +++ b/lib/scm/gitea.class.php @@ -0,0 +1,837 @@ +client = $client; + $this->root = rtrim($root, '/') . '/'; + $this->token = $password; + $this->branch = isset($_COOKIE['repoBranch']) ? $_COOKIE['repoBranch'] : 'HEAD'; + } + + /** + * List files. + * + * @param string $path + * @param string $revision + * @access public + * @return array + */ + public function ls($path, $revision = 'HEAD') + { + if(!scm::checkRevision($revision)) return array(); + $api = "tree"; + + $param = new stdclass(); + $param->path = ltrim($path, '/'); + $param->ref = $revision; + $param->recursive = 0; + if(!empty($this->branch)) $param->ref = $this->branch; + + $list = $this->fetch($api, $param, true); + if(empty($list)) return array(); + + $infos = array(); + foreach($list as $file) + { + if(!isset($file->type)) continue; + + $info = new stdClass(); + $info->name = $file->name; + $info->kind = $file->type == 'blob' ? 'file' : 'dir'; + + if($file->type == 'blob') + { + $file = $this->files($file->path, $this->branch); + + $info->revision = zget($file, 'revision', ''); + $info->comment = zget($file, 'comment', ''); + $info->account = zget($file, 'committer', ''); + $info->date = zget($file, 'date', ''); + $info->size = zget($file, 'size', ''); + } + else + { + $commits = $this->getCommitsByPath($file->path, '', '', 1); + if(empty($commits)) continue; + $commit = $commits[0]; + + $info->revision = $commit->id; + $info->comment = $commit->message; + $info->account = $commit->committer_name; + $info->date = date('Y-m-d H:i:s', strtotime($commit->committed_date)); + $info->size = 0; + } + + $infos[] = $info; + unset($info); + } + + /* Sort by kind */ + foreach($infos as $key => $info) $kinds[$key] = $info->kind; + if($infos) array_multisort($kinds, SORT_ASC, $infos); + return $infos; + } + + /** + * Get files info. + * + * The API path requested is: "GET /projects/:id/repository/files/:file_path". + * Known issue of GitLab API: if a '%' in 'file_path', GitLab API will show a error 'file_path should be a valid file path'. + * + * @param string $path + * @param string $ref + * @access public + * @return object + * @doc https://docs.gitlab.com/ee/api/repository_files.html + */ + public function files($path, $ref = 'master') + { + $path = urlencode($path); + $api = "files/$path"; + $param = new stdclass(); + $param->ref = $ref; + $file = $this->fetch($api, $param); + if(!isset($file->file_name)) return false; + + $commits = $this->getCommitsByPath($path, '', '', 1); + $file->revision = $file->commit_id; + $file->size = $this->formatBytes($file->size); + + if(!empty($commits)) + { + $commit = $commits[0]; + $file->revision = $commit->id; + $file->committer = $commit->committer_name; + $file->comment = $commit->message; + $file->date = date('Y-m-d H:i:s', strtotime($commit->committed_date)); + } + + return $file; + } + + /** + * Get tags + * + * @param string $path + * @param string $revision + * @access public + * @return array + */ + public function tags($path, $revision = 'HEAD') + { + $api = "tags"; + $tags = array(); + + $params = array(); + $params['per_page'] = '100'; + $params['order_by'] = 'updated'; + $params['sort'] = 'asc'; + for($page = 1; true; $page ++) + { + $params['page'] = $page; + $list = $this->fetch($api, $params); + if(empty($list)) break; + + foreach($list as $tag) $tags[] = $tag->name; + if(count($list) < $params['per_page']) break; + } + + return $tags; + } + + /** + * Get branches. + * + * @access public + * @return array + */ + public function branch() + { + /* Max size of per_page in gitlab API is 100. */ + $params = array(); + $params['per_page'] = '100'; + + $branches = array(); + $default = array(); + for($page = 1; true; $page ++) + { + $params['page'] = $page; + $branchList = $this->fetch("branches", $params); + if(empty($branchList)) break; + + foreach($branchList as $branch) + { + if(!isset($branch->name)) continue; + if($branch->default) + { + $default[$branch->name] = $branch->name; + } + else + { + $branches[$branch->name] = $branch->name; + } + } + + /* Last page. */ + if(count($branchList) < $params['per_page']) break; + } + + if(empty($branches) and empty($default)) $branches['master'] = 'master'; + asort($branches); + + $branches = $default + $branches; + return $branches; + } + + /** + * Get last log. + * + * @param string $path + * @param int $count + * @access public + * @return array + */ + public function getLastLog($path, $count = 10) + { + return $this->log($path); + } + + /** + * Get logs. + * + * @param string $path + * @param string $fromRevision + * @param string $toRevision + * @param int $count + * @access public + * @return array + */ + public function log($path, $fromRevision = 0, $toRevision = 'HEAD', $count = 0) + { + if(!scm::checkRevision($fromRevision)) return array(); + if(!scm::checkRevision($toRevision)) return array(); + + $path = ltrim($path, DIRECTORY_SEPARATOR); + $count = $count == 0 ? '' : "-n $count"; + + $list = $this->getCommitsByPath($path, $fromRevision, $toRevision); + foreach($list as $commit) + { + if(isset($commit->id)) $commit->diffs = $this->getFilesByCommit($commit->id); + } + + return $this->parseLog($list); + } + + /** + * Blame file + * + * @param string $path + * @param string $revision + * @access public + * @return array + */ + public function blame($path, $revision) + { + if(!scm::checkRevision($revision)) return array(); + + $path = ltrim($path, DIRECTORY_SEPARATOR); + $path = urlencode($path); + $api = "files/$path/blame"; + $param = new stdclass; + $param->ref = ($revision and $revision != 'HEAD') ? $revision : $this->branch; + $results = $this->fetch($api, $param); + + $blames = array(); + $revLine = 0; + $revision = ''; + + $lineNumber = 1; + foreach($results as $blame) + { + $line = array(); + $line['revision'] = $blame->commit->id; + $line['committer'] = $blame->commit->committer_name; + $line['time'] = $blame->commit->committer_name; + $line['line'] = $lineNumber; + $line['lines'] = count($blame->lines); + $line['content'] = array_shift($blame->lines); + + $blames[$lineNumber] = $line; + + $lineNumber ++; + + foreach($blame->lines as $line) + { + $blames[$lineNumber] = array('line' => $lineNumber, 'content' => $line); + $lineNumber ++; + } + } + + return $blames; + } + + /** + * Diff file. + * + * @param string $path + * @param string $fromRevision + * @param string $toRevision + * @param string $fromProject + * @param string $extra + * @access public + * @return array + */ + public function diff($path, $fromRevision, $toRevision, $fromProject = '', $extra = '') + { + if(!scm::checkRevision($fromRevision) and $extra != 'isBranchOrTag') return array(); + if(!scm::checkRevision($toRevision) and $extra != 'isBranchOrTag') return array(); + + $api = "compare"; + $params = array('from' => $fromRevision, 'to' => $toRevision); + if($fromProject) $params['from_project_id'] = $fromProject; + + if($toRevision == 'HEAD' and $this->branch) $params['to'] = $this->branch; + $results = $this->fetch($api, $params); + if(!isset($results->diffs)) return array(); + + foreach($results->diffs as $key => $diff) + { + if($path != '' and strpos($diff->new_path, $path) === false) unset($results->diffs[$key]); + } + $diffs = $results->diffs; + $lines = array(); + foreach($diffs as $diff) + { + $lines[] = sprintf("diff --git a/%s b/%s", $diff->old_path, $diff->new_path); + $lines[] = sprintf("index %s ... %s %s ", $fromRevision, $toRevision, $diff->b_mode); + $lines[] = sprintf("--a/%s", $diff->old_path); + $lines[] = sprintf("--b/%s", $diff->new_path); + $diffLines = explode("\n", $diff->diff); + foreach($diffLines as $diffLine) $lines[] = $diffLine; + } + return $lines; + } + + /** + * Cat file. + * + * @param string $entry + * @param string $revision + * @access public + * @return string + */ + public function cat($entry, $revision = 'HEAD') + { + if(!scm::checkRevision($revision)) return false; + if($revision == 'HEAD' and $this->branch) $revision = $this->branch; + $file = $this->files($entry, $revision); + return base64_decode($file->content); + } + + /** + * Get info. + * + * @param string $entry + * @param string $revision + * @access public + * @return object + */ + public function info($entry, $revision = 'HEAD') + { + if(!scm::checkRevision($revision)) return false; + + $info = new stdclass(); + $info->kind = 'dir'; + $info->path = $entry; + $info->revision = $revision; + $info->root = ''; + if($revision == 'HEAD' and $this->branch) $info->revision = $this->branch; + + if($entry) + { + $parent = dirname($entry); + if($parent == '.') $parent = '/'; + if($parent == '') $parent = '/'; + $list = $this->tree($parent, 0); + $file = new stdclass(); + + foreach($list as $node) if($node->path == $entry) $file = $node; + + $commits = $this->getCommitsByPath($entry); + + if(!empty($commits)) $file->revision = zget($commits[0], 'id', ''); + $info->kind = (isset($file->type) and $file->type == 'tree') ? 'dir' : 'file'; + } + + return $info; + } + + /** + * Exec git cmd. + * + * @param string $cmd + * @access public + * @todo Exec commands by gitlab api. + * @return array + */ + public function exec($cmd) + { + return execCmd(escapeCmd("$this->client $cmd"), 'array'); + } + + /** + * Parse diff. + * + * @param array $lines + * @access public + * @return array + */ + public function parseDiff($lines) + { + if(empty($lines)) return array(); + $diffs = array(); + $num = count($lines); + $endLine = end($lines); + if(strpos($endLine, '\ No newline at end of file') === 0) $num -= 1; + + $newFile = false; + $allFiles = array(); + for($i = 0; $i < $num; $i ++) + { + $diffFile = new stdclass(); + if(strpos($lines[$i], "diff --git ") === 0) + { + $fileInfo = explode(' ',$lines[$i]); + $fileName = substr($fileInfo[2], strpos($fileInfo[2], '/') + 1); + + /* Prevent duplicate display of files. */ + if(in_array($fileName, $allFiles)) continue; + $allFiles[] = $fileName; + + $diffFile->fileName = $fileName; + for($i++; $i < $num; $i ++) + { + $diff = new stdclass(); + /* Fix bug #1757. */ + if($lines[$i] == '+++ /dev/null') $newFile = true; + if(strpos($lines[$i], '+++', 0) !== false) continue; + if(strpos($lines[$i], '---', 0) !== false) continue; + if(strpos($lines[$i], '======', 0) !== false) continue; + if(preg_match('/^@@ -(\\d+)(,(\\d+))?\\s+\\+(\\d+)(,(\\d+))?\\s+@@/A', $lines[$i])) + { + $startLines = trim(str_replace(array('@', '+', '-'), '', $lines[$i])); + list($oldStartLine, $newStartLine) = explode(' ', $startLines); + list($diff->oldStartLine) = explode(',', $oldStartLine); + list($diff->newStartLine) = explode(',', $newStartLine); + $oldCurrentLine = $diff->oldStartLine; + $newCurrentLine = $diff->newStartLine; + if($newFile) + { + $oldCurrentLine = $diff->newStartLine; + $newCurrentLine = $diff->oldStartLine; + } + $newLines = array(); + for($i++; $i < $num; $i ++) + { + if(preg_match('/^@@ -(\\d+)(,(\\d+))?\\s+\\+(\\d+)(,(\\d+))?\\s+@@/A', $lines[$i])) + { + $i --; + break; + } + if(strpos($lines[$i], "diff --git ") === 0) break; + + $line = $lines[$i]; + if(strpos($line, '\ No newline at end of file') === 0)continue; + $sign = empty($line) ? '' : $line[0]; + if($sign == '-' and $newFile) $sign = '+'; + $type = $sign != '-' ? $sign == '+' ? 'new' : 'all' : 'old'; + if($sign == '-' || $sign == '+') + { + $line = substr_replace($line, ' ', 1, 0); + if($newFile) $line = preg_replace('/^\-/', '+', $line); + } + + $newLine = new stdclass(); + $newLine->type = $type; + $newLine->oldlc = $type != 'new' ? $oldCurrentLine : ''; + $newLine->newlc = $type != 'old' ? $newCurrentLine : ''; + $newLine->line = htmlSpecialString($line); + + if($type != 'new') $oldCurrentLine++; + if($type != 'old') $newCurrentLine++; + + $newLines[] = $newLine; + } + + $diff->lines = $newLines; + $diffFile->contents[] = $diff; + } + + if(isset($lines[$i]) and strpos($lines[$i], "diff --git ") === 0) + { + $i --; + $newFile = false; + break; + } + } + $diffs[] = $diffFile; + } + } + return $diffs; + } + + /** + * Get commit count. + * + * @param int $commits + * @param string $lastVersion + * @access public + * @return int + */ + public function getCommitCount($commits = 0, $lastVersion = '') + { + if(!scm::checkRevision($lastVersion)) return false; + + chdir($this->root); + $revision = $this->branch ? $this->branch : 'HEAD'; + return execCmd(escapeCmd("$this->client rev-list --count $revision -- ./"), 'string'); + } + + /** + * Get first revision. + * + * @access public + * @return string + */ + public function getFirstRevision() + { + chdir($this->root); + $list = execCmd(escapeCmd("$this->client rev-list --reverse HEAD -- ./"), 'array'); + return $list[0]; + } + + /** + * Get latest revision + * + * @access public + * @return string + */ + public function getLatestRevision() + { + chdir($this->root); + $revision = $this->branch ? $this->branch : 'HEAD'; + $list = execCmd(escapeCmd("$this->client rev-list -1 $revision -- ./"), 'array'); + return $list[0]; + } + + /** + * Get commits. + * + * @param string $version + * @param int $count + * @param string $branch + * @access public + * @return array + */ + public function getCommits($version = '', $count = 0, $branch = '') + { + if(!scm::checkRevision($version)) return array(); + $api = "commits"; + $commits = array(); + $files = array(); + + if(empty($count)) $count = 10; + + if(!empty($version) and $count == 1) + { + $api .= '/' . $version; + $commit = $this->fetch($api); + if(isset($commit->id)) + { + $log = new stdclass; + $log->committer = $commit->committer_name; + $log->revision = $commit->id; + $log->comment = $commit->message; + $log->time = date('Y-m-d H:i:s', strtotime($commit->created_at)); + + $commits[$commit->id] = $log; + $files[$commit->id] = $this->getFilesByCommit($log->revision); + + return array('commits' => $commits, 'files' => $files); + } + } + + $params = array(); + $params['ref_name'] = $branch; + $params['per_page'] = $count; + $params['all'] = 0; + + if($version and $version != 'HEAD') + { + /* Get since param. */ + if(substr($version, 0, 5) == 'since') + { + $since = true; + $version = substr($version, 5); + } + + $committedDate = $this->getCommittedDate($version); + if(!$committedDate) return array('commits' => array(), 'files' => array()); + + if(!empty($since)) + { + $params['since'] = $committedDate; + } + else + { + $params['until'] = $committedDate; + } + } + + $list = $this->fetch($api, $params); + + foreach($list as $commit) + { + if(!is_object($commit)) continue; + + $log = new stdclass; + $log->committer = $commit->committer_name; + $log->revision = $commit->id; + $log->comment = $commit->message; + $log->time = date('Y-m-d H:i:s', strtotime($commit->created_at)); + + $commits[$commit->id] = $log; + $files[$commit->id] = $this->getFilesByCommit($log->revision); + } + + return array('commits' => $commits, 'files' => $files); + } + + /** + * getCommit + * + * @param int $sha + * @access public + * @return void + */ + public function getCommittedDate($sha) + { + if(!scm::checkRevision($sha)) return null; + if(!$sha or $sha == 'HEAD') return date('c'); + + global $dao; + $time = $dao->select('time')->from(TABLE_REPOHISTORY)->where('revision')->eq($sha)->fetch('time'); + if($time) return date('c', strtotime($time)); + + $result = $this->fetch("commits/$sha"); + return (isset($result->committed_date)) ? $result->committed_date : false; + } + + /** + * Get commits by path. + * + * @param string $path + * @param string $fromRevision + * @param string $toRevision + * @param int $perPage + * @access public + * @return array + */ + public function getCommitsByPath($path, $fromRevision = '', $toRevision = '', $perPage = 0) + { + $path = ltrim($path, DIRECTORY_SEPARATOR); + $api = "commits"; + + $param = new stdclass(); + $param->path = urldecode($path); + $param->ref_name = ($toRevision != 'HEAD' and $toRevision) ? $toRevision : $this->branch; + + $fromDate = $this->getCommittedDate($fromRevision); + $toDate = $this->getCommittedDate($toRevision); + + $since = ''; + $until = ''; + if($fromRevision and $toRevision) + { + $since = min($fromDate, $toDate); + $until = max($fromDate, $toDate); + } + elseif($fromRevision) + { + $since = $fromDate; + } + if($since) $param->since = $since; + if($until) $param->until = $until; + + if($perPage) $param->per_page = $perPage; + + return $this->fetch($api, $param); + } + + /** + * Get files by commit. + * + * @param string $commit + * @access public + * @return void + */ + public function getFilesByCommit($revision) + { + if(!scm::checkRevision($revision)) return array(); + $api = "commits/{$revision}/diff"; + $params = new stdclass; + $params->page = 1; + $params->per_page = 100; + + $allResults = array(); + while(true) + { + $results = $this->fetch($api, $params); + $params->page ++; + if(!is_array($results)) $results = array(); + $allResults = $allResults + $results; + if(count($results) < 100) break; + } + + $files = array(); + foreach($allResults as $row) + { + $file = new stdclass(); + $file->revision = $revision; + $file->path = '/' . $row->new_path; + $file->type = 'file'; + + $file->action = 'M'; + if($row->new_file) $file->action = 'A'; + if($row->renamed_file) $file->action = 'R'; + if($row->deleted_file) $file->action = 'D'; + $files[] = $file; + } + + return $files; + } + + /** + * Repository/tree api. + * + * @param string $path + * @param bool $recursive + * @access public + * @return mixed + */ + public function tree($path, $recursive = 1) + { + $api = "tree"; + + $params = array(); + $params['path'] = ltrim($path, '/'); + $params['ref'] = $this->branch; + $params['recursive'] = (int) $recursive; + return $this->fetch($api, $params); + } + + /** + * Fetch data from gitlab api. + * + * @param string $api + * @access public + * @return mixed + */ + public function fetch($api, $params = array(), $needToLoop = false) + { + $params = (array) $params; + $params['private_token'] = $this->token; + $params['per_page'] = isset($params['per_page']) ? $params['per_page'] : 100; + + $api = ltrim($api, '/'); + $api = $this->root . $api . '?' . http_build_query($params); + if($needToLoop) + { + $allResults = array(); + for($page = 1; true; $page++) + { + $results = json_decode(commonModel::http($api . "&page={$page}")); + if(!is_array($results)) break; + if(!empty($results)) $allResults = array_merge($allResults, $results); + if(count($results) < 100) break; + } + + return $allResults; + } + else + { + $response = commonModel::http($api); + if(!empty(commonModel::$requestErrors)) + { + commonModel::$requestErrors = array(); + return array(); + } + + return json_decode($response); + } + } + + /** + * Format bytes shown. + * + * @param int $size + * @static + * @access public + * @return string + */ + public static function formatBytes($size) + { + if($size < 1024) return $size . 'Bytes'; + if(round($size / (1024 * 1024), 2) > 1) return round($size / (1024 * 1024), 2) . 'G'; + if(round($size / 1024, 2) > 1) return round($size / 1024, 2) . 'M'; + return round($size, 2) . 'KB'; + } + + /** + * Parse log. + * + * @param array $logs + * @access public + * @return array + */ + public function parseLog($logs) + { + $parsedLogs = array(); + $i = 0; + foreach($logs as $commit) + { + if(!isset($commit->id)) continue; + $parsedLog = new stdclass(); + $parsedLog->revision = $commit->id; + $parsedLog->committer = $commit->committer_name; + $parsedLog->time = date('Y-m-d H:i:s', strtotime($commit->committed_date)); + $parsedLog->comment = $commit->message; + $parsedLog->change = array(); + foreach($commit->diffs as $diff) + { + $parsedLog->change[$diff->path] = array(); + $parsedLog->change[$diff->path]['action'] = $diff->action; + $parsedLog->change[$diff->path]['kind'] = $diff->type; + } + $parsedLogs[] = $parsedLog; + } + + return $parsedLogs; + } +} diff --git a/module/gitea/model.php b/module/gitea/model.php index 2f72de8403..f1fabf2ffe 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -224,4 +224,40 @@ class giteaModel extends model ->andWhere('account')->eq($account) ->fetchPairs('providerID'); } + + /** + * Get project by api. + * + * @param int $giteaID + * @param int $projectID + * @access public + * @return void + */ + public function apiGetSingleProject($giteaID, $projectID) + { + $apiRoot = $this->getApiRoot($giteaID); + if(!$apiRoot) return array(); + + $url = sprintf($apiRoot, "/repos/$projectID"); + return json_decode(commonModel::http($url)); + } + + /** + * Get projects by api. + * + * @param int $giteaID + * @param bool $sudo + * @access public + * @return array + */ + public function apiGetProjects($giteaID, $sudo = 'true') + { + $apiRoot = $this->getApiRoot($giteaID, $sudo); + if(!$apiRoot) return array(); + + $url = sprintf($apiRoot, "/repos/search"); + $results = json_decode(commonModel::http($url)); + + return $results->data; + } } diff --git a/module/repo/config.php b/module/repo/config.php index 3c258706c1..af7bfa2cd0 100644 --- a/module/repo/config.php +++ b/module/repo/config.php @@ -49,6 +49,8 @@ $config->repo->gitlab = new stdclass; $config->repo->gitlab->perPage = 300; $config->repo->gitlab->apiPath = "%s/api/v4/projects/%s/repository/"; +$config->repo->gitServiceList = array('gitlab', 'gitea'); + $config->repo->rules['module']['task'] = 'Task'; $config->repo->rules['module']['bug'] = 'Bug'; $config->repo->rules['module']['story'] = 'Story'; diff --git a/module/repo/control.php b/module/repo/control.php index ac03e050e7..b1bcb3be74 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -142,14 +142,14 @@ class repo extends control $products = $this->loadModel('product')->getProductPairsByProject($objectID); $productID = count($products) > 0 ? key($products) : ''; - $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->create; - $this->view->position[] = $this->lang->repo->create; - $this->view->groups = $this->loadModel('group')->getPairs(); - $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted'); - $this->view->products = $products; - $this->view->productID = $productID; - $this->view->gitlabHosts = $this->loadModel('gitlab')->getPairs(); - $this->view->objectID = $objectID; + $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->create; + $this->view->position[] = $this->lang->repo->create; + $this->view->groups = $this->loadModel('group')->getPairs(); + $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted'); + $this->view->products = $products; + $this->view->productID = $productID; + $this->view->serviceHosts = $this->loadModel('gitlab')->getPairs(); + $this->view->objectID = $objectID; $this->display(); } @@ -182,25 +182,29 @@ class repo extends control $this->app->loadLang('action'); - if(strtolower($repo->SCM) == 'gitlab') + $scm = strtolower($repo->SCM); + if(in_array($scm, $this->config->repo->gitServiceList)) { - $gitlabID = isset($repo->gitlab) ? $repo->gitlab : 0; - $projects = $this->loadModel('gitlab')->apiGetProjects($gitlabID); - $options = array(); - foreach($projects as $project) $options[$project->id] = $project->name_with_namespace; + $serviceID = isset($repo->gitService) ? $repo->gitService : 0; + $projects = $this->loadModel($scm)->apiGetProjects($serviceID); + $options = array(); + foreach($projects as $project) + { + if($scm == 'gitlab') $options[$project->id] = $project->name_with_namespace; + if($scm == 'gitea') $options[$project->full_name] = $project->full_name; + } $this->view->projects = $options; } - $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->edit; - $repo->repoType = $repo->id . '-' . $repo->SCM; - $this->view->repo = $repo; - $this->view->repoID = $repoID; - $this->view->objectID = $objectID; - $this->view->groups = $this->loadModel('group')->getPairs(); - $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted'); - $this->view->products = $objectID ? $this->loadModel('product')->getProductPairsByProject($objectID) : $this->loadModel('product')->getPairs(); - $this->view->gitlabHosts = array('' => '') + $this->loadModel('gitlab')->getPairs(); + $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->edit; + $this->view->repo = $repo; + $this->view->repoID = $repoID; + $this->view->objectID = $objectID; + $this->view->groups = $this->loadModel('group')->getPairs(); + $this->view->users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted'); + $this->view->products = $objectID ? $this->loadModel('product')->getProductPairsByProject($objectID) : $this->loadModel('product')->getPairs(); + $this->view->serviceHosts = array('' => '') + $this->loadModel('pipeline')->getPairs($repo->SCM); $this->view->position[] = html::a(inlink('maintain'), $this->lang->repo->common); $this->view->position[] = $this->lang->repo->edit; @@ -1165,6 +1169,54 @@ class repo extends control $this->display(); } + /** + * Ajax get hosts. + * + * @param int $scm + * @access public + * @return void + */ + public function ajaxGetHosts($scm) + { + $scm = strtolower($scm); + $hosts = $this->loadModel($scm)->getPairs(); + return print(html::select('pipelineHost', $hosts, '', "class='form-control chosen'")); + } + + /** + * Ajax get projects by server. + * + * @param int $serverID + * @access public + * @return void + */ + public function ajaxGetProjects($serverID) + { + $server = $this->loadModel('pipeline')->getByID($serverID); + $getProjectFunc = 'ajaxGet' . $server->type . 'Projects'; + + $this->$getProjectFunc($serverID); + } + + /** + * Ajax get gitea projects. + * + * @param string $gitlabID + * @param string $projectIdList + * @access public + * @return void + */ + public function ajaxGetGiteaProjects($giteaID) + { + $projects = $this->loadModel('gitea')->apiGetProjects($giteaID); + if(!$projects) $this->send(array('message' => array())); + + $options = ""; + foreach($projects as $project) $options .= ""; + + return print($options); + } + /** * Ajax get gitlab projects. * diff --git a/module/repo/js/create.js b/module/repo/js/create.js index a5ad8b9a92..d6db74f6e3 100644 --- a/module/repo/js/create.js +++ b/module/repo/js/create.js @@ -23,28 +23,35 @@ $(function() } }); - $('#gitlabHost').change(function() + $('#serviceHost').change(function() { - host = $('#gitlabHost').val(); - url = createLink('repo', 'ajaxGetGitlabProjects', "host=" + host); + var host = $('#serviceHost').val(); + var url = createLink('repo', 'ajaxGetProjects', "host=" + host); if(host == '') return false; $.get(url, function(response) { - $('#gitlabProject').html('').append(response); - $('#gitlabProject').chosen().trigger("chosen:updated");; + $('#serviceProject').html('').append(response); + $('#serviceProject').chosen().trigger("chosen:updated");; }); }); - $('#gitlabProject').change(function() + $('#serviceProject').change(function() { $option = $(this).find('option:selected'); $('#name').val($option.data('name')); }); - $('#gitlabHost').change(); + $('#serviceHost').change(); }); +/** + * Changed SCM. + * + * @param string $scm + * @access public + * @return void + */ function scmChanged(scm) { if(scm == 'Git') @@ -62,6 +69,22 @@ function scmChanged(scm) $('.tips-svn').removeClass('hidden'); } - $('tr.gitlab').toggle(scm == 'Gitlab'); - $('tr.hide-gitlab').toggle(scm != 'Gitlab'); + if(scm == 'Git' || scm == 'Subversion') + { + $('tr.service').toggle(false); + $('tr.hide-service').toggle(true); + } + else + { + $('tr.service').toggle(true); + $('tr.hide-service').toggle(false); + + var url = createLink('repo', 'ajaxGetHosts', "scm=" + scm); + $.get(url, function(response) + { + $('#serviceHost').html(response); + $('#serviceHost').chosen().trigger("chosen:updated");; + $('#serviceHost').change(); + }); + } } diff --git a/module/repo/js/edit.js b/module/repo/js/edit.js index 60505a9229..229f4907ab 100644 --- a/module/repo/js/edit.js +++ b/module/repo/js/edit.js @@ -1,26 +1,26 @@ $(function() { - scmChanged(scm); + scmChanged(scm, true); $('#submit').mousedown(function() { $form = $(this).closest('form'); $form.css('min-height', $form.height()); }) - $('#gitlabHost').change(function() + $('#serviceHost').change(function() { - host = $('#gitlabHost').val(); + host = $('#serviceHost').val(); if(host == '') return false; - url = createLink('repo', 'ajaxGetGitlabProjects', "host=" + host); + url = createLink('repo', 'ajaxGetProjects', "host=" + host); $.get(url, function(response) { - $('#gitlabProject').html('').append(response); - $('#gitlabProject').chosen().trigger("chosen:updated");; + $('#serviceProject').html('').append(response); + $('#serviceProject').chosen().trigger("chosen:updated");; }); }); - $('#gitlabProject').change(function() + $('#serviceProject').change(function() { $option = $(this).find('option:selected'); if(!$option.data('name')) return false; @@ -29,7 +29,14 @@ $(function() }); }); -function scmChanged(scm) +/** + * Changed SCM. + * + * @param string $scm + * @access public + * @return void + */ +function scmChanged(scm, isFirstRequest = false) { if(scm == 'Git') { @@ -46,6 +53,25 @@ function scmChanged(scm) $('.tips-svn').removeClass('hidden'); } - $('tr.gitlab').toggle(scm == 'Gitlab'); - $('tr.hide-gitlab').toggle(scm != 'Gitlab'); + if(scm == 'Git' || scm == 'Subversion') + { + $('tr.service').toggle(false); + $('tr.hide-service').toggle(true); + } + else + { + $('tr.service').toggle(true); + $('tr.hide-service').toggle(false); + + if(!isFirstRequest) + { + var url = createLink('repo', 'ajaxGetHosts', "scm=" + scm); + $.get(url, function(response) + { + $('#serviceHost').html(response); + $('#serviceHost').chosen().trigger("chosen:updated");; + $('#serviceHost').change(); + }); + } + } } diff --git a/module/repo/lang/de.php b/module/repo/lang/de.php index e17e9084cc..cffe5ebcfd 100644 --- a/module/repo/lang/de.php +++ b/module/repo/lang/de.php @@ -142,6 +142,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8'; $lang->repo->encodingList['gbk'] = 'GBK'; $lang->repo->scmList['Gitlab'] = 'GitLab'; +$lang->repo->scmList['Gitea'] = 'Gitea'; $lang->repo->scmList['Git'] = 'Git'; $lang->repo->scmList['Subversion'] = 'SVN'; @@ -149,6 +150,9 @@ $lang->repo->gitlabHost = 'GitLab Host'; $lang->repo->gitlabToken = 'GitLab Token'; $lang->repo->gitlabProject = 'Project'; +$lang->repo->serviceHost = 'Host'; +$lang->repo->serviceProject = 'Project'; + $lang->repo->placeholder = new stdclass; $lang->repo->placeholder->gitlabHost = 'Input url of gitlab'; diff --git a/module/repo/lang/en.php b/module/repo/lang/en.php index 62ab96d159..725f3d2263 100644 --- a/module/repo/lang/en.php +++ b/module/repo/lang/en.php @@ -142,6 +142,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8'; $lang->repo->encodingList['gbk'] = 'GBK'; $lang->repo->scmList['Gitlab'] = 'GitLab'; +$lang->repo->scmList['Gitea'] = 'Gitea'; $lang->repo->scmList['Git'] = 'Git'; $lang->repo->scmList['Subversion'] = 'SVN'; @@ -149,6 +150,9 @@ $lang->repo->gitlabHost = 'GitLab Host'; $lang->repo->gitlabToken = 'GitLab Token'; $lang->repo->gitlabProject = 'Project'; +$lang->repo->serviceHost = 'Host'; +$lang->repo->serviceProject = 'Project'; + $lang->repo->placeholder = new stdclass; $lang->repo->placeholder->gitlabHost = 'Input url of gitlab'; diff --git a/module/repo/lang/fr.php b/module/repo/lang/fr.php index 160d388e3f..22661b03db 100644 --- a/module/repo/lang/fr.php +++ b/module/repo/lang/fr.php @@ -142,6 +142,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8'; $lang->repo->encodingList['gbk'] = 'GBK'; $lang->repo->scmList['Gitlab'] = 'GitLab'; +$lang->repo->scmList['Gitea'] = 'Gitea'; $lang->repo->scmList['Git'] = 'Git'; $lang->repo->scmList['Subversion'] = 'Subversion'; @@ -149,6 +150,9 @@ $lang->repo->gitlabHost = 'GitLab Host'; $lang->repo->gitlabToken = 'GitLab Token'; $lang->repo->gitlabProject = 'Project'; +$lang->repo->serviceHost = 'Host'; +$lang->repo->serviceProject = 'Project'; + $lang->repo->placeholder = new stdclass; $lang->repo->placeholder->gitlabHost = 'Input url of gitlab'; diff --git a/module/repo/lang/vi.php b/module/repo/lang/vi.php index 01a694336e..e84f6866e6 100644 --- a/module/repo/lang/vi.php +++ b/module/repo/lang/vi.php @@ -137,9 +137,18 @@ $lang->repo->logStyles['D'] = 'Xóa'; $lang->repo->encodingList['utf_8'] = 'UTF-8'; $lang->repo->encodingList['gbk'] = 'GBK'; +$lang->repo->scmList['Gitlab'] = 'GitLab'; +$lang->repo->scmList['Gitea'] = 'Gitea'; $lang->repo->scmList['Git'] = 'Git'; $lang->repo->scmList['Subversion'] = 'SVN'; +$lang->repo->gitlabHost = 'GitLab Host'; +$lang->repo->gitlabToken = 'GitLab Token'; +$lang->repo->gitlabProject = 'Project'; + +$lang->repo->serviceHost = 'Host'; +$lang->repo->serviceProject = 'Project'; + $lang->repo->notice = new stdclass(); $lang->repo->notice->syncing = 'Đang đồng bộ. Vui lòng đợi ...'; $lang->repo->notice->syncComplete = 'Synchronized. Now redirecting ...'; diff --git a/module/repo/lang/zh-cn.php b/module/repo/lang/zh-cn.php index 964d445042..d9c12cd196 100644 --- a/module/repo/lang/zh-cn.php +++ b/module/repo/lang/zh-cn.php @@ -142,6 +142,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8'; $lang->repo->encodingList['gbk'] = 'GBK'; $lang->repo->scmList['Gitlab'] = 'GitLab'; +$lang->repo->scmList['Gitea'] = 'Gitea'; $lang->repo->scmList['Git'] = '本地 Git'; $lang->repo->scmList['Subversion'] = 'Subversion'; @@ -149,6 +150,9 @@ $lang->repo->gitlabHost = 'GitLab Server'; $lang->repo->gitlabToken = 'GitLab Token'; $lang->repo->gitlabProject = 'GitLab 项目'; +$lang->repo->serviceHost = '服务器'; +$lang->repo->serviceProject = '仓库'; + $lang->repo->placeholder = new stdclass; $lang->repo->placeholder->gitlabHost = '请填写GitLab访问地址'; diff --git a/module/repo/lang/zh-tw.php b/module/repo/lang/zh-tw.php index 839ae5e4b0..9811b114f1 100644 --- a/module/repo/lang/zh-tw.php +++ b/module/repo/lang/zh-tw.php @@ -135,6 +135,7 @@ $lang->repo->encodingList['utf_8'] = 'UTF-8'; $lang->repo->encodingList['gbk'] = 'GBK'; $lang->repo->scmList['Gitlab'] = 'GitLab'; +$lang->repo->scmList['Gitea'] = 'Gitea'; $lang->repo->scmList['Git'] = '本地 Git'; $lang->repo->scmList['Subversion'] = 'Subversion'; @@ -142,6 +143,9 @@ $lang->repo->gitlabHost = 'GitLab Server'; $lang->repo->gitlabToken = 'GitLab Token'; $lang->repo->gitlabProject = 'GitLab 項目'; +$lang->repo->serviceHost = '服务器'; +$lang->repo->serviceProject = '仓库'; + $lang->repo->placeholder = new stdclass; $lang->repo->placeholder->gitlabHost = '請填寫GitLab訪問地址'; diff --git a/module/repo/model.php b/module/repo/model.php index d417ca9f3a..bdc537385e 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -137,7 +137,7 @@ class repoModel extends model } } - if($repo->SCM == 'Gitlab') $repo = $this->processGitlab($repo); + if(in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList)) $repo = $this->processGitService($repo); } return $repos; @@ -164,7 +164,7 @@ class repoModel extends model if($repo->encrypt == 'base64') $repo->password = base64_decode($repo->password); $repo->acl = json_decode($repo->acl); if($type == 'haspriv' and !$this->checkPriv($repo)) unset($repos[$i]); - if(strtolower($repo->SCM) == 'gitlab') $repo = $this->processGitlab($repo); + if(in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList)) $repo = $this->processGitService($repo); } return $repos; @@ -181,19 +181,20 @@ class repoModel extends model if(!$this->checkClient()) return false; if(!$this->checkConnection()) return false; - if($this->post->SCM == 'Gitlab') + $isPipelineServer = in_array(strtolower($this->post->SCM), $this->config->repo->gitServiceList) ? true : false; + if($isPipelineServer) { - if($this->post->gitlabHost == '') dao::$errors['gitlabHost'] = sprintf($this->lang->error->notempty, $this->lang->repo->gitlabHost); - if($this->post->gitlabProject == '') dao::$errors['gitlabProject'] = sprintf($this->lang->error->notempty, $this->lang->repo->gitlabProject); + if($this->post->serviceHost == '') dao::$errors['serviceHost'] = sprintf($this->lang->error->notempty, $this->lang->repo->serviceHost); + if($this->post->serviceProject == '') dao::$errors['serviceProject'] = sprintf($this->lang->error->notempty, $this->lang->repo->serviceProject); if(dao::isError()) return false; } $data = fixer::input('post') - ->setIf($this->post->SCM == 'Gitlab', 'password', $this->post->gitlabToken) - ->setIf($this->post->SCM == 'Gitlab', 'path', $this->post->gitlabProject) - ->setIf($this->post->SCM == 'Gitlab', 'client', $this->post->gitlabHost) - ->setIf($this->post->SCM == 'Gitlab', 'extra', $this->post->gitlabProject) - ->setIf($this->post->SCM == 'Gitlab', 'prefix', '') + ->setIf($isPipelineServer, 'password', $this->post->serviceToken) + ->setIf($isPipelineServer, 'path', $this->post->serviceProject) + ->setIf($isPipelineServer, 'client', $this->post->serviceHost) + ->setIf($isPipelineServer, 'extra', $this->post->serviceProject) + ->setIf($isPipelineServer, 'prefix', '') ->setIf($this->post->SCM == 'Git', 'account', '') ->setIf($this->post->SCM == 'Git', 'password', '') ->skipSpecial('path,client,account,password') @@ -208,7 +209,7 @@ class repoModel extends model ->andWhere('client')->eq($data->client) ->andWhere('path')->eq($data->path) ->fetch(); - if(!empty($repo)) dao::$errors['gitlabProject'] = sprintf($this->lang->error->unique, $this->lang->repo->gitlabProject, $repo->id); + if(!empty($repo)) dao::$errors['serviceProject'] = sprintf($this->lang->error->unique, $this->lang->repo->serviceProject, $repo->id); if(dao::isError()) return false; } @@ -225,9 +226,9 @@ class repoModel extends model } if($data->encrypt == 'base64') $data->password = base64_encode($data->password); - $this->dao->insert(TABLE_REPO)->data($data, $skip = 'gitlabHost,gitlabToken,gitlabProject') + $this->dao->insert(TABLE_REPO)->data($data, $skip = 'serviceHost,serviceToken,serviceProject') ->batchCheck($this->config->repo->create->requiredFields, 'notempty') - ->checkIF($data->SCM == 'Gitlab', 'gitlabProject', 'notempty') + ->checkIF($isPipelineServer, 'serviceProject', 'notempty') ->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty') ->checkIF($data->SCM == 'Git', 'path', 'unique', "`SCM` = 'Git'") ->checkIF($data->SCM == 'Subversion', 'path', 'unique', "`SCM` = 'Subversion'") @@ -261,17 +262,18 @@ class repoModel extends model { $repo = $this->getRepoByID($id); - if($this->post->SCM == 'Gitlab') + $isPipelineServer = in_array(strtolower($this->post->SCM), $this->config->repo->gitServiceList) ? true : false; + if($isPipelineServer) { - if($this->post->gitlabHost == '') dao::$errors['gitlabHost'] = sprintf($this->lang->error->notempty, $this->lang->repo->gitlabHost); - if($this->post->gitlabProject == '') dao::$errors['gitlabProject'] = sprintf($this->lang->error->notempty, $this->lang->repo->gitlabProject); + if($this->post->serviceHost == '') dao::$errors['serviceHost'] = sprintf($this->lang->error->notempty, $this->lang->repo->serviceHost); + if($this->post->serviceProject == '') dao::$errors['serviceProject'] = sprintf($this->lang->error->notempty, $this->lang->repo->serviceProject); } $data = fixer::input('post') - ->setIf($this->post->SCM == 'Gitlab', 'password', $this->post->gitlabToken) - ->setIf($this->post->SCM == 'Gitlab', 'path', $this->post->gitlabProject) - ->setIf($this->post->SCM == 'Gitlab', 'client', $this->post->gitlabHost) - ->setIf($this->post->SCM == 'Gitlab', 'extra', $this->post->gitlabProject) + ->setIf($isPipelineServer, 'password', $this->post->serviceToken) + ->setIf($isPipelineServer, 'path', $this->post->serviceProject) + ->setIf($isPipelineServer, 'client', $this->post->serviceHost) + ->setIf($isPipelineServer, 'extra', $this->post->serviceProject) ->setDefault('prefix', $repo->prefix) ->setIf($this->post->SCM == 'Gitlab', 'prefix', '') ->setDefault('client', 'svn') @@ -306,7 +308,7 @@ class repoModel extends model ->andWhere('path')->eq($data->path) ->andWhere('id')->ne($id) ->fetch(); - if(!empty($repo)) dao::$errors['gitlabProject'] = sprintf($this->lang->error->unique, $this->lang->repo->gitlabProject, $repo->id); + if(!empty($repo)) dao::$errors['serviceProject'] = sprintf($this->lang->error->unique, $this->lang->repo->serviceProject, $repo->id); if(dao::isError()) return false; } @@ -314,7 +316,7 @@ class repoModel extends model if(!$this->checkConnection()) return false; if($data->encrypt == 'base64') $data->password = base64_encode($data->password); - $this->dao->update(TABLE_REPO)->data($data, $skip = 'gitlabHost,gitlabToken,gitlabProject') + $this->dao->update(TABLE_REPO)->data($data, $skip = 'serviceHost,serviceToken,serviceProject') ->batchCheck($this->config->repo->edit->requiredFields, 'notempty') ->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty') ->checkIF($data->SCM == 'Gitlab', 'extra', 'notempty') @@ -415,10 +417,8 @@ class repoModel extends model { $repoPairs = $this->getRepoPairs($type, $projectID); - $repos = array(); - $repos['Gitlab'] = array(); - $repos['SVN'] = array(); - $repos['Git'] = array(); + $repos = array(); + foreach($this->lang->repo->scmList as $scmType => $scm) $repos[$scmType] = array(); foreach($repoPairs as $id => $repo) { @@ -427,6 +427,11 @@ class repoModel extends model $repo = str_replace('[gitlab]', '', $repo); $repos['Gitlab'][$id] = $repo; } + if(strpos($repo, '[gitea]') !== false) + { + $repo = str_replace('[gitea]', '', $repo); + $repos['Gitea'][$id] = $repo; + } if(strpos($repo, '[svn]') !== false) { $repo = str_replace('[svn]', '', $repo); @@ -454,7 +459,7 @@ class repoModel extends model if(!$repo) return false; if($repo->encrypt == 'base64') $repo->password = base64_decode($repo->password); - if(strtolower($repo->SCM) == 'gitlab') $repo = $this->processGitlab($repo); + if(in_array(strtolower($repo->SCM), $this->config->repo->gitServiceList)) $repo = $this->processGitService($repo); $repo->acl = json_decode($repo->acl); return $repo; } @@ -1273,7 +1278,7 @@ class repoModel extends model */ public function checkClient() { - if($this->post->SCM == 'Gitlab') return true; + if(in_array(strtolower($this->post->SCM), $this->config->repo->gitServiceList)) return true; if(!$this->config->features->checkClient) return true; if(!$this->post->client) @@ -2015,21 +2020,21 @@ class repoModel extends model } /** - * Process gitlab repo. + * Process git service repo. * * @param object $repo * @access public * @return object */ - public function processGitlab($repo) + public function processGitService($repo) { - $gitlab = $this->loadModel('gitlab')->getByID($repo->client); // The $repo->client is gitlabID. + $service = $this->loadModel('pipeline')->getByID($repo->client); - $repo->gitlab = $gitlab ? $gitlab->id : 0; - $repo->project = $gitlab ? $repo->path : ''; // The projectID in gitlab. - $repo->path = $gitlab ? sprintf($this->config->repo->gitlab->apiPath, $gitlab->url, $repo->path) : ''; - $repo->client = $gitlab ? $gitlab->url : ''; - $repo->password = $gitlab ? $gitlab->token : ''; + $repo->gitService = $service ? $service->id : 0; + $repo->project = $service ? $repo->path : ''; // The projectID in gitlab. + $repo->path = $service ? sprintf($this->config->repo->gitlab->apiPath, $service->url, $repo->path) : ''; + $repo->client = $service ? $service->url : ''; + $repo->password = $service ? $service->token : ''; return $repo; } @@ -2150,13 +2155,22 @@ class repoModel extends model } elseif($repo->SCM == 'Gitlab') { - $project = $this->loadModel('gitlab')->apiGetSingleProject($repo->gitlab, $repo->project); + $project = $this->loadModel('gitlab')->apiGetSingleProject($repo->gitService, $repo->project); if(isset($project->id)) { $url->http = $project->http_url_to_repo; $url->ssh = $project->ssh_url_to_repo; } } + elseif($repo->SCM == 'Gitea') + { + $project = $this->loadModel('gitea')->apiGetSingleProject($repo->gitService, $repo->project); + if(isset($project->id)) + { + $url->http = $project->clone_url; + $url->ssh = $project->ssh_url; + } + } else { $this->scm = $this->app->loadClass('scm'); diff --git a/module/repo/view/create.html.php b/module/repo/view/create.html.php index 0c7b890b18..ea5aa9a668 100644 --- a/module/repo/view/create.html.php +++ b/module/repo/view/create.html.php @@ -32,20 +32,20 @@ repo->scmList, 'Gitlab', "onchange='scmChanged(this.value)' class='form-control chosen'"); ?> repo->syncTips; ?> - - repo->gitlabHost;?> - repo->placeholder->gitlabHost}'");?> + + repo->serviceHost;?> + - - repo->gitlabProject;?> - + + repo->serviceProject;?> + repo->name; ?> - + repo->path; ?> @@ -58,7 +58,7 @@ repo->encodingsTips; ?> - + repo->client;?> @@ -66,11 +66,11 @@ repo->example->client->svn;?> - + repo->account;?> - + repo->password;?>
diff --git a/module/repo/view/edit.html.php b/module/repo/view/edit.html.php index efa6f3c76e..344d2535ba 100644 --- a/module/repo/view/edit.html.php +++ b/module/repo/view/edit.html.php @@ -36,20 +36,20 @@ repo->scmList, $repo->SCM, "onchange='scmChanged(this.value)' class='form-control chosen'"); ?> repo->syncTips; ?> - - repo->gitlabHost;?> - gitlab) ? $repo->gitlab : '', "class='form-control chosen' placeholder='{$lang->repo->placeholder->gitlabHost}'");?> + + repo->serviceHost;?> + gitService) ? $repo->gitService : '', "class='form-control chosen'");?> - - repo->gitlabProject;?> - project) ? $repo->project : '', "class='form-control chosen'");?> + + repo->serviceProject;?> + project) ? $repo->project : '', "class='form-control chosen'");?> repo->name; ?> name, "class='form-control'"); ?> - + repo->path; ?> path, "class='form-control'"); ?> @@ -62,7 +62,7 @@ encoding, "class='form-control'"); ?> repo->encodingsTips; ?> - + repo->client;?> client, "class='form-control'")?> @@ -70,11 +70,11 @@ repo->example->client->svn;?> - + repo->account;?> account, "class='form-control'");?> - + repo->password;?>
From 625631c62594e060a464dc24e362d22fa8371b7c Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Mon, 11 Jul 2022 08:59:50 +0000 Subject: [PATCH 02/85] * Adjust scm. --- lib/scm/gitea.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php index c0f5150779..41b8285932 100644 --- a/lib/scm/gitea.class.php +++ b/lib/scm/gitea.class.php @@ -8,9 +8,9 @@ class gitea * Construct * * @param string $client gitea api url. - * @param string $root id of gitlab project. + * @param string $root id of gitea project. * @param string $username null - * @param string $password token of gitlab api. + * @param string $password token of gitea api. * @param string $encoding * @access public * @return void @@ -97,7 +97,7 @@ class gitea * @param string $ref * @access public * @return object - * @doc https://docs.gitlab.com/ee/api/repository_files.html + * @doc https://docs.gitea.com/ee/api/repository_files.html */ public function files($path, $ref = 'master') { @@ -162,7 +162,7 @@ class gitea */ public function branch() { - /* Max size of per_page in gitlab API is 100. */ + /* Max size of per_page in gitea API is 100. */ $params = array(); $params['per_page'] = '100'; @@ -387,7 +387,7 @@ class gitea * * @param string $cmd * @access public - * @todo Exec commands by gitlab api. + * @todo Exec commands by gitea api. * @return array */ public function exec($cmd) @@ -747,7 +747,7 @@ class gitea } /** - * Fetch data from gitlab api. + * Fetch data from gitea api. * * @param string $api * @access public From e5ffd04c34b14409199c6c720dff569d462f9548 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 09:45:31 +0800 Subject: [PATCH 03/85] * Finish task #60565,60566. --- module/gitlab/control.php | 461 ++++--------------- module/gitlab/js/managebranchpriv.js | 72 +++ module/gitlab/js/managetagpriv.js | 72 +++ module/gitlab/lang/de.php | 9 +- module/gitlab/lang/en.php | 9 +- module/gitlab/lang/fr.php | 9 +- module/gitlab/lang/vi.php | 9 +- module/gitlab/lang/zh-cn.php | 9 +- module/gitlab/model.php | 156 +++---- module/gitlab/view/browsebranchpriv.html.php | 81 ---- module/gitlab/view/browseproject.html.php | 4 +- module/gitlab/view/browsetagpriv.html.php | 82 ---- module/gitlab/view/createbranchpriv.html.php | 47 -- module/gitlab/view/createtagpriv.html.php | 43 -- module/gitlab/view/edittagpriv.html.php | 44 -- module/gitlab/view/managebranchpriv.html.php | 82 ++++ module/gitlab/view/managetagpriv.html.php | 76 +++ module/group/lang/resource.php | 18 +- 18 files changed, 485 insertions(+), 798 deletions(-) create mode 100644 module/gitlab/js/managebranchpriv.js create mode 100644 module/gitlab/js/managetagpriv.js delete mode 100644 module/gitlab/view/browsebranchpriv.html.php delete mode 100644 module/gitlab/view/browsetagpriv.html.php delete mode 100644 module/gitlab/view/createbranchpriv.html.php delete mode 100644 module/gitlab/view/createtagpriv.html.php delete mode 100644 module/gitlab/view/edittagpriv.html.php create mode 100644 module/gitlab/view/managebranchpriv.html.php create mode 100644 module/gitlab/view/managetagpriv.html.php diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 5c8074064a..0f3d774d41 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -911,176 +911,6 @@ class gitlab extends control $this->display(); } - /** - * Browse gitlab protect branch. - * - * @param int $gitlabID - * @param int $projectID - * @param string $orderBy - * @param int $recTotal - * @param int $recPerPage - * @param int $pageID - * @access public - * @return void - */ - public function browseBranchPriv($gitlabID, $projectID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1) - { - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - - if(!$this->app->user->admin) - { - $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); - if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); - if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); - } - - $keyword = fixer::input('post')->setDefault('keyword', '')->get('keyword'); - $branches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, $keyword, $orderBy); - - /* Pager. */ - $this->app->loadClass('pager', $static = true); - $recTotal = count($branches); - $pager = new pager($recTotal, $recPerPage, $pageID); - $branchList = array_chunk($branches, $pager->recPerPage); - - $this->view->keyword = $keyword; - $this->view->pager = $pager; - $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseBranchPriv; - $this->view->levelLang = $this->lang->gitlab->branch->branchCreationLevelList; - $this->view->gitlabID = $gitlabID; - $this->view->projectID = $projectID; - $this->view->project = $project; - $this->view->orderBy = $orderBy; - $this->view->branchList = empty($branchList) ? $branchList: $branchList[$pageID - 1]; - $this->display(); - } - - /** - * Set a gitlab protect branch. - * - * @param int $gitlabID - * @param int $projectID - * @param string $branch - * @access public - * @return void - */ - public function createBranchPriv($gitlabID, $projectID, $branch = '') - { - if(!$this->app->user->admin) - { - $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); - if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); - - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); - } - - /* Fix error when request type is PATH_INFO and the branch name contains '-'.*/ - if($branch) $branch = urldecode(helper::safe64Decode($branch)); - - if($_POST) - { - $this->gitlab->createBranchPriv($gitlabID, $projectID, $branch); - - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browseBranchPriv', "gitlabID=$gitlabID&projectID=$projectID"))); - } - - $branchPriv = new stdClass(); - $branchPriv->name = ''; - $branchPriv->mergeAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default. - $branchPriv->pushAccessLevel = 40; // Initialize data, and the operation authority is the maintainers by default. - - $title = $this->lang->gitlab->createBranchPriv; - - if($branch) - { - $title = $this->lang->gitlab->editBranchPriv; - $branchPriv = $this->gitlab->apiGetSingleBranchPriv($gitlabID, $projectID, $branch); - $branchPriv->name = helper::safe64Encode(urlencode($branchPriv->name)); - $branchPriv->mergeAccessLevel = $this->gitlab->checkAccessLevel($branchPriv->merge_access_levels); - $branchPriv->pushAccessLevel = $this->gitlab->checkAccessLevel($branchPriv->push_access_levels); - } - - $gitlabBranches = $this->gitlab->apiGetBranches($gitlabID, $projectID); - $protectBranches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, '', 'name_asc'); - $protectNames = array_keys($protectBranches); - - $branches = array(); - foreach($gitlabBranches as $oneBranch) - { - if(!in_array($oneBranch->name, $protectNames) || $oneBranch->name == $branch) - { - $branchName = helper::safe64Encode(urlencode($oneBranch->name)); - $branches[$branchName] = $oneBranch->name; - } - } - - $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $title; - $this->view->pageTitle = $title; - $this->view->gitlabID = $gitlabID; - $this->view->branch = $branch; - $this->view->projectID = $projectID; - $this->view->branches = $branches; - $this->view->branchPriv = $branchPriv; - $this->display(); - } - - /** - * Edit a gitlab branch protect. - * - * @param int $gitlabID - * @param int $projectID - * @param string $branch - * @access public - * @return void - */ - public function editBranchPriv($gitlabID, $projectID, $branch) - { - echo $this->fetch('gitlab', 'createBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch"); - } - - /** - * Delete a gitlab protect branch. - * - * @param int $gitlabID - * @param int $projectID - * @param string $branch - * @param string $confirm - * @access public - * @return void - */ - public function deleteBranchPriv($gitlabID, $projectID, $branch, $confirm = 'no') - { - if(!$this->app->user->admin) - { - $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); - if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); - - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); - } - - if($confirm != 'yes') - { - $branch = urlencode($branch); - return print(js::confirm($this->lang->gitlab->branch->confirmDelete , inlink('deleteBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branch&confirm=yes"))); - } - - /* Fix error when request type is PATH_INFO and the branch name contains '-'.*/ - $branch = urldecode(helper::safe64Decode($branch)); - $reponse = $this->gitlab->apiDeleteBranchPriv($gitlabID, $projectID, $branch); - - /* 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('gitlabbranchPriv', $branch, 'deleted', '', $branch); - return print(js::reload('parent')); - } - - echo js::alert($reponse->message); - } - /** * Browse gitlab tag. * @@ -1135,206 +965,6 @@ 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) - { - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - - if(!$this->app->user->admin) - { - $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); - if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); - - if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); - } - - $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->gitlabID = $gitlabID; - $this->view->projectID = $projectID; - $this->view->keyword = $keyword; - $this->view->project = $project; - $this->view->gitlabTagList = empty($tagList) ? $tagList: $tagList[$pageID - 1]; - $this->view->orderBy = $orderBy; - $this->display(); - } - - /** - * Set a gitlab protect tag. - * - * @param int $gitlabID - * @param int $projectID - * @access public - * @return void - */ - public function createTagPriv($gitlabID, $projectID) - { - if(!$this->app->user->admin) - { - $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); - if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); - - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); - } - - 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->apiGetTagPrivs($gitlabID, $projectID, '', 'name_asc'); - $protectNames = array_keys($protectTags); - - $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 = '') - { - if(!$this->app->user->admin) - { - $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); - if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); - - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); - } - - /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ - $tag = urldecode(helper::safe64Decode($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. - * - * @param int $gitlabID - * @param int $projectID - * @param string $tag - * @access public - * @return void - */ - public function deleteTagPriv($gitlabID, $projectID, $tag) - { - if(!$this->app->user->admin) - { - $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); - if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); - - $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); - if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); - } - - /* Fix error when request type is PATH_INFO and the tag name contains '-'.*/ - $tag = urldecode(helper::safe64Decode($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); - return print(js::reload('parent')); - } - - echo js::alert($reponse->message); - } - /** * Import gitlab issue to zentaopms. * @@ -1746,4 +1376,95 @@ class gitlab extends control echo js::alert($reponse->message); } + + /** + * Manage a gitlab branch protected. + * + * @param int $repoID + * @param int $projectID + * @access public + * @return void + */ + public function manageBranchPriv($gitlabID, $projectID) + { + if(!$this->app->user->admin) + { + $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); + if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); + if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + } + + $hasAccessBranches = $this->gitlab->apiGetBranchPrivs($gitlabID, $projectID, '', 'name_asc'); + foreach($hasAccessBranches as $branch) + { + $branch->pushAccess = $this->gitlab->checkAccessLevel($branch->push_access_levels); + $branch->mergeAccess = $this->gitlab->checkAccessLevel($branch->merge_access_levels); + } + + if(!empty($_POST)) + { + $result = $this->gitlab->manageBranchPrivs($gitlabID, $projectID, $hasAccessBranches); + if(!empty($result)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->gitlab->svaeFailed, implode(', ', $result)))); + + return $this->send(array('message' => $this->lang->saveSuccess, 'result' => 'success', 'locate' => inlink('browseProject', "gitlabID=$gitlabID"))); + } + $allBranches = $this->gitlab->apiGetBranches($gitlabID, $projectID); + $noAccessBranches = array(); + foreach($allBranches as $branch) + { + if(!isset($hasAccessBranches[$branch->name])) $noAccessBranches[$branch->name] = $branch->name; + } + + $this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseBranchPriv; + $this->view->gitlabID = $gitlabID; + $this->view->projectID = $projectID; + $this->view->hasAccessBranches = $hasAccessBranches; + $this->view->noAccessBranches = $noAccessBranches; + $this->display(); + } + + /** + * Manage a gitlab tag protected. + * + * @param int $repoID + * @param int $projectID + * @access public + * @return void + */ + public function manageTagPriv($gitlabID, $projectID) + { + if(!$this->app->user->admin) + { + $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); + if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); + if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); + } + + $hasAccessTags = $this->gitlab->apiGetTagPrivs($gitlabID, $projectID, '', 'name_asc'); + foreach($hasAccessTags as $tag) + { + $tag->createAccess = $this->gitlab->checkAccessLevel($tag->create_access_levels); + } + + if(!empty($_POST)) + { + $result = $this->gitlab->manageTagPrivs($gitlabID, $projectID, $hasAccessTags); + if(!empty($result)) return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->gitlab->svaeFailed, implode(', ', $result)))); + + 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; + } + + $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->display(); + } } diff --git a/module/gitlab/js/managebranchpriv.js b/module/gitlab/js/managebranchpriv.js new file mode 100644 index 0000000000..ca2a04c27b --- /dev/null +++ b/module/gitlab/js/managebranchpriv.js @@ -0,0 +1,72 @@ +/* Update other picker on change */ +$.zui.Picker.DEFAULTS.onChange = function(event) +{ + var picker = event.picker; + if(!picker.$formItem.is('[name^=branches]')) return; + + var select = picker.$formItem[0]; + var newItem = event.value.length ? $.extend({}, picker.getListItem(event.value), {disabled: true}) : $.extend({}, picker.getListItem(event.oldValue), {disabled: false}); + + $('.user-picker[name^=branches]').each(function() + { + if(this === select) return; + + var $select = $(this); + var selectPicker = $select.data('zui.picker'); + + if(selectPicker) selectPicker.updateOptionList([$.extend({}, newItem)]); + }); +} + +/** + * Save team members. + * + * @access public + * @return void + */ +function savePriv() +{ + $('#saveBtn').addClass('hidden'); + $('#submit').removeClass('hidden'); + $('#submit').click(); +} + +/** + * Add item. + * + * @param object $obj + * @access public + * @return void + */ +function addItem(obj) +{ + var item = $('#addItem').html().replace(/%i%/g, itemIndex); + var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); + var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'}); + itemIndex++; + + var disabledItems = []; + $('.user-picker[name^=branches]').each(function() + { + if(this === $accounts[0]) return; + var $select = $(this); + var picker = $select.data('zui.picker'); + if(!picker) return; + var selectItem = picker.getListItem(picker.getValue()); + if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true})); + }); + if(disabledItems.length) $accounts.data('zui.picker').updateOptionList(disabledItems); +} + +/** + * Delete item. + * + * @param object $obj + * @access public + * @return void + */ +function deleteItem(obj) +{ + if($('#teamForm .table-form tbody').children().length < 2) return false; + $(obj).closest('tr').remove(); +} diff --git a/module/gitlab/js/managetagpriv.js b/module/gitlab/js/managetagpriv.js new file mode 100644 index 0000000000..6e290efb1f --- /dev/null +++ b/module/gitlab/js/managetagpriv.js @@ -0,0 +1,72 @@ +/* Update other picker on change */ +$.zui.Picker.DEFAULTS.onChange = function(event) +{ + var picker = event.picker; + if(!picker.$formItem.is('[name^=tags]')) return; + + var select = picker.$formItem[0]; + var newItem = event.value.length ? $.extend({}, picker.getListItem(event.value), {disabled: true}) : $.extend({}, picker.getListItem(event.oldValue), {disabled: false}); + + $('.user-picker[name^=tags]').each(function() + { + if(this === select) return; + + var $select = $(this); + var selectPicker = $select.data('zui.picker'); + + if(selectPicker) selectPicker.updateOptionList([$.extend({}, newItem)]); + }); +} + +/** + * Save team members. + * + * @access public + * @return void + */ +function savePriv() +{ + $('#saveBtn').addClass('hidden'); + $('#submit').removeClass('hidden'); + $('#submit').click(); +} + +/** + * Add item. + * + * @param object $obj + * @access public + * @return void + */ +function addItem(obj) +{ + var item = $('#addItem').html().replace(/%i%/g, itemIndex); + var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); + var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'}); + itemIndex++; + + var disabledItems = []; + $('.user-picker[name^=tags]').each(function() + { + if(this === $accounts[0]) return; + var $select = $(this); + var picker = $select.data('zui.picker'); + if(!picker) return; + var selectItem = picker.getListItem(picker.getValue()); + if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true})); + }); + if(disabledItems.length) $accounts.data('zui.picker').updateOptionList(disabledItems); +} + +/** + * Delete item. + * + * @param object $obj + * @access public + * @return void + */ +function deleteItem(obj) +{ + if($('#teamForm .table-form tbody').children().length < 2) return false; + $(obj).closest('tr').remove(); +} diff --git a/module/gitlab/lang/de.php b/module/gitlab/lang/de.php index 169875c665..41d82d8582 100644 --- a/module/gitlab/lang/de.php +++ b/module/gitlab/lang/de.php @@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "User"; $lang->gitlab->browseGroup = "Group"; $lang->gitlab->browseBranch = "GitLab Branch List"; $lang->gitlab->browseTag = "GitLab Tag List"; -$lang->gitlab->browseTagPriv = "GitLab Tag protected List"; +$lang->gitlab->browseTagPriv = "Protected tag"; $lang->gitlab->gitlabIssue = "GitLab Issue"; $lang->gitlab->zentaoProduct = 'Zentao Product'; $lang->gitlab->objectType = 'Type'; // task, bug, story @@ -52,14 +52,9 @@ $lang->gitlab->createBranch = 'Add branch'; $lang->gitlab->manageGroupMembers = 'Manage group member'; $lang->gitlab->createWebhook = 'Create Webhook'; $lang->gitlab->browseBranchPriv = 'Protect branch'; -$lang->gitlab->createBranchPriv = 'Cerate branch protected'; -$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 = 'Create tag protected'; -$lang->gitlab->editTagPriv = 'Edit tag protected'; -$lang->gitlab->deleteTagPriv = 'Delete tag protected'; +$lang->gitlab->svaeFailed = '『%s』save failed'; $lang->gitlab->id = 'ID'; $lang->gitlab->name = "Server Name"; diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 169875c665..41d82d8582 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "User"; $lang->gitlab->browseGroup = "Group"; $lang->gitlab->browseBranch = "GitLab Branch List"; $lang->gitlab->browseTag = "GitLab Tag List"; -$lang->gitlab->browseTagPriv = "GitLab Tag protected List"; +$lang->gitlab->browseTagPriv = "Protected tag"; $lang->gitlab->gitlabIssue = "GitLab Issue"; $lang->gitlab->zentaoProduct = 'Zentao Product'; $lang->gitlab->objectType = 'Type'; // task, bug, story @@ -52,14 +52,9 @@ $lang->gitlab->createBranch = 'Add branch'; $lang->gitlab->manageGroupMembers = 'Manage group member'; $lang->gitlab->createWebhook = 'Create Webhook'; $lang->gitlab->browseBranchPriv = 'Protect branch'; -$lang->gitlab->createBranchPriv = 'Cerate branch protected'; -$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 = 'Create tag protected'; -$lang->gitlab->editTagPriv = 'Edit tag protected'; -$lang->gitlab->deleteTagPriv = 'Delete tag protected'; +$lang->gitlab->svaeFailed = '『%s』save failed'; $lang->gitlab->id = 'ID'; $lang->gitlab->name = "Server Name"; diff --git a/module/gitlab/lang/fr.php b/module/gitlab/lang/fr.php index 169875c665..41d82d8582 100644 --- a/module/gitlab/lang/fr.php +++ b/module/gitlab/lang/fr.php @@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "User"; $lang->gitlab->browseGroup = "Group"; $lang->gitlab->browseBranch = "GitLab Branch List"; $lang->gitlab->browseTag = "GitLab Tag List"; -$lang->gitlab->browseTagPriv = "GitLab Tag protected List"; +$lang->gitlab->browseTagPriv = "Protected tag"; $lang->gitlab->gitlabIssue = "GitLab Issue"; $lang->gitlab->zentaoProduct = 'Zentao Product'; $lang->gitlab->objectType = 'Type'; // task, bug, story @@ -52,14 +52,9 @@ $lang->gitlab->createBranch = 'Add branch'; $lang->gitlab->manageGroupMembers = 'Manage group member'; $lang->gitlab->createWebhook = 'Create Webhook'; $lang->gitlab->browseBranchPriv = 'Protect branch'; -$lang->gitlab->createBranchPriv = 'Cerate branch protected'; -$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 = 'Create tag protected'; -$lang->gitlab->editTagPriv = 'Edit tag protected'; -$lang->gitlab->deleteTagPriv = 'Delete tag protected'; +$lang->gitlab->svaeFailed = '『%s』save failed'; $lang->gitlab->id = 'ID'; $lang->gitlab->name = "Server Name"; diff --git a/module/gitlab/lang/vi.php b/module/gitlab/lang/vi.php index 169875c665..41d82d8582 100644 --- a/module/gitlab/lang/vi.php +++ b/module/gitlab/lang/vi.php @@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "User"; $lang->gitlab->browseGroup = "Group"; $lang->gitlab->browseBranch = "GitLab Branch List"; $lang->gitlab->browseTag = "GitLab Tag List"; -$lang->gitlab->browseTagPriv = "GitLab Tag protected List"; +$lang->gitlab->browseTagPriv = "Protected tag"; $lang->gitlab->gitlabIssue = "GitLab Issue"; $lang->gitlab->zentaoProduct = 'Zentao Product'; $lang->gitlab->objectType = 'Type'; // task, bug, story @@ -52,14 +52,9 @@ $lang->gitlab->createBranch = 'Add branch'; $lang->gitlab->manageGroupMembers = 'Manage group member'; $lang->gitlab->createWebhook = 'Create Webhook'; $lang->gitlab->browseBranchPriv = 'Protect branch'; -$lang->gitlab->createBranchPriv = 'Cerate branch protected'; -$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 = 'Create tag protected'; -$lang->gitlab->editTagPriv = 'Edit tag protected'; -$lang->gitlab->deleteTagPriv = 'Delete tag protected'; +$lang->gitlab->svaeFailed = '『%s』save failed'; $lang->gitlab->id = 'ID'; $lang->gitlab->name = "Server Name"; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index d9ac66d15f..7273c0c8ef 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -34,7 +34,7 @@ $lang->gitlab->browseUser = "用户"; $lang->gitlab->browseGroup = "群组"; $lang->gitlab->browseBranch = "GitLab分支列表"; $lang->gitlab->browseTag = "GitLab标签列表"; -$lang->gitlab->browseTagPriv = "GitLab标签保护列表"; +$lang->gitlab->browseTagPriv = "标签保护管理"; $lang->gitlab->gitlabIssue = "{$lang->gitlab->common} issue"; $lang->gitlab->zentaoProduct = '禅道产品'; $lang->gitlab->objectType = '类型'; // task, bug, story @@ -52,14 +52,9 @@ $lang->gitlab->createBranch = '添加分支'; $lang->gitlab->manageGroupMembers = '群组成员管理'; $lang->gitlab->createWebhook = '创建Webhook'; $lang->gitlab->browseBranchPriv = '分支保护管理'; -$lang->gitlab->createBranchPriv = '创建分支保护'; -$lang->gitlab->editBranchPriv = '编辑分支保护'; -$lang->gitlab->deleteBranchPriv = '删除分支保护'; $lang->gitlab->createTag = '创建标签'; $lang->gitlab->deleteTag = '删除标签'; -$lang->gitlab->createTagPriv = '创建标签保护'; -$lang->gitlab->editTagPriv = '编辑标签保护'; -$lang->gitlab->deleteTagPriv = '删除标签保护'; +$lang->gitlab->svaeFailed = '『%s』保存失败'; $lang->gitlab->id = 'ID'; $lang->gitlab->name = "服务器名称"; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index aa7d73dca6..6cef6d84c1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2549,59 +2549,54 @@ class gitlabModel extends model } /** - * Get single protct branch by API. + * Manage branch privs. * * @param int $gitlabID * @param int $projectID - * @param string $branch + * @param array $protected * @access public - * @return object + * @return array */ - public function apiGetSingleBranchPriv($gitlabID, $projectID, $branch) + public function manageBranchPrivs($gitlabID, $projectID, $protected = array()) { - if(empty($gitlabID)) return false; - $branch = urlencode($branch); - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/protected_branches/$branch"); - return json_decode(commonModel::http($url)); - } + $data = (array)fixer::input('post')->get(); + extract($data); + $failure = array(); - /** - * Create gitlab potect branch. - * - * @param int $gitlabID - * @param int $projectID - * @param string $branch - * @access public - * @return bool - */ - public function createBranchPriv($gitlabID, $projectID, $branch = '') - { - $priv = fixer::input('post')->get(); - if(empty($priv->name)) + /* Remove privs. */ + foreach($protected as $name => $branch) { - dao::$errors['name'][] = $this->lang->gitlab->branch->emptyPrivNameError; - return false; + if(!in_array($name, $branches)) + { + $result = $this->apiDeleteBranchPriv($gitlabID, $projectID, $name); + if($result and substr($result->message, 0, 2) != '20') $failure[] = $name; + } } - $priv->name = urldecode(helper::safe64Decode($priv->name)); - $singleBranch = $this->apiGetSingleBranchPriv($gitlabID, $projectID, $priv->name); - if(empty($branch) && !empty($singleBranch->id)) + $priv = new stdClass(); + foreach($branches as $key => $name) { - dao::$errors['name'][] = $this->lang->gitlab->branch->issetPrivNameError; - return false; + /* Process exists data. */ + if(isset($protected[$name])) + { + if($protected[$name]->pushAccess == $pushLevels[$key] and $protected[$name]->mergeAccess == $mergeLevels[$key]) + { + continue; + } + else + { + $result = $this->apiDeleteBranchPriv($gitlabID, $projectID, $name); + if(isset($result->message) and substr($result->message, 0, 2) != '20') $failure[] = $name; + } + } + + $priv->name = $name; + $priv->push_access_level = $pushLevels[$key]; + $priv->merge_access_level = $mergeLevels[$key]; + $response = $this->apiCreateBranchPriv($gitlabID, $projectID, $priv); + if(isset($response->message) and substr($response->message, 0, 2) != '20') $failure[] = $name; } - - if(!empty($branch) && !empty($singleBranch->id)) $this->apiDeleteBranchPriv($gitlabID, $projectID, $branch); - $response = $this->apiCreateBranchPriv($gitlabID, $projectID, $priv); - - if(!empty($response->id)) - { - $action = empty($branch) ? 'created' : 'edited'; - $this->loadModel('action')->create('gitlabbranchpriv', $response->id, $action, '', $response->name); - return true; - } - - return $this->apiErrorHandling($response); + return array_unique($failure); } /** @@ -2630,7 +2625,7 @@ class gitlabModel extends model * @param int $projectID * @param string $branch * @access public - * @return object + * @return array */ public function apiDeleteBranchPriv($gitlabID, $projectID, $branch) { @@ -2642,58 +2637,53 @@ class gitlabModel extends model } /** - * Create gitlab protect tag. + * Manage tag privs. * * @param int $gitlabID * @param int $projectID - * @param string $tag + * @param array $protected * @access public - * @return bool + * @return array */ - public function createTagPriv($gitlabID, $projectID, $tag = '') + public function manageTagPrivs($gitlabID, $projectID, $protected = array()) { - $priv = fixer::input('post')->get(); - if(empty($priv->name)) + $data = (array)fixer::input('post')->get(); + extract($data); + $failure = array(); + + /* Remove privs. */ + foreach($protected as $name => $tag) { - dao::$errors['name'][] = $this->lang->gitlab->tag->emptyPrivNameError; - return false; + if(!in_array($name, $tags)) + { + $result = $this->apiDeleteTagPriv($gitlabID, $projectID, $name); + if($result and substr($result->message, 0, 2) != '20') $failure[] = $name; + } } - $singleTag = $this->apiGetSingleTagPriv($gitlabID, $projectID, $priv->name); - if(empty($tag) && !empty($singleTag->id)) + $priv = new stdClass(); + foreach($tags as $key => $name) { - dao::$errors['name'][] = $this->lang->gitlab->tag->issetPrivNameError; - return false; + /* Process exists data. */ + if(isset($protected[$name])) + { + if($protected[$name]->createAccess == $createLevels[$key]) + { + continue; + } + else + { + $result = $this->apiDeleteTagPriv($gitlabID, $projectID, $name); + if(isset($result->message) and substr($result->message, 0, 2) != '20') $failure[] = $name; + } + } + + $priv->name = $name; + $priv->create_access_level = $createLevels[$key]; + $response = $this->apiCreateTagPriv($gitlabID, $projectID, $priv); + if(isset($response->message) and substr($response->message, 0, 2) != '20') $failure[] = $name; } - - 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; - $tag = urlencode($tag); - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/protected_tags/$tag"); - return json_decode(commonModel::http($url)); + return array_unique($failure); } /** diff --git a/module/gitlab/view/browsebranchpriv.html.php b/module/gitlab/view/browsebranchpriv.html.php deleted file mode 100644 index 181c913742..0000000000 --- a/module/gitlab/view/browsebranchpriv.html.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @package gitlab - * @version $Id$ - * @link http://www.zentao.net - */ -?> - - - -
-

- noData;?> - - createLink('gitlab', 'createBranchPriv', "gitlabID=$gitlabID&projectID=$projectID"), " " . $lang->gitlab->createBranchPriv, '', "class='btn btn-info'");?> - -

-
- -
-
- - recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?> - - - - - - - - - - $branch): ?> - merge_access_level = $this->gitlab->checkAccessLevel($branch->merge_access_levels); ?> - push_access_level = $this->gitlab->checkAccessLevel($branch->push_access_levels); ?> - - - - - - - - -
gitlab->branch->name);?>gitlab->branch->mergeAllowed;?>gitlab->branch->pushAllowed;?>actions;?>
name;?>merge_access_level];?>push_access_level];?> - name)); - if(common::hasPriv('gitlab', 'editBranchPriv')) common::printLink('gitlab', 'editBranchPriv', "gitlabID=$gitlabID&projectID=$projectID&branch=$branchName", " ", '', "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=$branchName"), '', 'hiddenwin', "title='{$lang->gitlab->deleteBranchPriv}' class='btn'"); - ?> -
- - - -
-
- - diff --git a/module/gitlab/view/browseproject.html.php b/module/gitlab/view/browseproject.html.php index 93fddbd2f7..e2e9c57d1d 100644 --- a/module/gitlab/view/browseproject.html.php +++ b/module/gitlab/view/browseproject.html.php @@ -60,8 +60,8 @@ last_activity_at, 0, 10);?> id", '', 'list', 'branch-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch)); - echo common::buildIconButton('gitlab', 'browseTagPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'tag-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch)); + echo common::buildIconButton('gitlab', 'manageBranchPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'branch-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch)); + echo common::buildIconButton('gitlab', 'manageTagPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'tag-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch)); echo common::buildIconButton('gitlab', 'manageProjectMembers', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'team', '', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id])); echo common::buildIconButton('gitlab', 'createWebhook', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'change', 'hiddenwin', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id])); echo common::buildIconButton('gitlab', 'importIssue', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'link', '', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id])); diff --git a/module/gitlab/view/browsetagpriv.html.php b/module/gitlab/view/browsetagpriv.html.php deleted file mode 100644 index 792e05531e..0000000000 --- a/module/gitlab/view/browsetagpriv.html.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @package gitlab - * @version $Id$ - * @link http://www.zentao.net - */ -?> - -recTotal}&recPerPage={$pager->recPerPage}&pageID=1")?> - - - -
-

- noData;?> - - createLink('gitlab', 'createTagPriv', "gitlabID=$gitlabID&projectID=$projectID"), " " . $lang->gitlab->createTagPriv, '', "class='btn btn-info'");?> - -

-
- -
-
- - recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?> - - - - - - - - - - $gitlabTag): ?> - accessLevel = $this->gitlab->checkAccessLevel($gitlabTag->accessLevels); ?> - - - - - - - - -
gitlab->tag->name);?>gitlab->tag->lastCommitter;?>gitlab->tag->accessLevel);?>actions;?>
name;?>lastCommitter;?>gitlab->branch->branchCreationLevelList, $gitlabTag->accessLevel);?> - name)); - common::printLink('gitlab', 'editTagPriv', "gitlabID=$gitlabID&projectID=$projectID&tag_name=$tagName", " ", '', "title={$lang->gitlab->editTagPriv} class='btn btn-primary'"); - common::printLink('gitlab', 'deleteTagPriv', "gitlabID=$gitlabID&projectID={$projectID}&tag_name=$tagName", " ", '', "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/createbranchpriv.html.php b/module/gitlab/view/createbranchpriv.html.php deleted file mode 100644 index 52c3e691f2..0000000000 --- a/module/gitlab/view/createbranchpriv.html.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @package gitlab - * @version $Id$ - * @link http://www.zentao.net - */ -?> - -
-
-
-
-

-
-
- name) echo html::hidden('name', $branchPriv->name);?> - - - - - - - - - - - - - - - - - -
gitlab->branch->name;?>name, "class='form-control chosen' " . ($branch ? 'disabled' : ''));?>
gitlab->branch->mergeAllowed;?>gitlab->branch->branchCreationLevelList, $branchPriv->mergeAccessLevel, "class='form-control'");?>
gitlab->branch->pushAllowed;?>gitlab->branch->branchCreationLevelList, $branchPriv->pushAccessLevel, "class='form-control'");?>
- - goback, '', 'class="btn btn-wide"');?> -
-
-
-
-
- diff --git a/module/gitlab/view/createtagpriv.html.php b/module/gitlab/view/createtagpriv.html.php deleted file mode 100644 index cf45b66372..0000000000 --- a/module/gitlab/view/createtagpriv.html.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @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 deleted file mode 100644 index aec4bbcbf2..0000000000 --- a/module/gitlab/view/edittagpriv.html.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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"');?> -
-
-
-
-
- diff --git a/module/gitlab/view/managebranchpriv.html.php b/module/gitlab/view/managebranchpriv.html.php new file mode 100644 index 0000000000..c33f4272ff --- /dev/null +++ b/module/gitlab/view/managebranchpriv.html.php @@ -0,0 +1,82 @@ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
gitlab->branch->name;?>gitlab->branch->mergeAllowed;?>gitlab->branch->pushAllowed;?>actions;?>
name, "class='form-control' readonly");?>gitlab->branch->branchCreationLevelList, $branch->mergeAccess, "class='form-control chosen'");?> + gitlab->branch->branchCreationLevelList, $branch->pushAccess, "class='form-control chosen'");?> + name);?> + + ", '', "onclick='addItem(this)' class='btn btn-link'");?> + ", '', "onclick='deleteItem(this)' class='btn btn-link'");?> +
'') + $noAccessBranches, '', "class='form-control user-picker'");?>gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?>gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?> + ", '', "onclick='addItem(this)' class='btn btn-link'");?> + ", '', "onclick='deleteItem(this)' class='btn btn-link'");?> +
+ save, 'onclick="savePriv()" id="saveBtn"', 'btn btn-wide btn-primary'); + echo html::backButton(); + ?> +
+ +
+
+
+ + + + + + + + + +
+ diff --git a/module/gitlab/view/managetagpriv.html.php b/module/gitlab/view/managetagpriv.html.php new file mode 100644 index 0000000000..c22ed7462a --- /dev/null +++ b/module/gitlab/view/managetagpriv.html.php @@ -0,0 +1,76 @@ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
gitlab->tag->name;?>gitlab->tag->accessLevel;?>actions;?>
name, "class='form-control' readonly");?>gitlab->branch->branchCreationLevelList, $tag->createAccess, "class='form-control chosen'");?> + name);?> + ", '', "onclick='addItem(this)' class='btn btn-link'");?> + ", '', "onclick='deleteItem(this)' class='btn btn-link'");?> +
'') + $noAccessTags, '', "class='form-control user-picker'");?>gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?> + ", '', "onclick='addItem(this)' class='btn btn-link'");?> + ", '', "onclick='deleteItem(this)' class='btn btn-link'");?> +
+ save, 'onclick="savePriv()" id="saveBtn"', 'btn btn-wide btn-primary'); + echo html::backButton(); + ?> +
+ +
+
+
+ + + + + + + + +
+ diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 9893779893..361267c995 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -1344,17 +1344,11 @@ $lang->resource->gitlab->browseBranch = 'browseBranch'; $lang->resource->gitlab->webhook = 'webhook'; $lang->resource->gitlab->createWebhook = 'createWebhook'; $lang->resource->gitlab->manageProjectMembers = 'manageProjectMembers'; -$lang->resource->gitlab->browseBranchPriv = 'browseBranchPriv'; -$lang->resource->gitlab->createBranchPriv = 'createBranchPriv'; -$lang->resource->gitlab->editBranchPriv = 'editBranchPriv'; -$lang->resource->gitlab->deleteBranchPriv = 'deleteBranchPriv'; +$lang->resource->gitlab->manageBranchPriv = 'browseBranchPriv'; +$lang->resource->gitlab->manageTagPriv = 'browseTagPriv'; $lang->resource->gitlab->browseTag = 'browseTag'; $lang->resource->gitlab->createTag = 'createTag'; $lang->resource->gitlab->deleteTag = 'deleteTag'; -$lang->resource->gitlab->browseTagPriv = 'browseTagPriv'; -$lang->resource->gitlab->createTagPriv = 'createTagPriv'; -$lang->resource->gitlab->editTagPriv = 'editTagPriv'; -$lang->resource->gitlab->deleteTagPriv = 'deleteTagPriv'; $lang->gitlab->methodOrder[5] = 'browse'; $lang->gitlab->methodOrder[10] = 'create'; @@ -1381,9 +1375,11 @@ $lang->gitlab->methodOrder[115] = 'browseBranch'; $lang->gitlab->methodOrder[120] = 'webhook'; $lang->gitlab->methodOrder[125] = 'createWebhook'; $lang->gitlab->methodOrder[130] = 'manageProjectMembers'; -$lang->gitlab->methodOrder[135] = 'browseTag'; -$lang->gitlab->methodOrder[140] = 'browseTagPriv'; -$lang->gitlab->methodOrder[145] = 'deleteTagPriv'; +$lang->gitlab->methodOrder[135] = 'manageBranchPriv'; +$lang->gitlab->methodOrder[140] = 'manageTagPriv'; +$lang->gitlab->methodOrder[145] = 'browseTag'; +$lang->gitlab->methodOrder[150] = 'createTag'; +$lang->gitlab->methodOrder[155] = 'deleteTag'; /* Gitea. */ $lang->resource->gitea = new stdclass(); From 8e2c8317227fb8b939551924addcc4d6657fcfa6 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 09:51:36 +0800 Subject: [PATCH 04/85] * Modify param name. --- module/gitlab/js/managebranchpriv.js | 4 ++-- module/gitlab/js/managetagpriv.js | 4 ++-- module/gitlab/view/managebranchpriv.html.php | 2 +- module/gitlab/view/managetagpriv.html.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/module/gitlab/js/managebranchpriv.js b/module/gitlab/js/managebranchpriv.js index ca2a04c27b..b00adf44e6 100644 --- a/module/gitlab/js/managebranchpriv.js +++ b/module/gitlab/js/managebranchpriv.js @@ -19,7 +19,7 @@ $.zui.Picker.DEFAULTS.onChange = function(event) } /** - * Save team members. + * Save branch priv. * * @access public * @return void @@ -67,6 +67,6 @@ function addItem(obj) */ function deleteItem(obj) { - if($('#teamForm .table-form tbody').children().length < 2) return false; + if($('#privForm .table-form tbody').children().length < 2) return false; $(obj).closest('tr').remove(); } diff --git a/module/gitlab/js/managetagpriv.js b/module/gitlab/js/managetagpriv.js index 6e290efb1f..1afcbfd09a 100644 --- a/module/gitlab/js/managetagpriv.js +++ b/module/gitlab/js/managetagpriv.js @@ -19,7 +19,7 @@ $.zui.Picker.DEFAULTS.onChange = function(event) } /** - * Save team members. + * Save tag priv. * * @access public * @return void @@ -67,6 +67,6 @@ function addItem(obj) */ function deleteItem(obj) { - if($('#teamForm .table-form tbody').children().length < 2) return false; + if($('#privForm .table-form tbody').children().length < 2) return false; $(obj).closest('tr').remove(); } diff --git a/module/gitlab/view/managebranchpriv.html.php b/module/gitlab/view/managebranchpriv.html.php index c33f4272ff..714a03bda1 100644 --- a/module/gitlab/view/managebranchpriv.html.php +++ b/module/gitlab/view/managebranchpriv.html.php @@ -7,7 +7,7 @@
-
+ diff --git a/module/gitlab/view/managetagpriv.html.php b/module/gitlab/view/managetagpriv.html.php index c22ed7462a..bbb53f69dd 100644 --- a/module/gitlab/view/managetagpriv.html.php +++ b/module/gitlab/view/managetagpriv.html.php @@ -7,7 +7,7 @@
- +
From 223ab3a2f8fe39c3bf2d2876e86021cb5882ffb5 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 13:13:04 +0800 Subject: [PATCH 05/85] * Adjust code. --- module/gitlab/js/managebranchpriv.js | 6 +++--- module/gitlab/js/managetagpriv.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/module/gitlab/js/managebranchpriv.js b/module/gitlab/js/managebranchpriv.js index b00adf44e6..4a8fcb1cf7 100644 --- a/module/gitlab/js/managebranchpriv.js +++ b/module/gitlab/js/managebranchpriv.js @@ -40,8 +40,8 @@ function savePriv() */ function addItem(obj) { - var item = $('#addItem').html().replace(/%i%/g, itemIndex); - var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); + var item = $('#addItem').html().replace(/%i%/g, itemIndex); + var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'}); itemIndex++; @@ -50,7 +50,7 @@ function addItem(obj) { if(this === $accounts[0]) return; var $select = $(this); - var picker = $select.data('zui.picker'); + var picker = $select.data('zui.picker'); if(!picker) return; var selectItem = picker.getListItem(picker.getValue()); if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true})); diff --git a/module/gitlab/js/managetagpriv.js b/module/gitlab/js/managetagpriv.js index 1afcbfd09a..d7ab47bfd1 100644 --- a/module/gitlab/js/managetagpriv.js +++ b/module/gitlab/js/managetagpriv.js @@ -40,8 +40,8 @@ function savePriv() */ function addItem(obj) { - var item = $('#addItem').html().replace(/%i%/g, itemIndex); - var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); + var item = $('#addItem').html().replace(/%i%/g, itemIndex); + var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'}); itemIndex++; @@ -50,7 +50,7 @@ function addItem(obj) { if(this === $accounts[0]) return; var $select = $(this); - var picker = $select.data('zui.picker'); + var picker = $select.data('zui.picker'); if(!picker) return; var selectItem = picker.getListItem(picker.getValue()); if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true})); From ae7c259ab1d3809a2c2516d164f51dd1051c0764 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 13:18:54 +0800 Subject: [PATCH 06/85] * Adjust codes. --- module/gitlab/model.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 6cef6d84c1..6ba139764b 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2579,15 +2579,10 @@ class gitlabModel extends model /* Process exists data. */ if(isset($protected[$name])) { - if($protected[$name]->pushAccess == $pushLevels[$key] and $protected[$name]->mergeAccess == $mergeLevels[$key]) - { - continue; - } - else - { - $result = $this->apiDeleteBranchPriv($gitlabID, $projectID, $name); - if(isset($result->message) and substr($result->message, 0, 2) != '20') $failure[] = $name; - } + if($protected[$name]->pushAccess == $pushLevels[$key] and $protected[$name]->mergeAccess == $mergeLevels[$key]) continue; + + $result = $this->apiDeleteBranchPriv($gitlabID, $projectID, $name); + if(isset($result->message) and substr($result->message, 0, 2) != '20') $failure[] = $name; } $priv->name = $name; @@ -2667,15 +2662,10 @@ class gitlabModel extends model /* Process exists data. */ if(isset($protected[$name])) { - if($protected[$name]->createAccess == $createLevels[$key]) - { - continue; - } - else - { - $result = $this->apiDeleteTagPriv($gitlabID, $projectID, $name); - if(isset($result->message) and substr($result->message, 0, 2) != '20') $failure[] = $name; - } + if($protected[$name]->createAccess == $createLevels[$key]) continue; + + $result = $this->apiDeleteTagPriv($gitlabID, $projectID, $name); + if(isset($result->message) and substr($result->message, 0, 2) != '20') $failure[] = $name; } $priv->name = $name; From 6cef93edd9534e07d1ffae2f83be2a79cafe5555 Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Tue, 12 Jul 2022 06:30:13 +0000 Subject: [PATCH 07/85] * Finish task #60453. --- module/action/lang/de.php | 1 + module/action/lang/en.php | 1 + module/action/lang/fr.php | 1 + module/action/lang/vi.php | 1 + module/action/lang/zh-cn.php | 1 + module/action/lang/zh-tw.php | 1 + module/action/model.php | 4 +- module/gitea/control.php | 32 +++++ module/gitea/lang/de.php | 7 ++ module/gitea/lang/en.php | 7 ++ module/gitea/lang/fr.php | 7 ++ module/gitea/lang/vi.php | 7 ++ module/gitea/lang/zh-cn.php | 7 ++ module/gitea/lang/zh-tw.php | 7 ++ module/gitea/model.php | 184 ++++++++++++++++++++++++++++- module/gitea/view/browse.html.php | 2 + module/gitlab/control.php | 20 ++-- module/gitlab/view/browse.html.php | 4 +- module/group/lang/resource.php | 12 +- 19 files changed, 282 insertions(+), 24 deletions(-) diff --git a/module/action/lang/de.php b/module/action/lang/de.php index 988570d7ce..3e6cb30e3f 100644 --- a/module/action/lang/de.php +++ b/module/action/lang/de.php @@ -133,6 +133,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch'; $lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches'; $lang->action->objectTypes['gitlabtag'] = 'GitLab Tag'; $lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected'; +$lang->action->objectTypes['giteauser'] = 'Gitea User'; $lang->action->objectTypes['kanbanspace'] = 'Kanban Space'; $lang->action->objectTypes['kanban'] = 'Kanban'; $lang->action->objectTypes['kanbanregion'] = 'Kanban Region'; diff --git a/module/action/lang/en.php b/module/action/lang/en.php index e195c73ad7..2ca3bbdd58 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -133,6 +133,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch'; $lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches'; $lang->action->objectTypes['gitlabtag'] = 'GitLab Tag'; $lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected'; +$lang->action->objectTypes['giteauser'] = 'Gitea User'; $lang->action->objectTypes['kanbanspace'] = 'Kanban Space'; $lang->action->objectTypes['kanban'] = 'Kanban'; $lang->action->objectTypes['kanbanregion'] = 'Kanban Region'; diff --git a/module/action/lang/fr.php b/module/action/lang/fr.php index fb1c45ebc5..75212cf95b 100644 --- a/module/action/lang/fr.php +++ b/module/action/lang/fr.php @@ -133,6 +133,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch'; $lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches'; $lang->action->objectTypes['gitlabtag'] = 'GitLab Tag'; $lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected'; +$lang->action->objectTypes['giteauser'] = 'Gitea User'; $lang->action->objectTypes['kanbanspace'] = 'Kanban Space'; $lang->action->objectTypes['kanban'] = 'Kanban'; $lang->action->objectTypes['kanbanregion'] = 'Kanban Region'; diff --git a/module/action/lang/vi.php b/module/action/lang/vi.php index 681dc1b71f..7e7aa0909a 100644 --- a/module/action/lang/vi.php +++ b/module/action/lang/vi.php @@ -111,6 +111,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab Branch'; $lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab Protected Branches'; $lang->action->objectTypes['gitlabtag'] = 'GitLab Tag'; $lang->action->objectTypes['gitlabtagpriv'] = 'GitLab Tag Protected'; +$lang->action->objectTypes['giteauser'] = 'Gitea User'; $lang->action->objectTypes['kanbanspace'] = 'Kanban Space'; $lang->action->objectTypes['kanban'] = 'Kanban'; $lang->action->objectTypes['kanbanregion'] = 'Kanban Region'; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index 4b332524af..84a25b2372 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -133,6 +133,7 @@ $lang->action->objectTypes['gitlabbranch'] = 'GitLab分支'; $lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab保护分支'; $lang->action->objectTypes['gitlabtag'] = 'GitLab标签'; $lang->action->objectTypes['gitlabtagpriv'] = 'GitLab标签保护'; +$lang->action->objectTypes['giteauser'] = 'Gitea用户'; $lang->action->objectTypes['kanbanspace'] = '看板空间'; $lang->action->objectTypes['kanban'] = '看板'; $lang->action->objectTypes['kanbanregion'] = '看板区域'; diff --git a/module/action/lang/zh-tw.php b/module/action/lang/zh-tw.php index 9a66017d80..04ebfaedf6 100755 --- a/module/action/lang/zh-tw.php +++ b/module/action/lang/zh-tw.php @@ -127,6 +127,7 @@ $lang->action->objectTypes['gitlabgroup'] = 'GitLab群組'; $lang->action->objectTypes['gitlabbranch'] = 'GitLab分支'; $lang->action->objectTypes['gitlabbranchpriv'] = 'GitLab保護分支'; $lang->action->objectTypes['gitlabtag'] = 'GitLab標籤'; +$lang->action->objectTypes['giteauser'] = 'Gitea用戶'; $lang->action->objectTypes['kanbanspace'] = '看板空間'; $lang->action->objectTypes['kanban'] = '看板'; $lang->action->objectTypes['kanbanregion'] = '看板區域'; diff --git a/module/action/model.php b/module/action/model.php index ca7525cfd4..9512d4cbd8 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -1254,8 +1254,8 @@ class actionModel extends model /* If action type is login or logout, needn't link. */ if($actionType == 'svncommited' or $actionType == 'gitcommited') $action->actor = zget($commiters, $action->actor); - /* Get gitlab objectname. */ - if(empty($action->objectName) and substr($objectType, 0, 6) == 'gitlab') $action->objectName = $action->extra; + /* Get gitlab or gitea objectname. */ + if(empty($action->objectName) and (substr($objectType, 0, 6) == 'gitlab' or substr($objectType, 0, 5) == 'gitea')) $action->objectName = $action->extra; /* Other actions, create a link. */ if(!$this->setObjectLink($action, $deptUsers)) diff --git a/module/gitea/control.php b/module/gitea/control.php index 413f2c2e52..2c6cc08a2a 100644 --- a/module/gitea/control.php +++ b/module/gitea/control.php @@ -43,6 +43,11 @@ class gitea extends control /* Admin user don't need bind. */ $giteaList = $this->gitea->getList($orderBy, $pager); + foreach($giteaList as $gitea) + { + $gitea->isBindUser = true; + if(!$this->app->user->admin and !isset($myGiteas[$gitea->id])) $gitea->isBindUser = false; + } $this->view->title = $this->lang->gitea->common . $this->lang->colon . $this->lang->gitea->browse; $this->view->giteaList = $giteaList; @@ -164,4 +169,31 @@ class gitea extends control return true; } + + /** + * Bind gitea user to zentao users. + * + * @param int $giteaID + * @access public + * @return void + */ + public function bindUser($giteaID) + { + $zentaoUsers = $this->dao->select('account,email,realname')->from(TABLE_USER)->fetchAll('account'); + $userPairs = $this->loadModel('user')->getPairs('noclosed|noletter'); + + if($_POST) + { + $this->gitea->bindUser($giteaID); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->server->http_referer)); + } + + $this->view->title = $this->lang->gitea->bindUser; + $this->view->userPairs = $userPairs; + $this->view->giteaUsers = $this->gitea->apiGetUsers($giteaID); + $this->view->bindedUsers = $this->gitea->getUserAccountIdPairs($giteaID); + $this->view->matchedResult = $this->gitea->getMatchedUsers($giteaID, $this->view->giteaUsers, $zentaoUsers); + $this->display(); + } } diff --git a/module/gitea/lang/de.php b/module/gitea/lang/de.php index 5d0779ba55..b4716e7bed 100644 --- a/module/gitea/lang/de.php +++ b/module/gitea/lang/de.php @@ -8,6 +8,13 @@ $lang->gitea->edit = 'Edit Gitea'; $lang->gitea->view = 'View Gitea'; $lang->gitea->delete = 'Delete Gitea'; $lang->gitea->confirmDelete = 'Do you want to delete this Gitea server?'; +$lang->gitea->bindUser = 'Bind User'; +$lang->gitea->giteaAccount = 'Gitea Account'; +$lang->gitea->zentaoAccount = 'Zentao Account'; +$lang->gitea->bindingStatus = 'Binding Status'; +$lang->gitea->notBind = 'Not bind'; +$lang->gitea->binded = 'Binded'; +$lang->gitea->bindDynamic = '%s and Zentao user %s'; $lang->gitea->browseAction = 'Gitea List'; $lang->gitea->deleteAction = 'Delete Gitea'; diff --git a/module/gitea/lang/en.php b/module/gitea/lang/en.php index 5d0779ba55..b4716e7bed 100644 --- a/module/gitea/lang/en.php +++ b/module/gitea/lang/en.php @@ -8,6 +8,13 @@ $lang->gitea->edit = 'Edit Gitea'; $lang->gitea->view = 'View Gitea'; $lang->gitea->delete = 'Delete Gitea'; $lang->gitea->confirmDelete = 'Do you want to delete this Gitea server?'; +$lang->gitea->bindUser = 'Bind User'; +$lang->gitea->giteaAccount = 'Gitea Account'; +$lang->gitea->zentaoAccount = 'Zentao Account'; +$lang->gitea->bindingStatus = 'Binding Status'; +$lang->gitea->notBind = 'Not bind'; +$lang->gitea->binded = 'Binded'; +$lang->gitea->bindDynamic = '%s and Zentao user %s'; $lang->gitea->browseAction = 'Gitea List'; $lang->gitea->deleteAction = 'Delete Gitea'; diff --git a/module/gitea/lang/fr.php b/module/gitea/lang/fr.php index 5d0779ba55..b4716e7bed 100644 --- a/module/gitea/lang/fr.php +++ b/module/gitea/lang/fr.php @@ -8,6 +8,13 @@ $lang->gitea->edit = 'Edit Gitea'; $lang->gitea->view = 'View Gitea'; $lang->gitea->delete = 'Delete Gitea'; $lang->gitea->confirmDelete = 'Do you want to delete this Gitea server?'; +$lang->gitea->bindUser = 'Bind User'; +$lang->gitea->giteaAccount = 'Gitea Account'; +$lang->gitea->zentaoAccount = 'Zentao Account'; +$lang->gitea->bindingStatus = 'Binding Status'; +$lang->gitea->notBind = 'Not bind'; +$lang->gitea->binded = 'Binded'; +$lang->gitea->bindDynamic = '%s and Zentao user %s'; $lang->gitea->browseAction = 'Gitea List'; $lang->gitea->deleteAction = 'Delete Gitea'; diff --git a/module/gitea/lang/vi.php b/module/gitea/lang/vi.php index 5d0779ba55..b4716e7bed 100644 --- a/module/gitea/lang/vi.php +++ b/module/gitea/lang/vi.php @@ -8,6 +8,13 @@ $lang->gitea->edit = 'Edit Gitea'; $lang->gitea->view = 'View Gitea'; $lang->gitea->delete = 'Delete Gitea'; $lang->gitea->confirmDelete = 'Do you want to delete this Gitea server?'; +$lang->gitea->bindUser = 'Bind User'; +$lang->gitea->giteaAccount = 'Gitea Account'; +$lang->gitea->zentaoAccount = 'Zentao Account'; +$lang->gitea->bindingStatus = 'Binding Status'; +$lang->gitea->notBind = 'Not bind'; +$lang->gitea->binded = 'Binded'; +$lang->gitea->bindDynamic = '%s and Zentao user %s'; $lang->gitea->browseAction = 'Gitea List'; $lang->gitea->deleteAction = 'Delete Gitea'; diff --git a/module/gitea/lang/zh-cn.php b/module/gitea/lang/zh-cn.php index dd8da67d29..7e273df350 100644 --- a/module/gitea/lang/zh-cn.php +++ b/module/gitea/lang/zh-cn.php @@ -8,6 +8,13 @@ $lang->gitea->edit = '编辑Gitea'; $lang->gitea->view = '查看Gitea'; $lang->gitea->delete = '删除Gitea'; $lang->gitea->confirmDelete = '确认删除该Gitea吗?'; +$lang->gitea->bindUser = '绑定用户'; +$lang->gitea->giteaAccount = 'Gitea用户'; +$lang->gitea->zentaoAccount = '禅道用户'; +$lang->gitea->bindingStatus = '绑定状态'; +$lang->gitea->notBind = '未绑定'; +$lang->gitea->binded = '已绑定'; +$lang->gitea->bindDynamic = '%s与禅道用户%s'; $lang->gitea->browseAction = 'Gitea列表'; $lang->gitea->deleteAction = '删除Gitea'; diff --git a/module/gitea/lang/zh-tw.php b/module/gitea/lang/zh-tw.php index dd8da67d29..7e273df350 100644 --- a/module/gitea/lang/zh-tw.php +++ b/module/gitea/lang/zh-tw.php @@ -8,6 +8,13 @@ $lang->gitea->edit = '编辑Gitea'; $lang->gitea->view = '查看Gitea'; $lang->gitea->delete = '删除Gitea'; $lang->gitea->confirmDelete = '确认删除该Gitea吗?'; +$lang->gitea->bindUser = '绑定用户'; +$lang->gitea->giteaAccount = 'Gitea用户'; +$lang->gitea->zentaoAccount = '禅道用户'; +$lang->gitea->bindingStatus = '绑定状态'; +$lang->gitea->notBind = '未绑定'; +$lang->gitea->binded = '已绑定'; +$lang->gitea->bindDynamic = '%s与禅道用户%s'; $lang->gitea->browseAction = 'Gitea列表'; $lang->gitea->deleteAction = '删除Gitea'; diff --git a/module/gitea/model.php b/module/gitea/model.php index f1fabf2ffe..6a9ad9ef99 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -104,6 +104,62 @@ class giteaModel extends model return $this->loadModel('pipeline')->update($id); } + /** + * Bind users. + * + * @param int $giteaID + * @access public + * @return array + */ + public function bindUser($giteaID) + { + $users = $this->post->zentaoUsers; + $giteaNames = $this->post->giteaUserNames; + $accountList = array(); + $repeatUsers = array(); + foreach($users as $openID => $user) + { + if(empty($user)) continue; + if(isset($accountList[$user])) $repeatUsers[] = zget($userPairs, $user); + $accountList[$user] = $openID; + } + + if(count($repeatUsers)) + { + dao::$errors[] = sprintf($this->lang->gitea->bindUserError, join(',', $repeatUsers)); + return false; + } + + $user = new stdclass; + $user->providerID = $giteaID; + $user->providerType = 'gitea'; + + $oldUsers = $this->dao->select('*')->from(TABLE_OAUTH)->where('providerType')->eq($user->providerType)->andWhere('providerID')->eq($user->providerID)->fetchAll('openID'); + foreach($users as $openID => $account) + { + $existAccount = isset($oldUsers[$openID]) ? $oldUsers[$openID] : ''; + + if($existAccount and $existAccount->account != $account) + { + $this->dao->delete() + ->from(TABLE_OAUTH) + ->where('openID')->eq($openID) + ->andWhere('providerType')->eq($user->providerType) + ->andWhere('providerID')->eq($user->providerID) + ->exec(); + $this->loadModel('action')->create('giteauser', $openID, 'unbind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$existAccount->account]->realname)); + } + if(!$existAccount or $existAccount->account != $account) + { + if(!$account) continue; + $user->account = $account; + $user->openID = $openID; + $this->dao->insert(TABLE_OAUTH)->data($user)->exec(); + $this->loadModel('action')->create('giteauser', $openID, 'bind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$account]->realname)); + } + } + } + /** * Api error handling. * @@ -225,6 +281,70 @@ class giteaModel extends model ->fetchPairs('providerID'); } + /** + * Get zentao account gitea user id pairs of one gitea. + * + * @param int $giteaID + * @access public + * @return array + */ + public function getUserAccountIdPairs($giteaID, $fields = 'account,openID') + { + return $this->dao->select($fields)->from(TABLE_OAUTH) + ->where('providerType')->eq('gitea') + ->andWhere('providerID')->eq($giteaID) + ->fetchPairs(); + } + + /** + * Get matched gitea users. + * + * @param int $giteaID + * @param array $giteaUsers + * @param array $zentaoUsers + * @access public + * @return array + */ + public function getMatchedUsers($giteaID, $giteaUsers, $zentaoUsers) + { + $matches = new stdclass; + foreach($giteaUsers as $giteaUser) + { + foreach($zentaoUsers as $zentaoUser) + { + if($giteaUser->account == $zentaoUser->account) $matches->accounts[$giteaUser->account][] = $zentaoUser->account; + if($giteaUser->realname == $zentaoUser->realname) $matches->names[$giteaUser->realname][] = $zentaoUser->account; + if($giteaUser->email == $zentaoUser->email) $matches->emails[$giteaUser->email][] = $zentaoUser->account; + } + } + + $bindedUsers = $this->getUserAccountIdPairs($giteaID, 'openID,account'); + $matchedUsers = array(); + foreach($giteaUsers as $giteaUser) + { + if(isset($bindedUsers[$giteaUser->id])) + { + $giteaUser->zentaoAccount = $bindedUsers[$giteaUser->id]; + $matchedUsers[] = $giteaUser; + continue; + } + + $matchedZentaoUsers = array(); + if(isset($matches->accounts[$giteaUser->account])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->accounts[$giteaUser->account]); + if(isset($matches->emails[$giteaUser->email])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->emails[$giteaUser->email]); + if(isset($matches->names[$giteaUser->realname])) $matchedZentaoUsers = array_merge($matchedZentaoUsers, $matches->names[$giteaUser->realname]); + + $matchedZentaoUsers = array_unique($matchedZentaoUsers); + if(count($matchedZentaoUsers) == 1) + { + $giteaUser->zentaoAccount = current($matchedZentaoUsers); + $matchedUsers[] = $giteaUser; + } + } + + return $matchedUsers; + } + /** * Get project by api. * @@ -250,14 +370,70 @@ class giteaModel extends model * @access public * @return array */ - public function apiGetProjects($giteaID, $sudo = 'true') + public function apiGetProjects($giteaID, $sudo = true) { $apiRoot = $this->getApiRoot($giteaID, $sudo); if(!$apiRoot) return array(); - $url = sprintf($apiRoot, "/repos/search"); - $results = json_decode(commonModel::http($url)); + $url = sprintf($apiRoot, "/repos/search"); + $allResults = array(); + for($page = 1; true; $page++) + { + $results = json_decode(commonModel::http($url . "&page={$page}&limit=50")); + if(!is_array($results->data)) break; + if(!empty($results->data)) $allResults = array_merge($allResults, $results->data); + if(count($results->data) < 50) break; + } - return $results->data; + return $allResults; + } + + /** + * Get gitea user list. + * + * @param int $giteaID + * @param bool $onlyLinked + * @access public + * @return array + */ + public function apiGetUsers($giteaID, $onlyLinked = false) + { + $response = array(); + $apiRoot = $this->getApiRoot($giteaID); + + for($page = 1; true; $page++) + { + $url = sprintf($apiRoot, "/users/search") . "&page={$page}&limit=50"; + $result = json_decode(commonModel::http($url)); + if(empty($result->data)) break; + + $response = array_merge($response, $result->data); + $page += 1; + } + + if(empty($response)) return array(); + + /* Get linked users. */ + $linkedUsers = array(); + if($onlyLinked) $linkedUsers = $this->getUserAccountIdPairs($giteaID, 'openID,account'); + + $users = array(); + foreach($response as $giteaUser) + { + if($onlyLinked and !isset($linkedUsers[$giteaUser->id])) continue; + + $user = new stdclass; + $user->id = $giteaUser->id; + $user->realname = $giteaUser->full_name ? $giteaUser->full_name : $giteaUser->username; + $user->account = $giteaUser->username; + $user->email = zget($giteaUser, 'email', ''); + $user->avatar = $giteaUser->avatar_url; + $user->createdAt = zget($giteaUser, 'created', ''); + $user->lastActivityOn = zget($giteaUser, 'last_login', ''); + + $users[] = $user; + } + + return $users; } } diff --git a/module/gitea/view/browse.html.php b/module/gitea/view/browse.html.php index d8a23425ac..b92dd8cab0 100644 --- a/module/gitea/view/browse.html.php +++ b/module/gitea/view/browse.html.php @@ -55,7 +55,9 @@ diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 5c8074064a..42e19702c6 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -47,9 +47,7 @@ class gitlab extends control foreach($gitlabList as $gitlab) { - $token = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token); - $gitlab->isAdminToken = (isset($token->is_admin) and $token->is_admin); - $gitlab->isBindUser = true; + $gitlab->isBindUser = true; if(!$this->app->user->admin and !isset($myGitLabs[$gitlab->id])) $gitlab->isBindUser = false; } @@ -1346,7 +1344,7 @@ class gitlab extends control { $repo = $this->loadModel('repo')->getRepoByID($repoID); $productIDList = explode(',', $repo->product); - $gitlabID = $repo->gitlab; + $gitlabID = $repo->gitService; $projectID = $repo->project; $gitlab = $this->gitlab->getByID($gitlabID); @@ -1491,7 +1489,7 @@ class gitlab extends control $bindedUsers = $this->dao->select('account,openID') ->from(TABLE_OAUTH) ->where('providerType')->eq('gitlab') - ->andWhere('providerID')->eq($repo->gitlab) + ->andWhere('providerID')->eq($repo->gitService) ->fetchPairs(); if(empty($repo->acl)) @@ -1511,7 +1509,7 @@ class gitlab extends control } } - $gitlabCurrentMembers = $this->gitlab->apiGetProjectMembers($repo->gitlab, $repo->project); + $gitlabCurrentMembers = $this->gitlab->apiGetProjectMembers($repo->gitService, $repo->project); $addedMembers = $updatedMembers = $deletedMembers = array(); /* Get the updated data. */ @@ -1570,17 +1568,17 @@ class gitlab extends control foreach($addedMembers as $addedMember) { - $this->gitlab->apiCreateProjectMember($repo->gitlab, $repo->project, $addedMember); + $this->gitlab->apiCreateProjectMember($repo->gitService, $repo->project, $addedMember); } foreach($updatedMembers as $updatedMember) { - $this->gitlab->apiUpdateProjectMember($repo->gitlab, $repo->project, $updatedMember); + $this->gitlab->apiUpdateProjectMember($repo->gitService, $repo->project, $updatedMember); } foreach($deletedMembers as $deletedMemberID) { - $this->gitlab->apiDeleteProjectMember($repo->gitlab, $repo->project, $deletedMemberID); + $this->gitlab->apiDeleteProjectMember($repo->gitService, $repo->project, $deletedMemberID); } $repo->acl->users = array_values($accounts); @@ -1590,7 +1588,7 @@ class gitlab extends control $repo = $this->loadModel('repo')->getRepoByID($repoID); $users = $this->loadModel('user')->getPairs('noletter|noempty|nodeleted|noclosed'); - $projectMembers = $this->gitlab->apiGetProjectMembers($repo->gitlab, $repo->project); + $projectMembers = $this->gitlab->apiGetProjectMembers($repo->gitService, $repo->project); if(!is_array($projectMembers)) $projectMembers = array(); /* Get users accesslevel. */ @@ -1598,7 +1596,7 @@ class gitlab extends control $bindedUsers = $this->dao->select('openID,account') ->from(TABLE_OAUTH) ->where('providerType')->eq('gitlab') - ->andWhere('providerID')->eq($repo->gitlab) + ->andWhere('providerID')->eq($repo->gitService) ->fetchPairs(); foreach($projectMembers as $projectMember) diff --git a/module/gitlab/view/browse.html.php b/module/gitlab/view/browse.html.php index af931fd6d9..a83c6de4bf 100644 --- a/module/gitlab/view/browse.html.php +++ b/module/gitlab/view/browse.html.php @@ -43,7 +43,7 @@ $gitlab): ?> - + From 513ef2652388d92061fa12c75394d82b17a1d0e3 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 16:08:37 +0800 Subject: [PATCH 11/85] * Adjust code. --- lib/scm/gitea.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php index 84b02072d3..bef1bc4748 100644 --- a/lib/scm/gitea.class.php +++ b/lib/scm/gitea.class.php @@ -34,7 +34,7 @@ class gitea public function ls($path, $revision = 'HEAD') { if(!scm::checkRevision($revision)) return array(); - $api = "contents"; + $api = "contents"; $param = new stdclass(); $param->path = ltrim($path, '/'); @@ -101,8 +101,8 @@ class gitea */ public function files($path, $ref = 'master') { - $path = urlencode($path); - $api = "contents/$path"; + $path = urlencode($path); + $api = "contents/$path"; $param = new stdclass(); $param->ref = $ref; $file = $this->fetch($api, $param); From b2b8da2e093564c59a1a90efc8b0c00312a4005f Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 16:09:59 +0800 Subject: [PATCH 12/85] * Adjust code. --- lib/scm/scm.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scm/scm.class.php b/lib/scm/scm.class.php index 9cbd9cb79a..4dc69b4236 100644 --- a/lib/scm/scm.class.php +++ b/lib/scm/scm.class.php @@ -251,7 +251,7 @@ class scm * @param string $branch * @param string $ext * @access public - * @return void + * @return string */ public function getDownloadUrl($branch = '', $ext = 'zip') { From 93a58b786ea66289b7f0df7e9848a444f4a3b8c2 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 16:11:38 +0800 Subject: [PATCH 13/85] * Adjust code. --- module/repo/control.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/repo/control.php b/module/repo/control.php index 7d31cc353b..9f58f99ef2 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -1367,7 +1367,7 @@ class repo extends control } $repo = $this->repo->getRepoByID($repoID); - if(in_array($repo->SCM, array('Gitlab', 'Gitea'))) + if(in_array($repo->SCM, $this->config->repo->gitServiceList)) { $this->scm = $this->app->loadClass('scm'); $this->scm->setEngine($repo); From f516d6713e41fcb95f2e380f9c0f4d446a309737 Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Tue, 12 Jul 2022 08:34:40 +0000 Subject: [PATCH 14/85] * Adjust bind user. --- module/gitea/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/gitea/model.php b/module/gitea/model.php index 216ea6d062..8849c51eb2 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -339,9 +339,9 @@ class giteaModel extends model $matchedUsers = array(); foreach($giteaUsers as $giteaUser) { - if(isset($bindedUsers[$giteaUser->id])) + if(isset($bindedUsers[$giteaUser->account])) { - $giteaUser->zentaoAccount = $bindedUsers[$giteaUser->id]; + $giteaUser->zentaoAccount = $bindedUsers[$giteaUser->account]; $matchedUsers[] = $giteaUser; continue; } From 945a5d2af0efd3a161486059f7626ff1e1871029 Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Tue, 12 Jul 2022 08:54:17 +0000 Subject: [PATCH 15/85] * Finish task #60569. --- module/repo/model.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/repo/model.php b/module/repo/model.php index bdc537385e..1346ecdf36 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -53,6 +53,8 @@ class repoModel extends model echo(js::alert($this->lang->repo->error->accessDenied)); return print(js::locate('back')); } + + if($repo->SCM != 'Gitlab') unset($this->lang->devops->menu->mr); } $this->lang->switcherMenu = $this->getSwitcher($repoID); From b3c4e3075b3d9b28078a881eec98dfc271f128a6 Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Tue, 12 Jul 2022 09:00:40 +0000 Subject: [PATCH 16/85] * Adjust lang error. --- module/compile/control.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/compile/control.php b/module/compile/control.php index c17fa7d59a..c640359571 100644 --- a/module/compile/control.php +++ b/module/compile/control.php @@ -46,6 +46,8 @@ class compile extends control $this->view->job = $job; } + + $this->app->loadLang('job'); $this->loadModel('ci')->setMenu($repoID); $this->app->loadClass('pager', $static = true); From 5b4bdf9dc7ed5c1c852a344f414923efe5bbe0cf Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 17:01:11 +0800 Subject: [PATCH 17/85] * Finish task #60454. --- lib/scm/gitea.class.php | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php index bef1bc4748..f1a00b033e 100644 --- a/lib/scm/gitea.class.php +++ b/lib/scm/gitea.class.php @@ -36,8 +36,9 @@ class gitea if(!scm::checkRevision($revision)) return array(); $api = "contents"; + $path = ltrim($path, '/'); + if($path) $api .= "/$path"; $param = new stdclass(); - $param->path = ltrim($path, '/'); $param->ref = $revision; $param->recursive = 0; if(!empty($this->branch)) $param->ref = $this->branch; @@ -52,9 +53,9 @@ class gitea $info = new stdClass(); $info->name = $file->name; - $info->kind = $file->type == 'blob' ? 'file' : 'dir'; + $info->kind = $file->type; - if($file->type == 'blob') + if($file->type == 'file') { $file = $this->files($file->path, $this->branch); @@ -624,28 +625,10 @@ class gitea $api = "commits"; $param = new stdclass(); - $param->path = urldecode($path); - $param->ref_name = ($toRevision != 'HEAD' and $toRevision) ? $toRevision : $this->branch; - - $fromDate = $this->getCommittedDate($fromRevision); - $toDate = $this->getCommittedDate($toRevision); - - $since = ''; - $until = ''; - if($fromRevision and $toRevision) - { - $since = min($fromDate, $toDate); - $until = max($fromDate, $toDate); - } - elseif($fromRevision) - { - $since = $fromDate; - } - if($since) $param->since = $since; - if($until) $param->until = $until; + $param->path = urldecode($path); + $param->sha = ($toRevision != 'HEAD' and $toRevision) ? $toRevision : $this->branch; if($perPage) $param->per_page = $perPage; - return $this->fetch($api, $param); } From bbc2fdce3a18e7d8d58c965492c827a1413bd70f Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Wed, 13 Jul 2022 10:20:19 +0800 Subject: [PATCH 18/85] * Fix bug #25147,25148. --- module/gitlab/js/managebranchpriv.js | 12 +++++++----- module/gitlab/js/managetagpriv.js | 16 +++++++++------- module/gitlab/view/managebranchpriv.html.php | 12 ++++++------ module/gitlab/view/managetagpriv.html.php | 6 +++--- module/repo/control.php | 4 ++-- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/module/gitlab/js/managebranchpriv.js b/module/gitlab/js/managebranchpriv.js index 4a8fcb1cf7..9ce313c324 100644 --- a/module/gitlab/js/managebranchpriv.js +++ b/module/gitlab/js/managebranchpriv.js @@ -42,20 +42,20 @@ function addItem(obj) { var item = $('#addItem').html().replace(/%i%/g, itemIndex); var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); - var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'}); + var $branches = $tr.find('select').addClass('user-picker').trigger('list:updated').picker({type: 'user'}); itemIndex++; var disabledItems = []; $('.user-picker[name^=branches]').each(function() { - if(this === $accounts[0]) return; + if(this === $branches[0]) return; var $select = $(this); - var picker = $select.data('zui.picker'); + var picker = $select.data('zui.picker'); if(!picker) return; var selectItem = picker.getListItem(picker.getValue()); if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true})); }); - if(disabledItems.length) $accounts.data('zui.picker').updateOptionList(disabledItems); + if(disabledItems.length) $branches.data('zui.picker').updateOptionList(disabledItems); } /** @@ -67,6 +67,8 @@ function addItem(obj) */ function deleteItem(obj) { - if($('#privForm .table-form tbody').children().length < 2) return false; + if($('#privForm .table tbody').children().length < 2) return false; + + $(obj).closest('tr').find('.picker .picker-selection-remove').click(); $(obj).closest('tr').remove(); } diff --git a/module/gitlab/js/managetagpriv.js b/module/gitlab/js/managetagpriv.js index d7ab47bfd1..8593340bad 100644 --- a/module/gitlab/js/managetagpriv.js +++ b/module/gitlab/js/managetagpriv.js @@ -40,22 +40,22 @@ function savePriv() */ function addItem(obj) { - var item = $('#addItem').html().replace(/%i%/g, itemIndex); - var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); - var $accounts = $tr.find('select:first').addClass('user-picker').trigger('list:updated').picker({type: 'user'}); + var item = $('#addItem').html().replace(/%i%/g, itemIndex); + var $tr = $('' + item + '').insertAfter($(obj).closest('tr')); + var $tags = $tr.find('select').addClass('user-picker').trigger('list:updated').picker({type: 'user'}); itemIndex++; var disabledItems = []; $('.user-picker[name^=tags]').each(function() { - if(this === $accounts[0]) return; + if(this === $tags[0]) return; var $select = $(this); - var picker = $select.data('zui.picker'); + var picker = $select.data('zui.picker'); if(!picker) return; var selectItem = picker.getListItem(picker.getValue()); if(selectItem) disabledItems.push($.extend({}, selectItem, {disabled: true})); }); - if(disabledItems.length) $accounts.data('zui.picker').updateOptionList(disabledItems); + if(disabledItems.length) $tags.data('zui.picker').updateOptionList(disabledItems); } /** @@ -67,6 +67,8 @@ function addItem(obj) */ function deleteItem(obj) { - if($('#privForm .table-form tbody').children().length < 2) return false; + if($('#privForm .table tbody').children().length < 2) return false; + + $(obj).closest('tr').find('.picker .picker-selection-remove').click(); $(obj).closest('tr').remove(); } diff --git a/module/gitlab/view/managebranchpriv.html.php b/module/gitlab/view/managebranchpriv.html.php index 714a03bda1..52ea2da2e4 100644 --- a/module/gitlab/view/managebranchpriv.html.php +++ b/module/gitlab/view/managebranchpriv.html.php @@ -23,9 +23,9 @@ - + - - + +
url, $gitea->url, '_target');?> isBindUser ? true : false; common::printIcon('gitea', 'edit', "giteaID=$id", '', 'list', 'edit'); + echo common::buildIconButton('gitea', 'bindUser', "giteaID=$id", '', 'list', 'link', '', '', false, '', '', 0, $disabled); common::printIcon('gitea', 'delete', "giteaID=$id", '', 'list', 'trash', 'hiddenwin'); ?>
@@ -55,7 +55,7 @@ url, $gitlab->url, '_target');?> isAdminToken) or !$gitlab->isBindUser) ? false : true; + $disabled = $gitlab->isBindUser ? true : false; common::printIcon('gitlab', 'edit', "gitlabID=$id", '', 'list', 'edit'); echo common::buildIconButton('gitlab', 'bindUser', "gitlabID=$id", '', 'list', 'link', '', '', false, '', '', 0, $disabled); common::printIcon('gitlab', 'delete', "gitlabID=$id", '', 'list', 'trash', 'hiddenwin'); diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 9893779893..1e12f7a30b 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -1387,17 +1387,19 @@ $lang->gitlab->methodOrder[145] = 'deleteTagPriv'; /* Gitea. */ $lang->resource->gitea = new stdclass(); -$lang->resource->gitea->browse = 'browse'; -$lang->resource->gitea->create = 'create'; -$lang->resource->gitea->edit = 'edit'; -$lang->resource->gitea->view = 'view'; -$lang->resource->gitea->delete = 'delete'; +$lang->resource->gitea->browse = 'browse'; +$lang->resource->gitea->create = 'create'; +$lang->resource->gitea->edit = 'edit'; +$lang->resource->gitea->view = 'view'; +$lang->resource->gitea->delete = 'delete'; +$lang->resource->gitea->bindUser = 'bindUser'; $lang->gitea->methodOrder[5] = 'browse'; $lang->gitea->methodOrder[10] = 'create'; $lang->gitea->methodOrder[15] = 'edit'; $lang->gitea->methodOrder[20] = 'view'; $lang->gitea->methodOrder[25] = 'delete'; +$lang->gitea->methodOrder[30] = 'bindUser'; /* SonarQube. */ $lang->resource->sonarqube = new stdclass(); From ed24e40025202d96ea1d39e185290cd75f383400 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 15:36:57 +0800 Subject: [PATCH 08/85] * Modify page error. --- module/gitlab/control.php | 4 ++++ module/gitlab/model.php | 19 ------------------- module/gitlab/view/browseproject.html.php | 4 ++-- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0f3d774d41..4c4f74257c 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -1391,6 +1391,8 @@ class gitlab extends control { $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); + + $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); } @@ -1437,6 +1439,8 @@ class gitlab extends control { $openID = $this->gitlab->getUserIDByZentaoAccount($gitlabID, $this->app->user->account); if(!$openID) return print(js::alert($this->lang->gitlab->mustBindUser) . js::locate($this->createLink('gitlab', 'browse'))); + + $project = $this->gitlab->apiGetSingleProject($gitlabID, $projectID); if(!$this->gitlab->checkUserAccess($gitlabID, $projectID, $project)) return print(js::alert($this->lang->gitlab->noAccess) . js::locate($this->createLink('gitlab', 'browse'))); } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 6ba139764b..d5a627dfc1 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -2876,23 +2876,4 @@ class gitlabModel extends model $html .= ''; return $html; } - - /** - * Download zip code. - * - * @param int $gitlabID - * @param int $projectID - * @param string $branch - * @param string $ext tar.gz|tar.bz2|tbz|tbz2|tb2|bz2|tar|zip - * @access public - * @return string - */ - public function downloadCode($gitlabID = 0, $projectID = 0, $branch = '', $ext = 'zip') - { - if(empty($gitlabID) or empty($projectID)) return false; - - $url = sprintf($this->getApiRoot($gitlabID), "/projects/$projectID/repository/archive." . $ext); - if($branch) $url .= '&sha=' . $branch; - return $url; - } } diff --git a/module/gitlab/view/browseproject.html.php b/module/gitlab/view/browseproject.html.php index e2e9c57d1d..486412f9d7 100644 --- a/module/gitlab/view/browseproject.html.php +++ b/module/gitlab/view/browseproject.html.php @@ -60,8 +60,8 @@ last_activity_at, 0, 10);?> id", '', 'list', 'branch-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch)); - echo common::buildIconButton('gitlab', 'manageTagPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'tag-lock', '', '', false, '', '', 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch)); + echo common::buildIconButton('gitlab', 'manageBranchPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'branch-lock', '', '', false, '', $this->lang->gitlab->browseBranchPriv, 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch)); + echo common::buildIconButton('gitlab', 'manageTagPriv', "gitlabID=$gitlabID&projectID=$gitlabProject->id", '', 'list', 'tag-lock', '', '', false, '', $this->lang->gitlab->browseTagPriv, 0, ($gitlabProject->isMaintainer and $gitlabProject->default_branch)); echo common::buildIconButton('gitlab', 'manageProjectMembers', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'team', '', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id])); echo common::buildIconButton('gitlab', 'createWebhook', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'change', 'hiddenwin', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id])); echo common::buildIconButton('gitlab', 'importIssue', 'repoID=' . zget($repoPairs, $gitlabProject->id), '', 'list', 'link', '', '', false, '', '', 0, isset($repoPairs[$gitlabProject->id])); From 75bf140f6d02cac3c6a9d8a31658817dda69fdd5 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 12 Jul 2022 15:37:16 +0800 Subject: [PATCH 09/85] * Modify repo page data. --- lib/scm/gitea.class.php | 161 ++++++++++++++++----------------------- lib/scm/gitlab.class.php | 17 +++++ lib/scm/scm.class.php | 13 ++++ module/repo/config.php | 3 + module/repo/control.php | 6 +- module/repo/model.php | 2 +- 6 files changed, 102 insertions(+), 100 deletions(-) diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php index 41b8285932..84b02072d3 100644 --- a/lib/scm/gitea.class.php +++ b/lib/scm/gitea.class.php @@ -34,7 +34,7 @@ class gitea public function ls($path, $revision = 'HEAD') { if(!scm::checkRevision($revision)) return array(); - $api = "tree"; + $api = "contents"; $param = new stdclass(); $param->path = ltrim($path, '/'); @@ -70,10 +70,10 @@ class gitea if(empty($commits)) continue; $commit = $commits[0]; - $info->revision = $commit->id; - $info->comment = $commit->message; - $info->account = $commit->committer_name; - $info->date = date('Y-m-d H:i:s', strtotime($commit->committed_date)); + $info->revision = $commit->sha; + $info->comment = $commit->commit->message; + $info->account = $commit->commit->committer->name; + $info->date = date('Y-m-d H:i:s', strtotime($commit->commit->committer->date)); $info->size = 0; } @@ -102,23 +102,23 @@ class gitea public function files($path, $ref = 'master') { $path = urlencode($path); - $api = "files/$path"; + $api = "contents/$path"; $param = new stdclass(); $param->ref = $ref; $file = $this->fetch($api, $param); - if(!isset($file->file_name)) return false; + if(!isset($file->name)) return false; $commits = $this->getCommitsByPath($path, '', '', 1); - $file->revision = $file->commit_id; + $file->revision = $file->sha; $file->size = $this->formatBytes($file->size); if(!empty($commits)) { $commit = $commits[0]; - $file->revision = $commit->id; - $file->committer = $commit->committer_name; - $file->comment = $commit->message; - $file->date = date('Y-m-d H:i:s', strtotime($commit->committed_date)); + $file->revision = $commit->sha; + $file->committer = $commit->commit->committer->name; + $file->comment = $commit->commit->message; + $file->date = date('Y-m-d H:i:s', strtotime($commit->commit->committer->date)); } return $file; @@ -145,7 +145,7 @@ class gitea { $params['page'] = $page; $list = $this->fetch($api, $params); - if(empty($list)) break; + if(empty($list) or $list == '[]') break; foreach($list as $tag) $tags[] = $tag->name; if(count($list) < $params['per_page']) break; @@ -177,7 +177,7 @@ class gitea foreach($branchList as $branch) { if(!isset($branch->name)) continue; - if($branch->default) + if($branch->name == 'main') { $default[$branch->name] = $branch->name; } @@ -232,7 +232,7 @@ class gitea $list = $this->getCommitsByPath($path, $fromRevision, $toRevision); foreach($list as $commit) { - if(isset($commit->id)) $commit->diffs = $this->getFilesByCommit($commit->id); + if(isset($commit->sha)) $commit->diffs = $this->getFilesByCommit($commit->sha); } return $this->parseLog($list); @@ -248,42 +248,7 @@ class gitea */ public function blame($path, $revision) { - if(!scm::checkRevision($revision)) return array(); - - $path = ltrim($path, DIRECTORY_SEPARATOR); - $path = urlencode($path); - $api = "files/$path/blame"; - $param = new stdclass; - $param->ref = ($revision and $revision != 'HEAD') ? $revision : $this->branch; - $results = $this->fetch($api, $param); - - $blames = array(); - $revLine = 0; - $revision = ''; - - $lineNumber = 1; - foreach($results as $blame) - { - $line = array(); - $line['revision'] = $blame->commit->id; - $line['committer'] = $blame->commit->committer_name; - $line['time'] = $blame->commit->committer_name; - $line['line'] = $lineNumber; - $line['lines'] = count($blame->lines); - $line['content'] = array_shift($blame->lines); - - $blames[$lineNumber] = $line; - - $lineNumber ++; - - foreach($blame->lines as $line) - { - $blames[$lineNumber] = array('line' => $lineNumber, 'content' => $line); - $lineNumber ++; - } - } - - return $blames; + return array(); } /** @@ -562,16 +527,16 @@ class gitea { $api .= '/' . $version; $commit = $this->fetch($api); - if(isset($commit->id)) + if(isset($commit->sha)) { $log = new stdclass; - $log->committer = $commit->committer_name; - $log->revision = $commit->id; - $log->comment = $commit->message; - $log->time = date('Y-m-d H:i:s', strtotime($commit->created_at)); + $log->committer = $commit->commit->committer->name; + $log->revision = $commit->sha; + $log->comment = $commit->commit->message; + $log->time = date('Y-m-d H:i:s', strtotime($commit->commit->committer->date)); - $commits[$commit->id] = $log; - $files[$commit->id] = $this->getFilesByCommit($log->revision); + $commits[$commit->sha] = $log; + $files[$commit->sha] = $this->getFilesByCommit($log->revision); return array('commits' => $commits, 'files' => $files); } @@ -608,16 +573,16 @@ class gitea foreach($list as $commit) { - if(!is_object($commit)) continue; + if(!is_object($commit->commit)) continue; $log = new stdclass; - $log->committer = $commit->committer_name; - $log->revision = $commit->id; - $log->comment = $commit->message; - $log->time = date('Y-m-d H:i:s', strtotime($commit->created_at)); + $log->committer = $commit->commit->committer->name; + $log->revision = $commit->sha; + $log->comment = $commit->commit->message; + $log->time = date('Y-m-d H:i:s', strtotime($commit->commit->committer->date)); - $commits[$commit->id] = $log; - $files[$commit->id] = $this->getFilesByCommit($log->revision); + $commits[$commit->sha] = $log; + $files[$commit->sha] = $this->getFilesByCommit($log->revision); } return array('commits' => $commits, 'files' => $files); @@ -694,33 +659,18 @@ class gitea public function getFilesByCommit($revision) { if(!scm::checkRevision($revision)) return array(); - $api = "commits/{$revision}/diff"; - $params = new stdclass; - $params->page = 1; - $params->per_page = 100; - - $allResults = array(); - while(true) - { - $results = $this->fetch($api, $params); - $params->page ++; - if(!is_array($results)) $results = array(); - $allResults = $allResults + $results; - if(count($results) < 100) break; - } + $api = "contents"; + $results = $this->fetch($api, array('ref' => $revision)); + if(empty($results)) return array(); $files = array(); - foreach($allResults as $row) + foreach($results as $row) { - $file = new stdclass(); + $file = new stdclass(); $file->revision = $revision; - $file->path = '/' . $row->new_path; - $file->type = 'file'; - - $file->action = 'M'; - if($row->new_file) $file->action = 'A'; - if($row->renamed_file) $file->action = 'R'; - if($row->deleted_file) $file->action = 'D'; + $file->action = 'A'; + $file->type = $row->type; + $file->path = '/' . trim($row->path); $files[] = $file; } @@ -737,7 +687,7 @@ class gitea */ public function tree($path, $recursive = 1) { - $api = "tree"; + $api = "contents"; $params = array(); $params['path'] = ltrim($path, '/'); @@ -756,8 +706,8 @@ class gitea public function fetch($api, $params = array(), $needToLoop = false) { $params = (array) $params; - $params['private_token'] = $this->token; - $params['per_page'] = isset($params['per_page']) ? $params['per_page'] : 100; + $params['token'] = $this->token; + $params['per_page'] = isset($params['per_page']) ? $params['per_page'] : 100; $api = ltrim($api, '/'); $api = $this->root . $api . '?' . http_build_query($params); @@ -783,7 +733,8 @@ class gitea return array(); } - return json_decode($response); + $res = json_decode($response); + return empty($res) ? trim($response) : $res; } } @@ -816,12 +767,12 @@ class gitea $i = 0; foreach($logs as $commit) { - if(!isset($commit->id)) continue; + if(!isset($commit->sha)) continue; $parsedLog = new stdclass(); - $parsedLog->revision = $commit->id; - $parsedLog->committer = $commit->committer_name; - $parsedLog->time = date('Y-m-d H:i:s', strtotime($commit->committed_date)); - $parsedLog->comment = $commit->message; + $parsedLog->revision = $commit->sha; + $parsedLog->committer = $commit->commit->committer->name; + $parsedLog->time = date('Y-m-d H:i:s', strtotime($commit->commit->committer->date)); + $parsedLog->comment = $commit->commit->message; $parsedLog->change = array(); foreach($commit->diffs as $diff) { @@ -834,4 +785,20 @@ class gitea return $parsedLogs; } + + /** + * Get download url. + * + * @param string $branch + * @param string $ext + * @access public + * @return string + */ + public function getDownloadUrl($branch = 'master', $ext = 'zip') + { + $params = (array) $params; + $params['token'] = $this->token; + + return "{$this->root}archive/{$branch}.{$ext}" . '?' . http_build_query($params); + } } diff --git a/lib/scm/gitlab.class.php b/lib/scm/gitlab.class.php index 324d03a9cc..583b0b1475 100644 --- a/lib/scm/gitlab.class.php +++ b/lib/scm/gitlab.class.php @@ -834,4 +834,21 @@ class gitlab return $parsedLogs; } + + /** + * Get download url. + * + * @param string $branch + * @param string $ext + * @access public + * @return string + */ + public function getDownloadUrl($branch = 'master', $ext = 'zip') + { + $params = (array) $params; + $params['private_token'] = $this->token; + $params['sha'] = $branch; + + return "{$this->root}archive.{$ext}" . '?' . http_build_query($params); + } } diff --git a/lib/scm/scm.class.php b/lib/scm/scm.class.php index 06648998c3..9cbd9cb79a 100644 --- a/lib/scm/scm.class.php +++ b/lib/scm/scm.class.php @@ -244,6 +244,19 @@ class scm if(preg_match('/[^a-z0-9\-_\.\^\w][\x{4e00}-\x{9fa5}]/ui', $revision)) return false; return true; } + + /** + * Get download url. + * + * @param string $branch + * @param string $ext + * @access public + * @return void + */ + public function getDownloadUrl($branch = '', $ext = 'zip') + { + return $this->engine->getDownloadUrl($branch, $ext); + } } /** diff --git a/module/repo/config.php b/module/repo/config.php index af7bfa2cd0..4bd26c4601 100644 --- a/module/repo/config.php +++ b/module/repo/config.php @@ -49,6 +49,9 @@ $config->repo->gitlab = new stdclass; $config->repo->gitlab->perPage = 300; $config->repo->gitlab->apiPath = "%s/api/v4/projects/%s/repository/"; +$config->repo->gitea = new stdclass; +$config->repo->gitea->apiPath = "%s/api/v1/repos/%s/"; + $config->repo->gitServiceList = array('gitlab', 'gitea'); $config->repo->rules['module']['task'] = 'Task'; diff --git a/module/repo/control.php b/module/repo/control.php index b1bcb3be74..7d31cc353b 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -1367,9 +1367,11 @@ class repo extends control } $repo = $this->repo->getRepoByID($repoID); - if($repo->SCM == 'Gitlab') + if(in_array($repo->SCM, array('Gitlab', 'Gitea'))) { - $url = $this->loadModel('gitlab')->downloadCode($repo->gitlab, $repo->project, $branch); + $this->scm = $this->app->loadClass('scm'); + $this->scm->setEngine($repo); + $url = $this->scm->getDownloadUrl($branch); } elseif($repo->SCM == 'Git') { diff --git a/module/repo/model.php b/module/repo/model.php index bdc537385e..9a32306156 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -2032,7 +2032,7 @@ class repoModel extends model $repo->gitService = $service ? $service->id : 0; $repo->project = $service ? $repo->path : ''; // The projectID in gitlab. - $repo->path = $service ? sprintf($this->config->repo->gitlab->apiPath, $service->url, $repo->path) : ''; + $repo->path = $service ? sprintf($this->config->repo->{$service->type}->apiPath, $service->url, $repo->path) : ''; $repo->client = $service ? $service->url : ''; $repo->password = $service ? $service->token : ''; return $repo; From 0c420911a73a9e2cd640847945ec8e0aaeccaa6b Mon Sep 17 00:00:00 2001 From: liyuchun <563917701@qq.com> Date: Tue, 12 Jul 2022 08:02:28 +0000 Subject: [PATCH 10/85] * Finish task #60452. --- module/gitea/control.php | 1 + module/gitea/model.php | 21 +++++++- module/gitea/view/binduser.html.php | 83 +++++++++++++++++++++++++++++ module/gitea/view/browse.html.php | 3 +- 4 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 module/gitea/view/binduser.html.php diff --git a/module/gitea/control.php b/module/gitea/control.php index 2c6cc08a2a..56f80776f0 100644 --- a/module/gitea/control.php +++ b/module/gitea/control.php @@ -43,6 +43,7 @@ class gitea extends control /* Admin user don't need bind. */ $giteaList = $this->gitea->getList($orderBy, $pager); + $myGiteas = $this->gitea->getGiteaListByAccount(); foreach($giteaList as $gitea) { $gitea->isBindUser = true; diff --git a/module/gitea/model.php b/module/gitea/model.php index 6a9ad9ef99..216ea6d062 100644 --- a/module/gitea/model.php +++ b/module/gitea/model.php @@ -147,7 +147,7 @@ class giteaModel extends model ->andWhere('providerType')->eq($user->providerType) ->andWhere('providerID')->eq($user->providerID) ->exec(); - $this->loadModel('action')->create('giteauser', $openID, 'unbind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$existAccount->account]->realname)); + $this->loadModel('action')->create('giteauser', $giteaID, 'unbind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$existAccount->account]->realname)); } if(!$existAccount or $existAccount->account != $account) { @@ -155,7 +155,7 @@ class giteaModel extends model $user->account = $account; $user->openID = $openID; $this->dao->insert(TABLE_OAUTH)->data($user)->exec(); - $this->loadModel('action')->create('giteauser', $openID, 'bind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$account]->realname)); + $this->loadModel('action')->create('giteauser', $giteaID, 'bind', '', sprintf($this->lang->gitea->bindDynamic, $giteaNames[$openID], $zentaoUsers[$account]->realname)); } } } @@ -296,6 +296,23 @@ class giteaModel extends model ->fetchPairs(); } + /** + * Get gitea user id by zentao account. + * + * @param int $giteaID + * @param string $zentaoAccount + * @access public + * @return array + */ + public function getUserIDByZentaoAccount($giteaID, $zentaoAccount) + { + return $this->dao->select('openID')->from(TABLE_OAUTH) + ->where('providerType')->eq('gitea') + ->andWhere('providerID')->eq($giteaID) + ->andWhere('account')->eq($zentaoAccount) + ->fetch('openID'); + } + /** * Get matched gitea users. * diff --git a/module/gitea/view/binduser.html.php b/module/gitea/view/binduser.html.php new file mode 100644 index 0000000000..83c2982d7c --- /dev/null +++ b/module/gitea/view/binduser.html.php @@ -0,0 +1,83 @@ + + * @package gitea + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
+

gitea->bindUser;?>

+
+ +
+ + + + + + + + + + + zentaoAccount)) continue;?> + account]", $giteaUser->realname);?> + + + + + + + + + zentaoAccount)) continue;?> + account]", $giteaUser->realname);?> + + + + + + + + + + + + + +
gitea->giteaAccount;?>gitea->zentaoAccount;?>gitea->bindingStatus;?>
avatar, "height=40");?> + realname;?> +
+ account;?> + email) echo " <" . $giteaUser->email . ">";?> +
account]", $userPairs, '', "class='form-control select chosen'" );?>gitea->notBind;?>
avatar, "height=40");?> + realname;?> +
+ account;?> + email) echo " <" . $giteaUser->email . ">";?> +
account]", $userPairs, $giteaUser->zentaoAccount, "class='form-control select chosen'" );?> + zentaoAccount])):?> + zentaoAccount, '');?> + + gitea->binded;?> + + ' . $lang->gitea->bindedError . '';?> + + + gitea->notBind;?> + +
+ + goback, '', 'class="btn btn-wide"');?> +
+
+ +
+ diff --git a/module/gitea/view/browse.html.php b/module/gitea/view/browse.html.php index b92dd8cab0..fb02e955fc 100644 --- a/module/gitea/view/browse.html.php +++ b/module/gitea/view/browse.html.php @@ -55,9 +55,8 @@
url, $gitea->url, '_target');?> isBindUser ? true : false; common::printIcon('gitea', 'edit', "giteaID=$id", '', 'list', 'edit'); - echo common::buildIconButton('gitea', 'bindUser', "giteaID=$id", '', 'list', 'link', '', '', false, '', '', 0, $disabled); + echo common::buildIconButton('gitea', 'bindUser', "giteaID=$id", '', 'list', 'link', '', '', false, '', '', 0, $gitea->isBindUser); common::printIcon('gitea', 'delete', "giteaID=$id", '', 'list', 'trash', 'hiddenwin'); ?>
name, "class='form-control' readonly");?>gitlab->branch->branchCreationLevelList, $branch->mergeAccess, "class='form-control chosen'");?>gitlab->branch->branchCreationLevelList, $branch->mergeAccess, "class='form-control user-picker'");?> - gitlab->branch->branchCreationLevelList, $branch->pushAccess, "class='form-control chosen'");?> + gitlab->branch->branchCreationLevelList, $branch->pushAccess, "class='form-control user-picker'");?> name);?> @@ -40,8 +40,8 @@
'') + $noAccessBranches, '', "class='form-control user-picker'");?>gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?>gitlab->branch->branchCreationLevelList, 40, "class='form-control chosen'");?>gitlab->branch->branchCreationLevelList, 40, "class='form-control user-picker'");?>gitlab->branch->branchCreationLevelList, 40, "class='form-control user-picker'");?> ", '', "onclick='addItem(this)' class='btn btn-link'");?> ", '', "onclick='deleteItem(this)' class='btn btn-link'");?> @@ -70,8 +70,8 @@ - - + + - + - + - gitlabID][$MR->sourceProject]) ? $projects[$MR->gitlabID][$MR->sourceProject]->name_with_namespace . ':' . $MR->sourceBranch : $MR->sourceProject . ':' . $MR->sourceBranch; ?> - gitlabID][$MR->targetProject]) ? $projects[$MR->gitlabID][$MR->targetProject]->name_with_namespace . ':' . $MR->targetBranch : $MR->targetProject . ':' . $MR->targetBranch; ?> + hostID][$MR->sourceProject]) ? $projects[$MR->hostID][$MR->sourceProject]->name_with_namespace . ':' . $MR->sourceBranch : $MR->sourceProject . ':' . $MR->sourceBranch; ?> + hostID][$MR->targetProject]) ? $projects[$MR->hostID][$MR->targetProject]->name_with_namespace . ':' . $MR->targetBranch : $MR->targetProject . ':' . $MR->targetBranch; ?> @@ -79,8 +79,8 @@