Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/query/PhabricatorFileQuery.php
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | protected function loadPage() { | ||||
if (!$files) { | if (!$files) { | ||||
return $files; | return $files; | ||||
} | } | ||||
// We need to load attached objects to perform policy checks for files. | // We need to load attached objects to perform policy checks for files. | ||||
// First, load the edges. | // First, load the edges. | ||||
$edge_type = PhabricatorEdgeConfig::TYPE_FILE_HAS_OBJECT; | $edge_type = PhabricatorEdgeConfig::TYPE_FILE_HAS_OBJECT; | ||||
$phids = mpull($files, 'getPHID'); | $file_phids = mpull($files, 'getPHID'); | ||||
$edges = id(new PhabricatorEdgeQuery()) | $edges = id(new PhabricatorEdgeQuery()) | ||||
->withSourcePHIDs($phids) | ->withSourcePHIDs($file_phids) | ||||
->withEdgeTypes(array($edge_type)) | ->withEdgeTypes(array($edge_type)) | ||||
->execute(); | ->execute(); | ||||
$object_phids = array(); | $object_phids = array(); | ||||
foreach ($files as $file) { | foreach ($files as $file) { | ||||
$phids = array_keys($edges[$file->getPHID()][$edge_type]); | $phids = array_keys($edges[$file->getPHID()][$edge_type]); | ||||
$file->attachObjectPHIDs($phids); | $file->attachObjectPHIDs($phids); | ||||
foreach ($phids as $phid) { | foreach ($phids as $phid) { | ||||
$object_phids[$phid] = true; | $object_phids[$phid] = true; | ||||
} | } | ||||
} | } | ||||
// If this file is a transform of another file, load that file too. If you | |||||
// can see the original file, you can see the thumbnail. | |||||
// TODO: It might be nice to put this directly on PhabricatorFile and remove | |||||
// the PhabricatorTransformedFile table, which would be a little simpler. | |||||
$xforms = id(new PhabricatorTransformedFile())->loadAllWhere( | |||||
'transformedPHID IN (%Ls)', | |||||
$file_phids); | |||||
$xform_phids = mpull($xforms, 'getOriginalPHID', 'getTransformedPHID'); | |||||
foreach ($xform_phids as $derived_phid => $original_phid) { | |||||
$object_phids[$original_phid] = true; | |||||
} | |||||
$object_phids = array_keys($object_phids); | $object_phids = array_keys($object_phids); | ||||
// Now, load the objects. | // Now, load the objects. | ||||
$objects = array(); | $objects = array(); | ||||
if ($object_phids) { | if ($object_phids) { | ||||
// NOTE: We're explicitly turning policy exceptions off, since the rule | // 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". | // here is "you can see the file if you can see ANY associated object". | ||||
Show All 9 Lines | if ($object_phids) { | ||||
$objects = mpull($objects, null, 'getPHID'); | $objects = mpull($objects, null, 'getPHID'); | ||||
} | } | ||||
foreach ($files as $file) { | foreach ($files as $file) { | ||||
$file_objects = array_select_keys($objects, $file->getObjectPHIDs()); | $file_objects = array_select_keys($objects, $file->getObjectPHIDs()); | ||||
$file->attachObjects($file_objects); | $file->attachObjects($file_objects); | ||||
} | } | ||||
foreach ($files as $key => $file) { | |||||
$original_phid = idx($xform_phids, $file->getPHID()); | |||||
if ($original_phid == PhabricatorPHIDConstants::PHID_VOID) { | |||||
btrahan: you could use PHID_VOID as the default in the idx() call, and then just use one if… | |||||
// This is a special case for builtin files, which are handled | |||||
// oddly. | |||||
$original = null; | |||||
} else if ($original_phid) { | |||||
$original = idx($objects, $original_phid); | |||||
if (!$original) { | |||||
// If the viewer can't see the original file, also prevent them from | |||||
// seeing the transformed file. | |||||
$this->didRejectResult($file); | |||||
unset($files[$key]); | |||||
continue; | |||||
} | |||||
} else { | |||||
$original = null; | |||||
} | |||||
$file->attachOriginalFile($original); | |||||
} | |||||
return $files; | return $files; | ||||
} | } | ||||
private function buildJoinClause(AphrontDatabaseConnection $conn_r) { | private function buildJoinClause(AphrontDatabaseConnection $conn_r) { | ||||
$joins = array(); | $joins = array(); | ||||
if ($this->transforms) { | if ($this->transforms) { | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |
you could use PHID_VOID as the default in the idx() call, and then just use one if ($original_phid != PHID_VOID)