1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 20:10:55 +01:00

Implement PolicyAwareQuery for triggers

Summary:
Ref T6881. I tried to cheat here by not implementing this, but we need it for destroying triggers directly with `bin/remove destroy`, since that needs to load them by PHID.

So, cheat slightly less. Implement PolicyAware but not CursorPagedPolicyAware.

Test Plan:
  - Used `bin/remove destroy` to destroy a trigger by PHID.
  - Browsed daemon console.
  - Ran trigger daemon.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T6881

Differential Revision: https://secure.phabricator.com/D11445
This commit is contained in:
epriestley 2015-01-20 13:32:43 -08:00
parent 934df0e735
commit 77bcbed9f9
7 changed files with 59 additions and 17 deletions

View file

@ -5889,12 +5889,13 @@ phutil_register_library_map(array(
'PhabricatorWorkerTrigger' => array(
'PhabricatorWorkerDAO',
'PhabricatorDestructibleInterface',
'PhabricatorPolicyInterface',
),
'PhabricatorWorkerTriggerEvent' => 'PhabricatorWorkerDAO',
'PhabricatorWorkerTriggerManagementFireWorkflow' => 'PhabricatorWorkerTriggerManagementWorkflow',
'PhabricatorWorkerTriggerManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorWorkerTriggerPHIDType' => 'PhabricatorPHIDType',
'PhabricatorWorkerTriggerQuery' => 'PhabricatorOffsetPagedQuery',
'PhabricatorWorkerTriggerQuery' => 'PhabricatorPolicyAwareQuery',
'PhabricatorWorkerYieldException' => 'Exception',
'PhabricatorWorkingCopyDiscoveryTestCase' => 'PhabricatorWorkingCopyTestCase',
'PhabricatorWorkingCopyPullTestCase' => 'PhabricatorWorkingCopyTestCase',

View file

@ -3,9 +3,8 @@
final class PhabricatorDaemonConsoleController
extends PhabricatorDaemonController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$window_start = (time() - (60 * 15));
@ -71,7 +70,7 @@ final class PhabricatorDaemonConsoleController
}
$logs = id(new PhabricatorDaemonLogQuery())
->setViewer($user)
->setViewer($viewer)
->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)
->setAllowStatusWrites(true)
->execute();
@ -123,7 +122,7 @@ final class PhabricatorDaemonConsoleController
$completed_panel->appendChild($completed_table);
$daemon_table = new PhabricatorDaemonLogListView();
$daemon_table->setUser($user);
$daemon_table->setUser($viewer);
$daemon_table->setDaemonLogs($logs);
$daemon_panel = new PHUIObjectBoxView();
@ -190,6 +189,7 @@ final class PhabricatorDaemonConsoleController
->setNoDataString(pht('Task queue is empty.')));
$triggers = id(new PhabricatorWorkerTriggerQuery())
->setViewer($viewer)
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
->needEvents(true)
->setLimit(10)

View file

@ -102,6 +102,7 @@ final class PhabricatorTriggerDaemon
$limit = 100;
$query = id(new PhabricatorWorkerTriggerQuery())
->setViewer($this->getViewer())
->withVersionBetween($cursor, null)
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_VERSION)
->needEvents(true)
@ -183,6 +184,7 @@ final class PhabricatorTriggerDaemon
$now = PhabricatorTime::getNow();
$triggers = id(new PhabricatorWorkerTriggerQuery())
->setViewer($this->getViewer())
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
->withNextEventBetween(null, $now)
->needEvents(true)
@ -249,6 +251,7 @@ final class PhabricatorTriggerDaemon
$sleep = 60;
$next_triggers = id(new PhabricatorWorkerTriggerQuery())
->setViewer($this->getViewer())
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
->setLimit(1)
->needEvents(true)

View file

@ -22,6 +22,7 @@ abstract class PhabricatorWorkerTriggerManagementWorkflow
}
$triggers = id(new PhabricatorWorkerTriggerQuery())
->setViewer($this->getViewer())
->withIDs($ids)
->needEvents(true)
->execute();

View file

@ -9,19 +9,15 @@ final class PhabricatorWorkerTriggerPHIDType extends PhabricatorPHIDType {
}
public function newObject() {
return new PhabricatorWorkerTriggerPHIDType();
return new PhabricatorWorkerTrigger();
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
// TODO: Maybe straighten this out eventually, but these aren't policy
// objects and don't have an applicable query which we can return here.
// Since we should never call this normally, just leave it stubbed for
// now.
throw new PhutilMethodNotImplementedException();
return id(new PhabricatorWorkerTriggerQuery())
->withPHIDs($phids);
}
public function loadHandles(

View file

@ -1,7 +1,11 @@
<?php
final class PhabricatorWorkerTriggerQuery
extends PhabricatorOffsetPagedQuery {
extends PhabricatorPolicyAwareQuery {
// NOTE: This is a PolicyAware query so it can work with other infrastructure
// like handles; triggers themselves are low-level and do not have
// meaninguful policies.
const ORDER_ID = 'id';
const ORDER_EXECUTION = 'execution';
@ -17,6 +21,10 @@ final class PhabricatorWorkerTriggerQuery
private $needEvents;
private $order = self::ORDER_ID;
public function getQueryApplicationClass() {
return null;
}
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
@ -59,7 +67,13 @@ final class PhabricatorWorkerTriggerQuery
return $this;
}
public function execute() {
public function nextPage(array $page) {
// NOTE: We don't implement paging because we don't currently ever need
// it and paging ORDER_EXCUTION is a hassle.
throw new PhutilMethodNotImplementedException();
}
public function loadPage() {
$task_table = new PhabricatorWorkerTrigger();
$conn_r = $task_table->establishConnection('r');

View file

@ -3,7 +3,8 @@
final class PhabricatorWorkerTrigger
extends PhabricatorWorkerDAO
implements
PhabricatorDestructibleInterface {
PhabricatorDestructibleInterface,
PhabricatorPolicyInterface {
protected $triggerVersion;
protected $clockClass;
@ -143,7 +144,7 @@ final class PhabricatorWorkerTrigger
// gymnastics, so don't bother trying to get it totally correct for now.
if ($this->getEvent()) {
return $this->getEvent()->getNextEpoch();
return $this->getEvent()->getNextEventEpoch();
} else {
return $this->getNextEventEpoch(null, $is_reschedule = false);
}
@ -167,4 +168,30 @@ final class PhabricatorWorkerTrigger
$this->saveTransaction();
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
// NOTE: Triggers are low-level infrastructure and do not have real
// policies, but implementing the policy interface allows us to use
// infrastructure like handles.
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
return PhabricatorPolicies::getMostOpenPolicy();
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return true;
}
public function describeAutomaticCapability($capability) {
return null;
}
}