1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Allow users to set an explicit visibility for manual file uploads at creation time

Summary: Ref T4589. Depends on D10129. In addition to letting users change the visibility policy for files, also allow them to choose a policy explicitly when a file is uploaded.

Test Plan: Uploaded several files using the plain old uploader, saw appropriate visibility policies applied.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4589

Differential Revision: https://secure.phabricator.com/D10130
This commit is contained in:
epriestley 2014-08-02 14:45:59 -07:00
parent 4c04d4d019
commit 1f1828e0c0

View file

@ -4,11 +4,15 @@ final class PhabricatorFileUploadController extends PhabricatorFileController {
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $viewer = $request->getUser();
$file = new PhabricatorFile();
$e_file = true; $e_file = true;
$errors = array(); $errors = array();
if ($request->isFormPost()) { if ($request->isFormPost()) {
$view_policy = $request->getStr('viewPolicy');
if (!$request->getFileExists('file')) { if (!$request->getFileExists('file')) {
$e_file = pht('Required'); $e_file = pht('Required');
$errors[] = pht('You must select a file to upload.'); $errors[] = pht('You must select a file to upload.');
@ -17,7 +21,8 @@ final class PhabricatorFileUploadController extends PhabricatorFileController {
idx($_FILES, 'file'), idx($_FILES, 'file'),
array( array(
'name' => $request->getStr('name'), 'name' => $request->getStr('name'),
'authorPHID' => $user->getPHID(), 'authorPHID' => $viewer->getPHID(),
'viewPolicy' => $view_policy,
'isExplicitUpload' => true, 'isExplicitUpload' => true,
)); ));
} }
@ -25,6 +30,8 @@ final class PhabricatorFileUploadController extends PhabricatorFileController {
if (!$errors) { if (!$errors) {
return id(new AphrontRedirectResponse())->setURI($file->getInfoURI()); return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
} }
$file->setViewPolicy($view_policy);
} }
$support_id = celerity_generate_unique_node_id(); $support_id = celerity_generate_unique_node_id();
@ -38,8 +45,13 @@ final class PhabricatorFileUploadController extends PhabricatorFileController {
'You can also upload files by dragging and dropping them from your '. 'You can also upload files by dragging and dropping them from your '.
'desktop onto this page or the Phabricator home page.'))); 'desktop onto this page or the Phabricator home page.')));
$policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
->setObject($file)
->execute();
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->setEncType('multipart/form-data') ->setEncType('multipart/form-data')
->appendChild( ->appendChild(
id(new AphrontFormFileControl()) id(new AphrontFormFileControl())
@ -51,8 +63,14 @@ final class PhabricatorFileUploadController extends PhabricatorFileController {
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel(pht('Name')) ->setLabel(pht('Name'))
->setName('name') ->setName('name')
->setValue($request->getStr('name')) ->setValue($request->getStr('name')))
->setCaption(pht('Optional file display name.'))) ->appendChild(
id(new AphrontFormPolicyControl())
->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($file)
->setPolicies($policies)
->setName('viewPolicy'))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue(pht('Upload')) ->setValue(pht('Upload'))
@ -65,7 +83,7 @@ final class PhabricatorFileUploadController extends PhabricatorFileController {
$title = pht('Upload File'); $title = pht('Upload File');
$global_upload = id(new PhabricatorGlobalUploadTargetView()) $global_upload = id(new PhabricatorGlobalUploadTargetView())
->setUser($user) ->setUser($viewer)
->setShowIfSupportedID($support_id); ->setShowIfSupportedID($support_id);
$form_box = id(new PHUIObjectBoxView()) $form_box = id(new PHUIObjectBoxView())