diff --git a/module/gitlab/control.php b/module/gitlab/control.php index be5aeeaa68..b820050279 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -252,6 +252,10 @@ class gitlab extends control if(!is_object($user)) return $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError)))); if(!isset($user->is_admin) or !$user->is_admin) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); + + /* Verify version compatibility. */ + $result = $this->gitlab->getVersion($gitlabURL, $token); + if(empty($result) or !isset($result->version) or ((float)$result->version < (float)$this->gitlab->minCompatibleVersion)) return $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->notCompatible)))); } /** diff --git a/module/gitlab/lang/en.php b/module/gitlab/lang/en.php index 69682ea83b..29d98a3547 100644 --- a/module/gitlab/lang/en.php +++ b/module/gitlab/lang/en.php @@ -75,6 +75,7 @@ $lang->gitlab->emptyError = " cannot be empty"; $lang->gitlab->createSuccess = "Create success"; $lang->gitlab->mustBindUser = 'You have not registered the GitLab account, please contact the administrator to register.'; $lang->gitlab->noAccess = 'Permission denied'; +$lang->gitlab->notCompatible = 'The current GitLab version is not compatible with ZenTao, please upgrade the GitLab version and try again'; $lang->gitlab->placeholder = new stdclass; $lang->gitlab->placeholder->name = ''; diff --git a/module/gitlab/lang/zh-cn.php b/module/gitlab/lang/zh-cn.php index 7b3a4b25ad..1e6bc6cee9 100644 --- a/module/gitlab/lang/zh-cn.php +++ b/module/gitlab/lang/zh-cn.php @@ -75,6 +75,7 @@ $lang->gitlab->emptyError = "不能为空"; $lang->gitlab->createSuccess = "创建成功"; $lang->gitlab->mustBindUser = '您还未绑定GitLab用户,请联系管理员进行绑定'; $lang->gitlab->noAccess = '权限不足'; +$lang->gitlab->notCompatible = '当前GitLab版本与禅道不兼容,请升级GitLab版本后重试'; $lang->gitlab->placeholder = new stdclass; $lang->gitlab->placeholder->name = ''; diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 3a552325e7..6c8dfd4d56 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -20,6 +20,9 @@ class gitlabModel extends model public $developerAccess = 30; public $maintainerAccess = 40; + /* Minimum compatible version. */ + public $minCompatibleVersion = '9.0'; + /** * Get a gitlab by id. * @@ -2809,4 +2812,18 @@ class gitlabModel extends model return false; } + + /** + * Get gitlab version. + * + * @param string $host + * @param string $token + * @access public + * @return array + */ + public function getVersion($host, $token) + { + $host = rtrim($host, '/') . "/api/v4%s?private_token=$token"; + return $this->apiGet($host, '/version'); + } }