1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-01 03:02:43 +01:00
phorge-phorge/src/applications/auth/query/PhabricatorAuthSSHKeySearchEngine.php
epriestley 08bea1d363 Add ViewController and SearchEngine for SSH Public Keys
Summary:
Ref T10917. This primarily prepares these for transactions by giving us a place to:

  - review old deactivated keys; and
  - review changes to keys.

Future changes will add transactions and a timeline so key changes are recorded exhaustively and can be more easily audited.

Test Plan:
{F1652089}

{F1652090}

{F1652091}

{F1652092}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10917

Differential Revision: https://secure.phabricator.com/D15946
2016-05-19 09:48:46 -07:00

105 lines
2.3 KiB
PHP

<?php
final class PhabricatorAuthSSHKeySearchEngine
extends PhabricatorApplicationSearchEngine {
private $sshKeyObject;
public function setSSHKeyObject(PhabricatorSSHPublicKeyInterface $object) {
$this->sshKeyObject = $object;
return $this;
}
public function getSSHKeyObject() {
return $this->sshKeyObject;
}
public function canUseInPanelContext() {
return false;
}
public function getResultTypeDescription() {
return pht('SSH Keys');
}
public function getApplicationClassName() {
return 'PhabricatorAuthApplication';
}
public function newQuery() {
$object = $this->getSSHKeyObject();
$object_phid = $object->getPHID();
return id(new PhabricatorAuthSSHKeyQuery())
->withObjectPHIDs(array($object_phid));
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
return $query;
}
protected function buildCustomSearchFields() {
return array();
}
protected function getURI($path) {
$object = $this->getSSHKeyObject();
$object_phid = $object->getPHID();
return "/auth/sshkey/for/{$object_phid}/{$path}";
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Keys'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $keys,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($keys, 'PhabricatorAuthSSHKey');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($keys as $key) {
$item = id(new PHUIObjectItemView())
->setObjectName(pht('SSH Key %d', $key->getID()))
->setHeader($key->getName())
->setHref($key->getURI());
if (!$key->getIsActive()) {
$item->setDisabled(true);
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No matching SSH keys.'));
return $result;
}
}