diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d03128da7c..0fc4120b59 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2634,7 +2634,7 @@ phutil_register_library_map(array( 'HeraldRuleEditHistoryController' => 'HeraldController', 'HeraldRuleEditHistoryView' => 'AphrontView', 'HeraldRuleListView' => 'AphrontView', - 'HeraldRuleQuery' => 'PhabricatorOffsetPagedQuery', + 'HeraldRuleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'HeraldTestConsoleController' => 'HeraldController', 'HeraldTranscript' => 'HeraldDAO', 'HeraldTranscriptController' => 'HeraldController', diff --git a/src/applications/herald/controller/HeraldHomeController.php b/src/applications/herald/controller/HeraldHomeController.php index 223d70998f..5f55c8b51d 100644 --- a/src/applications/herald/controller/HeraldHomeController.php +++ b/src/applications/herald/controller/HeraldHomeController.php @@ -26,7 +26,8 @@ final class HeraldHomeController extends HeraldController { return id(new AphrontRedirectResponse())->setURI($uri); } - $query = new HeraldRuleQuery(); + $query = id(new HeraldRuleQuery()) + ->setViewer($user); $content_type_map = HeraldContentTypeConfig::getContentTypeMap(); if (empty($content_type_map[$this->contentType])) { diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index 44d25a29af..41cabf6ef6 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -540,8 +540,11 @@ final class HeraldRuleController extends HeraldController { * allows one rule to depend upon the success or failure of another rule. */ private function loadRulesThisRuleMayDependUpon(HeraldRule $rule) { + $viewer = $this->getRequest()->getUser(); + // Any rule can depend on a global rule. $all_rules = id(new HeraldRuleQuery()) + ->setViewer($viewer) ->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_GLOBAL)) ->withContentTypes(array($rule->getContentType())) ->execute(); @@ -549,6 +552,7 @@ final class HeraldRuleController extends HeraldController { if ($rule->getRuleType() == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) { // Personal rules may depend upon your other personal rules. $all_rules += id(new HeraldRuleQuery()) + ->setViewer($viewer) ->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL)) ->withContentTypes(array($rule->getContentType())) ->withAuthorPHIDs(array($rule->getAuthorPHID())) diff --git a/src/applications/herald/query/HeraldRuleQuery.php b/src/applications/herald/query/HeraldRuleQuery.php index e1fed7f1bf..df0e31d045 100644 --- a/src/applications/herald/query/HeraldRuleQuery.php +++ b/src/applications/herald/query/HeraldRuleQuery.php @@ -1,6 +1,7 @@ viewer = $viewer; - return $this; - } - - public function getViewer() { - return $this->viewer; - } - public function withIDs(array $ids) { $this->ids = $ids; return $this; @@ -45,21 +34,17 @@ final class HeraldRuleQuery extends PhabricatorOffsetPagedQuery { return $this; } - public function execute() { + public function loadPage() { $table = new HeraldRule(); $conn_r = $table->establishConnection('r'); - $where = $this->buildWhereClause($conn_r); - $order = $this->buildOrderClause($conn_r); - $limit = $this->buildLimitClause($conn_r); - $data = queryfx_all( $conn_r, 'SELECT rule.* FROM %T rule %Q %Q %Q', $table->getTableName(), - $where, - $order, - $limit); + $this->buildWhereClause($conn_r), + $this->buildOrderClause($conn_r), + $this->buildLimitClause($conn_r)); return $table->loadAllFromArray($data); } @@ -102,11 +87,9 @@ final class HeraldRuleQuery extends PhabricatorOffsetPagedQuery { $this->contentTypes); } + $where[] = $this->buildPagingClause($conn_r); + return $this->formatWhereClause($where); } - private function buildOrderClause($conn_r) { - return 'ORDER BY id DESC'; - } - }