@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
1<?php
2
3final class PhabricatorAuthSSHKeyViewController
4 extends PhabricatorAuthSSHKeyController {
5
6 public function shouldAllowPublic() {
7 return true;
8 }
9
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12
13 $id = $request->getURIData('id');
14
15 $ssh_key = id(new PhabricatorAuthSSHKeyQuery())
16 ->setViewer($viewer)
17 ->withIDs(array($id))
18 ->executeOne();
19 if (!$ssh_key) {
20 return new Aphront404Response();
21 }
22
23 $this->setSSHKeyObject($ssh_key->getObject());
24
25 $title = pht('SSH Key %d', $ssh_key->getID());
26
27 $curtain = $this->buildCurtain($ssh_key);
28 $details = $this->buildPropertySection($ssh_key);
29
30 $header = id(new PHUIHeaderView())
31 ->setUser($viewer)
32 ->setHeader($ssh_key->getName())
33 ->setHeaderIcon('fa-key');
34
35 if ($ssh_key->getIsActive()) {
36 $header->setStatus('fa-check', 'bluegrey', pht('Active'));
37 } else {
38 $header->setStatus('fa-ban', 'dark', pht('Revoked'));
39 }
40
41 $header->addActionLink(
42 id(new PHUIButtonView())
43 ->setTag('a')
44 ->setText(pht('View Active Keys'))
45 ->setHref($ssh_key->getObject()->getSSHPublicKeyManagementURI($viewer))
46 ->setIcon('fa-list-ul'));
47
48 $crumbs = $this->buildApplicationCrumbs();
49 $crumbs->addTextCrumb($title);
50 $crumbs->setBorder(true);
51
52 $timeline = $this->buildTransactionTimeline(
53 $ssh_key,
54 new PhabricatorAuthSSHKeyTransactionQuery());
55 $timeline->setShouldTerminate(true);
56
57 $view = id(new PHUITwoColumnView())
58 ->setHeader($header)
59 ->setCurtain($curtain)
60 ->setMainColumn(
61 array(
62 $details,
63 $timeline,
64 ));
65
66 return $this->newPage()
67 ->setTitle($title)
68 ->setCrumbs($crumbs)
69 ->appendChild($view);
70 }
71
72 private function buildCurtain(PhabricatorAuthSSHKey $ssh_key) {
73 $viewer = $this->getViewer();
74
75 $can_edit = PhabricatorPolicyFilter::hasCapability(
76 $viewer,
77 $ssh_key,
78 PhabricatorPolicyCapability::CAN_EDIT);
79
80 $id = $ssh_key->getID();
81
82 $edit_uri = $this->getApplicationURI("sshkey/edit/{$id}/");
83 $revoke_uri = $this->getApplicationURI("sshkey/revoke/{$id}/");
84
85 $curtain = $this->newCurtainView($ssh_key);
86
87 $curtain->addAction(
88 id(new PhabricatorActionView())
89 ->setIcon('fa-pencil')
90 ->setName(pht('Edit SSH Key'))
91 ->setHref($edit_uri)
92 ->setWorkflow(true)
93 ->setDisabled(!$can_edit));
94
95 $curtain->addAction(
96 id(new PhabricatorActionView())
97 ->setIcon('fa-times')
98 ->setName(pht('Revoke SSH Key'))
99 ->setHref($revoke_uri)
100 ->setWorkflow(true)
101 ->setDisabled(!$can_edit));
102
103 return $curtain;
104 }
105
106 private function buildPropertySection(
107 PhabricatorAuthSSHKey $ssh_key) {
108 $viewer = $this->getViewer();
109
110 $properties = id(new PHUIPropertyListView())
111 ->setUser($viewer);
112
113 $properties->addProperty(pht('Public Key'), $ssh_key->getEntireKey());
114 $properties->addProperty(
115 pht('Created'),
116 phabricator_datetime($ssh_key->getDateCreated(), $viewer));
117
118 return id(new PHUIObjectBoxView())
119 ->setHeaderText(pht('Details'))
120 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
121 ->appendChild($properties);
122 }
123
124}