Files
phabricator/src/applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php
Chad Little b9a13e56e4 Update Badges for PHUITwoColumnView
Summary: Updates the layout to two column, moves "Add Receipients" to dialog. Ref T10318

Test Plan: Give badges, revoke badges.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T10318

Differential Revision: https://secure.phabricator.com/D15382
2016-03-02 11:17:04 -08:00

77 lines
2.2 KiB
PHP

<?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))
->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();
}
$view_uri = $this->getApplicationURI('view/'.$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($view_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?',
phutil_tag('strong', array(), $badge->getName()),
phutil_tag('strong', array(), $handle->getName())))
->addCancelButton($view_uri)
->addSubmitButton(pht('Revoke Badge'));
return $dialog;
}
}