mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-28 08:20:57 +01:00
Drag-drop file upload.
Summary: - have files be uploaded by drag+drop instead of browse. - Files are named by their uploaded filename, the user isn't given a chance to enter a file name. Is this bad? - Store author PHID now with files - Allow an ?author=<username> to limit the /files/ list by author. - If one file is uploaded, the user is taken to its info page. - If several are uploaded, they are taken to a list of their files. Test Plan: - Quickly tested everything and it still worked, I'd recommend some people try this out before it gets committed though. It's a rather huge revision. Reviewers: epriestley, Ttech CC: Differential Revision: 612
This commit is contained in:
parent
49310391e0
commit
420235f9c4
18 changed files with 112 additions and 34 deletions
3
resources/sql/patches/055.add_author_to_files.sql
Normal file
3
resources/sql/patches/055.add_author_to_files.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE phabricator_file.file
|
||||
ADD COLUMN authorPHID VARCHAR(64) BINARY,
|
||||
ADD KEY (authorPHID);
|
|
@ -76,7 +76,8 @@ class PhabricatorOAuthDefaultRegistrationController
|
|||
$file = PhabricatorFile::newFromFileData(
|
||||
$image,
|
||||
array(
|
||||
'name' => $provider->getProviderKey().'-profile.jpg'
|
||||
'name' => $provider->getProviderKey().'-profile.jpg',
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$user->setProfileImagePHID($file->getPHID());
|
||||
}
|
||||
|
|
|
@ -45,11 +45,13 @@ class ConduitAPI_file_upload_Method extends ConduitAPIMethod {
|
|||
$data = $request->getValue('data_base64');
|
||||
$name = $request->getValue('name');
|
||||
$data = base64_decode($data, $strict = true);
|
||||
$user = $request->getUser();
|
||||
|
||||
$file = PhabricatorFile::newFromFileData(
|
||||
$data,
|
||||
array(
|
||||
'name' => $name
|
||||
'name' => $name,
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
return $file->getPHID();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ class PhabricatorFileDropUploadController extends PhabricatorFileController {
|
|||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$data = file_get_contents('php://input');
|
||||
$name = $request->getStr('name');
|
||||
|
@ -28,6 +29,7 @@ class PhabricatorFileDropUploadController extends PhabricatorFileController {
|
|||
$data,
|
||||
array(
|
||||
'name' => $request->getStr('name'),
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
|
||||
$view = new AphrontAttachedFileView();
|
||||
|
|
|
@ -22,13 +22,32 @@ class PhabricatorFileListController extends PhabricatorFileController {
|
|||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$author_username = $request->getStr('author');
|
||||
if ($author_username) {
|
||||
$author = id(new PhabricatorUser())->loadOneWhere(
|
||||
'userName = %s',
|
||||
$author_username);
|
||||
|
||||
if (!$author) {
|
||||
return id(new Aphront404Response());
|
||||
}
|
||||
}
|
||||
|
||||
$pager = new AphrontPagerView();
|
||||
$pager->setOffset($request->getInt('page'));
|
||||
|
||||
$files = id(new PhabricatorFile())->loadAllWhere(
|
||||
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
||||
$pager->getOffset(),
|
||||
$pager->getPageSize() + 1);
|
||||
if ($author) {
|
||||
$files = id(new PhabricatorFile())->loadAllWhere(
|
||||
'authorPHID = %s ORDER BY id DESC LIMIT %d, %d',
|
||||
$author->getPHID(),
|
||||
$pager->getOffset(),
|
||||
$pager->getPageSize() + 1);
|
||||
} else {
|
||||
$files = id(new PhabricatorFile())->loadAllWhere(
|
||||
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
||||
$pager->getOffset(),
|
||||
$pager->getPageSize() + 1);
|
||||
}
|
||||
|
||||
$files = $pager->sliceResults($files);
|
||||
$pager->setURI($request->getRequestURI(), 'page');
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'applications/files/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||
phutil_require_module('phabricator', 'view/control/pager');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
|
|
@ -39,6 +39,7 @@ class PhabricatorFileMacroEditController extends PhabricatorFileController {
|
|||
$e_name = true;
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
if ($request->isFormPost()) {
|
||||
|
||||
$macro->setName($request->getStr('name'));
|
||||
|
@ -60,6 +61,7 @@ class PhabricatorFileMacroEditController extends PhabricatorFileController {
|
|||
idx($_FILES, 'file'),
|
||||
array(
|
||||
'name' => $request->getStr('name'),
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$macro->setFilePHID($file->getPHID());
|
||||
|
||||
|
|
|
@ -21,43 +21,47 @@ class PhabricatorFileUploadController extends PhabricatorFileController {
|
|||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
if ($request->isFormPost()) {
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
idx($_FILES, 'file'),
|
||||
array(
|
||||
'name' => $request->getStr('name'),
|
||||
));
|
||||
$user = $request->getUser();
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/file/info/'.phutil_escape_uri($file->getPHID()).'/');
|
||||
if ($request->isFormPost()) {
|
||||
$files = $request->getArr('file');
|
||||
|
||||
if (count($files) > 1) {
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/file/?author='.phutil_escape_uri($user->getUserName()));
|
||||
} else {
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI('/file/info/'.end($files).'/');
|
||||
}
|
||||
}
|
||||
|
||||
$panel_id = celerity_generate_unique_node_id();
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form->setAction('/file/upload/');
|
||||
$form->setUser($request->getUser());
|
||||
|
||||
$form
|
||||
->setEncType('multipart/form-data')
|
||||
|
||||
->appendChild(
|
||||
id(new AphrontFormFileControl())
|
||||
->setLabel('File')
|
||||
->setName('file')
|
||||
->setError(true))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('Name')
|
||||
->setName('name')
|
||||
->setCaption('Optional file display name.'))
|
||||
id(new AphrontFormDragAndDropUploadControl())
|
||||
->setLabel('Files')
|
||||
->setName('file')
|
||||
->setError(true)
|
||||
->setDragAndDropTarget($panel_id)
|
||||
->setActivatedClass('aphront-panel-view-drag-and-drop'))
|
||||
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Upload')
|
||||
->addCancelButton('/file/'));
|
||||
->setValue('Done here!'));
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->setHeader('Upload File');
|
||||
|
||||
$panel->appendChild($form);
|
||||
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
||||
$panel->setID($panel_id);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array($panel),
|
||||
|
|
|
@ -8,11 +8,10 @@
|
|||
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/files/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
phutil_require_module('phabricator', 'view/form/control/file');
|
||||
phutil_require_module('phabricator', 'view/form/control/draganddropupload');
|
||||
phutil_require_module('phabricator', 'view/form/control/submit');
|
||||
phutil_require_module('phabricator', 'view/form/control/text');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
|
|
|
@ -71,6 +71,20 @@ class PhabricatorFileViewController extends PhabricatorFileController {
|
|||
break;
|
||||
}
|
||||
|
||||
$author_child = null;
|
||||
if ($file->getAuthorPHID()) {
|
||||
$author = id(new PhabricatorUser())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$file->getAuthorPHID());
|
||||
|
||||
if ($author) {
|
||||
$author_child = id(new AphrontFormStaticControl())
|
||||
->setLabel('Author')
|
||||
->setName('author')
|
||||
->setValue($author->getUserName());
|
||||
}
|
||||
}
|
||||
|
||||
$form = new AphrontFormView();
|
||||
|
||||
if ($file->isViewableInBrowser()) {
|
||||
|
@ -80,7 +94,7 @@ class PhabricatorFileViewController extends PhabricatorFileController {
|
|||
$form->setAction('/file/download/'.$file->getPHID().'/');
|
||||
$button_name = 'Download File';
|
||||
}
|
||||
$form->setUser($this->getRequest()->getUser());
|
||||
$form->setUser($user);
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormStaticControl())
|
||||
|
@ -92,6 +106,7 @@ class PhabricatorFileViewController extends PhabricatorFileController {
|
|||
->setLabel('PHID')
|
||||
->setName('phid')
|
||||
->setValue($file->getPHID()))
|
||||
->appendChild($author_child)
|
||||
->appendChild(
|
||||
id(new AphrontFormStaticControl())
|
||||
->setLabel('Created')
|
||||
|
|
|
@ -13,6 +13,7 @@ phutil_require_module('phabricator', 'applications/files/controller/base');
|
|||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/transformed');
|
||||
phutil_require_module('phabricator', 'applications/files/uri');
|
||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
phutil_require_module('phabricator', 'view/form/control/static');
|
||||
|
|
|
@ -29,6 +29,7 @@ class PhabricatorFile extends PhabricatorFileDAO {
|
|||
protected $name;
|
||||
protected $mimeType;
|
||||
protected $byteSize;
|
||||
protected $authorPHID;
|
||||
|
||||
protected $storageEngine;
|
||||
protected $storageFormat;
|
||||
|
@ -88,9 +89,14 @@ class PhabricatorFile extends PhabricatorFileDAO {
|
|||
$file_name = idx($params, 'name');
|
||||
$file_name = self::normalizeFileName($file_name);
|
||||
|
||||
// If for whatever reason, authorPHID isn't passed as a param
|
||||
// (always the case with newFromFileDownload()), store a ''
|
||||
$authorPHID = idx($params, 'authorPHID');
|
||||
|
||||
$file = new PhabricatorFile();
|
||||
$file->setName($file_name);
|
||||
$file->setByteSize(strlen($data));
|
||||
$file->setAuthorPHID($authorPHID);
|
||||
|
||||
$blob = new PhabricatorFileStorageBlob();
|
||||
$blob->setData($data);
|
||||
|
|
|
@ -53,7 +53,11 @@ class ManiphestTransactionSaveController extends ManiphestController {
|
|||
if (!empty($_FILES['file'])) {
|
||||
$err = idx($_FILES['file'], 'error');
|
||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||
$file = PhabricatorFile::newFromPHPUpload($_FILES['file']);
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
$_FILES['file'],
|
||||
array(
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class PhabricatorMetaMTASendGridReceiveController
|
|||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$raw_headers = $request->getStr('headers');
|
||||
$raw_headers = explode("\n", rtrim($raw_headers));
|
||||
|
@ -51,7 +52,11 @@ class PhabricatorMetaMTASendGridReceiveController
|
|||
$file_phids = array();
|
||||
foreach ($_FILES as $file_raw) {
|
||||
try {
|
||||
$file = PhabricatorFile::newFromPHPUpload($file_raw);
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
$file_raw,
|
||||
array(
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$file_phids[] = $file->getPHID();
|
||||
} catch (Exception $ex) {
|
||||
phlog($ex);
|
||||
|
|
|
@ -59,6 +59,7 @@ class PhabricatorPasteCreateController extends PhabricatorPasteController {
|
|||
array(
|
||||
'name' => $title,
|
||||
'mime-type' => 'text/plain; charset=utf-8',
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$paste->setFilePHID($paste_file->getPHID());
|
||||
$paste->setAuthorPHID($user->getPHID());
|
||||
|
|
|
@ -40,7 +40,11 @@ class PhabricatorPeopleProfileEditController
|
|||
if (!empty($_FILES['image'])) {
|
||||
$err = idx($_FILES['image'], 'error');
|
||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||
$file = PhabricatorFile::newFromPHPUpload($_FILES['image']);
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
$_FILES['image'],
|
||||
array(
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$okay = $file->isTransformableImage();
|
||||
if ($okay) {
|
||||
$xformer = new PhabricatorImageTransformer();
|
||||
|
|
|
@ -117,7 +117,11 @@ class PhabricatorUserSettingsController extends PhabricatorPeopleController {
|
|||
if (!empty($_FILES['profile'])) {
|
||||
$err = idx($_FILES['profile'], 'error');
|
||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||
$file = PhabricatorFile::newFromPHPUpload($_FILES['profile']);
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
$_FILES['profile'],
|
||||
array(
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$okay = $file->isTransformableImage();
|
||||
if ($okay) {
|
||||
$xformer = new PhabricatorImageTransformer();
|
||||
|
|
|
@ -57,7 +57,11 @@ class PhabricatorProjectProfileEditController
|
|||
if (!empty($_FILES['image'])) {
|
||||
$err = idx($_FILES['image'], 'error');
|
||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||
$file = PhabricatorFile::newFromPHPUpload($_FILES['image']);
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
$_FILES['image'],
|
||||
array(
|
||||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
$okay = $file->isTransformableImage();
|
||||
if ($okay) {
|
||||
$xformer = new PhabricatorImageTransformer();
|
||||
|
|
Loading…
Reference in a new issue