Differential D15946 Diff 38400 src/applications/auth/controller/PhabricatorAuthSSHKeyDeactivateController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/PhabricatorAuthSSHKeyDeactivateController.php
- This file was moved from src/applications/auth/controller/PhabricatorAuthSSHKeyDeleteController.php.
<?php | <?php | ||||
final class PhabricatorAuthSSHKeyDeleteController | final class PhabricatorAuthSSHKeyDeactivateController | ||||
extends PhabricatorAuthSSHKeyController { | extends PhabricatorAuthSSHKeyController { | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$key = id(new PhabricatorAuthSSHKeyQuery()) | $key = id(new PhabricatorAuthSSHKeyQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($request->getURIData('id'))) | ->withIDs(array($request->getURIData('id'))) | ||||
->withIsActive(true) | |||||
->requireCapabilities( | ->requireCapabilities( | ||||
array( | array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
)) | )) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$key) { | if (!$key) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$cancel_uri = $key->getObject()->getSSHPublicKeyManagementURI($viewer); | $cancel_uri = $key->getURI(); | ||||
$token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( | $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( | ||||
$viewer, | $viewer, | ||||
$request, | $request, | ||||
$cancel_uri); | $cancel_uri); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
// TODO: Convert to transactions. | // TODO: Convert to transactions. | ||||
$key->setIsActive(null); | $key->setIsActive(null); | ||||
$key->save(); | $key->save(); | ||||
return id(new AphrontRedirectResponse())->setURI($cancel_uri); | return id(new AphrontRedirectResponse())->setURI($cancel_uri); | ||||
} | } | ||||
$name = phutil_tag('strong', array(), $key->getName()); | $name = phutil_tag('strong', array(), $key->getName()); | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle(pht('Really delete SSH Public Key?')) | ->setTitle(pht('Deactivate SSH Public Key')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'The key "%s" will be permanently deleted, and you will not longer '. | 'The key "%s" will be permanently deactivated, and you will no '. | ||||
'be able to use the corresponding private key to authenticate.', | 'longer be able to use the corresponding private key to '. | ||||
'authenticate.', | |||||
$name)) | $name)) | ||||
->addSubmitButton(pht('Delete Public Key')) | ->addSubmitButton(pht('Deactivate Public Key')) | ||||
->addCancelButton($cancel_uri); | ->addCancelButton($cancel_uri); | ||||
} | } | ||||
} | } |