Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 67e5aed

Browse files
committed
ENH: refs #0377. Upload validation for java uploader and the web api
Also make sure to unlink temporary files once they are processed.
1 parent 0c101e5 commit 67e5aed

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

core/controllers/UploadController.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,27 @@ function processjavauploadAction()
282282
throw new Zend_Exception('You are attempting to upload into the incorrect parent folder');
283283
}
284284

285+
$testingMode = Zend_Registry::get('configGlobal')->environment == 'testing';
285286
$this->Component->Httpupload->setTmpDirectory($this->getTempDirectory());
286-
$this->Component->Httpupload->setTestingMode(Zend_Registry::get('configGlobal')->environment == 'testing');
287+
$this->Component->Httpupload->setTestingMode($testingMode);
287288
$this->Component->Httpupload->setTokenParamName('uploadUniqueIdentifier');
288289
$data = $this->Component->Httpupload->process($params);
289290

291+
$validations = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_VALIDATE_UPLOAD',
292+
array('filename' => $data['filename'],
293+
'size' => $data['size'],
294+
'path' => $data['path'],
295+
'folderId' => $parentId));
296+
foreach($validations as $validation)
297+
{
298+
if(!$validation['status'])
299+
{
300+
unlink($data['path']);
301+
echo '[ERROR]'.$validation['message'];
302+
throw new Zend_Exception($validation['message']);
303+
}
304+
}
305+
290306
if(!empty($data['path']) && file_exists($data['path']) && $data['size'] > 0)
291307
{
292308
if(!isset($params['testingmode']) && isset($this->userSession->JavaUpload->parent))
@@ -309,9 +325,17 @@ function processjavauploadAction()
309325
try
310326
{
311327
$item = $this->Component->Upload->createUploadedItem($this->userSession->Dao, $data['filename'], $data['path'], $parent, $license, $data['md5']);
328+
if(!$testingMode)
329+
{
330+
unlink($data['path']);
331+
}
312332
}
313333
catch(Exception $e)
314334
{
335+
if(!$testingMode)
336+
{
337+
unlink($data['path']);
338+
}
315339
echo "[ERROR] ".$e->getMessage();
316340
throw $e;
317341
}
@@ -426,7 +450,10 @@ public function saveuploadedAction()
426450
}
427451
}
428452
$item = $this->Component->Upload->createUploadedItem($this->userSession->Dao, $filename, $path, $parent, $license);
429-
unlink($path);
453+
if(!$this->isTestingEnv())
454+
{
455+
unlink($path);
456+
}
430457
$this->userSession->uploaded[] = $item->getKey();
431458
}
432459

modules/api/controllers/components/ApiComponent.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,22 @@ function uploadPerform($args)
434434
throw new Exception('Invalid upload mode', MIDAS_INVALID_PARAMETER);
435435
}
436436

437+
if(array_key_exists('folderid', $args))
438+
{
439+
$validations = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_VALIDATE_UPLOAD',
440+
array('filename' => $filename,
441+
'size' => $filesize,
442+
'path' => $filepath,
443+
'folderId' => $args['folderid']));
444+
foreach($validations as $validation)
445+
{
446+
if(!$validation['status'])
447+
{
448+
unlink($filepath);
449+
throw new Exception($validation['message'], MIDAS_INVALID_POLICY);
450+
}
451+
}
452+
}
437453
$uploadComponent = $componentLoader->loadComponent('Upload');
438454
$license = null;
439455
if(isset($folder))

0 commit comments

Comments
 (0)