Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14025492
D7826.id17704.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D7826.id17704.diff
View Options
Index: src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
===================================================================
--- src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
+++ src/applications/drydock/blueprint/DrydockBlueprintImplementation.php
@@ -26,9 +26,10 @@
}
protected function loadLease($lease_id) {
+ // TODO: Get rid of this?
$query = id(new DrydockLeaseQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
->withIDs(array($lease_id))
- ->needResources(true)
->execute();
$lease = idx($query, $lease_id);
Index: src/applications/drydock/controller/DrydockLeaseListController.php
===================================================================
--- src/applications/drydock/controller/DrydockLeaseListController.php
+++ src/applications/drydock/controller/DrydockLeaseListController.php
@@ -13,7 +13,7 @@
$pager->setOffset($request->getInt('offset'));
$leases = id(new DrydockLeaseQuery())
- ->needResources(true)
+ ->setViewer($user)
->executeWithOffsetPager($pager);
$title = pht('Leases');
Index: src/applications/drydock/controller/DrydockLeaseReleaseController.php
===================================================================
--- src/applications/drydock/controller/DrydockLeaseReleaseController.php
+++ src/applications/drydock/controller/DrydockLeaseReleaseController.php
@@ -12,7 +12,10 @@
$request = $this->getRequest();
$user = $request->getUser();
- $lease = id(new DrydockLease())->load($this->id);
+ $lease = id(new DrydockLeaseQuery())
+ ->setViewer($user)
+ ->withIDs(array($this->id))
+ ->executeOne();
if (!$lease) {
return new Aphront404Response();
}
@@ -45,7 +48,7 @@
return id(new AphrontDialogResponse())->setDialog($dialog);
}
- $resource = $lease->loadResource();
+ $resource = $lease->getResource();
$blueprint = $resource->getBlueprint();
$blueprint->releaseLease($resource, $lease);
Index: src/applications/drydock/controller/DrydockResourceViewController.php
===================================================================
--- src/applications/drydock/controller/DrydockResourceViewController.php
+++ src/applications/drydock/controller/DrydockResourceViewController.php
@@ -29,8 +29,8 @@
$resource_uri = $this->getApplicationURI($resource_uri);
$leases = id(new DrydockLeaseQuery())
+ ->setViewer($user)
->withResourceIDs(array($resource->getID()))
- ->needResources(true)
->execute();
$lease_list = $this->buildLeaseListView($leases);
Index: src/applications/drydock/management/DrydockManagementReleaseWorkflow.php
===================================================================
--- src/applications/drydock/management/DrydockManagementReleaseWorkflow.php
+++ src/applications/drydock/management/DrydockManagementReleaseWorkflow.php
@@ -25,14 +25,21 @@
"Specify one or more lease IDs to release.");
}
+ $viewer = PhabricatorUser::getOmnipotentUser();
+
+ $leases = id(new DrydockLeaseQuery())
+ ->setViewer($viewer)
+ ->withIDs($ids)
+ ->execute();
+
foreach ($ids as $id) {
- $lease = id(new DrydockLease())->load($id);
+ $lease = idx($leases, $id);
if (!$lease) {
$console->writeErr("Lease %d does not exist!\n", $id);
} else if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
$console->writeErr("Lease %d is not 'active'!\n", $id);
} else {
- $resource = $lease->loadResource();
+ $resource = $lease->getResource();
$blueprint = $resource->getBlueprint();
$blueprint->releaseLease($resource, $lease);
Index: src/applications/drydock/query/DrydockLeaseQuery.php
===================================================================
--- src/applications/drydock/query/DrydockLeaseQuery.php
+++ src/applications/drydock/query/DrydockLeaseQuery.php
@@ -1,27 +1,22 @@
<?php
-final class DrydockLeaseQuery extends PhabricatorOffsetPagedQuery {
+final class DrydockLeaseQuery
+ extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $resourceIDs;
- private $needResources;
-
- public function withResourceIDs(array $ids) {
- $this->resourceIDs = $ids;
- return $this;
- }
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
- public function needResources($need_resources) {
- $this->needResources = $need_resources;
+ public function withResourceIDs(array $ids) {
+ $this->resourceIDs = $ids;
return $this;
}
- public function execute() {
+ public function loadPage() {
$table = new DrydockLease();
$conn_r = $table->establishConnection('r');
@@ -33,25 +28,23 @@
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
- $leases = $table->loadAllFromArray($data);
+ return $table->loadAllFromArray($data);
+ }
- if ($leases && $this->needResources) {
- $resources = id(new DrydockResource())->loadAllWhere(
- 'id IN (%Ld)',
- mpull($leases, 'getResourceID'));
-
- foreach ($leases as $key => $lease) {
- if ($lease->getResourceID()) {
- $resource = idx($resources, $lease->getResourceID());
- if ($resource) {
- $lease->attachResource($resource);
- } else {
- unset($leases[$key]);
- }
- } else {
- unset($leases[$key]);
- }
+ public function willFilterPage(array $leases) {
+ $resources = id(new DrydockResourceQuery())
+ ->setParentQuery($this)
+ ->setViewer($this->getViewer())
+ ->withIDs(mpull($leases, 'getResourceID'))
+ ->execute();
+
+ foreach ($leases as $key => $lease) {
+ $resource = idx($resources, $lease->getResourceID());
+ if (!$resource) {
+ unset($leases[$key]);
+ continue;
}
+ $lease->attachResource($resource);
}
return $leases;
@@ -74,11 +67,13 @@
$this->ids);
}
+ $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';
}
}
Index: src/applications/drydock/storage/DrydockLease.php
===================================================================
--- src/applications/drydock/storage/DrydockLease.php
+++ src/applications/drydock/storage/DrydockLease.php
@@ -1,6 +1,7 @@
<?php
-final class DrydockLease extends DrydockDAO {
+final class DrydockLease extends DrydockDAO
+ implements PhabricatorPolicyInterface {
protected $resourceID;
protected $resourceType;
@@ -187,4 +188,26 @@
return $this;
}
+
+/* -( PhabricatorPolicyInterface )----------------------------------------- */
+
+
+ public function getCapabilities() {
+ return array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ );
+ }
+
+ public function getPolicy($capability) {
+ return $this->getResource()->getPolicy($capability);
+ }
+
+ public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
+ return $this->getResource()->hasAutomaticCapability($capability, $viewer);
+ }
+
+ public function describeAutomaticCapability($capability) {
+ return pht('Leases inherit policies from the resources they lease.');
+ }
+
}
Index: src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php
===================================================================
--- src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php
+++ src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php
@@ -59,6 +59,7 @@
->setHref($handle->getURI());
case self::TYPE_HOST:
$leases = id(new DrydockLeaseQuery())
+ ->setViewer($viewer)
->withIDs(array($data["drydock-lease"]))
->execute();
$lease = $leases[$data["drydock-lease"]];
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 8, 6:31 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6721110
Default Alt Text
D7826.id17704.diff (7 KB)
Attached To
Mode
D7826: Make DrydockLease a policy-aware object
Attached
Detach File
Event Timeline
Log In to Comment