From 59e3c8ce6125a6c30f7da7a4ec3a37911862d4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 12 Mar 2020 10:54:11 +0100 Subject: [PATCH] Add back initial state and check for filesize and canCreate permissions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Controller/PageController.php | 14 ++++++++------ package-lock.json | 15 +++++++++++++++ package.json | 3 ++- .../card/CardSidebarTabAttachments.vue | 18 ++++++++++++++++-- src/components/navigation/AppNavigation.vue | 6 +++++- tests/unit/controller/PageControllerTest.php | 6 ++++-- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index bcd45b1c6..720b4aaff 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -23,7 +23,9 @@ namespace OCA\Deck\Controller; +use OCA\Deck\AppInfo\Application; use OCA\Deck\Service\PermissionService; +use OCP\IInitialStateService; use OCP\IRequest; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Controller; @@ -34,11 +36,13 @@ class PageController extends Controller { private $permissionService; private $userId; private $l10n; + private $initialState; public function __construct( $AppName, IRequest $request, PermissionService $permissionService, + IInitialStateService $initialStateService, IL10N $l10n, $userId ) { @@ -46,6 +50,7 @@ class PageController extends Controller { $this->userId = $userId; $this->permissionService = $permissionService; + $this->initialState = $initialStateService; $this->l10n = $l10n; } @@ -57,13 +62,10 @@ class PageController extends Controller { * @NoCSRFRequired */ public function index() { - $params = [ - 'user' => $this->userId, - 'maxUploadSize' => (int)\OCP\Util::uploadLimit(), - 'canCreate' => $this->permissionService->canCreate() - ]; + $this->initialState->provideInitialState(Application::APP_ID, 'maxUploadSize', (int)\OCP\Util::uploadLimit()); + $this->initialState->provideInitialState(Application::APP_ID, 'canCreate', $this->permissionService->canCreate()); - return new TemplateResponse('deck', 'main', $params); + return new TemplateResponse('deck', 'main'); } } diff --git a/package-lock.json b/package-lock.json index 7b326bd34..07efc94ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3500,6 +3500,21 @@ } } }, + "@nextcloud/initial-state": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@nextcloud/initial-state/-/initial-state-1.1.0.tgz", + "integrity": "sha512-c8VNSv7CbcPdaMNQO3ERJUMhsGyCvAgSBlvBHhugYHxGqlySjE+J+SqkpXmqB+eQ/DujDTahBX1IwoF3zjPtOw==", + "requires": { + "core-js": "3.6.1" + }, + "dependencies": { + "core-js": { + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.1.tgz", + "integrity": "sha512-186WjSik2iTGfDjfdCZAxv2ormxtKgemjC3SI6PL31qOA0j5LhTDVjHChccoc7brwLvpvLPiMyRlcO88C4l1QQ==" + } + } + }, "@nextcloud/l10n": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@nextcloud/l10n/-/l10n-1.1.0.tgz", diff --git a/package.json b/package.json index 6ff7e4314..3dc8aac7b 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,10 @@ "@juliushaertl/vue-richtext": "^0.3.0", "@nextcloud/auth": "^1.2.1", "@nextcloud/axios": "^1.3.1", - "@nextcloud/l10n": "^1.1.0", "@nextcloud/dialogs": "^1.2.1", "@nextcloud/files": "^1.0.0", + "@nextcloud/initial-state": "^1.1.0", + "@nextcloud/l10n": "^1.1.0", "@nextcloud/moment": "^1.1.0", "@nextcloud/router": "^1.0.0", "@nextcloud/vue": "^1.4.0", diff --git a/src/components/card/CardSidebarTabAttachments.vue b/src/components/card/CardSidebarTabAttachments.vue index 5b2160e98..c8e154415 100644 --- a/src/components/card/CardSidebarTabAttachments.vue +++ b/src/components/card/CardSidebarTabAttachments.vue @@ -84,6 +84,9 @@ import { Actions, ActionButton, Modal } from '@nextcloud/vue' import { showError } from '@nextcloud/dialogs' import { formatFileSize } from '@nextcloud/files' import relativeDate from '../../mixins/relativeDate' +import { loadState } from '@nextcloud/initial-state' + +const maxUploadSizeState = loadState('deck', 'maxUploadSize') export default { name: 'CardSidebarTabAttachments', @@ -104,6 +107,7 @@ export default { modalShow: false, file: '', overwriteAttachment: null, + maxUploadSize: maxUploadSizeState, } }, computed: { @@ -140,11 +144,21 @@ export default { this.$refs.localAttachments.click() }, async onLocalAttachmentSelected(event) { + const file = event.target.files[0] + if (this.maxUploadSize > 0 && this.file.size > this.maxUploadSize) { + showError( + t('deck', `Failed to upload {name}`, { name: this.file.name }) + ' - ' + + t('deck', 'Maximum file size of {size} exceeded', { size: formatFileSize(this.maxUploadSize) }) + ) + event.target.value = '' + return + } + const bodyFormData = new FormData() bodyFormData.append('cardId', this.card.id) bodyFormData.append('type', 'deck_file') - bodyFormData.append('file', event.target.files[0]) - this.file = event.target.files[0] + bodyFormData.append('file', file) + try { await this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData }) } catch (err) { diff --git a/src/components/navigation/AppNavigation.vue b/src/components/navigation/AppNavigation.vue index 2e48baa6c..e9919dac5 100644 --- a/src/components/navigation/AppNavigation.vue +++ b/src/components/navigation/AppNavigation.vue @@ -39,7 +39,7 @@ :text="t('deck', 'Shared boards')" :boards="sharedBoards" icon="icon-shared" /> - +
request = $this->createMock(IRequest::class); $this->permissionService = $this->createMock(PermissionService::class); $this->config = $this->createMock(IConfig::class); + $this->initialState = $this->createMock(IInitialStateService::class); $this->controller = new PageController( - 'deck', $this->request, $this->permissionService, $this->l10n, $this->userId + 'deck', $this->request, $this->permissionService, $this->initialState, $this->l10n, $this->userId ); }