Add back initial state and check for filesize and canCreate permissions

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-03-12 10:54:11 +01:00
parent 1348990868
commit 59e3c8ce61
6 changed files with 50 additions and 12 deletions

View File

@@ -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) {

View File

@@ -39,7 +39,7 @@
:text="t('deck', 'Shared boards')"
:boards="sharedBoards"
icon="icon-shared" />
<AppNavigationAddBoard />
<AppNavigationAddBoard v-if="canCreate" />
</ul>
<div v-if="isAdmin"
id="app-settings"
@@ -73,6 +73,9 @@ import { Multiselect } from '@nextcloud/vue'
import AppNavigationAddBoard from './AppNavigationAddBoard'
import AppNavigationBoardCategory from './AppNavigationBoardCategory'
import { loadState } from '@nextcloud/initial-state'
const canCreateState = loadState('deck', 'canCreate')
export default {
name: 'AppNavigation',
@@ -96,6 +99,7 @@ export default {
groups: [],
groupLimit: [],
groupLimitDisabled: true,
canCreate: canCreateState,
}
},
computed: {