Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php
<?php | <?php | ||||
final class PhabricatorAuthSSHKeyTableView extends AphrontView { | final class PhabricatorAuthSSHKeyTableView extends AphrontView { | ||||
private $keys; | private $keys; | ||||
private $canEdit; | private $canEdit; | ||||
private $noDataString; | private $noDataString; | ||||
private $showTrusted; | private $showTrusted; | ||||
private $showID; | private $showID; | ||||
public static function newKeyActionsMenu( | |||||
PhabricatorUser $viewer, | |||||
PhabricatorSSHPublicKeyInterface $object) { | |||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | |||||
$viewer, | |||||
$object, | |||||
PhabricatorPolicyCapability::CAN_EDIT); | |||||
try { | |||||
PhabricatorSSHKeyGenerator::assertCanGenerateKeypair(); | |||||
$can_generate = true; | |||||
} catch (Exception $ex) { | |||||
$can_generate = false; | |||||
} | |||||
$object_phid = $object->getPHID(); | |||||
$generate_uri = "/auth/sshkey/generate/?objectPHID={$object_phid}"; | |||||
$upload_uri = "/auth/sshkey/upload/?objectPHID={$object_phid}"; | |||||
$view_uri = "/auth/sshkey/for/{$object_phid}/"; | |||||
$action_view = id(new PhabricatorActionListView()) | |||||
->setUser($viewer) | |||||
->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setHref($upload_uri) | |||||
->setWorkflow(true) | |||||
->setDisabled(!$can_edit) | |||||
->setName(pht('Upload Public Key')) | |||||
->setIcon('fa-upload')) | |||||
->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setHref($generate_uri) | |||||
->setWorkflow(true) | |||||
->setDisabled(!$can_edit || !$can_generate) | |||||
->setName(pht('Generate Keypair')) | |||||
->setIcon('fa-lock')) | |||||
->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setHref($view_uri) | |||||
->setName(pht('View History')) | |||||
->setIcon('fa-list-ul')); | |||||
return id(new PHUIButtonView()) | |||||
->setTag('a') | |||||
->setText(pht('SSH Key Actions')) | |||||
->setHref('#') | |||||
->setIcon('fa-gear') | |||||
->setDropdownMenu($action_view); | |||||
} | |||||
public function setNoDataString($no_data_string) { | public function setNoDataString($no_data_string) { | ||||
$this->noDataString = $no_data_string; | $this->noDataString = $no_data_string; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setCanEdit($can_edit) { | public function setCanEdit($can_edit) { | ||||
$this->canEdit = $can_edit; | $this->canEdit = $can_edit; | ||||
return $this; | return $this; | ||||
Show All 14 Lines | public function setKeys(array $keys) { | ||||
$this->keys = $keys; | $this->keys = $keys; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function render() { | public function render() { | ||||
$keys = $this->keys; | $keys = $this->keys; | ||||
$viewer = $this->getUser(); | $viewer = $this->getUser(); | ||||
if ($this->canEdit) { | |||||
$delete_class = 'small grey button'; | |||||
} else { | |||||
$delete_class = 'small grey button disabled'; | |||||
} | |||||
$trusted_icon = id(new PHUIIconView()) | $trusted_icon = id(new PHUIIconView()) | ||||
->setIcon('fa-star blue'); | ->setIcon('fa-star blue'); | ||||
$untrusted_icon = id(new PHUIIconView()) | $untrusted_icon = id(new PHUIIconView()) | ||||
->setIcon('fa-times grey'); | ->setIcon('fa-times grey'); | ||||
$rows = array(); | $rows = array(); | ||||
foreach ($keys as $key) { | foreach ($keys as $key) { | ||||
$rows[] = array( | $rows[] = array( | ||||
$key->getID(), | $key->getID(), | ||||
javelin_tag( | javelin_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => '/auth/sshkey/edit/'.$key->getID().'/', | 'href' => $key->getURI(), | ||||
'sigil' => 'workflow', | |||||
), | ), | ||||
$key->getName()), | $key->getName()), | ||||
$key->getIsTrusted() ? $trusted_icon : $untrusted_icon, | $key->getIsTrusted() ? $trusted_icon : $untrusted_icon, | ||||
$key->getKeyComment(), | $key->getKeyComment(), | ||||
$key->getKeyType(), | $key->getKeyType(), | ||||
phabricator_datetime($key->getDateCreated(), $viewer), | phabricator_datetime($key->getDateCreated(), $viewer), | ||||
javelin_tag( | |||||
'a', | |||||
array( | |||||
'href' => '/auth/sshkey/delete/'.$key->getID().'/', | |||||
'class' => $delete_class, | |||||
'sigil' => 'workflow', | |||||
), | |||||
pht('Delete')), | |||||
); | ); | ||||
} | } | ||||
$table = id(new AphrontTableView($rows)) | $table = id(new AphrontTableView($rows)) | ||||
->setNoDataString($this->noDataString) | ->setNoDataString($this->noDataString) | ||||
->setHeaders( | ->setHeaders( | ||||
array( | array( | ||||
pht('ID'), | pht('ID'), | ||||
pht('Name'), | pht('Name'), | ||||
pht('Trusted'), | pht('Trusted'), | ||||
pht('Comment'), | pht('Comment'), | ||||
pht('Type'), | pht('Type'), | ||||
pht('Added'), | pht('Added'), | ||||
null, | |||||
)) | )) | ||||
->setColumnVisibility( | ->setColumnVisibility( | ||||
array( | array( | ||||
$this->showID, | $this->showID, | ||||
true, | true, | ||||
$this->showTrusted, | $this->showTrusted, | ||||
)) | )) | ||||
->setColumnClasses( | ->setColumnClasses( | ||||
array( | array( | ||||
'', | '', | ||||
'wide pri', | 'wide pri', | ||||
'center', | 'center', | ||||
'', | '', | ||||
'', | '', | ||||
'right', | 'right', | ||||
'action', | |||||
)); | )); | ||||
return $table; | return $table; | ||||
} | } | ||||
} | } |