mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +01:00
Update a few things in Drydock for policies
Summary: DrydockResource has been updated to be policy-aware (although there are no policy columns). Test Plan: Clicked around in Drydock, viewed resources and leases, everything still seemed to work. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley CC: Korvin, epriestley, aran Maniphest Tasks: T3605, T4111 Differential Revision: https://secure.phabricator.com/D7595
This commit is contained in:
parent
bf2f599abb
commit
d571507651
4 changed files with 66 additions and 7 deletions
|
@ -2970,10 +2970,14 @@ phutil_register_library_map(array(
|
||||||
'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow',
|
'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow',
|
||||||
'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow',
|
'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow',
|
||||||
'DrydockPreallocatedHostBlueprint' => 'DrydockBlueprint',
|
'DrydockPreallocatedHostBlueprint' => 'DrydockBlueprint',
|
||||||
'DrydockResource' => 'DrydockDAO',
|
'DrydockResource' =>
|
||||||
|
array(
|
||||||
|
0 => 'DrydockDAO',
|
||||||
|
1 => 'PhabricatorPolicyInterface',
|
||||||
|
),
|
||||||
'DrydockResourceCloseController' => 'DrydockController',
|
'DrydockResourceCloseController' => 'DrydockController',
|
||||||
'DrydockResourceListController' => 'DrydockController',
|
'DrydockResourceListController' => 'DrydockController',
|
||||||
'DrydockResourceQuery' => 'PhabricatorOffsetPagedQuery',
|
'DrydockResourceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'DrydockResourceStatus' => 'DrydockConstants',
|
'DrydockResourceStatus' => 'DrydockConstants',
|
||||||
'DrydockResourceViewController' => 'DrydockController',
|
'DrydockResourceViewController' => 'DrydockController',
|
||||||
'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
|
'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
|
||||||
|
|
|
@ -14,6 +14,7 @@ final class DrydockResourceListController extends DrydockController {
|
||||||
$pager = new AphrontPagerView();
|
$pager = new AphrontPagerView();
|
||||||
$pager->setURI(new PhutilURI('/drydock/resource/'), 'offset');
|
$pager->setURI(new PhutilURI('/drydock/resource/'), 'offset');
|
||||||
$resources = id(new DrydockResourceQuery())
|
$resources = id(new DrydockResourceQuery())
|
||||||
|
->setViewer($user)
|
||||||
->executeWithOffsetPager($pager);
|
->executeWithOffsetPager($pager);
|
||||||
|
|
||||||
$resource_list = $this->buildResourceListView($resources);
|
$resource_list = $this->buildResourceListView($resources);
|
||||||
|
|
|
@ -1,15 +1,28 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class DrydockResourceQuery extends PhabricatorOffsetPagedQuery {
|
final class DrydockResourceQuery
|
||||||
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
private $ids;
|
private $ids;
|
||||||
|
private $statuses;
|
||||||
|
private $types;
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function withTypes(array $types) {
|
||||||
|
$this->types = $types;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withStatuses(array $statuses) {
|
||||||
|
$this->statuses = $statuses;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadPage() {
|
||||||
$table = new DrydockResource();
|
$table = new DrydockResource();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
|
@ -36,11 +49,27 @@ final class DrydockResourceQuery extends PhabricatorOffsetPagedQuery {
|
||||||
$this->ids);
|
$this->ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->types) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'type IN (%Ls)',
|
||||||
|
$this->types);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->statuses) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'status IN (%Ls)',
|
||||||
|
$this->statuses);
|
||||||
|
}
|
||||||
|
|
||||||
|
$where[] = $this->buildPagingClause($conn_r);
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
return $this->formatWhereClause($where);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildOrderClause(AphrontDatabaseConnection $conn_r) {
|
public function getQueryApplicationClass() {
|
||||||
return qsprintf($conn_r, 'ORDER BY id DESC');
|
return 'PhabricatorApplicationDrydock';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class DrydockResource extends DrydockDAO {
|
final class DrydockResource extends DrydockDAO
|
||||||
|
implements PhabricatorPolicyInterface {
|
||||||
|
|
||||||
protected $id;
|
protected $id;
|
||||||
protected $phid;
|
protected $phid;
|
||||||
|
@ -84,4 +85,28 @@ final class DrydockResource extends DrydockDAO {
|
||||||
$this->saveTransaction();
|
$this->saveTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
public function getCapabilities() {
|
||||||
|
return array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPolicy($capability) {
|
||||||
|
switch ($capability) {
|
||||||
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||||
|
return PhabricatorPolicies::getMostOpenPolicy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function describeAutomaticCapability($capability) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue