Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove drop target in read-only folders #8825

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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