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

Enable rename on shared resource #7390

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion packages/web-app-files/src/helpers/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export function buildSharedResource(
}
resource.canDownload = () => parseInt(share.state) === ShareStatus.accepted
resource.canShare = () => SharePermissions.share.enabled(share.permissions)
resource.canRename = () => SharePermissions.update.enabled(share.permissions)
resource.canRename = () => parseInt(share.state) === ShareStatus.accepted
resource.canBeDeleted = () => SharePermissions.delete.enabled(share.permissions)
} else {
resource.sharedWith = share.sharedWith || []
Expand Down
35 changes: 21 additions & 14 deletions packages/web-app-files/src/mixins/actions/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Resource } from 'web-client'
import { dirname, join } from 'path'
import { WebDAV } from 'web-client/src/webdav'
import { SpaceResource } from 'web-client/src/helpers'
import { SHARE_JAIL_ID } from 'files/src/services/folder'

export default {
computed: {
Expand Down Expand Up @@ -34,16 +35,6 @@ export default {
if (resources.length !== 1) {
return false
}
// FIXME: once renaming shares in share_jail has been sorted out backend side we can enable renaming shares again
if (
this.capabilities?.spaces?.share_jail === true &&
(isLocationSharesActive(this.$router, 'files-shares-with-me') ||
(isLocationSpacesActive(this.$router, 'files-spaces-generic') &&
this.space.driveType === 'share' &&
resources[0].path === '/'))
) {
return false
}

const renameDisabled = resources.some((resource) => {
return !resource.canRename()
Expand Down Expand Up @@ -184,17 +175,33 @@ export default {
this.toggleModalConfirmButton()

try {
const hasShareJail = this.capabilities?.spaces?.share_jail === true
space = space || this.space
const newPath = join(dirname(resource.path), newName)
await (this.$clientService.webdav as WebDAV).moveFiles(space, resource, space, {
path: newPath
})
await (this.$clientService.webdav as WebDAV).moveFiles(
space,
resource,
space,
{
path: newPath
},
{
hasShareJail,
shareJailId: SHARE_JAIL_ID
}
)
this.hideModal()

if (isSameResource(resource, this.currentFolder)) {
let driveAliasAndItem = this.space.getDriveAliasAndItem({ path: newPath } as Resource)

if (hasShareJail && resource.isReceivedShare()) {
driveAliasAndItem = `share/${newName}`
}

return this.$router.push({
params: {
driveAliasAndItem: this.space.getDriveAliasAndItem({ path: newPath } as Resource)
driveAliasAndItem
},
query: this.$route.query
})
Expand Down
11 changes: 9 additions & 2 deletions packages/web-client/src/webdav/moveFiles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { urlJoin } from 'web-pkg/src/utils'
import { isPublicSpaceResource, SpaceResource } from '../helpers'
import { isPublicSpaceResource, isShareSpaceResource, SpaceResource } from '../helpers'
import { WebDavOptions } from './types'

export const MoveFilesFactory = ({ sdk }: WebDavOptions) => {
Expand All @@ -9,8 +9,15 @@ export const MoveFilesFactory = ({ sdk }: WebDavOptions) => {
{ path: sourcePath },
targetSpace: SpaceResource,
{ path: targetPath },
options?: { overwrite?: boolean }
options?: { overwrite?: boolean; hasShareJail?: boolean; shareJailId?: string }
): Promise<void> {
if (options?.hasShareJail && isShareSpaceResource(sourceSpace)) {
return sdk.files.move(
`${sourceSpace.webDavPath}/${sourcePath || ''}`,
`/spaces/${options?.shareJailId}!${options?.shareJailId}/${targetPath || ''}`,
options?.overwrite || false
)
}
if (isPublicSpaceResource(sourceSpace)) {
return sdk.publicFiles.move(
urlJoin(sourceSpace.webDavPath.replace(/^\/public-files/, ''), sourcePath),
Expand Down