From 6a69b4699ecb1a7e039f53f05d11155364f5676d Mon Sep 17 00:00:00 2001 From: cpettet Date: Thu, 7 Aug 2014 12:14:17 -0700 Subject: [PATCH] file.upload set policy explicitly Summary: This is pretty basic allowing a user to set the policy as a valid string ('no-one' or 'users') or as a valid PHID. Without an explicit policy a permissive one is set. Test Plan: Tested using the python-phabricator module (very basic api wrapper). The arc cli syntax was evading me. ```import base64 from phabricator import Phabricator phab = Phabricator() with open('mypic.jpg') as f: encoded = base64.b64encode(f.read()) //set no-one as viewer which really means author only? phab.file.upload(name='mypicnoone.jpg', data_base64=encoded, viewPolicy='no-one') //set a specific phid as policy in this case a project phab.file.upload(name='mypicphid.jpg', data_base64=encoded, viewPolicy='PHID-PROJ-fgvvnafmhvkgn2d5a4rf') //no set policy ends up as 'users' i.e. ('all users') phab.file.upload(name='mypicdefault.jpg', data_base64=encoded)``` Not able to really test canCDN attribute but it should be fine and I tried to make it all consistent with D10166 Reviewers: 20after4, epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: 20after4, epriestley, Korvin Maniphest Tasks: T5685 Differential Revision: https://secure.phabricator.com/D10164 --- .../files/conduit/FileUploadConduitAPIMethod.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/applications/files/conduit/FileUploadConduitAPIMethod.php b/src/applications/files/conduit/FileUploadConduitAPIMethod.php index 14b2594dbc..389e314333 100644 --- a/src/applications/files/conduit/FileUploadConduitAPIMethod.php +++ b/src/applications/files/conduit/FileUploadConduitAPIMethod.php @@ -14,6 +14,8 @@ final class FileUploadConduitAPIMethod extends FileConduitAPIMethod { return array( 'data_base64' => 'required nonempty base64-bytes', 'name' => 'optional string', + 'viewPolicy' => 'optional valid policy string or ', + 'canCDN' => 'optional bool', ); } @@ -29,15 +31,26 @@ final class FileUploadConduitAPIMethod extends FileConduitAPIMethod { protected function execute(ConduitAPIRequest $request) { $data = $request->getValue('data_base64'); $name = $request->getValue('name'); - $data = base64_decode($data, $strict = true); + $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(); + } $file = PhabricatorFile::newFromFileData( $data, array( 'name' => $name, 'authorPHID' => $user->getPHID(), + 'viewPolicy' => $view_policy, + 'canCDN' => $can_cdn, + 'isExplicitUpload' => true, )); + return $file->getPHID(); }