1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-16 16:58:38 +01:00

Remove all readers and writers of "accountID" on "ExternalAccount"

Summary: Depends on D21019. Ref T13493. There are no more barriers to removing readers and writers of "accountID"; the new "ExternalAccountIdentity" table can replace it completely.

Test Plan: Linked and unlinked OAuth accounts, logged in with OAuth accounts, tried to double-link OAuth accounts, grepped for affected symbols.

Maniphest Tasks: T13493

Differential Revision: https://secure.phabricator.com/D21022
This commit is contained in:
epriestley 2020-02-22 10:47:32 -08:00
parent 84b5ad09e6
commit 802b5aca05
3 changed files with 76 additions and 26 deletions

View file

@ -156,7 +156,7 @@ abstract class PhutilOAuth1AuthAdapter extends PhutilAuthAdapter {
$authorize_token_uri = new PhutilURI($this->getAuthorizeTokenURI()); $authorize_token_uri = new PhutilURI($this->getAuthorizeTokenURI());
$authorize_token_uri->replaceQueryParam('oauth_token', $this->getToken()); $authorize_token_uri->replaceQueryParam('oauth_token', $this->getToken());
return (string)$authorize_token_uri; return phutil_string_cast($authorize_token_uri);
} }
protected function finishOAuthHandshake() { protected function finishOAuthHandshake() {

View file

@ -219,12 +219,11 @@ abstract class PhabricatorAuthProvider extends Phobject {
$accounts = id(new PhabricatorExternalAccountQuery()) $accounts = id(new PhabricatorExternalAccountQuery())
->setViewer($viewer) ->setViewer($viewer)
->withProviderConfigPHIDs(array($config->getPHID())) ->withProviderConfigPHIDs(array($config->getPHID()))
->withAccountIDs($raw_identifiers) ->withRawAccountIdentifiers($raw_identifiers)
->needAccountIdentifiers(true) ->needAccountIdentifiers(true)
->execute(); ->execute();
if (!$accounts) { if (!$accounts) {
$account = $this->newExternalAccount() $account = $this->newExternalAccount();
->setAccountID(head($raw_identifiers));
} else if (count($accounts) === 1) { } else if (count($accounts) === 1) {
$account = head($accounts); $account = head($accounts);
} else { } else {
@ -270,10 +269,6 @@ abstract class PhabricatorAuthProvider extends Phobject {
if (!$account) { if (!$account) {
$account = $this->newExternalAccount() $account = $this->newExternalAccount()
->setUserPHID($user->getPHID()); ->setUserPHID($user->getPHID());
// TODO: Remove this when "accountID" is removed; the column is not
// nullable.
$account->setAccountID('');
} }
return $this->didUpdateAccount($account); return $this->didUpdateAccount($account);
@ -375,6 +370,11 @@ abstract class PhabricatorAuthProvider extends Phobject {
->setAccountType($adapter->getAdapterType()) ->setAccountType($adapter->getAdapterType())
->setAccountDomain($adapter->getAdapterDomain()); ->setAccountDomain($adapter->getAdapterDomain());
// TODO: Remove this when "accountID" is removed; the column is not
// nullable.
$account->setAccountID('');
return $account; return $account;
} }

View file

@ -15,23 +15,18 @@ final class PhabricatorExternalAccountQuery
private $ids; private $ids;
private $phids; private $phids;
private $accountIDs;
private $userPHIDs; private $userPHIDs;
private $needImages; private $needImages;
private $accountSecrets; private $accountSecrets;
private $providerConfigPHIDs; private $providerConfigPHIDs;
private $needAccountIdentifiers; private $needAccountIdentifiers;
private $rawAccountIdentifiers;
public function withUserPHIDs(array $user_phids) { public function withUserPHIDs(array $user_phids) {
$this->userPHIDs = $user_phids; $this->userPHIDs = $user_phids;
return $this; return $this;
} }
public function withAccountIDs(array $account_ids) {
$this->accountIDs = $account_ids;
return $this;
}
public function withPHIDs(array $phids) { public function withPHIDs(array $phids) {
$this->phids = $phids; $this->phids = $phids;
return $this; return $this;
@ -62,6 +57,11 @@ final class PhabricatorExternalAccountQuery
return $this; return $this;
} }
public function withRawAccountIdentifiers(array $identifiers) {
$this->rawAccountIdentifiers = $identifiers;
return $this;
}
public function newResultObject() { public function newResultObject() {
return new PhabricatorExternalAccount(); return new PhabricatorExternalAccount();
} }
@ -152,48 +152,98 @@ final class PhabricatorExternalAccountQuery
if ($this->ids !== null) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'id IN (%Ld)', 'account.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids !== null) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'phid IN (%Ls)', 'account.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->accountIDs !== null) {
$where[] = qsprintf(
$conn,
'accountID IN (%Ls)',
$this->accountIDs);
}
if ($this->userPHIDs !== null) { if ($this->userPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'userPHID IN (%Ls)', 'account.userPHID IN (%Ls)',
$this->userPHIDs); $this->userPHIDs);
} }
if ($this->accountSecrets !== null) { if ($this->accountSecrets !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'accountSecret IN (%Ls)', 'account.accountSecret IN (%Ls)',
$this->accountSecrets); $this->accountSecrets);
} }
if ($this->providerConfigPHIDs !== null) { if ($this->providerConfigPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'providerConfigPHID IN (%Ls)', 'account.providerConfigPHID IN (%Ls)',
$this->providerConfigPHIDs); $this->providerConfigPHIDs);
// If we have a list of ProviderConfig PHIDs and are joining the
// identifiers table, also include the list as an additional constraint
// on the identifiers table.
// This does not change the query results (an Account and its
// Identifiers always have the same ProviderConfig PHID) but it allows
// us to use keys on the Identifier table more efficiently.
if ($this->shouldJoinIdentifiersTable()) {
$where[] = qsprintf(
$conn,
'identifier.providerConfigPHID IN (%Ls)',
$this->providerConfigPHIDs);
}
}
if ($this->rawAccountIdentifiers !== null) {
$hashes = array();
foreach ($this->rawAccountIdentifiers as $raw_identifier) {
$hashes[] = PhabricatorHash::digestForIndex($raw_identifier);
}
$where[] = qsprintf(
$conn,
'identifier.identifierHash IN (%Ls)',
$hashes);
} }
return $where; return $where;
} }
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = parent::buildJoinClauseParts($conn);
if ($this->shouldJoinIdentifiersTable()) {
$joins[] = qsprintf(
$conn,
'JOIN %R identifier ON account.phid = identifier.externalAccountPHID',
new PhabricatorExternalAccountIdentifier());
}
return $joins;
}
protected function shouldJoinIdentifiersTable() {
return ($this->rawAccountIdentifiers !== null);
}
protected function shouldGroupQueryResultRows() {
if ($this->shouldJoinIdentifiersTable()) {
return true;
}
return parent::shouldGroupQueryResultRows();
}
protected function getPrimaryTableAlias() {
return 'account';
}
public function getQueryApplicationClass() { public function getQueryApplicationClass() {
return 'PhabricatorPeopleApplication'; return 'PhabricatorPeopleApplication';
} }