2014-10-17 14:02:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AlmanacDeviceViewController
|
|
|
|
extends AlmanacDeviceController {
|
|
|
|
|
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
|
|
|
|
$name = $request->getURIData('name');
|
|
|
|
|
|
|
|
$device = id(new AlmanacDeviceQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withNames(array($name))
|
|
|
|
->executeOne();
|
|
|
|
if (!$device) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = pht('Device %s', $device->getName());
|
|
|
|
|
|
|
|
$property_list = $this->buildPropertyList($device);
|
|
|
|
$action_list = $this->buildActionList($device);
|
|
|
|
$property_list->setActionList($action_list);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setHeader($device->getName())
|
|
|
|
->setPolicyObject($device);
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($property_list);
|
|
|
|
|
2014-10-17 14:04:24 +02:00
|
|
|
$interfaces = $this->buildInterfaceList($device);
|
|
|
|
|
2014-10-17 14:02:14 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addTextCrumb($device->getName());
|
|
|
|
|
Transactions - deploy buildTransactionTimeline against a few more applications
Summary:
Ref T4712. Thus far, it seems that most "non-standard" things can be done pretty easily in the controller. Aside from deploying, this diff had to fix a few bugs / missing implementations of stuff.
(Notably, PhabricatorAuthProviderConfig, HeraldRule, PhabricatorSlowvotePoll, and AlmanacNetwork needed to implement PhabricatorApplicationTransactionInterface, PhabricatorAuthAuthProviderPHIDType had to be added, and a rendering bug in transactions of type PhabricatorOAuth2AuthProvider had to be fixed.)
Test Plan: Almanac - looked at binding, device, network, and service view controllers and verified timeline displayed properly. Herald - looked at a rule and verified timeline. Slowvote - looked at a vote and verified timeline. Auth - looked at an auth provider (Facebook) and verified proper display of transactions within timeline.
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T4712
Differential Revision: https://secure.phabricator.com/D10921
2014-12-02 23:33:59 +01:00
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
|
|
$device,
|
|
|
|
new AlmanacDeviceTransactionQuery());
|
|
|
|
$timeline->setShouldTerminate(true);
|
2014-10-17 14:02:14 +02:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$box,
|
2014-10-17 14:04:24 +02:00
|
|
|
$interfaces,
|
2014-11-06 00:28:36 +01:00
|
|
|
$this->buildAlmanacPropertiesTable($device),
|
2014-11-11 17:20:08 +01:00
|
|
|
$this->buildSSHKeysTable($device),
|
Transactions - deploy buildTransactionTimeline against a few more applications
Summary:
Ref T4712. Thus far, it seems that most "non-standard" things can be done pretty easily in the controller. Aside from deploying, this diff had to fix a few bugs / missing implementations of stuff.
(Notably, PhabricatorAuthProviderConfig, HeraldRule, PhabricatorSlowvotePoll, and AlmanacNetwork needed to implement PhabricatorApplicationTransactionInterface, PhabricatorAuthAuthProviderPHIDType had to be added, and a rendering bug in transactions of type PhabricatorOAuth2AuthProvider had to be fixed.)
Test Plan: Almanac - looked at binding, device, network, and service view controllers and verified timeline displayed properly. Herald - looked at a rule and verified timeline. Slowvote - looked at a vote and verified timeline. Auth - looked at an auth provider (Facebook) and verified proper display of transactions within timeline.
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T4712
Differential Revision: https://secure.phabricator.com/D10921
2014-12-02 23:33:59 +01:00
|
|
|
$timeline,
|
2014-10-17 14:02:14 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyList(AlmanacDevice $device) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
2014-11-06 00:30:00 +01:00
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($device);
|
2014-10-17 14:02:14 +02:00
|
|
|
|
|
|
|
return $properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildActionList(AlmanacDevice $device) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $device->getID();
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$device,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('fa-pencil')
|
|
|
|
->setName(pht('Edit Device'))
|
|
|
|
->setHref($this->getApplicationURI("device/edit/{$id}/"))
|
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
->setDisabled(!$can_edit));
|
|
|
|
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
2014-10-17 14:04:24 +02:00
|
|
|
private function buildInterfaceList(AlmanacDevice $device) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $device->getID();
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$device,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$interfaces = id(new AlmanacInterfaceQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withDevicePHIDs(array($device->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
foreach ($interfaces as $interface) {
|
|
|
|
$phids[] = $interface->getNetworkPHID();
|
|
|
|
$phids[] = $interface->getDevicePHID();
|
|
|
|
}
|
|
|
|
$handles = $this->loadViewerHandles($phids);
|
|
|
|
|
|
|
|
$table = id(new AlmanacInterfaceTableView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setInterfaces($interfaces)
|
|
|
|
->setHandles($handles);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Device Interfaces'))
|
|
|
|
->addActionLink(
|
|
|
|
id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setHref($this->getApplicationURI("interface/edit/?deviceID={$id}"))
|
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setText(pht('Add Interface'))
|
|
|
|
->setIcon(
|
|
|
|
id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-plus')));
|
|
|
|
|
|
|
|
return id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->appendChild($table);
|
|
|
|
}
|
|
|
|
|
2014-11-11 17:20:08 +01:00
|
|
|
private function buildSSHKeysTable(AlmanacDevice $device) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $device->getID();
|
|
|
|
$device_phid = $device->getPHID();
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$device,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$keys = id(new PhabricatorAuthSSHKeyQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withObjectPHIDs(array($device_phid))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$table = id(new PhabricatorAuthSSHKeyTableView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setKeys($keys)
|
|
|
|
->setCanEdit($can_edit)
|
2014-11-21 02:33:30 +01:00
|
|
|
->setShowID(true)
|
|
|
|
->setShowTrusted(true)
|
2014-11-11 17:20:08 +01:00
|
|
|
->setNoDataString(pht('This device has no associated SSH public keys.'));
|
|
|
|
|
|
|
|
try {
|
|
|
|
PhabricatorSSHKeyGenerator::assertCanGenerateKeypair();
|
|
|
|
$can_generate = true;
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$can_generate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$generate_uri = '/auth/sshkey/generate/?objectPHID='.$device_phid;
|
|
|
|
$upload_uri = '/auth/sshkey/upload/?objectPHID='.$device_phid;
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('SSH Public Keys'))
|
|
|
|
->addActionLink(
|
|
|
|
id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setHref($generate_uri)
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setDisabled(!$can_edit || !$can_generate)
|
|
|
|
->setText(pht('Generate Keypair'))
|
|
|
|
->setIcon(
|
|
|
|
id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-lock')))
|
|
|
|
->addActionLink(
|
|
|
|
id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setHref($upload_uri)
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setText(pht('Upload Public Key'))
|
|
|
|
->setIcon(
|
|
|
|
id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-upload')));
|
|
|
|
|
|
|
|
return id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->appendChild($table);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-10-17 14:02:14 +02:00
|
|
|
}
|