From 979187132d7b3d6750ba9e3b4b1bb7efbab501d7 Mon Sep 17 00:00:00 2001 From: Austin McKinley Date: Wed, 19 Dec 2018 11:31:02 -0800 Subject: [PATCH] Update accountadmin to use new admin empowerment code Summary: Fixes https://discourse.phabricator-community.org/t/admin-account-creation-fails-call-to-undefined-method-phabricatorusereditor-makeadminuser/2227. This callsite got skipped when updating the EmpowerController to use the new transactional admin approval code. Test Plan: Invoked `accountadmin` to promote a user, no longer got an exception. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D19915 --- scripts/user/account_admin.php | 21 ++++++++++++++++++- .../PhabricatorAuthRegisterController.php | 21 ++++++++++++++++++- .../PhabricatorUserEmpowerTransaction.php | 5 ++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/scripts/user/account_admin.php b/scripts/user/account_admin.php index 9e01896637..4ad722e125 100755 --- a/scripts/user/account_admin.php +++ b/scripts/user/account_admin.php @@ -200,9 +200,28 @@ $user->openTransaction(); $editor->updateUser($user, $verify_email); } - $editor->makeAdminUser($user, $set_admin); $editor->makeSystemAgentUser($user, $set_system_agent); + $xactions = array(); + $xactions[] = id(new PhabricatorUserTransaction()) + ->setTransactionType( + PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE) + ->setNewValue($set_admin); + + $actor = PhabricatorUser::getOmnipotentUser(); + $content_source = PhabricatorContentSource::newForSource( + PhabricatorConsoleContentSource::SOURCECONST); + + $people_application_phid = id(new PhabricatorPeopleApplication())->getPHID(); + + $transaction_editor = id(new PhabricatorUserTransactionEditor()) + ->setActor($actor) + ->setActingAsPHID($people_application_phid) + ->setContentSource($content_source) + ->setContinueOnMissingFields(true); + + $transaction_editor->applyTransactions($user, $xactions); + $user->saveTransaction(); echo pht('Saved changes.')."\n"; diff --git a/src/applications/auth/controller/PhabricatorAuthRegisterController.php b/src/applications/auth/controller/PhabricatorAuthRegisterController.php index 1138d52b33..9e1aef592c 100644 --- a/src/applications/auth/controller/PhabricatorAuthRegisterController.php +++ b/src/applications/auth/controller/PhabricatorAuthRegisterController.php @@ -416,7 +416,26 @@ final class PhabricatorAuthRegisterController } if ($is_setup) { - $editor->makeAdminUser($user, true); + $xactions = array(); + $xactions[] = id(new PhabricatorUserTransaction()) + ->setTransactionType( + PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE) + ->setNewValue(true); + + $actor = PhabricatorUser::getOmnipotentUser(); + $content_source = PhabricatorContentSource::newFromRequest( + $request); + + $people_application_phid = id(new PhabricatorPeopleApplication()) + ->getPHID(); + + $transaction_editor = id(new PhabricatorUserTransactionEditor()) + ->setActor($actor) + ->setActingAsPHID($people_application_phid) + ->setContentSource($content_source) + ->setContinueOnMissingFields(true); + + $transaction_editor->applyTransactions($user, $xactions); } $account->setUserPHID($user->getPHID()); diff --git a/src/applications/people/xaction/PhabricatorUserEmpowerTransaction.php b/src/applications/people/xaction/PhabricatorUserEmpowerTransaction.php index 12d6dc7523..1b561d3236 100644 --- a/src/applications/people/xaction/PhabricatorUserEmpowerTransaction.php +++ b/src/applications/people/xaction/PhabricatorUserEmpowerTransaction.php @@ -45,7 +45,10 @@ final class PhabricatorUserEmpowerTransaction 'status as an administrator.'), $xaction); } - if (!$actor->getIsAdmin()) { + $is_admin = $actor->getIsAdmin(); + $is_omnipotent = $actor->isOmnipotent(); + + if (!$is_admin && !$is_omnipotent) { $errors[] = $this->newInvalidError( pht('You must be an administrator to create administrators.'), $xaction);