forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorAuthSSHKeyController.php
78 lines (57 loc) · 1.78 KB
/
PhabricatorAuthSSHKeyController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
abstract class PhabricatorAuthSSHKeyController
extends PhabricatorAuthController {
private $keyObject;
public function setSSHKeyObject(PhabricatorSSHPublicKeyInterface $object) {
$this->keyObject = $object;
return $this;
}
public function getSSHKeyObject() {
return $this->keyObject;
}
protected function loadSSHKeyObject($object_phid, $need_edit) {
$viewer = $this->getViewer();
$query = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($object_phid));
if ($need_edit) {
$query->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
));
}
$object = $query->executeOne();
if (!$object) {
return null;
}
// If this kind of object can't have SSH keys, don't let the viewer
// add them.
if (!($object instanceof PhabricatorSSHPublicKeyInterface)) {
return null;
}
$this->keyObject = $object;
return $object;
}
protected function newKeyForObjectPHID($object_phid) {
$viewer = $this->getViewer();
$object = $this->loadSSHKeyObject($object_phid, true);
if (!$object) {
return null;
}
return PhabricatorAuthSSHKey::initializeNewSSHKey($viewer, $object);
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$viewer = $this->getViewer();
$key_object = $this->getSSHKeyObject();
if ($key_object) {
$object_phid = $key_object->getPHID();
$handles = $viewer->loadHandles(array($object_phid));
$handle = $handles[$object_phid];
$uri = $key_object->getSSHPublicKeyManagementURI($viewer);
$crumbs->addTextCrumb($handle->getObjectName(), $uri);
}
return $crumbs;
}
}