Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php
12256 views
1
<?php
2
3
final 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
public function setKeys(array $keys) {
84
assert_instances_of($keys, 'PhabricatorAuthSSHKey');
85
$this->keys = $keys;
86
return $this;
87
}
88
89
public function render() {
90
$keys = $this->keys;
91
$viewer = $this->getUser();
92
93
$trusted_icon = id(new PHUIIconView())
94
->setIcon('fa-star blue');
95
$untrusted_icon = id(new PHUIIconView())
96
->setIcon('fa-times grey');
97
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(),
106
),
107
$key->getName()),
108
$key->getIsTrusted() ? $trusted_icon : $untrusted_icon,
109
$key->getKeyComment(),
110
$key->getKeyType(),
111
phabricator_datetime($key->getDateCreated(), $viewer),
112
);
113
}
114
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'),
125
))
126
->setColumnVisibility(
127
array(
128
$this->showID,
129
true,
130
$this->showTrusted,
131
))
132
->setColumnClasses(
133
array(
134
'',
135
'wide pri',
136
'center',
137
'',
138
'',
139
'right',
140
));
141
142
return $table;
143
}
144
145
}
146
147