Differential D21837 Diff 52049 src/applications/files/engineextension/PhabricatorFilesCurtainExtension.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/engineextension/PhabricatorFilesCurtainExtension.php
Show All 28 Lines | $attachments = id(new PhabricatorFileAttachmentQuery()) | ||||
->needFiles(true) | ->needFiles(true) | ||||
->execute(); | ->execute(); | ||||
$visible_attachments = array_slice($attachments, 0, $visible_limit, true); | $visible_attachments = array_slice($attachments, 0, $visible_limit, true); | ||||
$visible_phids = mpull($visible_attachments, 'getFilePHID'); | $visible_phids = mpull($visible_attachments, 'getFilePHID'); | ||||
$handles = $viewer->loadHandles($visible_phids); | $handles = $viewer->loadHandles($visible_phids); | ||||
PhabricatorPolicyFilterSet::loadHandleViewCapabilities( | |||||
$viewer, | |||||
$handles, | |||||
array($object)); | |||||
$ref_list = id(new PHUICurtainObjectRefListView()) | $ref_list = id(new PHUICurtainObjectRefListView()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->setEmptyMessage(pht('None')); | ->setEmptyMessage(pht('None')); | ||||
$view_capability = PhabricatorPolicyCapability::CAN_VIEW; | |||||
$object_policies = PhabricatorPolicyQuery::loadPolicies( | |||||
$viewer, | |||||
$object); | |||||
$object_policy = idx($object_policies, $view_capability); | |||||
foreach ($visible_attachments as $attachment) { | foreach ($visible_attachments as $attachment) { | ||||
$file_phid = $attachment->getFilePHID(); | $file_phid = $attachment->getFilePHID(); | ||||
$handle = $handles[$file_phid]; | $handle = $handles[$file_phid]; | ||||
$ref = $ref_list->newObjectRefView() | $ref = $ref_list->newObjectRefView() | ||||
->setHandle($handle); | ->setHandle($handle); | ||||
if ($handle->hasCapabilities()) { | $file = $attachment->getFile(); | ||||
if (!$handle->hasViewCapability($object)) { | if (!$file) { | ||||
$ref->setExiled(true); | // ... | ||||
} else { | |||||
if (!$attachment->isPolicyAttachment()) { | |||||
$file_policies = PhabricatorPolicyQuery::loadPolicies( | |||||
$viewer, | |||||
$file); | |||||
$file_policy = idx($file_policies, $view_capability); | |||||
if ($object_policy->isStrongerThanOrEqualTo($file_policy)) { | |||||
// The file is not attached to the object, but the file policy | |||||
// allows anyone who can see the object to see the file too, so | |||||
// there is no material problem with the file not being attached. | |||||
} else { | |||||
$attach_uri = urisprintf( | |||||
'/file/ui/curtain/attach/%s/%s/', | |||||
$object->getPHID(), | |||||
$file->getPHID()); | |||||
$attached_link = javelin_tag( | |||||
'a', | |||||
array( | |||||
'href' => $attach_uri, | |||||
'sigil' => 'workflow', | |||||
), | |||||
pht('File Not Attached')); | |||||
$ref->setExiled( | |||||
true, | |||||
$attached_link); | |||||
} | |||||
} | } | ||||
} | } | ||||
$epoch = $attachment->getDateCreated(); | $epoch = $attachment->getDateCreated(); | ||||
$ref->setEpoch($epoch); | $ref->setEpoch($epoch); | ||||
} | } | ||||
$show_all = (count($visible_attachments) < count($attachments)); | $show_all = (count($visible_attachments) < count($attachments)); | ||||
if ($show_all) { | if ($show_all) { | ||||
$view_all_uri = urisprintf( | $view_all_uri = urisprintf( | ||||
'/file/ui/curtainlist/%s/', | '/file/ui/curtain/list/%s/', | ||||
$object->getPHID()); | $object->getPHID()); | ||||
$loaded_count = count($attachments); | $loaded_count = count($attachments); | ||||
if ($loaded_count > $exact_limit) { | if ($loaded_count > $exact_limit) { | ||||
$link_text = pht('View All Files'); | $link_text = pht('View All Files'); | ||||
} else { | } else { | ||||
$link_text = pht('View All %d Files', new PhutilNumber($loaded_count)); | $link_text = pht('View All %d Files', new PhutilNumber($loaded_count)); | ||||
} | } | ||||
$ref_list->newTailLink() | $ref_list->newTailLink() | ||||
->setURI($view_all_uri) | ->setURI($view_all_uri) | ||||
->setText($link_text) | ->setText($link_text) | ||||
->setWorkflow(true); | ->setWorkflow(true); | ||||
} | } | ||||
return $this->newPanel() | return $this->newPanel() | ||||
->setHeaderText(pht('Attached Files')) | ->setHeaderText(pht('Referenced Files')) | ||||
->setOrder(15000) | ->setOrder(15000) | ||||
->appendChild($ref_list); | ->appendChild($ref_list); | ||||
} | } | ||||
} | } |