Skip to content

Commit

Permalink
fix(files): Allow to copy or move file to folder with similar name
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux authored and backportbot[bot] committed Jan 20, 2024
1 parent 26b0bed commit 19a3e97
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apps/files/src/actions/moveOrCopyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ export const handleCopyMoveNodeTo = async (node: Node, destination: Folder, meth
* Do not allow as it would copy foo within itself
* - node: /foo/bar.txt, destination: /foo
* Allow copy a file to the same directory
* - node: "/foo/bar", destination: "/foo/bar 1"
* Allow to move or copy but we need to check with trailing / otherwise it would report false positive
*/
if (destination.path.startsWith(node.path)) {
if (`${destination.path}/`.startsWith(`${node.path}/`)) {
throw new Error(t('files', 'You cannot move a file/folder onto itself or into a subfolder of itself'))
}

Expand Down
31 changes: 31 additions & 0 deletions cypress/e2e/files/files_copy-move.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,37 @@ describe('Files: Move or copy files', { testIsolation: true }, () => {
getRowForFile('new-folder').should('not.exist')
})

// This was a bug previously
it('Can move a file to folder with similar name', () => {
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/original')
.mkdir(currentUser, '/original folder')
cy.login(currentUser)
cy.visit('/apps/files')

// intercept the copy so we can wait for it
cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')

getRowForFile('original').should('be.visible')
triggerActionForFile('original', 'move-copy')

// select new folder
cy.get('.file-picker [data-filename="original folder"]').should('be.visible').click()
// click copy
cy.get('.file-picker').contains('button', 'Move to original folder').should('be.visible').click()

cy.wait('@moveFile')
// wait until visible again
getRowForFile('original folder').should('be.visible')

// original should be moved -> not exist anymore
getRowForFile('original').should('not.exist')
getRowForFile('original folder').should('be.visible').find('[data-cy-files-list-row-name-link]').click()

cy.url().should('contain', 'dir=/original%20folder')
getRowForFile('original').should('be.visible')
getRowForFile('original folder').should('not.exist')
})

it('Can move a file to its parent folder', () => {
cy.mkdir(currentUser, '/new-folder')
cy.uploadContent(currentUser, new Blob(), 'text/plain', '/new-folder/original.txt')
Expand Down

0 comments on commit 19a3e97

Please sign in to comment.