Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / auth / view / PhabricatorAuthSSHKeyTableView.php
blob0452a14521755cc85ca13f084a4165b0cbafcdad
1 <?php
3 final class PhabricatorAuthSSHKeyTableView extends AphrontView {
5 private $keys;
6 private $canEdit;
7 private $noDataString;
8 private $showTrusted;
9 private $showID;
11 public static function newKeyActionsMenu(
12 PhabricatorUser $viewer,
13 PhabricatorSSHPublicKeyInterface $object) {
15 $can_edit = PhabricatorPolicyFilter::hasCapability(
16 $viewer,
17 $object,
18 PhabricatorPolicyCapability::CAN_EDIT);
20 try {
21 PhabricatorSSHKeyGenerator::assertCanGenerateKeypair();
22 $can_generate = true;
23 } catch (Exception $ex) {
24 $can_generate = false;
27 $object_phid = $object->getPHID();
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}/";
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'));
55 return id(new PHUIButtonView())
56 ->setTag('a')
57 ->setText(pht('SSH Key Actions'))
58 ->setHref('#')
59 ->setIcon('fa-gear')
60 ->setDropdownMenu($action_view);
63 public function setNoDataString($no_data_string) {
64 $this->noDataString = $no_data_string;
65 return $this;
68 public function setCanEdit($can_edit) {
69 $this->canEdit = $can_edit;
70 return $this;
73 public function setShowTrusted($show_trusted) {
74 $this->showTrusted = $show_trusted;
75 return $this;
78 public function setShowID($show_id) {
79 $this->showID = $show_id;
80 return $this;
83 public function setKeys(array $keys) {
84 assert_instances_of($keys, 'PhabricatorAuthSSHKey');
85 $this->keys = $keys;
86 return $this;
89 public function render() {
90 $keys = $this->keys;
91 $viewer = $this->getUser();
93 $trusted_icon = id(new PHUIIconView())
94 ->setIcon('fa-star blue');
95 $untrusted_icon = id(new PHUIIconView())
96 ->setIcon('fa-times grey');
98 $rows = array();
99 foreach ($keys as $key) {
100 $rows[] = array(
101 $key->getID(),
102 javelin_tag(
103 'a',
104 array(
105 'href' => $key->getURI(),
107 $key->getName()),
108 $key->getIsTrusted() ? $trusted_icon : $untrusted_icon,
109 $key->getKeyComment(),
110 $key->getKeyType(),
111 phabricator_datetime($key->getDateCreated(), $viewer),
115 $table = id(new AphrontTableView($rows))
116 ->setNoDataString($this->noDataString)
117 ->setHeaders(
118 array(
119 pht('ID'),
120 pht('Name'),
121 pht('Trusted'),
122 pht('Comment'),
123 pht('Type'),
124 pht('Added'),
126 ->setColumnVisibility(
127 array(
128 $this->showID,
129 true,
130 $this->showTrusted,
132 ->setColumnClasses(
133 array(
135 'wide pri',
136 'center',
139 'right',
142 return $table;