diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 5083867f8f..5dddf8cc9a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2970,10 +2970,14 @@ phutil_register_library_map(array( 'DrydockManagementWaitForLeaseWorkflow' => 'DrydockManagementWorkflow', 'DrydockManagementWorkflow' => 'PhutilArgumentWorkflow', 'DrydockPreallocatedHostBlueprint' => 'DrydockBlueprint', - 'DrydockResource' => 'DrydockDAO', + 'DrydockResource' => + array( + 0 => 'DrydockDAO', + 1 => 'PhabricatorPolicyInterface', + ), 'DrydockResourceCloseController' => 'DrydockController', 'DrydockResourceListController' => 'DrydockController', - 'DrydockResourceQuery' => 'PhabricatorOffsetPagedQuery', + 'DrydockResourceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'DrydockResourceStatus' => 'DrydockConstants', 'DrydockResourceViewController' => 'DrydockController', 'DrydockSSHCommandInterface' => 'DrydockCommandInterface', diff --git a/src/applications/drydock/controller/DrydockResourceListController.php b/src/applications/drydock/controller/DrydockResourceListController.php index c94d64c085..f93e343aa3 100644 --- a/src/applications/drydock/controller/DrydockResourceListController.php +++ b/src/applications/drydock/controller/DrydockResourceListController.php @@ -14,6 +14,7 @@ final class DrydockResourceListController extends DrydockController { $pager = new AphrontPagerView(); $pager->setURI(new PhutilURI('/drydock/resource/'), 'offset'); $resources = id(new DrydockResourceQuery()) + ->setViewer($user) ->executeWithOffsetPager($pager); $resource_list = $this->buildResourceListView($resources); diff --git a/src/applications/drydock/query/DrydockResourceQuery.php b/src/applications/drydock/query/DrydockResourceQuery.php index c33f73bbcd..2504aa2066 100644 --- a/src/applications/drydock/query/DrydockResourceQuery.php +++ b/src/applications/drydock/query/DrydockResourceQuery.php @@ -1,15 +1,28 @@ ids = $ids; 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(); $conn_r = $table->establishConnection('r'); @@ -36,11 +49,27 @@ final class DrydockResourceQuery extends PhabricatorOffsetPagedQuery { $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); } - private function buildOrderClause(AphrontDatabaseConnection $conn_r) { - return qsprintf($conn_r, 'ORDER BY id DESC'); + public function getQueryApplicationClass() { + return 'PhabricatorApplicationDrydock'; } } diff --git a/src/applications/drydock/storage/DrydockResource.php b/src/applications/drydock/storage/DrydockResource.php index c4fa978532..39911b0a97 100644 --- a/src/applications/drydock/storage/DrydockResource.php +++ b/src/applications/drydock/storage/DrydockResource.php @@ -1,6 +1,7 @@ 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; + } }