* Merge gitea, gogs, gitlab methods to pipeline model.
This commit is contained in:
@@ -195,7 +195,7 @@ class gitModel extends model
|
||||
|
||||
$scm = strtolower($repo->SCM);
|
||||
$userList = $this->loadModel($scm)->apiGetUsers($repo->gitService);
|
||||
$acountIDPairs = $this->{$scm}->getUserAccountIdPairs($repo->gitService, 'openID,account');
|
||||
$acountIDPairs = $this->loadModel('pipeline')->getUserBindedPairs($repo->gitService, $scm, 'openID,account');
|
||||
|
||||
$accountPairs = array();
|
||||
foreach($userList as $user) $accountPairs[$user->realname] = zget($acountIDPairs, $user->id, '');
|
||||
|
||||
@@ -204,10 +204,10 @@ class gitea extends control
|
||||
|
||||
$userList = array();
|
||||
$giteaUsers = $this->gitea->apiGetUsers($giteaID);
|
||||
$bindedUsers = $this->gitea->getUserAccountIdPairs($giteaID);
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($giteaID, 'gitea');
|
||||
$matchedResult = $this->gitea->getMatchedUsers($giteaID, $giteaUsers, $zentaoUsers);
|
||||
|
||||
foreach($giteaUsers as $giteaUserID => $giteaUser)
|
||||
foreach($giteaUsers as $giteaUser)
|
||||
{
|
||||
$user = new stdclass();
|
||||
$user->email = '';
|
||||
|
||||
+2
-17
@@ -277,21 +277,6 @@ 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 gitea user id by zentao account.
|
||||
*
|
||||
@@ -331,7 +316,7 @@ class giteaModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
$bindedUsers = $this->getUserAccountIdPairs($giteaID, 'openID,account');
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($giteaID, 'gitea', 'openID,account');
|
||||
$matchedUsers = array();
|
||||
foreach($giteaUsers as $giteaUser)
|
||||
{
|
||||
@@ -467,7 +452,7 @@ class giteaModel extends model
|
||||
|
||||
/* Get linked users. */
|
||||
$linkedUsers = array();
|
||||
if($onlyLinked) $linkedUsers = $this->getUserAccountIdPairs($giteaID, 'openID,account');
|
||||
if($onlyLinked) $linkedUsers = $this->loadModel('pipeline')->getUserBindedPairs($giteaID, 'gitea', 'openID,account');
|
||||
|
||||
$users = array();
|
||||
foreach($response as $giteaUser)
|
||||
|
||||
@@ -201,10 +201,10 @@ class gogs extends control
|
||||
|
||||
$userList = array();
|
||||
$gogsUsers = $this->gogs->apiGetUsers($gogsID);
|
||||
$bindedUsers = $this->gogs->getUserAccountIdPairs($gogsID);
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($gogsID, 'gogs');
|
||||
$matchedResult = $this->gogs->getMatchedUsers($gogsID, $gogsUsers, $zentaoUsers);
|
||||
|
||||
foreach($gogsUsers as $gogsUserID => $gogsUser)
|
||||
foreach($gogsUsers as $gogsUser)
|
||||
{
|
||||
$user = new stdclass();
|
||||
$user->email = '';
|
||||
|
||||
+2
-17
@@ -236,21 +236,6 @@ class gogsModel extends model
|
||||
->fetchPairs('providerID');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get zentao account gogs user id pairs of one gogs.
|
||||
*
|
||||
* @param int $gogsID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUserAccountIdPairs($gogsID, $fields = 'account,openID')
|
||||
{
|
||||
return $this->dao->select($fields)->from(TABLE_OAUTH)
|
||||
->where('providerType')->eq('gogs')
|
||||
->andWhere('providerID')->eq($gogsID)
|
||||
->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get gogs user id by zentao account.
|
||||
*
|
||||
@@ -290,7 +275,7 @@ class gogsModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
$bindedUsers = $this->getUserAccountIdPairs($gogsID, 'openID,account');
|
||||
$bindedUsers = $this->loadModel('pipeline')->getUserBindedPairs($gogsID, 'gogs', 'openID,account');
|
||||
$matchedUsers = array();
|
||||
foreach($gogsUsers as $gogsUser)
|
||||
{
|
||||
@@ -419,7 +404,7 @@ class gogsModel extends model
|
||||
|
||||
/* Get linked users. */
|
||||
$linkedUsers = array();
|
||||
if($onlyLinked) $linkedUsers = $this->getUserAccountIdPairs($gogsID, 'openID,account');
|
||||
if($onlyLinked) $linkedUsers = $this->loadModel('pipeline')->getUserBindedPairs($gogsID, 'gogs', 'openID,account');
|
||||
|
||||
$users = array();
|
||||
foreach($response as $gogsUser)
|
||||
|
||||
@@ -261,13 +261,13 @@ class mr extends control
|
||||
/* Fetch user list both in Zentao and current GitLab project. */
|
||||
$host = $this->loadModel('pipeline')->getByID($MR->hostID);
|
||||
$scm = $host->type;
|
||||
$gitUsers = $this->loadModel($scm)->getUserAccountIdPairs($MR->hostID);
|
||||
$gitUsers = $this->pipeline->getUserBindedPairs($MR->hostID, $scm)
|
||||
|
||||
/* Check permissions. */
|
||||
if(!$this->app->user->admin and $scm == 'gitlab')
|
||||
{
|
||||
$groupIDList = array(0 => 0);
|
||||
$groups = $this->$scm->apiGetGroups($MR->hostID, 'name_asc', 'developer');
|
||||
$groups = $this->loadModel($scm)->apiGetGroups($MR->hostID, 'name_asc', 'developer');
|
||||
foreach($groups as $group) $groupIDList[] = $group->id;
|
||||
|
||||
$sourceProject = $this->$scm->apiGetSingleProject($MR->hostID, $MR->sourceProject);
|
||||
|
||||
+4
-12
@@ -426,18 +426,10 @@ class mrModel extends model
|
||||
/* Sync MR in ZenTao database whatever status of MR in GitLab. */
|
||||
if(isset($rawMR->iid))
|
||||
{
|
||||
$map = $this->config->mr->maps->sync;
|
||||
if($rawMR->gitService == 'gitlab')
|
||||
{
|
||||
$gitUsers = $this->loadModel('gitlab')->getUserIdAccountPairs($MR->hostID);
|
||||
}
|
||||
else
|
||||
{
|
||||
$gitUsers = $this->loadModel($rawMR->gitService)->getUserAccountIdPairs($MR->hostID, 'openID,account');
|
||||
}
|
||||
$gitUsers = $this->loadModel('pipeline')->getUserBindedPairs($MR->hostID, $rawMR->gitService, 'openID,account');
|
||||
|
||||
$newMR = new stdclass;
|
||||
foreach($map as $syncField => $config)
|
||||
$newMR = new stdclass();
|
||||
foreach($this->config->mr->maps->sync as $syncField => $config)
|
||||
{
|
||||
$value = '';
|
||||
list($field, $optionType, $options) = explode('|', $config);
|
||||
@@ -469,7 +461,7 @@ class mrModel extends model
|
||||
->where('id')->eq($MR->id)
|
||||
->exec();
|
||||
}
|
||||
return $this->dao->findByID($MR->id)->from(TABLE_MR)->fetch();
|
||||
return $this->fetchByID($MR->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -241,7 +241,7 @@ class mrZen extends mr
|
||||
foreach($groups as $group) $groupIDList[] = $group->id;
|
||||
|
||||
$isDeveloper = $this->gitlab->checkUserAccess($MR->hostID, 0, $sourceProject, $groupIDList, 'developer');
|
||||
$gitUsers = $this->gitlab->getUserAccountIdPairs($MR->hostID);
|
||||
$gitUsers = $this->loadModel('pipeline')->getUserBindedPairs($MR->hostID, 'gitlab');
|
||||
if(isset($gitUsers[$this->app->user->account]) && $isDeveloper) return true;
|
||||
}
|
||||
elseif($hostType == 'gitea')
|
||||
|
||||
@@ -181,4 +181,23 @@ class pipelineModel extends model
|
||||
$actionID = $this->dao->lastInsertID();
|
||||
return $actionID;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取禅道用户绑定的第三方账号。
|
||||
* Get user binded third party accounts.
|
||||
*
|
||||
* @param int $providerID
|
||||
* @param string $providerType gitlab, gitea, gogs
|
||||
* @param string $fields key, value
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUserBindedPairs(int $providerID, string $providerType, string $fields = 'account,openID'): array
|
||||
{
|
||||
$providerType = strtolower($providerType);
|
||||
return $this->dao->select($fields)->from(TABLE_OAUTH)
|
||||
->where('providerType')->eq($providerType)
|
||||
->andWhere('providerID')->eq($providerID)
|
||||
->fetchPairs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1899,7 +1899,7 @@ class repoModel extends model
|
||||
|
||||
$accountPairs = array();
|
||||
$userList = $this->loadModel('gitlab')->apiGetUsers($repo->gitService);
|
||||
$acountIDPairs = $this->gitlab->getUserIdAccountPairs($repo->gitService);
|
||||
$acountIDPairs = $this->loadModel('pipeline')->getUserBindedPairs($repo->gitService, 'gitlab', 'openID,account');
|
||||
foreach($userList as $gitlabUser) $accountPairs[$gitlabUser->realname] = zget($acountIDPairs, $gitlabUser->id, '');
|
||||
|
||||
foreach($data->commits as $commit)
|
||||
|
||||
Reference in New Issue
Block a user