Differential D16178 Diff 38921 src/applications/tokens/controller/PhabricatorTokenArchiveController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/tokens/controller/PhabricatorTokenArchiveController.php
- This file was added.
<?php | |||||
final class PhabricatorTokenArchiveController | |||||
extends PhabricatorTokenController { | |||||
public function handleRequest(AphrontRequest $request) { | |||||
$viewer = $request->getViewer(); | |||||
$id = $request->getURIData('id'); | |||||
$token = id(new PhabricatorTokenQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($id)) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
if (!$token) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$view_uri = $this->getApplicationURI('view/'.$token->getID().'/'); | |||||
if ($request->isFormPost()) { | |||||
if ($token->isArchived()) { | |||||
$new_status = PhabricatorTokensToken::STATUS_ACTIVE; | |||||
} else { | |||||
$new_status = PhabricatorTokensToken::STATUS_ARCHIVED; | |||||
} | |||||
$xactions = array(); | |||||
$xactions[] = id(new PhabricatorTokensTransaction()) | |||||
->setTransactionType(PhabricatorTokensTransaction::TYPE_STATUS) | |||||
->setNewValue($new_status); | |||||
id(new PhabricatorTokenEditor()) | |||||
->setActor($viewer) | |||||
->setContentSourceFromRequest($request) | |||||
->setContinueOnNoEffect(true) | |||||
->setContinueOnMissingFields(true) | |||||
->applyTransactions($token, $xactions); | |||||
return id(new AphrontRedirectResponse())->setURI($view_uri); | |||||
} | |||||
if ($token->isArchived()) { | |||||
$title = pht('Activate Token'); | |||||
$body = pht('This token will immediately be available for '. | |||||
'general tomfoolery.'); | |||||
$button = pht('Activate Token'); | |||||
} else { | |||||
$title = pht('Archive Token'); | |||||
$body = pht( | |||||
'Really? You want to just "get rid" of this token? Kinda harsh.'); | |||||
$button = pht('Archive Token'); | |||||
} | |||||
return $this->newDialog() | |||||
->setTitle($title) | |||||
->appendChild($body) | |||||
->addCancelButton($view_uri) | |||||
->addSubmitButton($button); | |||||
} | |||||
} |