diff --git a/src/applications/repository/query/PhabricatorRepositoryIdentityQuery.php b/src/applications/repository/query/PhabricatorRepositoryIdentityQuery.php index ef038f045f..c64b1a296b 100644 --- a/src/applications/repository/query/PhabricatorRepositoryIdentityQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryIdentityQuery.php @@ -1,154 +1,131 @@ ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withIdentityNames(array $names) { $this->identityNames = $names; return $this; } public function withIdentityNameLike($name_like) { $this->identityNameLike = $name_like; return $this; } public function withEmailAddress($address) { $this->emailAddress = $address; return $this; } public function withAssigneePHIDs(array $assignees) { $this->assigneePHIDs = $assignees; return $this; } public function withHasEffectivePHID($has_effective_phid) { $this->hasEffectivePHID = $has_effective_phid; return $this; } public function newResultObject() { return new PhabricatorRepositoryIdentity(); } protected function getPrimaryTableAlias() { return 'repository_identity'; } protected function loadPage() { return $this->loadStandardPage($this->newResultObject()); } protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf( $conn, 'repository_identity.id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, 'repository_identity.phid IN (%Ls)', $this->phids); } if ($this->assigneePHIDs !== null) { $where[] = qsprintf( $conn, 'repository_identity.currentEffectiveUserPHID IN (%Ls)', $this->assigneePHIDs); } if ($this->hasEffectivePHID !== null) { if ($this->hasEffectivePHID) { $where[] = qsprintf( $conn, 'repository_identity.currentEffectiveUserPHID IS NOT NULL'); } else { $where[] = qsprintf( $conn, 'repository_identity.currentEffectiveUserPHID IS NULL'); } } if ($this->identityNames !== null) { $name_hashes = array(); foreach ($this->identityNames as $name) { $name_hashes[] = PhabricatorHash::digestForIndex($name); } $where[] = qsprintf( $conn, 'repository_identity.identityNameHash IN (%Ls)', $name_hashes); } if ($this->emailAddress !== null) { $identity_style = "<{$this->emailAddress}>"; $where[] = qsprintf( $conn, 'repository_identity.identityNameRaw LIKE %<', $identity_style); } if ($this->identityNameLike != null) { $where[] = qsprintf( $conn, 'repository_identity.identityNameRaw LIKE %~', $this->identityNameLike); } return $where; } - protected function didFilterPage(array $identities) { - $user_ids = array_filter( - mpull($identities, 'getCurrentEffectiveUserPHID', 'getID')); - if (!$user_ids) { - return $identities; - } - - $users = id(new PhabricatorPeopleQuery()) - ->withPHIDs($user_ids) - ->setViewer($this->getViewer()) - ->execute(); - $users = mpull($users, null, 'getPHID'); - - foreach ($identities as $identity) { - if ($identity->hasEffectiveUser()) { - $user = idx($users, $identity->getCurrentEffectiveUserPHID()); - $identity->attachEffectiveUser($user); - } - } - - return $identities; - } - public function getQueryApplicationClass() { return 'PhabricatorDiffusionApplication'; } } diff --git a/src/applications/repository/storage/PhabricatorRepositoryIdentity.php b/src/applications/repository/storage/PhabricatorRepositoryIdentity.php index 76c6aed9e0..e3833bd10e 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryIdentity.php +++ b/src/applications/repository/storage/PhabricatorRepositoryIdentity.php @@ -1,141 +1,130 @@ effectiveUser = $user; - return $this; - } - - public function getEffectiveUser() { - return $this->assertAttached($this->effectiveUser); - } - protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_BINARY => array( 'identityNameRaw' => true, ), self::CONFIG_COLUMN_SCHEMA => array( 'identityNameHash' => 'bytes12', 'identityNameEncoding' => 'text16?', 'automaticGuessedUserPHID' => 'phid?', 'manuallySetUserPHID' => 'phid?', 'currentEffectiveUserPHID' => 'phid?', ), self::CONFIG_KEY_SCHEMA => array( 'key_identity' => array( 'columns' => array('identityNameHash'), 'unique' => true, ), ), ) + parent::getConfiguration(); } public function getPHIDType() { return PhabricatorRepositoryIdentityPHIDType::TYPECONST; } public function setIdentityName($name_raw) { $this->setIdentityNameRaw($name_raw); $this->setIdentityNameHash(PhabricatorHash::digestForIndex($name_raw)); $this->setIdentityNameEncoding($this->detectEncodingForStorage($name_raw)); return $this; } public function getIdentityName() { return $this->getUTF8StringFromStorage( $this->getIdentityNameRaw(), $this->getIdentityNameEncoding()); } public function getIdentityEmailAddress() { $address = new PhutilEmailAddress($this->getIdentityName()); return $address->getAddress(); } public function getIdentityDisplayName() { $address = new PhutilEmailAddress($this->getIdentityName()); return $address->getDisplayName(); } public function getIdentityShortName() { // TODO return $this->getIdentityName(); } public function getURI() { return '/diffusion/identity/view/'.$this->getID().'/'; } public function hasEffectiveUser() { return ($this->currentEffectiveUserPHID != null); } public function getIdentityDisplayPHID() { if ($this->hasEffectiveUser()) { return $this->getCurrentEffectiveUserPHID(); } else { return $this->getPHID(); } } public function save() { if ($this->manuallySetUserPHID) { $this->currentEffectiveUserPHID = $this->manuallySetUserPHID; } else { $this->currentEffectiveUserPHID = $this->automaticGuessedUserPHID; } return parent::save(); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { return PhabricatorPolicies::getMostOpenPolicy(); } public function hasAutomaticCapability( $capability, PhabricatorUser $viewer) { return false; } /* -( PhabricatorApplicationTransactionInterface )------------------------- */ public function getApplicationTransactionEditor() { return new DiffusionRepositoryIdentityEditor(); } public function getApplicationTransactionTemplate() { return new PhabricatorRepositoryIdentityTransaction(); } }