From 73472acf0a93f675dc791e0d561a13a71e81f36e Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 27 Jun 2022 13:07:22 +0800 Subject: [PATCH] * Modify apit params. --- module/gitlab/control.php | 4 ++-- module/gitlab/model.php | 3 +-- test/model/gitlab/apigetcurrentuser.php | 16 +++++++--------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 1ed38204b1..6d2808fd1f 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -256,10 +256,10 @@ class gitlab extends control if(strpos($gitlab->url, 'http') !== 0) return $this->send(array('result' => 'fail', 'message' => array('url' => array(sprintf($this->lang->gitlab->hostError, $this->config->gitlab->minCompatibleVersion))))); if(!$gitlab->token) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); - $user = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token, true); + $user = $this->gitlab->apiGetCurrentUser($gitlab->url, $gitlab->token); if(!is_object($user)) return $this->send(array('result' => 'fail', 'message' => array('url' => array(sprintf($this->lang->gitlab->hostError, $this->config->gitlab->minCompatibleVersion))))); - if(!isset($user->id)) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError)))); + if(!isset($user->id) or !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($gitlab->url, $gitlab->token); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 5d6d51db07..9d7c3c2028 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -473,10 +473,9 @@ class gitlabModel extends model * @access public * @return array */ - public function apiGetCurrentUser($host, $token, $rootCheck = false) + public function apiGetCurrentUser($host, $token) { $host = rtrim($host, '/') . "/api/v4%s?private_token=$token"; - if($rootCheck) $host .= '&sudo=1'; return $this->apiGet($host, '/user'); } diff --git a/test/model/gitlab/apigetcurrentuser.php b/test/model/gitlab/apigetcurrentuser.php index e39207a935..608c116a70 100644 --- a/test/model/gitlab/apigetcurrentuser.php +++ b/test/model/gitlab/apigetcurrentuser.php @@ -14,26 +14,24 @@ $gitlab = $tester->loadModel('gitlab'); $host = ''; $token = ''; -$rootCheck = false; -$result = $gitlab->apiGetCurrentUser($host, $token, $rootCheck); +$result = $gitlab->apiGetCurrentUser($host, $token); if($result === false) $result = 'return false'; r($result) && p() && e('return false'); //使用空的数据获取用户信息 $host = 'http://192.168.1.161:5108'; -$result = $gitlab->apiGetCurrentUser($host, $token, $rootCheck); +$result = $gitlab->apiGetCurrentUser($host, $token); if(!$result) $result = 'return null'; r($result) && p() && e('return null'); //使用错误的host获取用户信息 $host = 'http://192.168.1.161:51080'; -$result = $gitlab->apiGetCurrentUser($host, $token, $rootCheck); -r($gitlab->apiGetCurrentUser($host, $token, $rootCheck)) && p('message') && e('401 Unauthorized'); //使用正确的host,错误的token获取用户信息 +$result = $gitlab->apiGetCurrentUser($host, $token); +r($gitlab->apiGetCurrentUser($host, $token)) && p('message') && e('401 Unauthorized'); //使用正确的host,错误的token获取用户信息 $token = 'x88fZokrp5hShia2jyBN'; -$result = $gitlab->apiGetCurrentUser($host, $token, $rootCheck); +$result = $gitlab->apiGetCurrentUser($host, $token); r($result) && p('id') && e('1'); //通过host,token获取用户信息 -$token = 'wVFHE6NZA-cJy-3U2y2J'; -$rootCheck = true; -$result = $gitlab->apiGetCurrentUser($host, $token, $rootCheck); +$token = 'wVFHE6NZA-cJy-3U2y2J'; +$result = $gitlab->apiGetCurrentUser($host, $token); r($result) && p('error') && e('insufficient_scope'); //通过host,权限不足的token获取用户信息