Skip to content

Commit

Permalink
fix: replacing folders
Browse files Browse the repository at this point in the history
Fixes the "Replace" conflict option when copying/moving a folder.

The mechanism of `isOverwritingParentFolder` falsely prevented this though it should only care about the edge case scenario when moving a sub-folder with the same name as the current folder's parent folder into the parent (via breadcrumbs). This needs an additional check if the current folder differs from the target location.
  • Loading branch information
JammingBen committed Mar 14, 2024
1 parent 7afd825 commit 66b6379
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-folder-replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Folder replace

The "Replace" conflict option, which previously didn't work at all when trying to copy/move a folder, has been fixed.

https://github.com/owncloud/web/issues/10515
https://github.com/owncloud/web/pull/10597
13 changes: 12 additions & 1 deletion packages/web-app-files/src/helpers/resource/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {
} from '@ownclouders/web-pkg'

import { TransferType } from '.'
import { Ref, unref } from 'vue'

export class ResourceTransfer extends ConflictDialog {
constructor(
private sourceSpace: SpaceResource,
private resourcesToMove: Resource[],
private targetSpace: SpaceResource,
private targetFolder: Resource,
private currentFolder: Ref<Resource>,
private clientService: ClientService,
private loadingService: LoadingService,
createModal: (modal: object) => void,
Expand Down Expand Up @@ -141,10 +143,19 @@ export class ResourceTransfer extends ConflictDialog {
}

// This is for an edge case if a user moves a subfolder with the same name as the parent folder into the parent of the parent folder (which is not possible because of the backend)
public isOverwritingParentFolder(resource, targetFolder, targetFolderResources) {
public isOverwritingParentFolder(
resource: Resource,
targetFolder: Resource,
targetFolderResources: Resource[]
) {
if (resource.type !== 'folder') {
return false
}

if (targetFolder.path === unref(this.currentFolder)?.path) {
return false
}

const folderName = basename(resource.path)
const newPath = join(targetFolder.path, folderName)
return targetFolderResources.some((resource) => resource.path === newPath)
Expand Down
2 changes: 2 additions & 0 deletions packages/web-app-files/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ClientService, LoadingTaskCallbackArguments } from '@ownclouders/web-pk
import { Language } from 'vue3-gettext'
import { eventBus } from '@ownclouders/web-pkg'
import { AncestorMetaData } from '@ownclouders/web-pkg'
import { computed } from 'vue'

const allowSharePermissions = (getters) => {
return (
Expand Down Expand Up @@ -95,6 +96,7 @@ export default {
resources,
targetSpace,
context.state.currentFolder,
computed(() => context.state.currentFolder),
clientService,
loadingService,
createModal,
Expand Down
1 change: 1 addition & 0 deletions packages/web-app-files/src/views/spaces/GenericSpace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ export default defineComponent({
selected,
this.space,
targetFolder,
this.currentFolder,
this.$clientService,
this.$loadingService,
this.createModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { mock, mockDeep, mockReset } from 'jest-mock-extended'
import { buildSpace, Resource } from '@ownclouders/web-client/src/helpers'
import { ListFilesResult } from '@ownclouders/web-client/src/webdav/listFiles'
import { Drive } from '@ownclouders/web-client/src/generated'
import { computed } from 'vue'

const clientServiceMock = mockDeep<ClientService>()
const loadingServiceMock = mock<LoadingService>({
Expand Down Expand Up @@ -62,6 +63,7 @@ describe('resourcesTransfer', () => {
resourcesToMove,
targetSpace,
resourcesToMove[0],
computed(() => mock<Resource>()),
clientServiceMock,
loadingServiceMock,
jest.fn(),
Expand Down Expand Up @@ -91,6 +93,7 @@ describe('resourcesTransfer', () => {
resourcesToMove,
targetSpace,
targetFolder,
computed(() => mock<Resource>()),
clientServiceMock,
loadingServiceMock,
jest.fn(),
Expand Down Expand Up @@ -131,6 +134,7 @@ describe('resourcesTransfer', () => {
resourcesToMove,
targetSpace,
resourcesToMove[0],
computed(() => mock<Resource>()),
clientServiceMock,
loadingServiceMock,
jest.fn(),
Expand Down Expand Up @@ -161,6 +165,7 @@ describe('resourcesTransfer', () => {
resourcesToMove,
targetSpace,
resourcesToMove[0],
computed(() => mock<Resource>()),
clientServiceMock,
loadingServiceMock,
jest.fn(),
Expand Down

0 comments on commit 66b6379

Please sign in to comment.