@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+59 -17
+2 -1
src/__phutil_library_map__.php
··· 5889 5889 'PhabricatorWorkerTrigger' => array( 5890 5890 'PhabricatorWorkerDAO', 5891 5891 'PhabricatorDestructibleInterface', 5892 + 'PhabricatorPolicyInterface', 5892 5893 ), 5893 5894 'PhabricatorWorkerTriggerEvent' => 'PhabricatorWorkerDAO', 5894 5895 'PhabricatorWorkerTriggerManagementFireWorkflow' => 'PhabricatorWorkerTriggerManagementWorkflow', 5895 5896 'PhabricatorWorkerTriggerManagementWorkflow' => 'PhabricatorManagementWorkflow', 5896 5897 'PhabricatorWorkerTriggerPHIDType' => 'PhabricatorPHIDType', 5897 - 'PhabricatorWorkerTriggerQuery' => 'PhabricatorOffsetPagedQuery', 5898 + 'PhabricatorWorkerTriggerQuery' => 'PhabricatorPolicyAwareQuery', 5898 5899 'PhabricatorWorkerYieldException' => 'Exception', 5899 5900 'PhabricatorWorkingCopyDiscoveryTestCase' => 'PhabricatorWorkingCopyTestCase', 5900 5901 'PhabricatorWorkingCopyPullTestCase' => 'PhabricatorWorkingCopyTestCase',
+5 -5
src/applications/daemon/controller/PhabricatorDaemonConsoleController.php
··· 3 3 final class PhabricatorDaemonConsoleController 4 4 extends PhabricatorDaemonController { 5 5 6 - public function processRequest() { 7 - $request = $this->getRequest(); 8 - $user = $request->getUser(); 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $this->getViewer(); 9 8 10 9 $window_start = (time() - (60 * 15)); 11 10 ··· 71 70 } 72 71 73 72 $logs = id(new PhabricatorDaemonLogQuery()) 74 - ->setViewer($user) 73 + ->setViewer($viewer) 75 74 ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE) 76 75 ->setAllowStatusWrites(true) 77 76 ->execute(); ··· 123 122 $completed_panel->appendChild($completed_table); 124 123 125 124 $daemon_table = new PhabricatorDaemonLogListView(); 126 - $daemon_table->setUser($user); 125 + $daemon_table->setUser($viewer); 127 126 $daemon_table->setDaemonLogs($logs); 128 127 129 128 $daemon_panel = new PHUIObjectBoxView(); ··· 190 189 ->setNoDataString(pht('Task queue is empty.'))); 191 190 192 191 $triggers = id(new PhabricatorWorkerTriggerQuery()) 192 + ->setViewer($viewer) 193 193 ->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION) 194 194 ->needEvents(true) 195 195 ->setLimit(10)
+3
src/infrastructure/daemon/workers/PhabricatorTriggerDaemon.php
··· 102 102 $limit = 100; 103 103 104 104 $query = id(new PhabricatorWorkerTriggerQuery()) 105 + ->setViewer($this->getViewer()) 105 106 ->withVersionBetween($cursor, null) 106 107 ->setOrder(PhabricatorWorkerTriggerQuery::ORDER_VERSION) 107 108 ->needEvents(true) ··· 183 184 $now = PhabricatorTime::getNow(); 184 185 185 186 $triggers = id(new PhabricatorWorkerTriggerQuery()) 187 + ->setViewer($this->getViewer()) 186 188 ->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION) 187 189 ->withNextEventBetween(null, $now) 188 190 ->needEvents(true) ··· 249 251 $sleep = 60; 250 252 251 253 $next_triggers = id(new PhabricatorWorkerTriggerQuery()) 254 + ->setViewer($this->getViewer()) 252 255 ->setOrder(PhabricatorWorkerTriggerQuery::ORDER_EXECUTION) 253 256 ->setLimit(1) 254 257 ->needEvents(true)
+1
src/infrastructure/daemon/workers/management/PhabricatorWorkerTriggerManagementWorkflow.php
··· 22 22 } 23 23 24 24 $triggers = id(new PhabricatorWorkerTriggerQuery()) 25 + ->setViewer($this->getViewer()) 25 26 ->withIDs($ids) 26 27 ->needEvents(true) 27 28 ->execute();
+3 -7
src/infrastructure/daemon/workers/phid/PhabricatorWorkerTriggerPHIDType.php
··· 9 9 } 10 10 11 11 public function newObject() { 12 - return new PhabricatorWorkerTriggerPHIDType(); 12 + return new PhabricatorWorkerTrigger(); 13 13 } 14 14 15 15 protected function buildQueryForObjects( 16 16 PhabricatorObjectQuery $query, 17 17 array $phids) { 18 18 19 - // TODO: Maybe straighten this out eventually, but these aren't policy 20 - // objects and don't have an applicable query which we can return here. 21 - // Since we should never call this normally, just leave it stubbed for 22 - // now. 23 - 24 - throw new PhutilMethodNotImplementedException(); 19 + return id(new PhabricatorWorkerTriggerQuery()) 20 + ->withPHIDs($phids); 25 21 } 26 22 27 23 public function loadHandles(
+16 -2
src/infrastructure/daemon/workers/query/PhabricatorWorkerTriggerQuery.php
··· 1 1 <?php 2 2 3 3 final class PhabricatorWorkerTriggerQuery 4 - extends PhabricatorOffsetPagedQuery { 4 + extends PhabricatorPolicyAwareQuery { 5 + 6 + // NOTE: This is a PolicyAware query so it can work with other infrastructure 7 + // like handles; triggers themselves are low-level and do not have 8 + // meaninguful policies. 5 9 6 10 const ORDER_ID = 'id'; 7 11 const ORDER_EXECUTION = 'execution'; ··· 16 20 17 21 private $needEvents; 18 22 private $order = self::ORDER_ID; 23 + 24 + public function getQueryApplicationClass() { 25 + return null; 26 + } 19 27 20 28 public function withIDs(array $ids) { 21 29 $this->ids = $ids; ··· 59 67 return $this; 60 68 } 61 69 62 - public function execute() { 70 + public function nextPage(array $page) { 71 + // NOTE: We don't implement paging because we don't currently ever need 72 + // it and paging ORDER_EXCUTION is a hassle. 73 + throw new PhutilMethodNotImplementedException(); 74 + } 75 + 76 + public function loadPage() { 63 77 $task_table = new PhabricatorWorkerTrigger(); 64 78 65 79 $conn_r = $task_table->establishConnection('r');
+29 -2
src/infrastructure/daemon/workers/storage/PhabricatorWorkerTrigger.php
··· 3 3 final class PhabricatorWorkerTrigger 4 4 extends PhabricatorWorkerDAO 5 5 implements 6 - PhabricatorDestructibleInterface { 6 + PhabricatorDestructibleInterface, 7 + PhabricatorPolicyInterface { 7 8 8 9 protected $triggerVersion; 9 10 protected $clockClass; ··· 143 144 // gymnastics, so don't bother trying to get it totally correct for now. 144 145 145 146 if ($this->getEvent()) { 146 - return $this->getEvent()->getNextEpoch(); 147 + return $this->getEvent()->getNextEventEpoch(); 147 148 } else { 148 149 return $this->getNextEventEpoch(null, $is_reschedule = false); 149 150 } ··· 165 166 166 167 $this->delete(); 167 168 $this->saveTransaction(); 169 + } 170 + 171 + 172 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 173 + 174 + 175 + // NOTE: Triggers are low-level infrastructure and do not have real 176 + // policies, but implementing the policy interface allows us to use 177 + // infrastructure like handles. 178 + 179 + public function getCapabilities() { 180 + return array( 181 + PhabricatorPolicyCapability::CAN_VIEW, 182 + ); 183 + } 184 + 185 + public function getPolicy($capability) { 186 + return PhabricatorPolicies::getMostOpenPolicy(); 187 + } 188 + 189 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 190 + return true; 191 + } 192 + 193 + public function describeAutomaticCapability($capability) { 194 + return null; 168 195 } 169 196 170 197 }