mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +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:
parent
b23697eec9
commit
07b8becfc6
34 changed files with 95 additions and 9 deletions
|
@ -22,6 +22,7 @@ final class PhabricatorConfigPHIDTypeConfig extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorConfigEntryQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,9 @@ final class PhabricatorConpherencePHIDTypeThread extends PhabricatorPHIDType {
|
|||
array $phids) {
|
||||
|
||||
return id(new ConpherenceThreadQuery())
|
||||
->withPHIDs($phids)
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorCountdownPHIDTypeCountdown extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorCountdownQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class DifferentialPHIDTypeRevision extends PhabricatorPHIDType {
|
|||
|
||||
return id(new DifferentialRevisionQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class DivinerPHIDTypeAtom extends PhabricatorPHIDType {
|
|||
|
||||
return id(new DivinerAtomQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class DivinerPHIDTypeBook extends PhabricatorPHIDType {
|
|||
|
||||
return id(new DivinerBookQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorFilePHIDTypeFile extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorFileQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class HeraldPHIDTypeRule extends PhabricatorPHIDType {
|
|||
|
||||
return id(new HeraldRuleQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -24,9 +24,10 @@ final class PhabricatorLegalpadPHIDTypeDocument extends PhabricatorPHIDType {
|
|||
array $phids) {
|
||||
|
||||
return id(new LegalpadDocumentQuery())
|
||||
->needDocumentBodies(true)
|
||||
->withPHIDs($phids)
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->needDocumentBodies(true)
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorMacroPHIDTypeMacro extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorMacroQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorMailingListPHIDTypeList extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorMailingListQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class ManiphestPHIDTypeTask extends PhabricatorPHIDType {
|
|||
|
||||
return id(new ManiphestTaskQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorOwnersPHIDTypePackage extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorOwnersPackageQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorPastePHIDTypePaste extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorPasteQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorPeoplePHIDTypeExternal extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorExternalAccountQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -21,10 +21,11 @@ final class PhabricatorPeoplePHIDTypeUser extends PhabricatorPHIDType {
|
|||
array $phids) {
|
||||
|
||||
return id(new PhabricatorPeopleQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->needProfileImage(true)
|
||||
->needStatus(true)
|
||||
->setViewer($query->getViewer())
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ final class PhabricatorPhamePHIDTypeBlog extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhameBlogQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ final class PhabricatorPhamePHIDTypePost extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhamePostQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhluxPHIDTypeVariable extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhluxVariableQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PholioPHIDTypeImage extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PholioImageQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PholioPHIDTypeMock extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PholioMockQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhrictionPHIDTypeDocument extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhrictionDocumentQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PonderPHIDTypeAnswer extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PonderAnswerQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PonderPHIDTypeQuestion extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PonderQuestionQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorProjectPHIDTypeProject extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorProjectQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class ReleephPHIDTypeBranch extends PhabricatorPHIDType {
|
|||
|
||||
return id(new ReleephBranchQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class ReleephPHIDTypeProject extends PhabricatorPHIDType {
|
|||
|
||||
return id(new ReleephProjectQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class ReleephPHIDTypeRequest extends PhabricatorPHIDType {
|
|||
|
||||
return id(new ReleephRequestQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -23,8 +23,10 @@ final class PhabricatorRepositoryPHIDTypeArcanistProject
|
|||
public function loadObjects(
|
||||
PhabricatorObjectQuery $query,
|
||||
array $phids) {
|
||||
|
||||
return id(new PhabricatorRepositoryArcanistProjectQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorRepositoryPHIDTypeCommit extends PhabricatorPHIDType {
|
|||
|
||||
return id(new DiffusionCommitQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ final class PhabricatorRepositoryPHIDTypeRepository
|
|||
|
||||
return id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorSlowvotePHIDTypePoll extends PhabricatorPHIDType {
|
|||
|
||||
return id(new PhabricatorSlowvoteQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->setParentQuery($query)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ final class PhabricatorApplicationTransactionPHIDTypeTransaction
|
|||
|
||||
$xactions = id(clone $query)
|
||||
->setViewer($object_query->getViewer())
|
||||
->setParentQuery($object_query)
|
||||
->withPHIDs($subtype_phids)
|
||||
->execute();
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
|
|||
|
||||
private $viewer;
|
||||
private $raisePolicyExceptions;
|
||||
private $parentQuery;
|
||||
private $rawResultLimit;
|
||||
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
|
||||
*/
|
||||
|
@ -89,7 +136,6 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
|
|||
* }
|
||||
*
|
||||
* If zero results match the query, this method returns `null`.
|
||||
*
|
||||
* If one result matches the query, this method returns that result.
|
||||
*
|
||||
* 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() {
|
||||
|
||||
$this->raisePolicyExceptions = true;
|
||||
$this->setRaisePolicyExceptions(true);
|
||||
try {
|
||||
$results = $this->execute();
|
||||
} catch (Exception $ex) {
|
||||
$this->raisePolicyExceptions = false;
|
||||
$this->setRaisePolicyExceptions(false);
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
|
@ -136,6 +182,12 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
|
|||
throw new Exception("Call setViewer() before execute()!");
|
||||
}
|
||||
|
||||
$parent_query = $this->getParentQuery();
|
||||
if ($parent_query) {
|
||||
$this->setRaisePolicyExceptions(
|
||||
$parent_query->shouldRaisePolicyExceptions());
|
||||
}
|
||||
|
||||
$results = array();
|
||||
|
||||
$filter = new PhabricatorPolicyFilter();
|
||||
|
@ -149,7 +201,7 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
|
|||
$capabilities = $this->capabilities;
|
||||
}
|
||||
$filter->requireCapabilities($capabilities);
|
||||
$filter->raisePolicyExceptions($this->raisePolicyExceptions);
|
||||
$filter->raisePolicyExceptions($this->shouldRaisePolicyExceptions());
|
||||
|
||||
$offset = (int)$this->getOffset();
|
||||
$limit = (int)$this->getLimit();
|
||||
|
|
Loading…
Reference in a new issue