mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Make HeraldRuleQuery policy-aware
Summary: Ref T2769. dem policy checks Test Plan: Loaded `/herald/`; loaded rule editor. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2769 Differential Revision: https://secure.phabricator.com/D6650
This commit is contained in:
parent
8eed5b1f14
commit
ceb7f830a4
4 changed files with 15 additions and 27 deletions
|
@ -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',
|
||||
|
|
|
@ -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])) {
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class HeraldRuleQuery extends PhabricatorOffsetPagedQuery {
|
||||
final class HeraldRuleQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $ids;
|
||||
private $phids;
|
||||
|
@ -8,18 +9,6 @@ final class HeraldRuleQuery extends PhabricatorOffsetPagedQuery {
|
|||
private $ruleTypes;
|
||||
private $contentTypes;
|
||||
|
||||
// TODO: Remove when this becomes policy-aware.
|
||||
private $viewer;
|
||||
|
||||
public function setViewer($viewer) {
|
||||
$this->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';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue