Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/passphrase/controller/PassphraseCredentialViewController.php
12256 views
1
<?php
2
3
final class PassphraseCredentialViewController extends PassphraseController {
4
5
public function handleRequest(AphrontRequest $request) {
6
$viewer = $request->getViewer();
7
$id = $request->getURIData('id');
8
9
$credential = id(new PassphraseCredentialQuery())
10
->setViewer($viewer)
11
->withIDs(array($id))
12
->executeOne();
13
if (!$credential) {
14
return new Aphront404Response();
15
}
16
17
$type = $credential->getImplementation();
18
19
$timeline = $this->buildTransactionTimeline(
20
$credential,
21
new PassphraseCredentialTransactionQuery());
22
$timeline->setShouldTerminate(true);
23
24
$title = pht('%s %s', $credential->getMonogram(), $credential->getName());
25
$crumbs = $this->buildApplicationCrumbs();
26
$crumbs->addTextCrumb($credential->getMonogram());
27
$crumbs->setBorder(true);
28
29
$header = $this->buildHeaderView($credential);
30
$curtain = $this->buildCurtain($credential, $type);
31
$subheader = $this->buildSubheaderView($credential);
32
$content = $this->buildPropertySectionView($credential, $type);
33
34
$view = id(new PHUITwoColumnView())
35
->setHeader($header)
36
->setSubheader($subheader)
37
->setCurtain($curtain)
38
->setMainColumn($timeline)
39
->addPropertySection(pht('Properties'), $content);
40
41
return $this->newPage()
42
->setTitle($title)
43
->setCrumbs($crumbs)
44
->appendChild($view);
45
}
46
47
private function buildHeaderView(PassphraseCredential $credential) {
48
$viewer = $this->getRequest()->getUser();
49
50
$header = id(new PHUIHeaderView())
51
->setUser($viewer)
52
->setHeader($credential->getName())
53
->setPolicyObject($credential)
54
->setHeaderIcon('fa-user-secret');
55
56
if ($credential->getIsDestroyed()) {
57
$header->setStatus('fa-ban', 'red', pht('Destroyed'));
58
}
59
60
return $header;
61
}
62
63
private function buildSubheaderView(
64
PassphraseCredential $credential) {
65
$viewer = $this->getViewer();
66
67
$author = $viewer->renderHandle($credential->getAuthorPHID())->render();
68
$date = phabricator_datetime($credential->getDateCreated(), $viewer);
69
$author = phutil_tag('strong', array(), $author);
70
71
$person = id(new PhabricatorPeopleQuery())
72
->setViewer($viewer)
73
->withPHIDs(array($credential->getAuthorPHID()))
74
->needProfileImage(true)
75
->executeOne();
76
77
if (!$person) {
78
return null;
79
}
80
81
$image_uri = $person->getProfileImageURI();
82
$image_href = '/p/'.$credential->getUsername();
83
84
$content = pht('Created by %s on %s.', $author, $date);
85
86
return id(new PHUIHeadThingView())
87
->setImage($image_uri)
88
->setImageHref($image_href)
89
->setContent($content);
90
}
91
92
private function buildCurtain(
93
PassphraseCredential $credential,
94
PassphraseCredentialType $type) {
95
$viewer = $this->getViewer();
96
97
$id = $credential->getID();
98
99
$is_locked = $credential->getIsLocked();
100
if ($is_locked) {
101
$credential_lock_text = pht('Locked Permanently');
102
$credential_lock_icon = 'fa-lock';
103
} else {
104
$credential_lock_text = pht('Lock Permanently');
105
$credential_lock_icon = 'fa-unlock';
106
}
107
108
$allow_conduit = $credential->getAllowConduit();
109
if ($allow_conduit) {
110
$credential_conduit_text = pht('Prevent Conduit Access');
111
$credential_conduit_icon = 'fa-ban';
112
} else {
113
$credential_conduit_text = pht('Allow Conduit Access');
114
$credential_conduit_icon = 'fa-wrench';
115
}
116
117
$can_edit = PhabricatorPolicyFilter::hasCapability(
118
$viewer,
119
$credential,
120
PhabricatorPolicyCapability::CAN_EDIT);
121
122
$can_conduit = ($can_edit && !$is_locked);
123
124
$curtain = $this->newCurtainView($credential);
125
126
$curtain->addAction(
127
id(new PhabricatorActionView())
128
->setName(pht('Edit Credential'))
129
->setIcon('fa-pencil')
130
->setHref($this->getApplicationURI("edit/{$id}/"))
131
->setDisabled(!$can_edit)
132
->setWorkflow(!$can_edit));
133
134
if (!$credential->getIsDestroyed()) {
135
$curtain->addAction(
136
id(new PhabricatorActionView())
137
->setName(pht('Destroy Credential'))
138
->setIcon('fa-times')
139
->setHref($this->getApplicationURI("destroy/{$id}/"))
140
->setDisabled(!$can_edit)
141
->setWorkflow(true));
142
143
$curtain->addAction(
144
id(new PhabricatorActionView())
145
->setName(pht('Show Secret'))
146
->setIcon('fa-eye')
147
->setHref($this->getApplicationURI("reveal/{$id}/"))
148
->setDisabled(!$can_edit || $is_locked)
149
->setWorkflow(true));
150
151
if ($type->hasPublicKey()) {
152
$curtain->addAction(
153
id(new PhabricatorActionView())
154
->setName(pht('Show Public Key'))
155
->setIcon('fa-download')
156
->setHref($this->getApplicationURI("public/{$id}/"))
157
->setWorkflow(true));
158
}
159
160
$curtain->addAction(
161
id(new PhabricatorActionView())
162
->setName($credential_conduit_text)
163
->setIcon($credential_conduit_icon)
164
->setHref($this->getApplicationURI("conduit/{$id}/"))
165
->setDisabled(!$can_conduit)
166
->setWorkflow(true));
167
168
$curtain->addAction(
169
id(new PhabricatorActionView())
170
->setName($credential_lock_text)
171
->setIcon($credential_lock_icon)
172
->setHref($this->getApplicationURI("lock/{$id}/"))
173
->setDisabled(!$can_edit || $is_locked)
174
->setWorkflow(true));
175
}
176
177
return $curtain;
178
}
179
180
private function buildPropertySectionView(
181
PassphraseCredential $credential,
182
PassphraseCredentialType $type) {
183
$viewer = $this->getRequest()->getUser();
184
185
$properties = id(new PHUIPropertyListView())
186
->setUser($viewer);
187
188
$properties->addProperty(
189
pht('Credential Type'),
190
$type->getCredentialTypeName());
191
192
if ($type->shouldRequireUsername()) {
193
$properties->addProperty(
194
pht('Username'),
195
$credential->getUsername());
196
}
197
198
$description = $credential->getDescription();
199
if (strlen($description)) {
200
$properties->addSectionHeader(
201
pht('Description'),
202
PHUIPropertyListView::ICON_SUMMARY);
203
$properties->addTextContent(
204
new PHUIRemarkupView($viewer, $description));
205
}
206
207
return $properties;
208
}
209
210
}
211
212