diff --git a/src/applications/files/query/PhabricatorFileQuery.php b/src/applications/files/query/PhabricatorFileQuery.php --- a/src/applications/files/query/PhabricatorFileQuery.php +++ b/src/applications/files/query/PhabricatorFileQuery.php @@ -137,10 +137,16 @@ $objects = array(); if ($object_phids) { + // NOTE: We're explicitly turning policy exceptions off, since the rule + // here is "you can see the file if you can see ANY associated object". + // Without this explicit flag, we'll incorrectly throw unless you can + // see ALL associated objects. + $objects = id(new PhabricatorObjectQuery()) ->setParentQuery($this) ->setViewer($this->getViewer()) ->withPHIDs($object_phids) + ->setRaisePolicyExceptions(false) ->execute(); $objects = mpull($objects, null, 'getPHID'); } diff --git a/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php --- a/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php +++ b/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php @@ -29,7 +29,6 @@ abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery { private $viewer; - private $raisePolicyExceptions; private $parentQuery; private $rawResultLimit; private $capabilities; @@ -37,6 +36,15 @@ private $policyFilteredPHIDs = array(); private $canUseApplication; + /** + * Should we continue or throw an exception when a query result is filtered + * by policy rules? + * + * Values are `true` (raise exceptions), `false` (do not raise exceptions) + * and `null` (inherit from parent query, with no exceptions by default). + */ + private $raisePolicyExceptions; + /* -( Query Configuration )------------------------------------------------ */ @@ -186,7 +194,7 @@ } $parent_query = $this->getParentQuery(); - if ($parent_query) { + if ($parent_query && ($this->raisePolicyExceptions === null)) { $this->setRaisePolicyExceptions( $parent_query->shouldRaisePolicyExceptions()); }