Skip to content

Commit c9fe162

Browse files
author
epriestley
committed
Fix an issue where file queries would throw incorrectly
Summary: Ref T4589. When you look at a file, we load attached objects in order to run the "you can see this if you can see any attached object" policy check. However, right now the subquery inherits the "throw on filter" flag from the parent query. This inheritance makes sense in other cases[1], but because this is an "ANY" rule it does not make sense here. In practice, it means that if the file is attached to several objects, and any of them gets filtered, you can not see the file. Instead, explicitly drop the flag for this subquery. [1] Sort of. It doesn't produce wrong results in other cases, but now that I think about it might produce a less-tailored error than it could. I'll look into this the next time I'm poking around. Test Plan: - Viewed an "All Users" file attached to a private Mock. - Prior to this patch, I incorrectly received an exception when the Mock was loaded. This is wrong; I should be able to see the file because the policy is "All Users". - After the patch, I can correctly view the file, just not the associated mock. {F127074} Reviewers: btrahan Reviewed By: btrahan Subscribers: 20after4, aran, epriestley Maniphest Tasks: T4589 Differential Revision: https://secure.phabricator.com/D8498
1 parent 9181929 commit c9fe162

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/applications/files/query/PhabricatorFileQuery.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,16 @@ protected function loadPage() {
137137

138138
$objects = array();
139139
if ($object_phids) {
140+
// NOTE: We're explicitly turning policy exceptions off, since the rule
141+
// here is "you can see the file if you can see ANY associated object".
142+
// Without this explicit flag, we'll incorrectly throw unless you can
143+
// see ALL associated objects.
144+
140145
$objects = id(new PhabricatorObjectQuery())
141146
->setParentQuery($this)
142147
->setViewer($this->getViewer())
143148
->withPHIDs($object_phids)
149+
->setRaisePolicyExceptions(false)
144150
->execute();
145151
$objects = mpull($objects, null, 'getPHID');
146152
}

src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,22 @@
2929
abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery {
3030

3131
private $viewer;
32-
private $raisePolicyExceptions;
3332
private $parentQuery;
3433
private $rawResultLimit;
3534
private $capabilities;
3635
private $workspace = array();
3736
private $policyFilteredPHIDs = array();
3837
private $canUseApplication;
3938

39+
/**
40+
* Should we continue or throw an exception when a query result is filtered
41+
* by policy rules?
42+
*
43+
* Values are `true` (raise exceptions), `false` (do not raise exceptions)
44+
* and `null` (inherit from parent query, with no exceptions by default).
45+
*/
46+
private $raisePolicyExceptions;
47+
4048

4149
/* -( Query Configuration )------------------------------------------------ */
4250

@@ -186,7 +194,7 @@ final public function execute() {
186194
}
187195

188196
$parent_query = $this->getParentQuery();
189-
if ($parent_query) {
197+
if ($parent_query && ($this->raisePolicyExceptions === null)) {
190198
$this->setRaisePolicyExceptions(
191199
$parent_query->shouldRaisePolicyExceptions());
192200
}

0 commit comments

Comments
 (0)