Differential D20717 Diff 49434 src/applications/phortune/controller/account/PhortuneAccountAddManagerController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/account/PhortuneAccountAddManagerController.php
<?php | <?php | ||||
final class PhortuneAccountAddManagerController extends PhortuneController { | final class PhortuneAccountAddManagerController | ||||
extends PhortuneAccountController { | |||||
public function handleRequest(AphrontRequest $request) { | protected function shouldRequireAccountEditCapability() { | ||||
return true; | |||||
} | |||||
protected function handleAccountRequest(AphrontRequest $request) { | |||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$id = $request->getURIData('accountID'); | $account = $this->getAccount(); | ||||
$account = id(new PhortuneAccountQuery()) | $id = $account->getID(); | ||||
->setViewer($viewer) | |||||
->withIDs(array($id)) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
if (!$account) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$v_managers = array(); | $v_managers = array(); | ||||
$e_managers = null; | $e_managers = null; | ||||
$account_uri = $this->getApplicationURI("/account/{$id}/managers/"); | $account_uri = $this->getApplicationURI("/account/{$id}/managers/"); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$xactions = array(); | $xactions = array(); | ||||
$v_managers = $request->getArr('managerPHIDs'); | $v_managers = $request->getArr('managerPHIDs'); | ||||
Show All 19 Lines | if ($request->isFormPost()) { | ||||
return id(new AphrontRedirectResponse())->setURI($account_uri); | return id(new AphrontRedirectResponse())->setURI($account_uri); | ||||
} catch (PhabricatorApplicationTransactionValidationException $ex) { | } catch (PhabricatorApplicationTransactionValidationException $ex) { | ||||
$validation_exception = $ex; | $validation_exception = $ex; | ||||
$e_managers = $ex->getShortMessage($type_edge); | $e_managers = $ex->getShortMessage($type_edge); | ||||
} | } | ||||
} | } | ||||
$account_phid = $account->getPHID(); | |||||
$handles = $viewer->loadHandles(array($account_phid)); | |||||
$handle = $handles[$account_phid]; | |||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setViewer($viewer) | ||||
->appendInstructions( | |||||
pht( | |||||
'Choose one or more users to add as account managers. Managers '. | |||||
'have full control of the account.')) | |||||
->appendControl( | |||||
id(new AphrontFormStaticControl()) | |||||
->setLabel(pht('Payment Account')) | |||||
->setValue($handle->renderLink())) | |||||
->appendControl( | ->appendControl( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setDatasource(new PhabricatorPeopleDatasource()) | ->setDatasource(new PhabricatorPeopleDatasource()) | ||||
->setLabel(pht('Managers')) | ->setLabel(pht('Add Managers')) | ||||
->setName('managerPHIDs') | ->setName('managerPHIDs') | ||||
->setValue($v_managers) | ->setValue($v_managers) | ||||
->setError($e_managers)); | ->setError($e_managers)); | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle(pht('Add New Managers')) | ->setTitle(pht('Add New Managers')) | ||||
->appendForm($form) | ->appendForm($form) | ||||
->setWidth(AphrontDialogView::WIDTH_FORM) | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
->addCancelButton($account_uri) | ->addCancelButton($account_uri) | ||||
->addSubmitButton(pht('Add Managers')); | ->addSubmitButton(pht('Add Managers')); | ||||
} | } | ||||
} | } |