From 7a93b443c3d340ddd33bbd93f1d1740b9b251664 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 17 Mar 2015 06:33:30 -0700 Subject: [PATCH] Make file upload policies more consistent Summary: Ref T7149. Currently, global drag and drop always uses the most open visibility policy on the install. This was appropriate before the application preference was introduced, but default to the application preference now. In particular, this supports a default value of "Administrators" in the Phacility cluster. Also simplify/clean up some code. Test Plan: - Set application default policy to "Adminstrators". - Uploaded file via drag-and-drop, saw "administrators" policy. - Uploaded file via `arc upload`, saw "administrators" policy. - Saw better URI for a text file upload after patch. - Uploaded file via drag-and-drop-to-textarea, saw "only viewer" policy. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7149 Differential Revision: https://secure.phabricator.com/D12093 --- .../files/conduit/FileInfoConduitAPIMethod.php | 2 +- .../files/conduit/FileUploadConduitAPIMethod.php | 13 +++++-------- .../view/PhabricatorGlobalUploadTargetView.php | 9 ++++++++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/applications/files/conduit/FileInfoConduitAPIMethod.php b/src/applications/files/conduit/FileInfoConduitAPIMethod.php index 4a5aa9cdce..d95b002b9a 100644 --- a/src/applications/files/conduit/FileInfoConduitAPIMethod.php +++ b/src/applications/files/conduit/FileInfoConduitAPIMethod.php @@ -45,7 +45,7 @@ final class FileInfoConduitAPIMethod extends FileConduitAPIMethod { throw new ConduitException('ERR-NOT-FOUND'); } - $uri = $file->getBestURI(); + $uri = $file->getInfoURI(); return array( 'id' => $file->getID(), diff --git a/src/applications/files/conduit/FileUploadConduitAPIMethod.php b/src/applications/files/conduit/FileUploadConduitAPIMethod.php index 389e314333..3601594dad 100644 --- a/src/applications/files/conduit/FileUploadConduitAPIMethod.php +++ b/src/applications/files/conduit/FileUploadConduitAPIMethod.php @@ -29,23 +29,20 @@ final class FileUploadConduitAPIMethod extends FileConduitAPIMethod { } protected function execute(ConduitAPIRequest $request) { - $data = $request->getValue('data_base64'); + $viewer = $request->getUser(); + $name = $request->getValue('name'); $can_cdn = $request->getValue('canCDN'); $view_policy = $request->getValue('viewPolicy'); - $user = $request->getUser(); - $data = base64_decode($data, $strict = true); - - if (!$view_policy) { - $view_policy = PhabricatorPolicies::getMostOpenPolicy(); - } + $data = $request->getValue('data_base64'); + $data = $this->decodeBase64($data); $file = PhabricatorFile::newFromFileData( $data, array( 'name' => $name, - 'authorPHID' => $user->getPHID(), + 'authorPHID' => $viewer->getPHID(), 'viewPolicy' => $view_policy, 'canCDN' => $can_cdn, 'isExplicitUpload' => true, diff --git a/src/applications/files/view/PhabricatorGlobalUploadTargetView.php b/src/applications/files/view/PhabricatorGlobalUploadTargetView.php index 8bfe1d6089..815d2ce1cc 100644 --- a/src/applications/files/view/PhabricatorGlobalUploadTargetView.php +++ b/src/applications/files/view/PhabricatorGlobalUploadTargetView.php @@ -23,12 +23,19 @@ final class PhabricatorGlobalUploadTargetView extends AphrontView { require_celerity_resource('global-drag-and-drop-css'); + // Use the configured default view policy. Drag and drop uploads use + // a more restrictive view policy if we don't specify a policy explicitly, + // as the more restrictive policy is correct for most drop targets (like + // Pholio uploads and Remarkup text areas). + + $view_policy = PhabricatorFile::initializeNewFile()->getViewPolicy(); + Javelin::initBehavior('global-drag-and-drop', array( 'ifSupported' => $this->showIfSupportedID, 'instructions' => $instructions_id, 'uploadURI' => '/file/dropupload/', 'browseURI' => '/file/query/authored/', - 'viewPolicy' => PhabricatorPolicies::getMostOpenPolicy(), + 'viewPolicy' => $view_policy, 'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(), ));