Differential D15943 Diff 38392 src/applications/auth/controller/PhabricatorAuthSSHKeyDeleteController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/PhabricatorAuthSSHKeyDeleteController.php
| <?php | <?php | ||||
| final class PhabricatorAuthSSHKeyDeleteController | final class PhabricatorAuthSSHKeyDeleteController | ||||
| 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->getObject()->getSSHPublicKeyManagementURI($viewer); | ||||
| $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: It would be nice to write an edge transaction here or something. | |||||
| $key->delete(); | // TODO: Convert to transactions. | ||||
| $key->setIsActive(null); | |||||
| $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('Really delete SSH Public Key?')) | ||||
| ->appendParagraph( | ->appendParagraph( | ||||
| Show All 9 Lines | |||||