Skip to content

Commit

Permalink
Merge pull request #8825 from owncloud/remove-drop-target-in-read-onl…
Browse files Browse the repository at this point in the history
…y-folders

Remove drop target in read-only folders
  • Loading branch information
JammingBen authored Apr 17, 2023
2 parents 18c7691 + 080df3f commit 23c2426
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Remove drop target in read-only folders

The drop target in read-only folders has been removed.

https://github.com/owncloud/web/pull/8825
https://github.com/owncloud/web/issues/8277
47 changes: 26 additions & 21 deletions packages/web-app-files/src/components/AppBar/CreateAndUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ import {
getCurrentInstance,
onMounted,
onBeforeUnmount,
PropType
PropType,
unref,
watch
} from 'vue'
import { useUpload } from 'web-runtime/src/composables/upload'
import { useUploadHelpers } from '../../composables/upload'
Expand Down Expand Up @@ -207,14 +209,16 @@ export default defineComponent({
let filesSelectedSub
let uploadCompletedSub
const currentFolder = computed(() => {
return store.getters['Files/currentFolder']
})
const canUpload = computed(() => {
return unref(currentFolder)?.canUpload({ user: store.getters.user })
})
onMounted(() => {
filesSelectedSub = uppyService.subscribe('filesSelected', instance.onFilesSelected)
uploadCompletedSub = uppyService.subscribe('uploadCompleted', instance.onUploadComplete)
uppyService.useDropTarget({
targetSelector: '#files-view',
uppyService
})
})
onBeforeUnmount(() => {
Expand All @@ -223,6 +227,18 @@ export default defineComponent({
uppyService.removeDropTarget()
})
watch(
canUpload,
() => {
if (unref(canUpload)) {
uppyService.useDropTarget({ targetSelector: '#files-view', uppyService })
} else {
uppyService.removeDropTarget()
}
},
{ immediate: true }
)
return {
...useFileActions({ store }),
...useUpload({
Expand All @@ -240,21 +256,17 @@ export default defineComponent({
isSpacesGenericLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-generic'),
hasShareJail: useCapabilityShareJailEnabled(),
hasSpaces: useCapabilitySpacesEnabled(),
isUserContext: useUserContext({ store })
isUserContext: useUserContext({ store }),
canUpload,
currentFolder
}
},
data: () => ({
newFileAction: null
}),
computed: {
...mapGetters(['capabilities', 'configuration', 'newFileHandlers', 'user']),
...mapGetters('Files', [
'ancestorMetaData',
'files',
'currentFolder',
'selectedFiles',
'clipboardResources'
]),
...mapGetters('Files', ['ancestorMetaData', 'files', 'selectedFiles', 'clipboardResources']),
...mapState('Files', ['areFileExtensionsShown']),
...mapGetters('runtime/spaces', ['spaces']),
Expand Down Expand Up @@ -314,13 +326,6 @@ export default defineComponent({
return !this.canUpload
},
canUpload() {
if (!this.currentFolder) {
return false
}
return this.currentFolder.canUpload({ user: this.user })
},
loadIndicatorsForNewFile() {
return this.isSpacesGenericLocation && this.space.driveType !== 'share'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ describe('CreateAndUpload component', () => {
expect(storeOptions.actions.showMessage).toHaveBeenCalled()
})
})
describe('drop target', () => {
it('is being initialized when user can upload', () => {
const { mocks } = getWrapper()
expect(mocks.$uppyService.useDropTarget).toHaveBeenCalled()
})
it('is not being initialized when user can not upload', () => {
const currentFolder = mockDeep<Resource>({ canUpload: () => false })
const { mocks } = getWrapper({ currentFolder })
expect(mocks.$uppyService.useDropTarget).not.toHaveBeenCalled()
})
})
})

function getWrapper({
Expand Down

0 comments on commit 23c2426

Please sign in to comment.