+ Add checkToken method.
This commit is contained in:
@@ -287,6 +287,8 @@ $config->openMethods[] = 'gitlab.managetagpriv';
|
||||
$config->openMethods[] = 'gitlab.browsetag';
|
||||
$config->openMethods[] = 'gitlab.createtag';
|
||||
$config->openMethods[] = 'gitlab.deletetag';
|
||||
$config->openMethods[] = 'gitfox.create';
|
||||
$config->openMethods[] = 'gitfox.edit';
|
||||
$config->openMethods[] = 'gogs.create';
|
||||
$config->openMethods[] = 'gogs.edit';
|
||||
$config->openMethods[] = 'gogs.binduser';
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
$config->gitfox->create = new stdclass;
|
||||
$config->gitfox->create->requiredFields = 'name,url,token';
|
||||
|
||||
$config->gitfox->edit = new stdclass;
|
||||
$config->gitfox->edit->requiredFields = 'name,url,token';
|
||||
|
||||
$config->gitfox->createbranch = new stdclass;
|
||||
$config->gitfox->createbranch->requiredFields = 'branch,ref';
|
||||
|
||||
$config->gitfox->createbranchpriv = new stdclass;
|
||||
$config->gitfox->createbranchpriv->requiredFields = 'name';
|
||||
|
||||
$config->gitfox->createtag = new stdclass;
|
||||
$config->gitfox->createtag->requiredFields = 'tag_name,ref';
|
||||
|
||||
$config->gitfox->labelPattern = new stdclass;
|
||||
$config->gitfox->labelPattern->task = '/^zentao_task\/\d+$/';
|
||||
$config->gitfox->labelPattern->bug = '/^zentao_bug\/\d+$/';
|
||||
$config->gitfox->labelPattern->story = '/^zentao_story\/\d+$/';
|
||||
|
||||
$config->gitfox->actions = array();
|
||||
$config->gitfox->actions['issue'] = array();
|
||||
|
||||
$config->gitfox->zentaoObjectLabel = new stdclass;
|
||||
$config->gitfox->zentaoObjectLabel->name = "zentao_%s/%s";
|
||||
$config->gitfox->zentaoObjectLabel->description = "%s";
|
||||
|
||||
$config->gitfox->zentaoObjectLabel->color = new stdclass;
|
||||
$config->gitfox->zentaoObjectLabel->color->task = '#0033CC';
|
||||
$config->gitfox->zentaoObjectLabel->color->story = '#69D100';
|
||||
$config->gitfox->zentaoObjectLabel->color->bug = '#D10069';
|
||||
$config->gitfox->zentaoObjectLabel->priority = "0";
|
||||
|
||||
$config->gitfox->webhookURL = "%s/api.php?m=gitfox&f=webhook&product=%s&gitfox=%s";
|
||||
|
||||
$config->gitfox->skippedFields = new stdclass;
|
||||
$config->gitfox->skippedFields->issueCreate = array();
|
||||
$config->gitfox->skippedFields->issueCreate['story'] = array();
|
||||
$config->gitfox->skippedFields->issueCreate['task'] = array();
|
||||
$config->gitfox->skippedFields->issueCreate['bug'] = array();
|
||||
|
||||
$config->gitfox->maps = new stdclass;
|
||||
$config->gitfox->maps->task = array();
|
||||
$config->gitfox->maps->task['name'] = 'title|field|';
|
||||
$config->gitfox->maps->task['desc'] = 'description|field|';
|
||||
$config->gitfox->maps->task['openedDate'] = 'created_at|field|datetime';
|
||||
$config->gitfox->maps->task['assignedTo'] = 'assignee_id|userPairs|';
|
||||
$config->gitfox->maps->task['lastEditedDate'] = 'updated_at|field|datetime';
|
||||
$config->gitfox->maps->task['deadline'] = 'due_date|field|date';
|
||||
$config->gitfox->maps->task['status'] = 'state|configItems|taskStateMap';
|
||||
$config->gitfox->maps->task['pri'] = 'weight|configItems|taskWeightMap';
|
||||
$config->gitfox->maps->task['lastEditedBy'] = 'updated_by_id|userPairs|';
|
||||
|
||||
$config->gitfox->maps->story = array();
|
||||
$config->gitfox->maps->story['title'] = 'title|field|';
|
||||
$config->gitfox->maps->story['spec'] = 'description|fields|verify';
|
||||
$config->gitfox->maps->story['openedDate'] = 'created_at|field|datetime';
|
||||
$config->gitfox->maps->story['assignedTo'] = 'assignee_id|userPairs|';
|
||||
$config->gitfox->maps->story['status'] = 'state|configItems|storyStateMap';
|
||||
$config->gitfox->maps->story['pri'] = 'weight|configItems|storyWeightMap';
|
||||
|
||||
$config->gitfox->maps->bug = array();
|
||||
$config->gitfox->maps->bug['title'] = 'title|field|';
|
||||
$config->gitfox->maps->bug['steps'] = 'description|field|';
|
||||
$config->gitfox->maps->bug['openedDate'] = 'created_at|field|datetime';
|
||||
$config->gitfox->maps->bug['deadline'] = 'due_date|field|date';
|
||||
$config->gitfox->maps->bug['assignedTo'] = 'assignee_id|userPairs|';
|
||||
$config->gitfox->maps->bug['status'] = 'state|configItems|bugStateMap';
|
||||
$config->gitfox->maps->bug['pri'] = 'weight|configItems|bugWeightMap';
|
||||
|
||||
$config->gitfox->taskWeightMap = array();
|
||||
$config->gitfox->taskWeightMap['1'] = '1';
|
||||
$config->gitfox->taskWeightMap['2'] = '2';
|
||||
$config->gitfox->taskWeightMap['3'] = '3';
|
||||
|
||||
$config->gitfox->taskStateMap = array();
|
||||
$config->gitfox->taskStateMap['doing'] = 'opened';
|
||||
$config->gitfox->taskStateMap['wait'] = 'opened';
|
||||
$config->gitfox->taskStateMap['closed'] = 'closed';
|
||||
$config->gitfox->taskStateMap['done'] = 'closed';
|
||||
$config->gitfox->taskStateMap['cancel'] = 'closed';
|
||||
|
||||
$config->gitfox->taskTypesToSync = 'design,devel,request,discuss,ui,affair,misc';
|
||||
|
||||
$config->gitfox->storyWeightMap = array();
|
||||
$config->gitfox->storyWeightMap['1'] = '1';
|
||||
$config->gitfox->storyWeightMap['2'] = '2';
|
||||
$config->gitfox->storyWeightMap['3'] = '3';
|
||||
|
||||
$config->gitfox->storyStateMap = array();
|
||||
$config->gitfox->storyStateMap['active'] = 'opened';
|
||||
$config->gitfox->storyStateMap['resolved'] = 'closed';
|
||||
$config->gitfox->storyStateMap['closed'] = 'closed';
|
||||
|
||||
$config->gitfox->bugWeightMap = array();
|
||||
$config->gitfox->bugWeightMap['1'] = '1';
|
||||
$config->gitfox->bugWeightMap['2'] = '2';
|
||||
$config->gitfox->bugWeightMap['3'] = '3';
|
||||
$config->gitfox->bugWeightMap['4'] = '4';
|
||||
|
||||
$config->gitfox->bugStateMap = array();
|
||||
$config->gitfox->bugStateMap['active'] = 'opened';
|
||||
$config->gitfox->bugStateMap['resolved'] = 'closed';
|
||||
$config->gitfox->bugStateMap['closed'] = 'closed';
|
||||
|
||||
$config->gitfox->objectTables = new stdclass;
|
||||
$config->gitfox->objectTables->story = TABLE_STORY;
|
||||
$config->gitfox->objectTables->task = TABLE_TASK;
|
||||
$config->gitfox->objectTables->bug = TABLE_BUG;
|
||||
|
||||
$config->gitfox->objectTypes = array();
|
||||
$config->gitfox->objectTypes[''] = '';
|
||||
$config->gitfox->objectTypes['task'] = '任务';
|
||||
$config->gitfox->objectTypes['bug'] = 'Bug';
|
||||
$config->gitfox->objectTypes['story'] = '需求';
|
||||
|
||||
$config->gitfox->accessLevel = array();
|
||||
$config->gitfox->accessLevel['guest'] = 10;
|
||||
$config->gitfox->accessLevel['reporter'] = 20;
|
||||
$config->gitfox->accessLevel['developer'] = 30;
|
||||
$config->gitfox->accessLevel['maintainer'] = 40;
|
||||
$config->gitfox->accessLevel['owner'] = 50;
|
||||
|
||||
$config->gitfox->menus['project'] = 'browseProject';
|
||||
$config->gitfox->menus['group'] = 'browseGroup';
|
||||
$config->gitfox->menus['user'] = 'browseUser';
|
||||
@@ -57,7 +57,7 @@ class gitfox extends control
|
||||
$user = $this->gitfox->checkTokenAccess($gitfox->url, $gitfox->token);
|
||||
|
||||
if(is_bool($user)) return $this->send(array('result' => 'fail', 'message' => array('url' => array(sprintf($this->lang->gitfox->hostError, $this->config->gitfox->minCompatibleVersion)))));
|
||||
if(!isset($user->id)) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitfox->tokenError))));
|
||||
if(!isset($user[0]->uid)) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->gitfox->tokenError))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+62
-5
@@ -11,6 +11,47 @@ declare(strict_types=1);
|
||||
*/
|
||||
class gitfoxModel extends model
|
||||
{
|
||||
/**
|
||||
* 获取gitfox根据id。
|
||||
* Get a gitfox by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return object|false
|
||||
*/
|
||||
public function getByID(int $id): object|false
|
||||
{
|
||||
return $this->loadModel('pipeline')->getByID($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitfox列表。
|
||||
* Get gitfox list.
|
||||
*
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getList(string $orderBy = 'id_desc', object $pager = null): array
|
||||
{
|
||||
$gitfoxList = $this->loadModel('pipeline')->getList('gitfox', $orderBy, $pager);
|
||||
|
||||
return $gitfoxList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitfox id name 键值对。
|
||||
* Get gitfox pairs.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getPairs(): array
|
||||
{
|
||||
return $this->loadModel('pipeline')->getPairs('gitfox');
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查token。
|
||||
* Check token access.
|
||||
@@ -22,15 +63,31 @@ class gitfoxModel extends model
|
||||
*/
|
||||
public function checkTokenAccess(string $url = '', string $token = ''): object|array|null|false
|
||||
{
|
||||
$apiRoot = rtrim($url, '/') . '/api/v4%s' . "?private_token={$token}";
|
||||
$url = sprintf($apiRoot, "/users") . "&per_page=5&active=true";
|
||||
$response = commonModel::http($url);
|
||||
$url = rtrim($url, '/') . '/api/v1/admin/users';
|
||||
$header = array('Authorization: Bearer ' . $token);
|
||||
$response = commonModel::http($url, null, array(), $header);
|
||||
|
||||
$users = json_decode($response);
|
||||
if(empty($users)) return false;
|
||||
if(isset($users->message) or isset($users->error)) return null;
|
||||
|
||||
$apiRoot .= '&sudo=' . $users[0]->id;
|
||||
return $this->apiGet($apiRoot, '/user');
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitfox api 基础url 根据gitfox id。
|
||||
* Get gitfox api base url by gitfox id.
|
||||
*
|
||||
* @param int $gitfoxID
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getApiRoot(int $gitfoxID): string
|
||||
{
|
||||
$gitfox = $this->getByID($gitfoxID);
|
||||
if(!$gitfox || $gitfox->type != 'gitfox') return '';
|
||||
|
||||
return rtrim($gitfox->url, '/') . '/api/v1%s';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ class space extends control
|
||||
|
||||
$this->app->loadLang('sonarqube');
|
||||
$this->app->loadLang('jenkins');
|
||||
$this->app->loadLang('gitfox');
|
||||
|
||||
$apps = array();
|
||||
$defaultApp = '';
|
||||
|
||||
@@ -51,6 +51,11 @@ function onChangeAppType(event)
|
||||
$('#url').attr('placeholder', gitlabUrlTips);
|
||||
$('#token').attr('placeholder', gitlabTokenTips);
|
||||
break;
|
||||
case 'gitfox':
|
||||
$('#createAppForm').attr('action', $.createLink('gitfox', 'create'));
|
||||
$('#url').attr('placeholder', gitfoxUrlTips);
|
||||
$('#token').attr('placeholder', gitfoxTokenTips);
|
||||
break;
|
||||
case 'gitea':
|
||||
$('#createAppForm').attr('action', $.createLink('gitea', 'create'));
|
||||
break;
|
||||
|
||||
@@ -18,6 +18,8 @@ $colWidth = isInModal() ? 'full' : '2/3';
|
||||
|
||||
jsVar('gitlabUrlTips', $lang->gitlab->placeholder->url);
|
||||
jsVar('gitlabTokenTips', $lang->gitlab->placeholder->token);
|
||||
jsVar('gitfoxUrlTips', $lang->gitfox->placeholder->url);
|
||||
jsVar('gitfoxTokenTips', $lang->gitfox->placeholder->token);
|
||||
jsVar('sonarqubeUrlTips', $lang->sonarqube->placeholder->url);
|
||||
jsVar('jenkinsTokenTips', $lang->jenkins->tokenFirst);
|
||||
jsVar('jenkinsPasswordTips', $lang->jenkins->tips);
|
||||
|
||||
Reference in New Issue
Block a user