mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Attach identities to commits and users to identities
Summary: Ref T12164. Make it easier to work with identity objects by attaching them to commits and attaching users to identities. Test Plan: Loaded some commits with `->needIdentities(true)` and checked the resulting objects. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T12164 Differential Revision: https://secure.phabricator.com/D19491
This commit is contained in:
parent
787c59744b
commit
05f333dfba
5 changed files with 74 additions and 3 deletions
|
@ -26,6 +26,7 @@ final class DiffusionCommitQuery
|
|||
|
||||
private $needCommitData;
|
||||
private $needDrafts;
|
||||
private $needIdentities;
|
||||
|
||||
private $mustFilterRefs = false;
|
||||
private $refRepository;
|
||||
|
@ -110,6 +111,11 @@ final class DiffusionCommitQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function needIdentities($need) {
|
||||
$this->needIdentities = $need;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function needAuditRequests($need) {
|
||||
$this->needAuditRequests = $need;
|
||||
return $this;
|
||||
|
@ -393,6 +399,24 @@ final class DiffusionCommitQuery
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->needIdentities) {
|
||||
$identity_phids = array_merge(
|
||||
mpull($commits, 'getAuthorIdentityPHID'),
|
||||
mpull($commits, 'getCommitterIdentityPHID'));
|
||||
|
||||
$data = id(new PhabricatorRepositoryIdentityQuery())
|
||||
->withPHIDs($identity_phids)
|
||||
->setViewer($this->getViewer())
|
||||
->execute();
|
||||
$data = mpull($data, null, 'getPHID');
|
||||
|
||||
foreach ($commits as $commit) {
|
||||
$author_identity = idx($data, $commit->getAuthorIdentityPHID());
|
||||
$committer_identity = idx($data, $commit->getCommitterIdentityPHID());
|
||||
$commit->attachIdentities($author_identity, $committer_identity);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->needDrafts) {
|
||||
PhabricatorDraftEngine::attachDrafts(
|
||||
$viewer,
|
||||
|
|
|
@ -28,6 +28,18 @@ final class PhabricatorRepositoryIdentityPHIDType
|
|||
public function loadHandles(
|
||||
PhabricatorHandleQuery $query,
|
||||
array $handles,
|
||||
array $objects) {}
|
||||
array $objects) {
|
||||
|
||||
foreach ($handles as $phid => $handle) {
|
||||
$identity = $objects[$phid];
|
||||
|
||||
$id = $identity->getID();
|
||||
$name = $identity->getIdentityNameRaw();
|
||||
|
||||
$handle->setObjectName(pht('Identity %d', $id));
|
||||
$handle->setName($name);
|
||||
$handle->setURI($identity->getURI());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -131,8 +131,10 @@ final class PhabricatorRepositoryIdentityQuery
|
|||
return $identities;
|
||||
}
|
||||
|
||||
$users = id(new PhabricatorUser())->loadAllWhere(
|
||||
'phid IN (%Ls)', $user_ids);
|
||||
$users = id(new PhabricatorPeopleQuery())
|
||||
->withPHIDs($user_ids)
|
||||
->setViewer($this->getViewer())
|
||||
->execute();
|
||||
$users = mpull($users, null, 'getPHID');
|
||||
|
||||
foreach ($identities as $identity) {
|
||||
|
|
|
@ -44,6 +44,9 @@ final class PhabricatorRepositoryCommit
|
|||
private $audits = self::ATTACHABLE;
|
||||
private $repository = self::ATTACHABLE;
|
||||
private $customFields = self::ATTACHABLE;
|
||||
private $authorIdentity = self::ATTACHABLE;
|
||||
private $committerIdentity = self::ATTACHABLE;
|
||||
|
||||
private $drafts = array();
|
||||
private $auditAuthorityPHIDs = array();
|
||||
|
||||
|
@ -191,6 +194,21 @@ final class PhabricatorRepositoryCommit
|
|||
return ($this->audits !== self::ATTACHABLE);
|
||||
}
|
||||
|
||||
public function attachIdentities(
|
||||
PhabricatorRepositoryIdentity $author,
|
||||
$committer = null) {
|
||||
$this->authorIdentity = $author;
|
||||
$this->committerIdentity = $committer;
|
||||
}
|
||||
|
||||
public function getAuthorIdentity() {
|
||||
return $this->assertAttached($this->authorIdentity);
|
||||
}
|
||||
|
||||
public function getCommiterIdentity() {
|
||||
return $this->assertAttached($this->committerIdentity);
|
||||
}
|
||||
|
||||
public function loadAndAttachAuditAuthority(
|
||||
PhabricatorUser $viewer,
|
||||
$actor_phid = null) {
|
||||
|
|
|
@ -14,6 +14,17 @@ final class PhabricatorRepositoryIdentity
|
|||
protected $manuallySetUserPHID;
|
||||
protected $currentEffectiveUserPHID;
|
||||
|
||||
private $effectiveUser = self::ATTACHABLE;
|
||||
|
||||
public function attachEffectiveUser(PhabricatorUser $user) {
|
||||
$this->effectiveUser = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEffectiveUser() {
|
||||
return $this->assertAttached($this->effectiveUser);
|
||||
}
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
|
@ -63,6 +74,10 @@ final class PhabricatorRepositoryIdentity
|
|||
return '/diffusion/identity/view/'.$this->getID().'/';
|
||||
}
|
||||
|
||||
public function hasEffectiveUser() {
|
||||
return ($this->currentEffectiveUserPHID != null);
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if ($this->manuallySetUserPHID) {
|
||||
$this->currentEffectiveUserPHID = $this->manuallySetUserPHID;
|
||||
|
|
Loading…
Reference in a new issue