1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00

Policy - introduce parentQuery and pass around policy configuration from parent to child

Summary: Ref T603. Ref D6941.

Test Plan: Clicked around all over - looked good. I plan to re-test D6941 to make sure the executeOne case works now as intended

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D6944
This commit is contained in:
Bob Trahan 2013-09-11 12:19:34 -07:00
parent b23697eec9
commit 07b8becfc6
34 changed files with 95 additions and 9 deletions

View file

@ -22,6 +22,7 @@ final class PhabricatorConfigPHIDTypeConfig extends PhabricatorPHIDType {
return id(new PhabricatorConfigEntryQuery()) return id(new PhabricatorConfigEntryQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -24,8 +24,9 @@ final class PhabricatorConpherencePHIDTypeThread extends PhabricatorPHIDType {
array $phids) { array $phids) {
return id(new ConpherenceThreadQuery()) return id(new ConpherenceThreadQuery())
->withPHIDs($phids)
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorCountdownPHIDTypeCountdown extends PhabricatorPHIDType {
return id(new PhabricatorCountdownQuery()) return id(new PhabricatorCountdownQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class DifferentialPHIDTypeRevision extends PhabricatorPHIDType {
return id(new DifferentialRevisionQuery()) return id(new DifferentialRevisionQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class DivinerPHIDTypeAtom extends PhabricatorPHIDType {
return id(new DivinerAtomQuery()) return id(new DivinerAtomQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class DivinerPHIDTypeBook extends PhabricatorPHIDType {
return id(new DivinerBookQuery()) return id(new DivinerBookQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorFilePHIDTypeFile extends PhabricatorPHIDType {
return id(new PhabricatorFileQuery()) return id(new PhabricatorFileQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class HeraldPHIDTypeRule extends PhabricatorPHIDType {
return id(new HeraldRuleQuery()) return id(new HeraldRuleQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -24,9 +24,10 @@ final class PhabricatorLegalpadPHIDTypeDocument extends PhabricatorPHIDType {
array $phids) { array $phids) {
return id(new LegalpadDocumentQuery()) return id(new LegalpadDocumentQuery())
->needDocumentBodies(true)
->withPHIDs($phids)
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids)
->needDocumentBodies(true)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorMacroPHIDTypeMacro extends PhabricatorPHIDType {
return id(new PhabricatorMacroQuery()) return id(new PhabricatorMacroQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorMailingListPHIDTypeList extends PhabricatorPHIDType {
return id(new PhabricatorMailingListQuery()) return id(new PhabricatorMailingListQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class ManiphestPHIDTypeTask extends PhabricatorPHIDType {
return id(new ManiphestTaskQuery()) return id(new ManiphestTaskQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorOwnersPHIDTypePackage extends PhabricatorPHIDType {
return id(new PhabricatorOwnersPackageQuery()) return id(new PhabricatorOwnersPackageQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorPastePHIDTypePaste extends PhabricatorPHIDType {
return id(new PhabricatorPasteQuery()) return id(new PhabricatorPasteQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorPeoplePHIDTypeExternal extends PhabricatorPHIDType {
return id(new PhabricatorExternalAccountQuery()) return id(new PhabricatorExternalAccountQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -21,10 +21,11 @@ final class PhabricatorPeoplePHIDTypeUser extends PhabricatorPHIDType {
array $phids) { array $phids) {
return id(new PhabricatorPeopleQuery()) return id(new PhabricatorPeopleQuery())
->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids)
->needProfileImage(true) ->needProfileImage(true)
->needStatus(true) ->needStatus(true)
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -25,6 +25,7 @@ final class PhabricatorPhamePHIDTypeBlog extends PhabricatorPHIDType {
return id(new PhameBlogQuery()) return id(new PhameBlogQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -25,6 +25,7 @@ final class PhabricatorPhamePHIDTypePost extends PhabricatorPHIDType {
return id(new PhamePostQuery()) return id(new PhamePostQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhluxPHIDTypeVariable extends PhabricatorPHIDType {
return id(new PhluxVariableQuery()) return id(new PhluxVariableQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PholioPHIDTypeImage extends PhabricatorPHIDType {
return id(new PholioImageQuery()) return id(new PholioImageQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PholioPHIDTypeMock extends PhabricatorPHIDType {
return id(new PholioMockQuery()) return id(new PholioMockQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhrictionPHIDTypeDocument extends PhabricatorPHIDType {
return id(new PhrictionDocumentQuery()) return id(new PhrictionDocumentQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PonderPHIDTypeAnswer extends PhabricatorPHIDType {
return id(new PonderAnswerQuery()) return id(new PonderAnswerQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PonderPHIDTypeQuestion extends PhabricatorPHIDType {
return id(new PonderQuestionQuery()) return id(new PonderQuestionQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorProjectPHIDTypeProject extends PhabricatorPHIDType {
return id(new PhabricatorProjectQuery()) return id(new PhabricatorProjectQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class ReleephPHIDTypeBranch extends PhabricatorPHIDType {
return id(new ReleephBranchQuery()) return id(new ReleephBranchQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class ReleephPHIDTypeProject extends PhabricatorPHIDType {
return id(new ReleephProjectQuery()) return id(new ReleephProjectQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class ReleephPHIDTypeRequest extends PhabricatorPHIDType {
return id(new ReleephRequestQuery()) return id(new ReleephRequestQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -23,8 +23,10 @@ final class PhabricatorRepositoryPHIDTypeArcanistProject
public function loadObjects( public function loadObjects(
PhabricatorObjectQuery $query, PhabricatorObjectQuery $query,
array $phids) { array $phids) {
return id(new PhabricatorRepositoryArcanistProjectQuery()) return id(new PhabricatorRepositoryArcanistProjectQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorRepositoryPHIDTypeCommit extends PhabricatorPHIDType {
return id(new DiffusionCommitQuery()) return id(new DiffusionCommitQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -23,6 +23,7 @@ final class PhabricatorRepositoryPHIDTypeRepository
return id(new PhabricatorRepositoryQuery()) return id(new PhabricatorRepositoryQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -22,6 +22,7 @@ final class PhabricatorSlowvotePHIDTypePoll extends PhabricatorPHIDType {
return id(new PhabricatorSlowvoteQuery()) return id(new PhabricatorSlowvoteQuery())
->setViewer($query->getViewer()) ->setViewer($query->getViewer())
->setParentQuery($query)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
} }

View file

@ -57,6 +57,7 @@ final class PhabricatorApplicationTransactionPHIDTypeTransaction
$xactions = id(clone $query) $xactions = id(clone $query)
->setViewer($object_query->getViewer()) ->setViewer($object_query->getViewer())
->setParentQuery($object_query)
->withPHIDs($subtype_phids) ->withPHIDs($subtype_phids)
->execute(); ->execute();

View file

@ -30,6 +30,7 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
private $viewer; private $viewer;
private $raisePolicyExceptions; private $raisePolicyExceptions;
private $parentQuery;
private $rawResultLimit; private $rawResultLimit;
private $capabilities; private $capabilities;
@ -63,6 +64,52 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
} }
/**
* Set the parent query of this query. This is useful for nested queries so
* that configuration like whether or not to raise policy exceptions is
* seamlessly passed along to child queries.
*
* @return this
* @task config
*/
final public function setParentQuery(PhabricatorPolicyAwareQuery $query) {
$this->parentQuery = $query;
return $this;
}
/**
* Get the parent query. See @{method:setParentQuery} for discussion.
*
* @return PhabricatorPolicyAwareQuery The parent query.
* @task config
*/
final public function getParentQuery() {
return $this->parentQuery;
}
/**
* Hook to configure whether this query should raise policy exceptions.
*
* @return this
* @task config
*/
final public function setRaisePolicyExceptions($bool) {
$this->raisePolicyExceptions = $bool;
return $this;
}
/**
* @return bool
* @task config
*/
final public function shouldRaisePolicyExceptions() {
return (bool) $this->raisePolicyExceptions;
}
/** /**
* @task config * @task config
*/ */
@ -89,7 +136,6 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
* } * }
* *
* If zero results match the query, this method returns `null`. * If zero results match the query, this method returns `null`.
*
* If one result matches the query, this method returns that result. * If one result matches the query, this method returns that result.
* *
* If two or more results match the query, this method throws an exception. * If two or more results match the query, this method throws an exception.
@ -105,11 +151,11 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
*/ */
final public function executeOne() { final public function executeOne() {
$this->raisePolicyExceptions = true; $this->setRaisePolicyExceptions(true);
try { try {
$results = $this->execute(); $results = $this->execute();
} catch (Exception $ex) { } catch (Exception $ex) {
$this->raisePolicyExceptions = false; $this->setRaisePolicyExceptions(false);
throw $ex; throw $ex;
} }
@ -136,6 +182,12 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
throw new Exception("Call setViewer() before execute()!"); throw new Exception("Call setViewer() before execute()!");
} }
$parent_query = $this->getParentQuery();
if ($parent_query) {
$this->setRaisePolicyExceptions(
$parent_query->shouldRaisePolicyExceptions());
}
$results = array(); $results = array();
$filter = new PhabricatorPolicyFilter(); $filter = new PhabricatorPolicyFilter();
@ -149,7 +201,7 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
$capabilities = $this->capabilities; $capabilities = $this->capabilities;
} }
$filter->requireCapabilities($capabilities); $filter->requireCapabilities($capabilities);
$filter->raisePolicyExceptions($this->raisePolicyExceptions); $filter->raisePolicyExceptions($this->shouldRaisePolicyExceptions());
$offset = (int)$this->getOffset(); $offset = (int)$this->getOffset();
$limit = (int)$this->getLimit(); $limit = (int)$this->getLimit();