Migrate PhabricatorUserLDAPInfo to PhabricatorExternalAccount
Summary: Ref T1536. This is similar to D6172 but much simpler: we don't need to retain external interfaces here and can do a straight migration. Test Plan: TBA Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1536 Differential Revision: https://secure.phabricator.com/D6173
This commit is contained in:
@@ -34,11 +34,13 @@ final class PhabricatorLDAPLoginController extends PhabricatorAuthController {
|
||||
|
||||
if ($current_user->getPHID()) {
|
||||
if ($ldap_info->getID()) {
|
||||
$existing_ldap = id(new PhabricatorUserLDAPInfo())->loadOneWhere(
|
||||
'userID = %d',
|
||||
$current_user->getID());
|
||||
$existing_ldap = id(new PhabricatorExternalAccount())->loadOneWhere(
|
||||
'accountType = %s AND accountDomain = %s AND userPHID = %s',
|
||||
'ldap',
|
||||
'self',
|
||||
$current_user->getPHID());
|
||||
|
||||
if ($ldap_info->getUserID() != $current_user->getID() ||
|
||||
if ($ldap_info->getUserPHID() != $current_user->getPHID() ||
|
||||
$existing_ldap) {
|
||||
$dialog = new AphrontDialogView();
|
||||
$dialog->setUser($current_user);
|
||||
@@ -71,7 +73,7 @@ final class PhabricatorLDAPLoginController extends PhabricatorAuthController {
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
|
||||
$ldap_info->setUserID($current_user->getID());
|
||||
$ldap_info->setUserPHID($current_user->getPHID());
|
||||
|
||||
$this->saveLDAPInfo($ldap_info);
|
||||
|
||||
@@ -82,8 +84,9 @@ final class PhabricatorLDAPLoginController extends PhabricatorAuthController {
|
||||
if ($ldap_info->getID()) {
|
||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||
|
||||
$known_user = id(new PhabricatorUser())->load(
|
||||
$ldap_info->getUserID());
|
||||
$known_user = id(new PhabricatorUser())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$ldap_info->getUserPHID());
|
||||
|
||||
$session_key = $known_user->establishSession('web');
|
||||
|
||||
@@ -152,19 +155,23 @@ final class PhabricatorLDAPLoginController extends PhabricatorAuthController {
|
||||
}
|
||||
|
||||
private function retrieveLDAPInfo(PhabricatorLDAPProvider $provider) {
|
||||
$ldap_info = id(new PhabricatorUserLDAPInfo())->loadOneWhere(
|
||||
'ldapUsername = %s',
|
||||
$ldap_info = id(new PhabricatorExternalAccount())->loadOneWhere(
|
||||
'accountType = %s AND accountDomain = %s AND accountID = %s',
|
||||
'ldap',
|
||||
'self',
|
||||
$provider->retrieveUsername());
|
||||
|
||||
if (!$ldap_info) {
|
||||
$ldap_info = new PhabricatorUserLDAPInfo();
|
||||
$ldap_info->setLDAPUsername($provider->retrieveUsername());
|
||||
$ldap_info = id(new PhabricatorExternalAccount())
|
||||
->setAccountType('ldap')
|
||||
->setAccountDomain('self')
|
||||
->setAccountID($provider->retrieveUsername());
|
||||
}
|
||||
|
||||
return $ldap_info;
|
||||
}
|
||||
|
||||
private function saveLDAPInfo(PhabricatorUserLDAPInfo $info) {
|
||||
private function saveLDAPInfo(PhabricatorExternalAccount $info) {
|
||||
// UNGUARDED WRITES: Logging-in users don't have their CSRF set up yet.
|
||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||
$info->save();
|
||||
|
||||
Reference in New Issue
Block a user