diff --git a/Classes/Controller/JoblistController.php b/Classes/Controller/JoblistController.php index 5840f7d7f944b0143631855de276c1b466d09d5f..5faa3c9aa901d3e037e40ba44fce355a2448a548 100644 --- a/Classes/Controller/JoblistController.php +++ b/Classes/Controller/JoblistController.php @@ -39,11 +39,16 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException; +use TYPO3\CMS\Extbase\Mvc\Request; +use TYPO3\CMS\Extbase\Utility\LocalizationUtility; /** * The joblist plugin controller */ 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 * @inject @@ -189,6 +194,11 @@ class JoblistController extends ActionController { } $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 { * @param JobApplication $applyData * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException * @throws \InvalidArgumentException + * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException */ public function applyAction(JobApplication $applyData) { $folderName = $this->request->getArgument('folderName'); @@ -457,4 +468,32 @@ class JoblistController extends ActionController { $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; + } } diff --git a/Configuration/TypoScript/Frontend/constants.ts b/Configuration/TypoScript/Frontend/constants.ts index f991c3f562ebec8cc18cf5d3697d9e0810bd4a98..8a85b59fc64deecaff8ae134d95747ecee39f132 100644 --- a/Configuration/TypoScript/Frontend/constants.ts +++ b/Configuration/TypoScript/Frontend/constants.ts @@ -17,6 +17,8 @@ plugin.tx_sgjobs { allowedFileExtensions = pdf # cat=plugin.tx_sgjobs/other; type=string; label=Allowed mime types for uploads in the Fluid template (comma separated) allowedMimeTypes = application/pdf + # cat=plugin.tx_sgjobs/other; type=string; label=Allowed maximum file size for uploads in kB + allowedMaxFileSize = 5000 } pagebrowser.settings { diff --git a/Configuration/TypoScript/Frontend/setup.ts b/Configuration/TypoScript/Frontend/setup.ts index ab78a4069fe0d76cbd2c8a74d58c615a0b3c38b2..c0e6406dabe0fd700a2f33640003eeb944db34cf 100644 --- a/Configuration/TypoScript/Frontend/setup.ts +++ b/Configuration/TypoScript/Frontend/setup.ts @@ -24,6 +24,7 @@ plugin.tx_sgjobs { settings { allowedFileExtensions = {$plugin.tx_sgjobs.settings.allowedFileExtensions} allowedMimeTypes = {$plugin.tx_sgjobs.settings.allowedMimeTypes} + allowedMaxFileSize = {$plugin.tx_sgjobs.settings.allowedMaxFileSize} } features { diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 3634116a7680d3f7be85d62b487001a8ad6fe8c8..f31a4a7713a452236bc209ba1104ed0018ffb579 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -138,6 +138,10 @@ <source>Please select one of the following pages:</source> <target>Bitte wählen Sie eine der folgenden Seiten aus:</target> </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"> <source>All vacancies</source> <target>Alle offenen Stellen</target> @@ -214,6 +218,10 @@ <source>Location*</source> <target>Standort*</target> </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"> <source>Message</source> <target>Ihre Nachricht</target> diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index d94719fd55d8aa1e7d41e9eb1f426465190637a6..458d63024742459755870338573ddb571cf5aff3 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -105,6 +105,9 @@ <trans-unit id="backend.selectRootPage"> <source>Please select one of the following pages:</source> </trans-unit> + <trans-unit id="error.maxFileSizeMessage"> + <source>The selected file exceeds the maximum file size</source> + </trans-unit> <trans-unit id="frontend.allVacancies"> <source>All vacancies</source> </trans-unit> @@ -162,6 +165,9 @@ <trans-unit id="frontend.apply.location"> <source>Location*</source> </trans-unit> + <trans-unit id="frontend.apply.maxFileSize"> + <source>Maximum file size:</source> + </trans-unit> <trans-unit id="frontend.apply.message"> <source>Message</source> </trans-unit> diff --git a/Resources/Private/Language/zh.locallang.xlf b/Resources/Private/Language/zh.locallang.xlf index 6157739349eda3d4a6f0a507f73866cd9f6ae459..9ee34e8b54eae4e0004b4ffce883e30924ebca75 100644 --- a/Resources/Private/Language/zh.locallang.xlf +++ b/Resources/Private/Language/zh.locallang.xlf @@ -61,6 +61,10 @@ <source>Zip</source> <target>邮编</target> </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"> <source>All vacancies</source> <target>所有èŒä½æœºä¼š</target> @@ -133,6 +137,10 @@ <source>Location*</source> <target>地点 *</target> </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"> <source>Message</source> <target>您的消æ¯</target> diff --git a/Resources/Private/Templates/Joblist/ApplyForm.html b/Resources/Private/Templates/Joblist/ApplyForm.html index bb438f4526638c6b10078a74fd0db2823cee373d..eb0929baea4652d2fb56b8e1421bbc13d1e3a382 100644 --- a/Resources/Private/Templates/Joblist/ApplyForm.html +++ b/Resources/Private/Templates/Joblist/ApplyForm.html @@ -14,6 +14,8 @@ </f:if> </div> <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:if condition="{job}"> <f:then> diff --git a/Resources/Public/JavaScript/sgJobs.js b/Resources/Public/JavaScript/sgJobs.js index 7e90dacf9eb9142089c42c74f9751f0b4e5c4a35..f7c9fd368c2e5e5396cf89c841f343beeb8d8f33 100644 --- a/Resources/Public/JavaScript/sgJobs.js +++ b/Resources/Public/JavaScript/sgJobs.js @@ -13,6 +13,9 @@ export default class SgJobs { constructor() { $('.remove-file').on('click', this._removeFile); $('#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 { * * @private */ - _filterJoblist() { + static _filterJoblist() { $('#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 = ''; + } + } }