Check for mimetype during template upload
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
e414e0c840
Коммит
db417fe8f7
|
@ -135,6 +135,13 @@ class TemplatesController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
if (!$this->manager->isValidTemplateMime($files['type'][0])) {
|
||||
return new JSONResponse(
|
||||
['data' => ['message' => $this->l10n->t('Only template files can be uploaded')]],
|
||||
Http::STATUS_BAD_REQUEST
|
||||
);
|
||||
}
|
||||
|
||||
$templateName = $files['name'][0];
|
||||
$templateFile = file_get_contents($files['tmp_name'][0]);
|
||||
|
||||
|
|
|
@ -203,13 +203,7 @@ class TemplateManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($type !== null && !in_array($templateFile->getMimeType(), self::$tplTypes[$type])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Todo validate mimetypes etc
|
||||
|
||||
return true;
|
||||
return $this->isValidTemplateMime($templateFile->getMimeType(), $type);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -489,4 +483,19 @@ class TemplateManager {
|
|||
'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
|
||||
];
|
||||
}
|
||||
|
||||
public function isValidTemplateMime($mime, $type = null) {
|
||||
if ($type === null) {
|
||||
$allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation']);
|
||||
if (!in_array($mime, $allMimes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type !== null && !in_array($mime, self::$tplTypes[$type])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче