Skip to content

Commit 9791871

Browse files
committedDec 19, 2018
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
1 parent aa3b2ec commit 9791871

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed
 

‎scripts/user/account_admin.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,28 @@
200200
$editor->updateUser($user, $verify_email);
201201
}
202202

203-
$editor->makeAdminUser($user, $set_admin);
204203
$editor->makeSystemAgentUser($user, $set_system_agent);
205204

205+
$xactions = array();
206+
$xactions[] = id(new PhabricatorUserTransaction())
207+
->setTransactionType(
208+
PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE)
209+
->setNewValue($set_admin);
210+
211+
$actor = PhabricatorUser::getOmnipotentUser();
212+
$content_source = PhabricatorContentSource::newForSource(
213+
PhabricatorConsoleContentSource::SOURCECONST);
214+
215+
$people_application_phid = id(new PhabricatorPeopleApplication())->getPHID();
216+
217+
$transaction_editor = id(new PhabricatorUserTransactionEditor())
218+
->setActor($actor)
219+
->setActingAsPHID($people_application_phid)
220+
->setContentSource($content_source)
221+
->setContinueOnMissingFields(true);
222+
223+
$transaction_editor->applyTransactions($user, $xactions);
224+
206225
$user->saveTransaction();
207226

208227
echo pht('Saved changes.')."\n";

‎src/applications/auth/controller/PhabricatorAuthRegisterController.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,26 @@ public function handleRequest(AphrontRequest $request) {
416416
}
417417

418418
if ($is_setup) {
419-
$editor->makeAdminUser($user, true);
419+
$xactions = array();
420+
$xactions[] = id(new PhabricatorUserTransaction())
421+
->setTransactionType(
422+
PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE)
423+
->setNewValue(true);
424+
425+
$actor = PhabricatorUser::getOmnipotentUser();
426+
$content_source = PhabricatorContentSource::newFromRequest(
427+
$request);
428+
429+
$people_application_phid = id(new PhabricatorPeopleApplication())
430+
->getPHID();
431+
432+
$transaction_editor = id(new PhabricatorUserTransactionEditor())
433+
->setActor($actor)
434+
->setActingAsPHID($people_application_phid)
435+
->setContentSource($content_source)
436+
->setContinueOnMissingFields(true);
437+
438+
$transaction_editor->applyTransactions($user, $xactions);
420439
}
421440

422441
$account->setUserPHID($user->getPHID());

‎src/applications/people/xaction/PhabricatorUserEmpowerTransaction.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public function validateTransactions($object, array $xactions) {
4545
'status as an administrator.'), $xaction);
4646
}
4747

48-
if (!$actor->getIsAdmin()) {
48+
$is_admin = $actor->getIsAdmin();
49+
$is_omnipotent = $actor->isOmnipotent();
50+
51+
if (!$is_admin && !$is_omnipotent) {
4952
$errors[] = $this->newInvalidError(
5053
pht('You must be an administrator to create administrators.'),
5154
$xaction);

0 commit comments

Comments
 (0)
Failed to load comments.