2014-04-02 12:05:49 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorPeopleEmpowerController
|
|
|
|
extends PhabricatorPeopleController {
|
|
|
|
|
2016-01-24 07:07:17 -08:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2014-04-02 12:05:49 -07:00
|
|
|
|
|
|
|
$user = id(new PhabricatorPeopleQuery())
|
2016-01-24 07:07:17 -08:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
2014-04-02 12:05:49 -07:00
|
|
|
->executeOne();
|
|
|
|
if (!$user) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-01-24 07:07:17 -08:00
|
|
|
$done_uri = $this->getApplicationURI("manage/{$id}/");
|
2014-04-02 12:05:49 -07:00
|
|
|
|
2014-04-30 17:44:59 -07:00
|
|
|
id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
|
2016-01-24 07:07:17 -08:00
|
|
|
$viewer,
|
2014-04-30 17:44:59 -07:00
|
|
|
$request,
|
2016-01-24 07:07:17 -08:00
|
|
|
$done_uri);
|
2014-04-30 17:44:59 -07:00
|
|
|
|
2016-01-24 07:07:17 -08:00
|
|
|
if ($user->getPHID() == $viewer->getPHID()) {
|
2014-04-02 12:05:49 -07:00
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Your Way is Blocked'))
|
|
|
|
->appendParagraph(
|
|
|
|
pht(
|
|
|
|
'After a time, your efforts fail. You can not adjust your own '.
|
|
|
|
'status as an administrator.'))
|
2016-01-24 07:07:17 -08:00
|
|
|
->addCancelButton($done_uri, pht('Accept Fate'));
|
2014-04-02 12:05:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
id(new PhabricatorUserEditor())
|
2016-01-24 07:07:17 -08:00
|
|
|
->setActor($viewer)
|
2014-04-02 12:05:49 -07:00
|
|
|
->makeAdminUser($user, !$user->getIsAdmin());
|
|
|
|
|
2016-01-24 07:07:17 -08:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($done_uri);
|
2014-04-02 12:05:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($user->getIsAdmin()) {
|
|
|
|
$title = pht('Remove as Administrator?');
|
|
|
|
$short = pht('Remove Administrator');
|
|
|
|
$body = pht(
|
|
|
|
'Remove %s as an administrator? They will no longer be able to '.
|
|
|
|
'perform administrative functions on this Phabricator install.',
|
|
|
|
phutil_tag('strong', array(), $user->getUsername()));
|
|
|
|
$submit = pht('Remove Administrator');
|
|
|
|
} else {
|
|
|
|
$title = pht('Make Administrator?');
|
|
|
|
$short = pht('Make Administrator');
|
|
|
|
$body = pht(
|
2014-12-19 09:48:55 -08:00
|
|
|
'Empower %s as an administrator? They will be able to create users, '.
|
2014-04-02 12:05:49 -07:00
|
|
|
'approve users, make and remove administrators, delete accounts, and '.
|
|
|
|
'perform other administrative functions on this Phabricator install.',
|
|
|
|
phutil_tag('strong', array(), $user->getUsername()));
|
|
|
|
$submit = pht('Make Administrator');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle($title)
|
|
|
|
->setShortTitle($short)
|
|
|
|
->appendParagraph($body)
|
2016-01-24 07:07:17 -08:00
|
|
|
->addCancelButton($done_uri)
|
2014-04-02 12:05:49 -07:00
|
|
|
->addSubmitButton($submit);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|