mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 00:02:41 +01:00
9b0fa5747b
Summary: Ref T2015. Moves a bunch of raw object loads into modern policy-aware queries. Also straightens out the Log and Lease policies a little bit: there are legitimate states where these objects are not attached to a resource (particularly, while a lease is being acquired). Handle these more gracefully. Test Plan: Lint / browsed stuff. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7836
138 lines
3.4 KiB
PHP
138 lines
3.4 KiB
PHP
<?php
|
|
|
|
final class DrydockLeaseViewController extends DrydockLeaseController {
|
|
|
|
private $id;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->id = $data['id'];
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$viewer = $request->getUser();
|
|
|
|
$lease = id(new DrydockLeaseQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($this->id))
|
|
->executeOne();
|
|
if (!$lease) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$lease_uri = $this->getApplicationURI('lease/'.$lease->getID().'/');
|
|
|
|
$title = pht('Lease %d', $lease->getID());
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
->setHeader($title);
|
|
|
|
$actions = $this->buildActionListView($lease);
|
|
$properties = $this->buildPropertyListView($lease, $actions);
|
|
|
|
$pager = new AphrontPagerView();
|
|
$pager->setURI(new PhutilURI($lease_uri), 'offset');
|
|
$pager->setOffset($request->getInt('offset'));
|
|
|
|
$logs = id(new DrydockLogQuery())
|
|
->setViewer($viewer)
|
|
->withLeaseIDs(array($lease->getID()))
|
|
->executeWithOffsetPager($pager);
|
|
|
|
$log_table = $this->buildLogTableView($logs);
|
|
$log_table->appendChild($pager);
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
$crumbs->setActionList($actions);
|
|
$crumbs->addTextCrumb($title, $lease_uri);
|
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
->setHeader($header)
|
|
->addPropertyList($properties);
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$crumbs,
|
|
$object_box,
|
|
$log_table,
|
|
),
|
|
array(
|
|
'device' => true,
|
|
'title' => $title,
|
|
));
|
|
|
|
}
|
|
|
|
private function buildActionListView(DrydockLease $lease) {
|
|
$view = id(new PhabricatorActionListView())
|
|
->setUser($this->getRequest()->getUser())
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
|
->setObject($lease);
|
|
|
|
$id = $lease->getID();
|
|
|
|
$can_release = ($lease->getStatus() == DrydockLeaseStatus::STATUS_ACTIVE);
|
|
|
|
$view->addAction(
|
|
id(new PhabricatorActionView())
|
|
->setName(pht('Release Lease'))
|
|
->setIcon('delete')
|
|
->setHref($this->getApplicationURI("/lease/{$id}/release/"))
|
|
->setWorkflow(true)
|
|
->setDisabled(!$can_release));
|
|
|
|
return $view;
|
|
}
|
|
|
|
private function buildPropertyListView(
|
|
DrydockLease $lease,
|
|
PhabricatorActionListView $actions) {
|
|
|
|
$view = new PHUIPropertyListView();
|
|
$view->setActionList($actions);
|
|
|
|
switch ($lease->getStatus()) {
|
|
case DrydockLeaseStatus::STATUS_ACTIVE:
|
|
$status = pht('Active');
|
|
break;
|
|
case DrydockLeaseStatus::STATUS_RELEASED:
|
|
$status = pht('Released');
|
|
break;
|
|
case DrydockLeaseStatus::STATUS_EXPIRED:
|
|
$status = pht('Expired');
|
|
break;
|
|
case DrydockLeaseStatus::STATUS_PENDING:
|
|
$status = pht('Pending');
|
|
break;
|
|
case DrydockLeaseStatus::STATUS_BROKEN:
|
|
$status = pht('Broken');
|
|
break;
|
|
default:
|
|
$status = pht('Unknown');
|
|
break;
|
|
}
|
|
|
|
$view->addProperty(
|
|
pht('Status'),
|
|
$status);
|
|
|
|
$view->addProperty(
|
|
pht('Resource Type'),
|
|
$lease->getResourceType());
|
|
|
|
$view->addProperty(
|
|
pht('Resource'),
|
|
$lease->getResourceID());
|
|
|
|
$attributes = $lease->getAttributes();
|
|
if ($attributes) {
|
|
$view->addSectionHeader(pht('Attributes'));
|
|
foreach ($attributes as $key => $value) {
|
|
$view->addProperty($key, $value);
|
|
}
|
|
}
|
|
|
|
return $view;
|
|
}
|
|
|
|
}
|