Differential D13626 Diff 33078 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 { | |||||
| public function handleRequest(AphrontRequest $request) { | |||||
| $viewer = $request->getViewer(); | |||||
| $id = $request->getURIData('id'); | |||||
| $badge = id(new PhabricatorBadgesQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withIDs(array($id)) | |||||
epriestley: Nuke / use `$request->getURIData()`. | |||||
| ->needRecipients(true) | |||||
| ->requireCapabilities( | |||||
| array( | |||||
Done Inline ActionshandleRequest() / getViewer() (see below) epriestley: handleRequest() / getViewer() (see below) | |||||
| 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(); | |||||
| $dialog = id(new AphrontDialogView()) | |||||
| ->setUser($viewer) | |||||
| ->setTitle(pht('Really Revoke Badge?')) | |||||
| ->appendParagraph( | |||||
| pht( | |||||
| 'Really revoke the badge "%s" from %s?', | |||||
Done Inline ActionsUnused. epriestley: Unused. | |||||
| phutil_tag('strong', array(), $badge->getName()), | |||||
| phutil_tag('strong', array(), $handle->getName()))) | |||||
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… | |||||
| ->addCancelButton($recipients_uri) | |||||
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… | |||||
| ->addSubmitButton(pht('Revoke Badge')); | |||||
| return $dialog; | |||||
| } | |||||
| } | |||||
Done Inline ActionsIn modern code, just return $dialog;. epriestley: In modern code, just `return $dialog;`. | |||||
Nuke / use $request->getURIData().