Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/controller/PhabricatorAuthSSHKeyController.php
12256 views
1
<?php
2
3
abstract class PhabricatorAuthSSHKeyController
4
extends PhabricatorAuthController {
5
6
private $keyObject;
7
8
public function setSSHKeyObject(PhabricatorSSHPublicKeyInterface $object) {
9
$this->keyObject = $object;
10
return $this;
11
}
12
13
public function getSSHKeyObject() {
14
return $this->keyObject;
15
}
16
17
protected function loadSSHKeyObject($object_phid, $need_edit) {
18
$viewer = $this->getViewer();
19
20
$query = id(new PhabricatorObjectQuery())
21
->setViewer($viewer)
22
->withPHIDs(array($object_phid));
23
24
if ($need_edit) {
25
$query->requireCapabilities(
26
array(
27
PhabricatorPolicyCapability::CAN_VIEW,
28
PhabricatorPolicyCapability::CAN_EDIT,
29
));
30
}
31
32
$object = $query->executeOne();
33
34
if (!$object) {
35
return null;
36
}
37
38
// If this kind of object can't have SSH keys, don't let the viewer
39
// add them.
40
if (!($object instanceof PhabricatorSSHPublicKeyInterface)) {
41
return null;
42
}
43
44
$this->keyObject = $object;
45
46
return $object;
47
}
48
49
protected function newKeyForObjectPHID($object_phid) {
50
$viewer = $this->getViewer();
51
52
$object = $this->loadSSHKeyObject($object_phid, true);
53
if (!$object) {
54
return null;
55
}
56
57
return PhabricatorAuthSSHKey::initializeNewSSHKey($viewer, $object);
58
}
59
60
protected function buildApplicationCrumbs() {
61
$crumbs = parent::buildApplicationCrumbs();
62
$viewer = $this->getViewer();
63
64
$key_object = $this->getSSHKeyObject();
65
if ($key_object) {
66
$object_phid = $key_object->getPHID();
67
$handles = $viewer->loadHandles(array($object_phid));
68
$handle = $handles[$object_phid];
69
70
$uri = $key_object->getSSHPublicKeyManagementURI($viewer);
71
72
$crumbs->addTextCrumb($handle->getObjectName(), $uri);
73
}
74
75
return $crumbs;
76
}
77
78
}
79
80