Path: blob/master/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php
12256 views
<?php12final class PhabricatorAuthSSHKeyTableView extends AphrontView {34private $keys;5private $canEdit;6private $noDataString;7private $showTrusted;8private $showID;910public static function newKeyActionsMenu(11PhabricatorUser $viewer,12PhabricatorSSHPublicKeyInterface $object) {1314$can_edit = PhabricatorPolicyFilter::hasCapability(15$viewer,16$object,17PhabricatorPolicyCapability::CAN_EDIT);1819try {20PhabricatorSSHKeyGenerator::assertCanGenerateKeypair();21$can_generate = true;22} catch (Exception $ex) {23$can_generate = false;24}2526$object_phid = $object->getPHID();2728$generate_uri = "/auth/sshkey/generate/?objectPHID={$object_phid}";29$upload_uri = "/auth/sshkey/upload/?objectPHID={$object_phid}";30$view_uri = "/auth/sshkey/for/{$object_phid}/";3132$action_view = id(new PhabricatorActionListView())33->setUser($viewer)34->addAction(35id(new PhabricatorActionView())36->setHref($upload_uri)37->setWorkflow(true)38->setDisabled(!$can_edit)39->setName(pht('Upload Public Key'))40->setIcon('fa-upload'))41->addAction(42id(new PhabricatorActionView())43->setHref($generate_uri)44->setWorkflow(true)45->setDisabled(!$can_edit || !$can_generate)46->setName(pht('Generate Keypair'))47->setIcon('fa-lock'))48->addAction(49id(new PhabricatorActionView())50->setHref($view_uri)51->setName(pht('View History'))52->setIcon('fa-list-ul'));5354return id(new PHUIButtonView())55->setTag('a')56->setText(pht('SSH Key Actions'))57->setHref('#')58->setIcon('fa-gear')59->setDropdownMenu($action_view);60}6162public function setNoDataString($no_data_string) {63$this->noDataString = $no_data_string;64return $this;65}6667public function setCanEdit($can_edit) {68$this->canEdit = $can_edit;69return $this;70}7172public function setShowTrusted($show_trusted) {73$this->showTrusted = $show_trusted;74return $this;75}7677public function setShowID($show_id) {78$this->showID = $show_id;79return $this;80}8182public function setKeys(array $keys) {83assert_instances_of($keys, 'PhabricatorAuthSSHKey');84$this->keys = $keys;85return $this;86}8788public function render() {89$keys = $this->keys;90$viewer = $this->getUser();9192$trusted_icon = id(new PHUIIconView())93->setIcon('fa-star blue');94$untrusted_icon = id(new PHUIIconView())95->setIcon('fa-times grey');9697$rows = array();98foreach ($keys as $key) {99$rows[] = array(100$key->getID(),101javelin_tag(102'a',103array(104'href' => $key->getURI(),105),106$key->getName()),107$key->getIsTrusted() ? $trusted_icon : $untrusted_icon,108$key->getKeyComment(),109$key->getKeyType(),110phabricator_datetime($key->getDateCreated(), $viewer),111);112}113114$table = id(new AphrontTableView($rows))115->setNoDataString($this->noDataString)116->setHeaders(117array(118pht('ID'),119pht('Name'),120pht('Trusted'),121pht('Comment'),122pht('Type'),123pht('Added'),124))125->setColumnVisibility(126array(127$this->showID,128true,129$this->showTrusted,130))131->setColumnClasses(132array(133'',134'wide pri',135'center',136'',137'',138'right',139));140141return $table;142}143144}145146147