mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 05:42:40 +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'));
|
$pager->setOffset($request->getInt('offset'));
|
||||||
|
|
||||||
$logs = id(new DrydockLogQuery())
|
$logs = id(new DrydockLogQuery())
|
||||||
|
->setViewer($user)
|
||||||
->withLeaseIDs(array($lease->getID()))
|
->withLeaseIDs(array($lease->getID()))
|
||||||
->executeWithOffsetPager($pager);
|
->executeWithOffsetPager($pager);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ final class DrydockLogController extends DrydockController {
|
||||||
|
|
||||||
$nav = $this->buildSideNav('log');
|
$nav = $this->buildSideNav('log');
|
||||||
|
|
||||||
$query = new DrydockLogQuery();
|
$query = id(new DrydockLogQuery())
|
||||||
|
->setViewer($user);
|
||||||
|
|
||||||
$resource_ids = $request->getStrList('resource');
|
$resource_ids = $request->getStrList('resource');
|
||||||
if ($resource_ids) {
|
if ($resource_ids) {
|
||||||
|
|
|
@ -41,6 +41,7 @@ final class DrydockResourceViewController extends DrydockController {
|
||||||
$pager->setOffset($request->getInt('offset'));
|
$pager->setOffset($request->getInt('offset'));
|
||||||
|
|
||||||
$logs = id(new DrydockLogQuery())
|
$logs = id(new DrydockLogQuery())
|
||||||
|
->setViewer($user)
|
||||||
->withResourceIDs(array($resource->getID()))
|
->withResourceIDs(array($resource->getID()))
|
||||||
->executeWithOffsetPager($pager);
|
->executeWithOffsetPager($pager);
|
||||||
|
|
||||||
|
|
|
@ -59,9 +59,8 @@ final class DrydockManagementLeaseWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
$logs = id(new DrydockLogQuery())
|
$logs = id(new DrydockLogQuery())
|
||||||
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
->withLeaseIDs(array($lease->getID()))
|
->withLeaseIDs(array($lease->getID()))
|
||||||
->withAfterID($cursor)
|
|
||||||
->setOrder(DrydockLogQuery::ORDER_ID)
|
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
if ($logs) {
|
if ($logs) {
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class DrydockLogQuery extends PhabricatorOffsetPagedQuery {
|
final class DrydockLogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
const ORDER_EPOCH = 'order-epoch';
|
|
||||||
const ORDER_ID = 'order-id';
|
|
||||||
|
|
||||||
private $resourceIDs;
|
private $resourceIDs;
|
||||||
private $leaseIDs;
|
private $leaseIDs;
|
||||||
private $afterID;
|
|
||||||
private $order = self::ORDER_EPOCH;
|
|
||||||
|
|
||||||
public function withResourceIDs(array $ids) {
|
public function withResourceIDs(array $ids) {
|
||||||
$this->resourceIDs = $ids;
|
$this->resourceIDs = $ids;
|
||||||
|
@ -20,17 +15,7 @@ final class DrydockLogQuery extends PhabricatorOffsetPagedQuery {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOrder($order) {
|
public function loadPage() {
|
||||||
$this->order = $order;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function withAfterID($id) {
|
|
||||||
$this->afterID = $id;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function execute() {
|
|
||||||
$table = new DrydockLog();
|
$table = new DrydockLog();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
|
@ -45,6 +30,26 @@ final class DrydockLogQuery extends PhabricatorOffsetPagedQuery {
|
||||||
return $table->loadAllFromArray($data);
|
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) {
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
|
@ -62,25 +67,13 @@ final class DrydockLogQuery extends PhabricatorOffsetPagedQuery {
|
||||||
$this->leaseIDs);
|
$this->leaseIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->afterID) {
|
$where[] = $this->buildPagingClause($conn_r);
|
||||||
$where[] = qsprintf(
|
|
||||||
$conn_r,
|
|
||||||
'id > %d',
|
|
||||||
$this->afterID);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
return $this->formatWhereClause($where);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildOrderClause(AphrontDatabaseConnection $conn_r) {
|
public function getQueryApplicationClass() {
|
||||||
switch ($this->order) {
|
return 'PhabricatorApplicationDrydock';
|
||||||
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}'!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,50 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class DrydockLog extends DrydockDAO {
|
final class DrydockLog extends DrydockDAO
|
||||||
|
implements PhabricatorPolicyInterface {
|
||||||
|
|
||||||
protected $resourceID;
|
protected $resourceID;
|
||||||
protected $leaseID;
|
protected $leaseID;
|
||||||
protected $epoch;
|
protected $epoch;
|
||||||
protected $message;
|
protected $message;
|
||||||
|
|
||||||
|
private $resource = self::ATTACHABLE;
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_TIMESTAMPS => false,
|
self::CONFIG_TIMESTAMPS => false,
|
||||||
) + parent::getConfiguration();
|
) + 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