Skip to content
Snippets Groups Projects
Commit aa3d2867 authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

Merge branch 'feature_max_file_size' into 'master'

Feature max file size

See merge request !7
parents 9184fc96 69be7603
No related branches found
No related tags found
1 merge request!7Feature max file size
...@@ -39,11 +39,16 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; ...@@ -39,11 +39,16 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException; use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/** /**
* The joblist plugin controller * The joblist plugin controller
*/ */
class JoblistController extends ActionController { class JoblistController extends ActionController {
// the array key for the error message in the post array
const ERROR_KEY_IN_POST = 'error';
/** /**
* @var \SGalinski\SgJobs\Domain\Repository\CompanyRepository * @var \SGalinski\SgJobs\Domain\Repository\CompanyRepository
* @inject * @inject
...@@ -189,6 +194,11 @@ class JoblistController extends ActionController { ...@@ -189,6 +194,11 @@ class JoblistController extends ActionController {
} }
$this->view->assign('applyData', $applyData); $this->view->assign('applyData', $applyData);
$this->view->assign('maxFileSize', $this->settings['allowedMaxFileSize']);
$this->view->assign('maxFileSizeMb', ((int) $this->settings['allowedMaxFileSize'] / 1000) . ' MByte');
$this->view->assign(
'maxFileSizeMessage', LocalizationUtility::translate('error.maxFileSizeMessage', 'sg_jobs')
);
} }
/** /**
...@@ -256,6 +266,7 @@ class JoblistController extends ActionController { ...@@ -256,6 +266,7 @@ class JoblistController extends ActionController {
* @param JobApplication $applyData * @param JobApplication $applyData
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
*/ */
public function applyAction(JobApplication $applyData) { public function applyAction(JobApplication $applyData) {
$folderName = $this->request->getArgument('folderName'); $folderName = $this->request->getArgument('folderName');
...@@ -457,4 +468,32 @@ class JoblistController extends ActionController { ...@@ -457,4 +468,32 @@ class JoblistController extends ActionController {
$this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]); $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]);
} }
} }
/**
* checks for allowed maximum file sizes
*
* @param JobApplication $applyData
* @return bool
* @throws \InvalidArgumentException
*/
private function checkFileSizes($applyData): bool {
$coverLetterSize = (int) $applyData->getCoverLetter()->getOriginalResource()->getSize() / 1000;
$cvSize = (int) $applyData->getCv()->getOriginalResource()->getSize() / 1000;
$certificateSize = (int) $applyData->getCertificate()->getOriginalResource()->getSize() / 1000;
$allowedMaxFileSize = (int) $this->settings['allowedMaxFileSize'];
if ($allowedMaxFileSize === 0) {
return TRUE;
}
if ($allowedMaxFileSize < $coverLetterSize
|| $allowedMaxFileSize < $cvSize
|| $allowedMaxFileSize < $certificateSize) {
return FALSE;
}
return TRUE;
}
} }
...@@ -17,6 +17,8 @@ plugin.tx_sgjobs { ...@@ -17,6 +17,8 @@ plugin.tx_sgjobs {
allowedFileExtensions = pdf allowedFileExtensions = pdf
# cat=plugin.tx_sgjobs/other; type=string; label=Allowed mime types for uploads in the Fluid template (comma separated) # cat=plugin.tx_sgjobs/other; type=string; label=Allowed mime types for uploads in the Fluid template (comma separated)
allowedMimeTypes = application/pdf allowedMimeTypes = application/pdf
# cat=plugin.tx_sgjobs/other; type=string; label=Allowed maximum file size for uploads in kB
allowedMaxFileSize = 5000
} }
pagebrowser.settings { pagebrowser.settings {
......
...@@ -24,6 +24,7 @@ plugin.tx_sgjobs { ...@@ -24,6 +24,7 @@ plugin.tx_sgjobs {
settings { settings {
allowedFileExtensions = {$plugin.tx_sgjobs.settings.allowedFileExtensions} allowedFileExtensions = {$plugin.tx_sgjobs.settings.allowedFileExtensions}
allowedMimeTypes = {$plugin.tx_sgjobs.settings.allowedMimeTypes} allowedMimeTypes = {$plugin.tx_sgjobs.settings.allowedMimeTypes}
allowedMaxFileSize = {$plugin.tx_sgjobs.settings.allowedMaxFileSize}
} }
features { features {
......
...@@ -138,6 +138,10 @@ ...@@ -138,6 +138,10 @@
<source>Please select one of the following pages:</source> <source>Please select one of the following pages:</source>
<target>Bitte wählen Sie eine der folgenden Seiten aus:</target> <target>Bitte wählen Sie eine der folgenden Seiten aus:</target>
</trans-unit> </trans-unit>
<trans-unit id="error.maxFileSizeMessage" approved="yes">
<source>The selected file exceeds the maximum file size</source>
<target>Die ausgewählte Datei ist zu groß!</target>
</trans-unit>
<trans-unit id="frontend.allVacancies" approved="yes"> <trans-unit id="frontend.allVacancies" approved="yes">
<source>All vacancies</source> <source>All vacancies</source>
<target>Alle offenen Stellen</target> <target>Alle offenen Stellen</target>
...@@ -214,6 +218,10 @@ ...@@ -214,6 +218,10 @@
<source>Location*</source> <source>Location*</source>
<target>Standort*</target> <target>Standort*</target>
</trans-unit> </trans-unit>
<trans-unit id="frontend.apply.maxFileSize" approved="yes">
<source>Maximum file size:</source>
<target>Maximale Dateigröße:</target>
</trans-unit>
<trans-unit id="frontend.apply.message" approved="yes"> <trans-unit id="frontend.apply.message" approved="yes">
<source>Message</source> <source>Message</source>
<target>Ihre Nachricht</target> <target>Ihre Nachricht</target>
......
...@@ -105,6 +105,9 @@ ...@@ -105,6 +105,9 @@
<trans-unit id="backend.selectRootPage"> <trans-unit id="backend.selectRootPage">
<source>Please select one of the following pages:</source> <source>Please select one of the following pages:</source>
</trans-unit> </trans-unit>
<trans-unit id="error.maxFileSizeMessage">
<source>The selected file exceeds the maximum file size</source>
</trans-unit>
<trans-unit id="frontend.allVacancies"> <trans-unit id="frontend.allVacancies">
<source>All vacancies</source> <source>All vacancies</source>
</trans-unit> </trans-unit>
...@@ -162,6 +165,9 @@ ...@@ -162,6 +165,9 @@
<trans-unit id="frontend.apply.location"> <trans-unit id="frontend.apply.location">
<source>Location*</source> <source>Location*</source>
</trans-unit> </trans-unit>
<trans-unit id="frontend.apply.maxFileSize">
<source>Maximum file size:</source>
</trans-unit>
<trans-unit id="frontend.apply.message"> <trans-unit id="frontend.apply.message">
<source>Message</source> <source>Message</source>
</trans-unit> </trans-unit>
......
...@@ -61,6 +61,10 @@ ...@@ -61,6 +61,10 @@
<source>Zip</source> <source>Zip</source>
<target>邮编</target> <target>邮编</target>
</trans-unit> </trans-unit>
<trans-unit id="error.maxFileSizeMessage" approved="yes">
<source>The selected file exceeds the maximum file size</source>
<target>The selected file exceeds the maximum file size</target>
</trans-unit>
<trans-unit id="frontend.allVacancies" approved="yes"> <trans-unit id="frontend.allVacancies" approved="yes">
<source>All vacancies</source> <source>All vacancies</source>
<target>所有职位机会</target> <target>所有职位机会</target>
...@@ -133,6 +137,10 @@ ...@@ -133,6 +137,10 @@
<source>Location*</source> <source>Location*</source>
<target>地点 *</target> <target>地点 *</target>
</trans-unit> </trans-unit>
<trans-unit id="frontend.apply.maxFileSize" approved="yes">
<source>Maximum file size:</source>
<target>Maximum file size:</target>
</trans-unit>
<trans-unit id="frontend.apply.message" approved="yes"> <trans-unit id="frontend.apply.message" approved="yes">
<source>Message</source> <source>Message</source>
<target>您的消息</target> <target>您的消息</target>
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
</f:if> </f:if>
</div> </div>
<div class="default-content-element"> <div class="default-content-element">
<input id="maxFileSize" type="hidden" data-maxFileSize="{maxFileSize}" />
<input id="maxFileSizeMessage" type="hidden" data-maxFileSizeMessage="{maxFileSizeMessage}" />
<f:form action="apply" controller="Joblist" method="post" name="applyData" object="{applyData}" enctype="multipart/form-data"> <f:form action="apply" controller="Joblist" method="post" name="applyData" object="{applyData}" enctype="multipart/form-data">
<f:if condition="{job}"> <f:if condition="{job}">
<f:then> <f:then>
......
...@@ -13,6 +13,9 @@ export default class SgJobs { ...@@ -13,6 +13,9 @@ export default class SgJobs {
constructor() { constructor() {
$('.remove-file').on('click', this._removeFile); $('.remove-file').on('click', this._removeFile);
$('#sgjobs-joblist').on('change', '.sgjobs-select', this._filterJoblist); $('#sgjobs-joblist').on('change', '.sgjobs-select', this._filterJoblist);
$('#apply-cover-letter').on('change', SgJobs._checkFileSize);
$('#apply-cv').on('change', SgJobs._checkFileSize);
$('#apply-certificate').on('change', SgJobs._checkFileSize);
} }
/** /**
...@@ -41,7 +44,19 @@ export default class SgJobs { ...@@ -41,7 +44,19 @@ export default class SgJobs {
* *
* @private * @private
*/ */
_filterJoblist() { static _filterJoblist() {
$('#sgjobs-filter').submit(); $('#sgjobs-filter').submit();
} }
/**
* Check the file size of the upload fields
*
* @private
*/
static _checkFileSize(event) {
if (event.currentTarget.files[0].size > document.querySelector('#maxFileSize').getAttribute('data-maxFilesize') * 1000) {
alert(document.querySelector('#maxFileSizeMessage').getAttribute('data-maxFileSizeMessage'));
event.currentTarget.value = '';
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment