Differential D13626 Diff 32928 src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php
- This file was added.
<?php | |||||
final class PhabricatorBadgesRemoveRecipientsController | |||||
extends PhabricatorBadgesController { | |||||
private $id; | |||||
public function willProcessRequest(array $data) { | |||||
$this->id = $data['id']; | |||||
} | |||||
public function processRequest() { | |||||
epriestley: Nuke / use `$request->getURIData()`. | |||||
$request = $this->getRequest(); | |||||
$viewer = $request->getUser(); | |||||
Done Inline ActionshandleRequest() / getViewer() (see below) epriestley: handleRequest() / getViewer() (see below) | |||||
$badge = id(new PhabricatorBadgesQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($this->id)) | |||||
->needRecipients(true) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
if (!$badge) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$recipient_phids = $badge->getRecipientPHIDs(); | |||||
$remove_phid = $request->getStr('phid'); | |||||
if (!in_array($remove_phid, $recipient_phids)) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$recipients_uri = | |||||
$this->getApplicationURI('recipients/'.$badge->getID().'/'); | |||||
if ($request->isFormPost()) { | |||||
$recipient_spec = array(); | |||||
$recipient_spec['-'] = array($remove_phid => $remove_phid); | |||||
$type_recipient = PhabricatorBadgeHasRecipientEdgeType::EDGECONST; | |||||
$xactions = array(); | |||||
$xactions[] = id(new PhabricatorBadgesTransaction()) | |||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | |||||
->setMetadataValue('edge:type', $type_recipient) | |||||
->setNewValue($recipient_spec); | |||||
$editor = id(new PhabricatorBadgesEditor($badge)) | |||||
->setActor($viewer) | |||||
->setContentSourceFromRequest($request) | |||||
->setContinueOnNoEffect(true) | |||||
->setContinueOnMissingFields(true) | |||||
->applyTransactions($badge, $xactions); | |||||
return id(new AphrontRedirectResponse()) | |||||
->setURI($recipients_uri); | |||||
} | |||||
$handle = id(new PhabricatorHandleQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($remove_phid)) | |||||
->executeOne(); | |||||
Done Inline ActionsUnused. epriestley: Unused. | |||||
$dialog = id(new AphrontDialogView()) | |||||
->setUser($viewer) | |||||
Done Inline ActionsIn modern code, this can be simplified as $this->newDialog(), which automatically calls setUser() for you. epriestley: In modern code, this can be simplified as `$this->newDialog()`, which automatically calls… | |||||
Done Inline ActionsCan't see to get $this->newDialog() to work, crashes and I get: EXCEPTION: (PhabricatorFileStorageConfigurationException) Malformed local disk storage root. You must provide an absolute path, and can not use '/' as the root. at [<phabricator>/src/applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php:104] All other dialogs see fine. I'll look more into next upate. chad: Can't see to get `$this->newDialog()` to work, crashes and I get:
```EXCEPTION… | |||||
->setTitle(pht('Really Revoke Badge?')) | |||||
Done Inline ActionsI fixed this error, but the Dialog still won't submit for me with $this->newDialog(). Nothing now in the logs. chad: I fixed this error, but the Dialog still won't submit for me with `$this->newDialog()`. Nothing… | |||||
->appendParagraph( | |||||
pht( | |||||
'Really revoke the badge "%s" from %s?', | |||||
phutil_tag('strong', array(), $badge->getName()), | |||||
phutil_tag('strong', array(), $handle->getName()))) | |||||
->addCancelButton($recipients_uri) | |||||
->addSubmitButton(pht('Revoke Badge')); | |||||
return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
} | |||||
Done Inline ActionsIn modern code, just return $dialog;. epriestley: In modern code, just `return $dialog;`. | |||||
} |
Nuke / use $request->getURIData().