Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14758060
D20112.id48021.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D20112.id48021.diff
View Options
diff --git a/resources/sql/autopatches/20190206.external.03.providerphid.sql b/resources/sql/autopatches/20190206.external.03.providerphid.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20190206.external.03.providerphid.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_user.user_externalaccount
+ ADD providerConfigPHID VARBINARY(64) NOT NULL;
diff --git a/resources/sql/autopatches/20190206.external.04.providerlink.php b/resources/sql/autopatches/20190206.external.04.providerlink.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20190206.external.04.providerlink.php
@@ -0,0 +1,36 @@
+<?php
+
+$account_table = new PhabricatorExternalAccount();
+$account_conn = $account_table->establishConnection('w');
+$table_name = $account_table->getTableName();
+
+$config_table = new PhabricatorAuthProviderConfig();
+$config_conn = $config_table->establishConnection('w');
+
+foreach (new LiskRawMigrationIterator($account_conn, $table_name) as $row) {
+ if (strlen($row['providerConfigPHID'])) {
+ continue;
+ }
+
+ $config_row = queryfx_one(
+ $config_conn,
+ 'SELECT phid
+ FROM %R
+ WHERE providerType = %s AND providerDomain = %s
+ LIMIT 1',
+ $config_table,
+ $row['accountType'],
+ $row['accountDomain']);
+ if (!$config_row) {
+ continue;
+ }
+
+ queryfx(
+ $account_conn,
+ 'UPDATE %R
+ SET providerConfigPHID = %s
+ WHERE id = %d',
+ $account_table,
+ $config_row['phid'],
+ $row['id']);
+}
diff --git a/src/applications/auth/controller/PhabricatorAuthRegisterController.php b/src/applications/auth/controller/PhabricatorAuthRegisterController.php
--- a/src/applications/auth/controller/PhabricatorAuthRegisterController.php
+++ b/src/applications/auth/controller/PhabricatorAuthRegisterController.php
@@ -671,7 +671,7 @@
}
$provider = head($providers);
- $account = $provider->getDefaultExternalAccount();
+ $account = $provider->newDefaultExternalAccount();
return array($account, $provider, $response);
}
diff --git a/src/applications/auth/provider/PhabricatorAuthProvider.php b/src/applications/auth/provider/PhabricatorAuthProvider.php
--- a/src/applications/auth/provider/PhabricatorAuthProvider.php
+++ b/src/applications/auth/provider/PhabricatorAuthProvider.php
@@ -220,9 +220,7 @@
$adapter->getAdapterDomain(),
$account_id);
if (!$account) {
- $account = id(new PhabricatorExternalAccount())
- ->setAccountType($adapter->getAdapterType())
- ->setAccountDomain($adapter->getAdapterDomain())
+ $account = $this->newExternalAccount()
->setAccountID($account_id);
}
@@ -299,8 +297,18 @@
return false;
}
- public function getDefaultExternalAccount() {
- throw new PhutilMethodNotImplementedException();
+ public function newDefaultExternalAccount() {
+ return $this->newExternalAccount();
+ }
+
+ protected function newExternalAccount() {
+ $config = $this->getProviderConfig();
+ $adapter = $this->getAdapter();
+
+ return id(new PhabricatorExternalAccount())
+ ->setAccountType($adapter->getAdapterType())
+ ->setAccountDomain($adapter->getAdapterDomain())
+ ->setProviderConfigPHID($config->getPHID());
}
public function getLoginOrder() {
diff --git a/src/applications/auth/provider/PhabricatorPasswordAuthProvider.php b/src/applications/auth/provider/PhabricatorPasswordAuthProvider.php
--- a/src/applications/auth/provider/PhabricatorPasswordAuthProvider.php
+++ b/src/applications/auth/provider/PhabricatorPasswordAuthProvider.php
@@ -358,14 +358,6 @@
return true;
}
- public function getDefaultExternalAccount() {
- $adapter = $this->getAdapter();
-
- return id(new PhabricatorExternalAccount())
- ->setAccountType($adapter->getAdapterType())
- ->setAccountDomain($adapter->getAdapterDomain());
- }
-
protected function willSaveAccount(PhabricatorExternalAccount $account) {
parent::willSaveAccount($account);
$account->setUserPHID($account->getAccountID());
diff --git a/src/applications/auth/query/PhabricatorExternalAccountQuery.php b/src/applications/auth/query/PhabricatorExternalAccountQuery.php
--- a/src/applications/auth/query/PhabricatorExternalAccountQuery.php
+++ b/src/applications/auth/query/PhabricatorExternalAccountQuery.php
@@ -71,6 +71,26 @@
}
protected function willFilterPage(array $accounts) {
+ $viewer = $this->getViewer();
+
+ $configs = id(new PhabricatorAuthProviderConfigQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(mpull($accounts, 'getProviderConfigPHID'))
+ ->execute();
+ $configs = mpull($configs, null, 'getPHID');
+
+ foreach ($accounts as $key => $account) {
+ $config_phid = $account->getProviderConfigPHID();
+ $config = idx($configs, $config_phid);
+
+ if (!$config) {
+ unset($accounts[$key]);
+ continue;
+ }
+
+ $account->attachProviderConfig($config);
+ }
+
if ($this->needImages) {
$file_phids = mpull($accounts, 'getProfileImagePHID');
$file_phids = array_filter($file_phids);
diff --git a/src/applications/people/storage/PhabricatorExternalAccount.php b/src/applications/people/storage/PhabricatorExternalAccount.php
--- a/src/applications/people/storage/PhabricatorExternalAccount.php
+++ b/src/applications/people/storage/PhabricatorExternalAccount.php
@@ -16,8 +16,10 @@
protected $accountURI;
protected $profileImagePHID;
protected $properties = array();
+ protected $providerConfigPHID;
private $profileImageFile = self::ATTACHABLE;
+ private $providerConfig = self::ATTACHABLE;
public function getProfileImageFile() {
return $this->assertAttached($this->profileImageFile);
@@ -65,13 +67,6 @@
) + parent::getConfiguration();
}
- public function getPhabricatorUser() {
- $tmp_usr = id(new PhabricatorUser())
- ->makeEphemeral()
- ->setPHID($this->getPHID());
- return $tmp_usr;
- }
-
public function getProviderKey() {
return $this->getAccountType().':'.$this->getAccountDomain();
}
@@ -93,13 +88,12 @@
}
public function isUsableForLogin() {
- $key = $this->getProviderKey();
- $provider = PhabricatorAuthProvider::getEnabledProviderByKey($key);
-
- if (!$provider) {
+ $config = $this->getProviderConfig();
+ if (!$config->getIsEnabled()) {
return false;
}
+ $provider = $config->getProvider();
if (!$provider->shouldAllowLogin()) {
return false;
}
@@ -125,6 +119,14 @@
return idx($map, $type, pht('"%s" User', $type));
}
+ public function attachProviderConfig(PhabricatorAuthProviderConfig $config) {
+ $this->providerConfig = $config;
+ return $this;
+ }
+
+ public function getProviderConfig() {
+ return $this->assertAttached($this->providerConfig);
+ }
/* -( PhabricatorPolicyInterface )----------------------------------------- */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 23, 4:50 AM (13 h, 45 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7036107
Default Alt Text
D20112.id48021.diff (6 KB)
Attached To
Mode
D20112: Give ExternalAccount a providerConfigPHID, tying it to a particular provider
Attached
Detach File
Event Timeline
Log In to Comment