mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 12:30:56 +01:00
Make DrydockLog policy-aware
Summary: Ref T2015. Update DrydockLog for policy awareness and give it a policy query. Test Plan: Browsed all the log interfaces. Reviewers: btrahan Reviewed By: btrahan CC: hach-que, aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7831
This commit is contained in:
parent
bc3912e641
commit
3db5833622
6 changed files with 65 additions and 36 deletions
|
@ -32,6 +32,7 @@ final class DrydockLeaseViewController extends DrydockController {
|
|||
$pager->setOffset($request->getInt('offset'));
|
||||
|
||||
$logs = id(new DrydockLogQuery())
|
||||
->setViewer($user)
|
||||
->withLeaseIDs(array($lease->getID()))
|
||||
->executeWithOffsetPager($pager);
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ final class DrydockLogController extends DrydockController {
|
|||
|
||||
$nav = $this->buildSideNav('log');
|
||||
|
||||
$query = new DrydockLogQuery();
|
||||
$query = id(new DrydockLogQuery())
|
||||
->setViewer($user);
|
||||
|
||||
$resource_ids = $request->getStrList('resource');
|
||||
if ($resource_ids) {
|
||||
|
|
|
@ -41,6 +41,7 @@ final class DrydockResourceViewController extends DrydockController {
|
|||
$pager->setOffset($request->getInt('offset'));
|
||||
|
||||
$logs = id(new DrydockLogQuery())
|
||||
->setViewer($user)
|
||||
->withResourceIDs(array($resource->getID()))
|
||||
->executeWithOffsetPager($pager);
|
||||
|
||||
|
|
|
@ -59,9 +59,8 @@ final class DrydockManagementLeaseWorkflow
|
|||
}
|
||||
|
||||
$logs = id(new DrydockLogQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withLeaseIDs(array($lease->getID()))
|
||||
->withAfterID($cursor)
|
||||
->setOrder(DrydockLogQuery::ORDER_ID)
|
||||
->execute();
|
||||
|
||||
if ($logs) {
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLogQuery extends PhabricatorOffsetPagedQuery {
|
||||
|
||||
const ORDER_EPOCH = 'order-epoch';
|
||||
const ORDER_ID = 'order-id';
|
||||
final class DrydockLogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $resourceIDs;
|
||||
private $leaseIDs;
|
||||
private $afterID;
|
||||
private $order = self::ORDER_EPOCH;
|
||||
|
||||
public function withResourceIDs(array $ids) {
|
||||
$this->resourceIDs = $ids;
|
||||
|
@ -20,17 +15,7 @@ final class DrydockLogQuery extends PhabricatorOffsetPagedQuery {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setOrder($order) {
|
||||
$this->order = $order;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withAfterID($id) {
|
||||
$this->afterID = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
public function loadPage() {
|
||||
$table = new DrydockLog();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
|
@ -45,6 +30,26 @@ final class DrydockLogQuery extends PhabricatorOffsetPagedQuery {
|
|||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
public function willFilterPage(array $logs) {
|
||||
$resource_ids = mpull($logs, 'getResourceID');
|
||||
$resources = id(new DrydockResourceQuery())
|
||||
->setParentQuery($this)
|
||||
->setViewer($this->getViewer())
|
||||
->withIDs($resource_ids)
|
||||
->execute();
|
||||
|
||||
foreach ($logs as $key => $log) {
|
||||
$resource = idx($resources, $log->getResourceID());
|
||||
if (!$resource) {
|
||||
unset($logs[$key]);
|
||||
continue;
|
||||
}
|
||||
$log->attachResource($resource);
|
||||
}
|
||||
|
||||
return $logs;
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
|
@ -62,25 +67,13 @@ final class DrydockLogQuery extends PhabricatorOffsetPagedQuery {
|
|||
$this->leaseIDs);
|
||||
}
|
||||
|
||||
if ($this->afterID) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id > %d',
|
||||
$this->afterID);
|
||||
}
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
private function buildOrderClause(AphrontDatabaseConnection $conn_r) {
|
||||
switch ($this->order) {
|
||||
case self::ORDER_EPOCH:
|
||||
return 'ORDER BY log.epoch DESC, log.id DESC';
|
||||
case self::ORDER_ID:
|
||||
return 'ORDER BY id ASC';
|
||||
default:
|
||||
throw new Exception("Unknown order '{$this->order}'!");
|
||||
}
|
||||
public function getQueryApplicationClass() {
|
||||
return 'PhabricatorApplicationDrydock';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,50 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLog extends DrydockDAO {
|
||||
final class DrydockLog extends DrydockDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
protected $resourceID;
|
||||
protected $leaseID;
|
||||
protected $epoch;
|
||||
protected $message;
|
||||
|
||||
private $resource = self::ATTACHABLE;
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_TIMESTAMPS => false,
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function attachResource(DrydockResource $resource) {
|
||||
$this->resource = $resource;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResource() {
|
||||
return $this->assertAttached($this->resource);
|
||||
}
|
||||
|
||||
|
||||
/* -( 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('Logs inherit the policy of their resources.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue