mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 12:30:56 +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:
parent
934df0e735
commit
77bcbed9f9
7 changed files with 59 additions and 17 deletions
|
@ -5889,12 +5889,13 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorWorkerTrigger' => array(
|
'PhabricatorWorkerTrigger' => array(
|
||||||
'PhabricatorWorkerDAO',
|
'PhabricatorWorkerDAO',
|
||||||
'PhabricatorDestructibleInterface',
|
'PhabricatorDestructibleInterface',
|
||||||
|
'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
'PhabricatorWorkerTriggerEvent' => 'PhabricatorWorkerDAO',
|
'PhabricatorWorkerTriggerEvent' => 'PhabricatorWorkerDAO',
|
||||||
'PhabricatorWorkerTriggerManagementFireWorkflow' => 'PhabricatorWorkerTriggerManagementWorkflow',
|
'PhabricatorWorkerTriggerManagementFireWorkflow' => 'PhabricatorWorkerTriggerManagementWorkflow',
|
||||||
'PhabricatorWorkerTriggerManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
'PhabricatorWorkerTriggerManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||||
'PhabricatorWorkerTriggerPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorWorkerTriggerPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorWorkerTriggerQuery' => 'PhabricatorOffsetPagedQuery',
|
'PhabricatorWorkerTriggerQuery' => 'PhabricatorPolicyAwareQuery',
|
||||||
'PhabricatorWorkerYieldException' => 'Exception',
|
'PhabricatorWorkerYieldException' => 'Exception',
|
||||||
'PhabricatorWorkingCopyDiscoveryTestCase' => 'PhabricatorWorkingCopyTestCase',
|
'PhabricatorWorkingCopyDiscoveryTestCase' => 'PhabricatorWorkingCopyTestCase',
|
||||||
'PhabricatorWorkingCopyPullTestCase' => 'PhabricatorWorkingCopyTestCase',
|
'PhabricatorWorkingCopyPullTestCase' => 'PhabricatorWorkingCopyTestCase',
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
final class PhabricatorDaemonConsoleController
|
final class PhabricatorDaemonConsoleController
|
||||||
extends PhabricatorDaemonController {
|
extends PhabricatorDaemonController {
|
||||||
|
|
||||||
public function processRequest() {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$request = $this->getRequest();
|
$viewer = $this->getViewer();
|
||||||
$user = $request->getUser();
|
|
||||||
|
|
||||||
$window_start = (time() - (60 * 15));
|
$window_start = (time() - (60 * 15));
|
||||||
|
|
||||||
|
@ -71,7 +70,7 @@ final class PhabricatorDaemonConsoleController
|
||||||
}
|
}
|
||||||
|
|
||||||
$logs = id(new PhabricatorDaemonLogQuery())
|
$logs = id(new PhabricatorDaemonLogQuery())
|
||||||
->setViewer($user)
|
->setViewer($viewer)
|
||||||
->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)
|
->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE)
|
||||||
->setAllowStatusWrites(true)
|
->setAllowStatusWrites(true)
|
||||||
->execute();
|
->execute();
|
||||||
|
@ -123,7 +122,7 @@ final class PhabricatorDaemonConsoleController
|
||||||
$completed_panel->appendChild($completed_table);
|
$completed_panel->appendChild($completed_table);
|
||||||
|
|
||||||
$daemon_table = new PhabricatorDaemonLogListView();
|
$daemon_table = new PhabricatorDaemonLogListView();
|
||||||
$daemon_table->setUser($user);
|
$daemon_table->setUser($viewer);
|
||||||
$daemon_table->setDaemonLogs($logs);
|
$daemon_table->setDaemonLogs($logs);
|
||||||
|
|
||||||
$daemon_panel = new PHUIObjectBoxView();
|
$daemon_panel = new PHUIObjectBoxView();
|
||||||
|
@ -190,6 +189,7 @@ final class PhabricatorDaemonConsoleController
|
||||||
->setNoDataString(pht('Task queue is empty.')));
|
->setNoDataString(pht('Task queue is empty.')));
|
||||||
|
|
||||||
$triggers = id(new PhabricatorWorkerTriggerQuery())
|
$triggers = id(new PhabricatorWorkerTriggerQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
|
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
|
||||||
->needEvents(true)
|
->needEvents(true)
|
||||||
->setLimit(10)
|
->setLimit(10)
|
||||||
|
|
|
@ -102,6 +102,7 @@ final class PhabricatorTriggerDaemon
|
||||||
$limit = 100;
|
$limit = 100;
|
||||||
|
|
||||||
$query = id(new PhabricatorWorkerTriggerQuery())
|
$query = id(new PhabricatorWorkerTriggerQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
->withVersionBetween($cursor, null)
|
->withVersionBetween($cursor, null)
|
||||||
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_VERSION)
|
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_VERSION)
|
||||||
->needEvents(true)
|
->needEvents(true)
|
||||||
|
@ -183,6 +184,7 @@ final class PhabricatorTriggerDaemon
|
||||||
$now = PhabricatorTime::getNow();
|
$now = PhabricatorTime::getNow();
|
||||||
|
|
||||||
$triggers = id(new PhabricatorWorkerTriggerQuery())
|
$triggers = id(new PhabricatorWorkerTriggerQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
|
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
|
||||||
->withNextEventBetween(null, $now)
|
->withNextEventBetween(null, $now)
|
||||||
->needEvents(true)
|
->needEvents(true)
|
||||||
|
@ -249,6 +251,7 @@ final class PhabricatorTriggerDaemon
|
||||||
$sleep = 60;
|
$sleep = 60;
|
||||||
|
|
||||||
$next_triggers = id(new PhabricatorWorkerTriggerQuery())
|
$next_triggers = id(new PhabricatorWorkerTriggerQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
|
->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION)
|
||||||
->setLimit(1)
|
->setLimit(1)
|
||||||
->needEvents(true)
|
->needEvents(true)
|
||||||
|
|
|
@ -22,6 +22,7 @@ abstract class PhabricatorWorkerTriggerManagementWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
$triggers = id(new PhabricatorWorkerTriggerQuery())
|
$triggers = id(new PhabricatorWorkerTriggerQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
->withIDs($ids)
|
->withIDs($ids)
|
||||||
->needEvents(true)
|
->needEvents(true)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
|
@ -9,19 +9,15 @@ final class PhabricatorWorkerTriggerPHIDType extends PhabricatorPHIDType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newObject() {
|
public function newObject() {
|
||||||
return new PhabricatorWorkerTriggerPHIDType();
|
return new PhabricatorWorkerTrigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildQueryForObjects(
|
protected function buildQueryForObjects(
|
||||||
PhabricatorObjectQuery $query,
|
PhabricatorObjectQuery $query,
|
||||||
array $phids) {
|
array $phids) {
|
||||||
|
|
||||||
// TODO: Maybe straighten this out eventually, but these aren't policy
|
return id(new PhabricatorWorkerTriggerQuery())
|
||||||
// objects and don't have an applicable query which we can return here.
|
->withPHIDs($phids);
|
||||||
// Since we should never call this normally, just leave it stubbed for
|
|
||||||
// now.
|
|
||||||
|
|
||||||
throw new PhutilMethodNotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadHandles(
|
public function loadHandles(
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PhabricatorWorkerTriggerQuery
|
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_ID = 'id';
|
||||||
const ORDER_EXECUTION = 'execution';
|
const ORDER_EXECUTION = 'execution';
|
||||||
|
@ -17,6 +21,10 @@ final class PhabricatorWorkerTriggerQuery
|
||||||
private $needEvents;
|
private $needEvents;
|
||||||
private $order = self::ORDER_ID;
|
private $order = self::ORDER_ID;
|
||||||
|
|
||||||
|
public function getQueryApplicationClass() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -59,7 +67,13 @@ final class PhabricatorWorkerTriggerQuery
|
||||||
return $this;
|
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();
|
$task_table = new PhabricatorWorkerTrigger();
|
||||||
|
|
||||||
$conn_r = $task_table->establishConnection('r');
|
$conn_r = $task_table->establishConnection('r');
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
final class PhabricatorWorkerTrigger
|
final class PhabricatorWorkerTrigger
|
||||||
extends PhabricatorWorkerDAO
|
extends PhabricatorWorkerDAO
|
||||||
implements
|
implements
|
||||||
PhabricatorDestructibleInterface {
|
PhabricatorDestructibleInterface,
|
||||||
|
PhabricatorPolicyInterface {
|
||||||
|
|
||||||
protected $triggerVersion;
|
protected $triggerVersion;
|
||||||
protected $clockClass;
|
protected $clockClass;
|
||||||
|
@ -143,7 +144,7 @@ final class PhabricatorWorkerTrigger
|
||||||
// gymnastics, so don't bother trying to get it totally correct for now.
|
// gymnastics, so don't bother trying to get it totally correct for now.
|
||||||
|
|
||||||
if ($this->getEvent()) {
|
if ($this->getEvent()) {
|
||||||
return $this->getEvent()->getNextEpoch();
|
return $this->getEvent()->getNextEventEpoch();
|
||||||
} else {
|
} else {
|
||||||
return $this->getNextEventEpoch(null, $is_reschedule = false);
|
return $this->getNextEventEpoch(null, $is_reschedule = false);
|
||||||
}
|
}
|
||||||
|
@ -167,4 +168,30 @@ final class PhabricatorWorkerTrigger
|
||||||
$this->saveTransaction();
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue