@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 148 lines 3.7 kB view raw
1<?php 2 3final class PhabricatorAuthSSHKeyTableView extends AphrontView { 4 5 private $keys; 6 private $canEdit; 7 private $noDataString; 8 private $showTrusted; 9 private $showID; 10 11 public static function newKeyActionsMenu( 12 PhabricatorUser $viewer, 13 PhabricatorSSHPublicKeyInterface $object) { 14 15 $can_edit = PhabricatorPolicyFilter::hasCapability( 16 $viewer, 17 $object, 18 PhabricatorPolicyCapability::CAN_EDIT); 19 20 try { 21 PhabricatorSSHKeyGenerator::assertCanGenerateKeypair(); 22 $can_generate = true; 23 } catch (Exception $ex) { 24 $can_generate = false; 25 } 26 27 $object_phid = $object->getPHID(); 28 29 $generate_uri = "/auth/sshkey/generate/?objectPHID={$object_phid}"; 30 $upload_uri = "/auth/sshkey/upload/?objectPHID={$object_phid}"; 31 $view_uri = "/auth/sshkey/for/{$object_phid}/"; 32 33 $action_view = id(new PhabricatorActionListView()) 34 ->setUser($viewer) 35 ->addAction( 36 id(new PhabricatorActionView()) 37 ->setHref($upload_uri) 38 ->setWorkflow(true) 39 ->setDisabled(!$can_edit) 40 ->setName(pht('Upload Public Key')) 41 ->setIcon('fa-upload')) 42 ->addAction( 43 id(new PhabricatorActionView()) 44 ->setHref($generate_uri) 45 ->setWorkflow(true) 46 ->setDisabled(!$can_edit || !$can_generate) 47 ->setName(pht('Generate Keypair')) 48 ->setIcon('fa-lock')) 49 ->addAction( 50 id(new PhabricatorActionView()) 51 ->setHref($view_uri) 52 ->setName(pht('View History')) 53 ->setIcon('fa-list-ul')); 54 55 return id(new PHUIButtonView()) 56 ->setTag('a') 57 ->setText(pht('SSH Key Actions')) 58 ->setHref('#') 59 ->setIcon('fa-gear') 60 ->setDropdownMenu($action_view); 61 } 62 63 public function setNoDataString($no_data_string) { 64 $this->noDataString = $no_data_string; 65 return $this; 66 } 67 68 public function setCanEdit($can_edit) { 69 $this->canEdit = $can_edit; 70 return $this; 71 } 72 73 public function setShowTrusted($show_trusted) { 74 $this->showTrusted = $show_trusted; 75 return $this; 76 } 77 78 public function setShowID($show_id) { 79 $this->showID = $show_id; 80 return $this; 81 } 82 83 /** 84 * @param array<PhabricatorAuthSSHKey> $keys 85 */ 86 public function setKeys(array $keys) { 87 assert_instances_of($keys, PhabricatorAuthSSHKey::class); 88 $this->keys = $keys; 89 return $this; 90 } 91 92 public function render() { 93 $keys = $this->keys; 94 $viewer = $this->getUser(); 95 96 $trusted_icon = id(new PHUIIconView()) 97 ->setIcon('fa-star blue'); 98 $untrusted_icon = id(new PHUIIconView()) 99 ->setIcon('fa-times grey'); 100 101 $rows = array(); 102 foreach ($keys as $key) { 103 $rows[] = array( 104 $key->getID(), 105 javelin_tag( 106 'a', 107 array( 108 'href' => $key->getURI(), 109 ), 110 $key->getName()), 111 $key->getIsTrusted() ? $trusted_icon : $untrusted_icon, 112 $key->getKeyComment(), 113 $key->getKeyType(), 114 phabricator_datetime($key->getDateCreated(), $viewer), 115 ); 116 } 117 118 $table = id(new AphrontTableView($rows)) 119 ->setNoDataString($this->noDataString) 120 ->setHeaders( 121 array( 122 pht('ID'), 123 pht('Name'), 124 pht('Trusted'), 125 pht('Comment'), 126 pht('Type'), 127 pht('Added'), 128 )) 129 ->setColumnVisibility( 130 array( 131 $this->showID, 132 true, 133 $this->showTrusted, 134 )) 135 ->setColumnClasses( 136 array( 137 '', 138 'wide pri', 139 'center', 140 '', 141 '', 142 'right', 143 )); 144 145 return $table; 146 } 147 148}