mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-04 04:32:43 +01:00
fa1ecb7f66
Summary: Ref T13043. Adds CLI support for revoking SSH keys. Also retargets UI language from "Deactivate" to "Revoke" to make it more clear that this is a one-way operation. This operation is already correctly implemented as a "Revoke" operation. Test Plan: Used `bin/auth revoke --type ssh` to revoke keys, verified they became revoked (with proper transactions) in the UI. Revoked keys from the web UI flow. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13043 Differential Revision: https://secure.phabricator.com/D18893
124 lines
3.2 KiB
PHP
124 lines
3.2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorAuthSSHKeyViewController
|
|
extends PhabricatorAuthSSHKeyController {
|
|
|
|
public function shouldAllowPublic() {
|
|
return true;
|
|
}
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
$ssh_key = id(new PhabricatorAuthSSHKeyQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($id))
|
|
->executeOne();
|
|
if (!$ssh_key) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$this->setSSHKeyObject($ssh_key->getObject());
|
|
|
|
$title = pht('SSH Key %d', $ssh_key->getID());
|
|
|
|
$curtain = $this->buildCurtain($ssh_key);
|
|
$details = $this->buildPropertySection($ssh_key);
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
->setUser($viewer)
|
|
->setHeader($ssh_key->getName())
|
|
->setHeaderIcon('fa-key');
|
|
|
|
if ($ssh_key->getIsActive()) {
|
|
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
|
|
} else {
|
|
$header->setStatus('fa-ban', 'dark', pht('Revoked'));
|
|
}
|
|
|
|
$header->addActionLink(
|
|
id(new PHUIButtonView())
|
|
->setTag('a')
|
|
->setText(pht('View Active Keys'))
|
|
->setHref($ssh_key->getObject()->getSSHPublicKeyManagementURI($viewer))
|
|
->setIcon('fa-list-ul'));
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
$crumbs->addTextCrumb($title);
|
|
$crumbs->setBorder(true);
|
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
$ssh_key,
|
|
new PhabricatorAuthSSHKeyTransactionQuery());
|
|
$timeline->setShouldTerminate(true);
|
|
|
|
$view = id(new PHUITwoColumnView())
|
|
->setHeader($header)
|
|
->setCurtain($curtain)
|
|
->setMainColumn(
|
|
array(
|
|
$details,
|
|
$timeline,
|
|
));
|
|
|
|
return $this->newPage()
|
|
->setTitle($title)
|
|
->setCrumbs($crumbs)
|
|
->appendChild($view);
|
|
}
|
|
|
|
private function buildCurtain(PhabricatorAuthSSHKey $ssh_key) {
|
|
$viewer = $this->getViewer();
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
$viewer,
|
|
$ssh_key,
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
$id = $ssh_key->getID();
|
|
|
|
$edit_uri = $this->getApplicationURI("sshkey/edit/{$id}/");
|
|
$revoke_uri = $this->getApplicationURI("sshkey/revoke/{$id}/");
|
|
|
|
$curtain = $this->newCurtainView($ssh_key);
|
|
|
|
$curtain->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setIcon('fa-pencil')
|
|
->setName(pht('Edit SSH Key'))
|
|
->setHref($edit_uri)
|
|
->setWorkflow(true)
|
|
->setDisabled(!$can_edit));
|
|
|
|
$curtain->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setIcon('fa-times')
|
|
->setName(pht('Revoke SSH Key'))
|
|
->setHref($revoke_uri)
|
|
->setWorkflow(true)
|
|
->setDisabled(!$can_edit));
|
|
|
|
return $curtain;
|
|
}
|
|
|
|
private function buildPropertySection(
|
|
PhabricatorAuthSSHKey $ssh_key) {
|
|
$viewer = $this->getViewer();
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
|
->setUser($viewer);
|
|
|
|
$properties->addProperty(pht('SSH Key Type'), $ssh_key->getKeyType());
|
|
$properties->addProperty(
|
|
pht('Created'),
|
|
phabricator_datetime($ssh_key->getDateCreated(), $viewer));
|
|
|
|
return id(new PHUIObjectBoxView())
|
|
->setHeaderText(pht('Details'))
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
|
->appendChild($properties);
|
|
}
|
|
|
|
}
|