From 07b8becfc6d58d2cc1bc2ea710cd8dc2df0399fe Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Wed, 11 Sep 2013 12:19:34 -0700 Subject: [PATCH] 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 --- .../phid/PhabricatorConfigPHIDTypeConfig.php | 1 + .../PhabricatorConpherencePHIDTypeThread.php | 3 +- .../PhabricatorCountdownPHIDTypeCountdown.php | 1 + .../phid/DifferentialPHIDTypeRevision.php | 1 + .../diviner/phid/DivinerPHIDTypeAtom.php | 1 + .../diviner/phid/DivinerPHIDTypeBook.php | 1 + .../phid/PhabricatorFilePHIDTypeFile.php | 1 + .../herald/phid/HeraldPHIDTypeRule.php | 1 + .../PhabricatorLegalpadPHIDTypeDocument.php | 5 +- .../phid/PhabricatorMacroPHIDTypeMacro.php | 1 + .../PhabricatorMailingListPHIDTypeList.php | 1 + .../maniphest/phid/ManiphestPHIDTypeTask.php | 1 + .../phid/PhabricatorOwnersPHIDTypePackage.php | 1 + .../phid/PhabricatorPastePHIDTypePaste.php | 1 + .../PhabricatorPeoplePHIDTypeExternal.php | 1 + .../phid/PhabricatorPeoplePHIDTypeUser.php | 5 +- .../phid/PhabricatorPhamePHIDTypeBlog.php | 1 + .../phid/PhabricatorPhamePHIDTypePost.php | 1 + .../phlux/phid/PhluxPHIDTypeVariable.php | 1 + .../pholio/phid/PholioPHIDTypeImage.php | 1 + .../pholio/phid/PholioPHIDTypeMock.php | 1 + .../phid/PhrictionPHIDTypeDocument.php | 1 + .../ponder/phid/PonderPHIDTypeAnswer.php | 1 + .../ponder/phid/PonderPHIDTypeQuestion.php | 1 + .../PhabricatorProjectPHIDTypeProject.php | 1 + .../releeph/phid/ReleephPHIDTypeBranch.php | 1 + .../releeph/phid/ReleephPHIDTypeProject.php | 1 + .../releeph/phid/ReleephPHIDTypeRequest.php | 1 + ...catorRepositoryPHIDTypeArcanistProject.php | 2 + .../PhabricatorRepositoryPHIDTypeCommit.php | 1 + ...habricatorRepositoryPHIDTypeRepository.php | 1 + .../phid/PhabricatorSlowvotePHIDTypePoll.php | 1 + ...licationTransactionPHIDTypeTransaction.php | 1 + .../policy/PhabricatorPolicyAwareQuery.php | 60 +++++++++++++++++-- 34 files changed, 95 insertions(+), 9 deletions(-) diff --git a/src/applications/config/phid/PhabricatorConfigPHIDTypeConfig.php b/src/applications/config/phid/PhabricatorConfigPHIDTypeConfig.php index 04234c27b4..ae297edbef 100644 --- a/src/applications/config/phid/PhabricatorConfigPHIDTypeConfig.php +++ b/src/applications/config/phid/PhabricatorConfigPHIDTypeConfig.php @@ -22,6 +22,7 @@ final class PhabricatorConfigPHIDTypeConfig extends PhabricatorPHIDType { return id(new PhabricatorConfigEntryQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/conpherence/phid/PhabricatorConpherencePHIDTypeThread.php b/src/applications/conpherence/phid/PhabricatorConpherencePHIDTypeThread.php index 5e360ad642..dba81f2642 100644 --- a/src/applications/conpherence/phid/PhabricatorConpherencePHIDTypeThread.php +++ b/src/applications/conpherence/phid/PhabricatorConpherencePHIDTypeThread.php @@ -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(); } diff --git a/src/applications/countdown/phid/PhabricatorCountdownPHIDTypeCountdown.php b/src/applications/countdown/phid/PhabricatorCountdownPHIDTypeCountdown.php index c2661c02a3..c816a1054d 100644 --- a/src/applications/countdown/phid/PhabricatorCountdownPHIDTypeCountdown.php +++ b/src/applications/countdown/phid/PhabricatorCountdownPHIDTypeCountdown.php @@ -22,6 +22,7 @@ final class PhabricatorCountdownPHIDTypeCountdown extends PhabricatorPHIDType { return id(new PhabricatorCountdownQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/differential/phid/DifferentialPHIDTypeRevision.php b/src/applications/differential/phid/DifferentialPHIDTypeRevision.php index 3a2ff3647d..414afc7d0d 100644 --- a/src/applications/differential/phid/DifferentialPHIDTypeRevision.php +++ b/src/applications/differential/phid/DifferentialPHIDTypeRevision.php @@ -22,6 +22,7 @@ final class DifferentialPHIDTypeRevision extends PhabricatorPHIDType { return id(new DifferentialRevisionQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/diviner/phid/DivinerPHIDTypeAtom.php b/src/applications/diviner/phid/DivinerPHIDTypeAtom.php index 51f8c472c3..a563ec45c6 100644 --- a/src/applications/diviner/phid/DivinerPHIDTypeAtom.php +++ b/src/applications/diviner/phid/DivinerPHIDTypeAtom.php @@ -22,6 +22,7 @@ final class DivinerPHIDTypeAtom extends PhabricatorPHIDType { return id(new DivinerAtomQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/diviner/phid/DivinerPHIDTypeBook.php b/src/applications/diviner/phid/DivinerPHIDTypeBook.php index c36bb1249a..2d80555371 100644 --- a/src/applications/diviner/phid/DivinerPHIDTypeBook.php +++ b/src/applications/diviner/phid/DivinerPHIDTypeBook.php @@ -22,6 +22,7 @@ final class DivinerPHIDTypeBook extends PhabricatorPHIDType { return id(new DivinerBookQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/files/phid/PhabricatorFilePHIDTypeFile.php b/src/applications/files/phid/PhabricatorFilePHIDTypeFile.php index 04c11128e5..50586bee78 100644 --- a/src/applications/files/phid/PhabricatorFilePHIDTypeFile.php +++ b/src/applications/files/phid/PhabricatorFilePHIDTypeFile.php @@ -22,6 +22,7 @@ final class PhabricatorFilePHIDTypeFile extends PhabricatorPHIDType { return id(new PhabricatorFileQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/herald/phid/HeraldPHIDTypeRule.php b/src/applications/herald/phid/HeraldPHIDTypeRule.php index 9e517cf61d..1c408cbb46 100644 --- a/src/applications/herald/phid/HeraldPHIDTypeRule.php +++ b/src/applications/herald/phid/HeraldPHIDTypeRule.php @@ -22,6 +22,7 @@ final class HeraldPHIDTypeRule extends PhabricatorPHIDType { return id(new HeraldRuleQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php b/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php index 345c8252e8..d1e1fcc8cc 100644 --- a/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php +++ b/src/applications/legalpad/phid/PhabricatorLegalpadPHIDTypeDocument.php @@ -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(); } diff --git a/src/applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php b/src/applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php index 906ddcfafd..bc9b7a8d61 100644 --- a/src/applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php +++ b/src/applications/macro/phid/PhabricatorMacroPHIDTypeMacro.php @@ -22,6 +22,7 @@ final class PhabricatorMacroPHIDTypeMacro extends PhabricatorPHIDType { return id(new PhabricatorMacroQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/mailinglists/phid/PhabricatorMailingListPHIDTypeList.php b/src/applications/mailinglists/phid/PhabricatorMailingListPHIDTypeList.php index ec9462d97d..eee01d277a 100644 --- a/src/applications/mailinglists/phid/PhabricatorMailingListPHIDTypeList.php +++ b/src/applications/mailinglists/phid/PhabricatorMailingListPHIDTypeList.php @@ -22,6 +22,7 @@ final class PhabricatorMailingListPHIDTypeList extends PhabricatorPHIDType { return id(new PhabricatorMailingListQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/maniphest/phid/ManiphestPHIDTypeTask.php b/src/applications/maniphest/phid/ManiphestPHIDTypeTask.php index b81bc354cf..dd076bc511 100644 --- a/src/applications/maniphest/phid/ManiphestPHIDTypeTask.php +++ b/src/applications/maniphest/phid/ManiphestPHIDTypeTask.php @@ -22,6 +22,7 @@ final class ManiphestPHIDTypeTask extends PhabricatorPHIDType { return id(new ManiphestTaskQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php b/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php index cf8ce0b667..af7976aad0 100644 --- a/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php +++ b/src/applications/owners/phid/PhabricatorOwnersPHIDTypePackage.php @@ -22,6 +22,7 @@ final class PhabricatorOwnersPHIDTypePackage extends PhabricatorPHIDType { return id(new PhabricatorOwnersPackageQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/paste/phid/PhabricatorPastePHIDTypePaste.php b/src/applications/paste/phid/PhabricatorPastePHIDTypePaste.php index 8e068f23cb..024cdd9f16 100644 --- a/src/applications/paste/phid/PhabricatorPastePHIDTypePaste.php +++ b/src/applications/paste/phid/PhabricatorPastePHIDTypePaste.php @@ -22,6 +22,7 @@ final class PhabricatorPastePHIDTypePaste extends PhabricatorPHIDType { return id(new PhabricatorPasteQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/people/phid/PhabricatorPeoplePHIDTypeExternal.php b/src/applications/people/phid/PhabricatorPeoplePHIDTypeExternal.php index 4332260034..b3c0044e60 100644 --- a/src/applications/people/phid/PhabricatorPeoplePHIDTypeExternal.php +++ b/src/applications/people/phid/PhabricatorPeoplePHIDTypeExternal.php @@ -22,6 +22,7 @@ final class PhabricatorPeoplePHIDTypeExternal extends PhabricatorPHIDType { return id(new PhabricatorExternalAccountQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/people/phid/PhabricatorPeoplePHIDTypeUser.php b/src/applications/people/phid/PhabricatorPeoplePHIDTypeUser.php index b9dbc51422..4cf6e21f30 100644 --- a/src/applications/people/phid/PhabricatorPeoplePHIDTypeUser.php +++ b/src/applications/people/phid/PhabricatorPeoplePHIDTypeUser.php @@ -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(); } diff --git a/src/applications/phame/phid/PhabricatorPhamePHIDTypeBlog.php b/src/applications/phame/phid/PhabricatorPhamePHIDTypeBlog.php index e13d378a7c..fe24e757b5 100644 --- a/src/applications/phame/phid/PhabricatorPhamePHIDTypeBlog.php +++ b/src/applications/phame/phid/PhabricatorPhamePHIDTypeBlog.php @@ -25,6 +25,7 @@ final class PhabricatorPhamePHIDTypeBlog extends PhabricatorPHIDType { return id(new PhameBlogQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/phame/phid/PhabricatorPhamePHIDTypePost.php b/src/applications/phame/phid/PhabricatorPhamePHIDTypePost.php index c9556c538f..790b1084f6 100644 --- a/src/applications/phame/phid/PhabricatorPhamePHIDTypePost.php +++ b/src/applications/phame/phid/PhabricatorPhamePHIDTypePost.php @@ -25,6 +25,7 @@ final class PhabricatorPhamePHIDTypePost extends PhabricatorPHIDType { return id(new PhamePostQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/phlux/phid/PhluxPHIDTypeVariable.php b/src/applications/phlux/phid/PhluxPHIDTypeVariable.php index cfb479c329..e6dc1a5f66 100644 --- a/src/applications/phlux/phid/PhluxPHIDTypeVariable.php +++ b/src/applications/phlux/phid/PhluxPHIDTypeVariable.php @@ -22,6 +22,7 @@ final class PhluxPHIDTypeVariable extends PhabricatorPHIDType { return id(new PhluxVariableQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/pholio/phid/PholioPHIDTypeImage.php b/src/applications/pholio/phid/PholioPHIDTypeImage.php index a9696803b7..87c5dadf48 100644 --- a/src/applications/pholio/phid/PholioPHIDTypeImage.php +++ b/src/applications/pholio/phid/PholioPHIDTypeImage.php @@ -22,6 +22,7 @@ final class PholioPHIDTypeImage extends PhabricatorPHIDType { return id(new PholioImageQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/pholio/phid/PholioPHIDTypeMock.php b/src/applications/pholio/phid/PholioPHIDTypeMock.php index dfc4467688..ced9f5e9cf 100644 --- a/src/applications/pholio/phid/PholioPHIDTypeMock.php +++ b/src/applications/pholio/phid/PholioPHIDTypeMock.php @@ -22,6 +22,7 @@ final class PholioPHIDTypeMock extends PhabricatorPHIDType { return id(new PholioMockQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/phriction/phid/PhrictionPHIDTypeDocument.php b/src/applications/phriction/phid/PhrictionPHIDTypeDocument.php index 3f357d9f68..554457bba0 100644 --- a/src/applications/phriction/phid/PhrictionPHIDTypeDocument.php +++ b/src/applications/phriction/phid/PhrictionPHIDTypeDocument.php @@ -22,6 +22,7 @@ final class PhrictionPHIDTypeDocument extends PhabricatorPHIDType { return id(new PhrictionDocumentQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/ponder/phid/PonderPHIDTypeAnswer.php b/src/applications/ponder/phid/PonderPHIDTypeAnswer.php index 388677e156..b6d10c2d7a 100644 --- a/src/applications/ponder/phid/PonderPHIDTypeAnswer.php +++ b/src/applications/ponder/phid/PonderPHIDTypeAnswer.php @@ -22,6 +22,7 @@ final class PonderPHIDTypeAnswer extends PhabricatorPHIDType { return id(new PonderAnswerQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/ponder/phid/PonderPHIDTypeQuestion.php b/src/applications/ponder/phid/PonderPHIDTypeQuestion.php index aba99a254d..32a81a5d28 100644 --- a/src/applications/ponder/phid/PonderPHIDTypeQuestion.php +++ b/src/applications/ponder/phid/PonderPHIDTypeQuestion.php @@ -22,6 +22,7 @@ final class PonderPHIDTypeQuestion extends PhabricatorPHIDType { return id(new PonderQuestionQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/project/phid/PhabricatorProjectPHIDTypeProject.php b/src/applications/project/phid/PhabricatorProjectPHIDTypeProject.php index 82b6936341..e160caebcb 100644 --- a/src/applications/project/phid/PhabricatorProjectPHIDTypeProject.php +++ b/src/applications/project/phid/PhabricatorProjectPHIDTypeProject.php @@ -22,6 +22,7 @@ final class PhabricatorProjectPHIDTypeProject extends PhabricatorPHIDType { return id(new PhabricatorProjectQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/releeph/phid/ReleephPHIDTypeBranch.php b/src/applications/releeph/phid/ReleephPHIDTypeBranch.php index b4a51a1399..7106dfc9a1 100644 --- a/src/applications/releeph/phid/ReleephPHIDTypeBranch.php +++ b/src/applications/releeph/phid/ReleephPHIDTypeBranch.php @@ -22,6 +22,7 @@ final class ReleephPHIDTypeBranch extends PhabricatorPHIDType { return id(new ReleephBranchQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/releeph/phid/ReleephPHIDTypeProject.php b/src/applications/releeph/phid/ReleephPHIDTypeProject.php index 753dff0315..f127b75849 100644 --- a/src/applications/releeph/phid/ReleephPHIDTypeProject.php +++ b/src/applications/releeph/phid/ReleephPHIDTypeProject.php @@ -22,6 +22,7 @@ final class ReleephPHIDTypeProject extends PhabricatorPHIDType { return id(new ReleephProjectQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/releeph/phid/ReleephPHIDTypeRequest.php b/src/applications/releeph/phid/ReleephPHIDTypeRequest.php index 116cda9503..a3529a612c 100644 --- a/src/applications/releeph/phid/ReleephPHIDTypeRequest.php +++ b/src/applications/releeph/phid/ReleephPHIDTypeRequest.php @@ -22,6 +22,7 @@ final class ReleephPHIDTypeRequest extends PhabricatorPHIDType { return id(new ReleephRequestQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php index 47f7df3f9a..49f24131a8 100644 --- a/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php +++ b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php @@ -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(); } diff --git a/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php index 72ed350e22..34f4c4be57 100644 --- a/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php +++ b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php @@ -22,6 +22,7 @@ final class PhabricatorRepositoryPHIDTypeCommit extends PhabricatorPHIDType { return id(new DiffusionCommitQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php index cfda831fd9..70e4c8bf48 100644 --- a/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php +++ b/src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php @@ -23,6 +23,7 @@ final class PhabricatorRepositoryPHIDTypeRepository return id(new PhabricatorRepositoryQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/slowvote/phid/PhabricatorSlowvotePHIDTypePoll.php b/src/applications/slowvote/phid/PhabricatorSlowvotePHIDTypePoll.php index 6eaf8d3230..7f40a8a7ac 100644 --- a/src/applications/slowvote/phid/PhabricatorSlowvotePHIDTypePoll.php +++ b/src/applications/slowvote/phid/PhabricatorSlowvotePHIDTypePoll.php @@ -22,6 +22,7 @@ final class PhabricatorSlowvotePHIDTypePoll extends PhabricatorPHIDType { return id(new PhabricatorSlowvoteQuery()) ->setViewer($query->getViewer()) + ->setParentQuery($query) ->withPHIDs($phids) ->execute(); } diff --git a/src/applications/transactions/phid/PhabricatorApplicationTransactionPHIDTypeTransaction.php b/src/applications/transactions/phid/PhabricatorApplicationTransactionPHIDTypeTransaction.php index 4e59f7ce20..d818dad226 100644 --- a/src/applications/transactions/phid/PhabricatorApplicationTransactionPHIDTypeTransaction.php +++ b/src/applications/transactions/phid/PhabricatorApplicationTransactionPHIDTypeTransaction.php @@ -57,6 +57,7 @@ final class PhabricatorApplicationTransactionPHIDTypeTransaction $xactions = id(clone $query) ->setViewer($object_query->getViewer()) + ->setParentQuery($object_query) ->withPHIDs($subtype_phids) ->execute(); diff --git a/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php index b16a47db73..a5e74c6a2b 100644 --- a/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php +++ b/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php @@ -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();