Path: blob/master/src/applications/files/controller/PhabricatorFileUICurtainAttachController.php
12242 views
<?php12final class PhabricatorFileUICurtainAttachController3extends PhabricatorFileController {45public function handleRequest(AphrontRequest $request) {6$viewer = $request->getViewer();78$object_phid = $request->getURIData('objectPHID');9$file_phid = $request->getURIData('filePHID');1011$object = id(new PhabricatorObjectQuery())12->setViewer($viewer)13->withPHIDs(array($object_phid))14->executeOne();15if (!$object) {16return new Aphront404Response();17}1819$attachment = id(new PhabricatorFileAttachmentQuery())20->setViewer($viewer)21->withObjectPHIDs(array($object->getPHID()))22->withFilePHIDs(array($file_phid))23->needFiles(true)24->withVisibleFiles(true)25->executeOne();26if (!$attachment) {27return new Aphront404Response();28}2930$handles = $viewer->loadHandles(31array(32$object_phid,33$file_phid,34));3536$object_handle = $handles[$object_phid];37$file_handle = $handles[$file_phid];38$cancel_uri = $object_handle->getURI();3940$dialog = $this->newDialog()41->setViewer($viewer)42->setTitle(pht('Attach File'))43->addCancelButton($cancel_uri, pht('Close'));4445$file_link = phutil_tag('strong', array(), $file_handle->renderLink());46$object_link = phutil_tag('strong', array(), $object_handle->renderLink());4748if ($attachment->isPolicyAttachment()) {49$body = pht(50'The file %s is already attached to the object %s.',51$file_link,52$object_link);5354return $dialog->appendParagraph($body);55}5657if (!$request->isDialogFormPost()) {58$dialog->appendRemarkup(59pht(60'(WARNING) This file is referenced by this object, but '.61'not formally attached to it. Users who can see the object may '.62'not be able to see the file.'));6364$dialog->appendParagraph(65pht(66'Do you want to attach the file %s to the object %s?',67$file_link,68$object_link));6970$dialog->addSubmitButton(pht('Attach File'));7172return $dialog;73}7475if (!$request->getBool('confirm')) {76$dialog->setTitle(pht('Confirm File Attachment'));7778$dialog->addHiddenInput('confirm', 1);7980$dialog->appendRemarkup(81pht(82'(IMPORTANT) If you attach this file to this object, any user who '.83'has permission to view the object will be able to view and '.84'download the file!'));8586$dialog->appendParagraph(87pht(88'Really attach the file %s to the object %s, allowing any user '.89'who can view the object to view and download the file?',90$file_link,91$object_link));9293$dialog->addSubmitButton(pht('Grant Permission'));9495return $dialog;96}9798if (!($object instanceof PhabricatorApplicationTransactionInterface)) {99$dialog->appendParagraph(100pht(101'This object (of class "%s") does not implement the required '.102'interface ("%s"), so files can not be manually attached to it.',103get_class($object),104'PhabricatorApplicationTransactionInterface'));105106return $dialog;107}108109$editor = $object->getApplicationTransactionEditor()110->setActor($viewer)111->setContentSourceFromRequest($request)112->setContinueOnNoEffect(true)113->setContinueOnMissingFields(true);114115$template = $object->getApplicationTransactionTemplate();116117$xactions = array();118119$xactions[] = id(clone $template)120->setTransactionType(PhabricatorTransactions::TYPE_FILE)121->setNewValue(122array(123$file_phid => PhabricatorFileAttachment::MODE_ATTACH,124));125126$editor->applyTransactions($object, $xactions);127128return $this->newRedirect()129->setURI($cancel_uri);130}131132}133134135