Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(backend:webdav): properly handle HEAD requests on directories, match lock source file when the file is a space root and extend lock owner information
johavenf1f4836d4038
diff --git a/backend/src/applications/webdav/services/webdav-methods.service.spec.ts b/backend/src/applications/webdav/services/webdav-methods.service.spec.tsindex 3d8b20bb..af2e059f 100644--- a/backend/src/applications/webdav/services/webdav-methods.service.spec.ts+++ b/backend/src/applications/webdav/services/webdav-methods.service.spec.ts@@ -22,7 +22,9 @@ import { WebDAVSpaces } from './webdav-spaces.service'// Mock external dependenciesjest.mock('../../files/utils/files', () => ({- isPathExists: jest.fn(),+ isPathExists: jest.fn().mockReturnValue(false),+ isPathIsDir: jest.fn(),+ fileName: jest.fn().mockReturnValue('fileName'),dirName: jest.fn(),genEtag: jest.fn().mockReturnValue('W/"etag-123"')}))@@ -77,7 +79,7 @@ describe('WebDAVMethods', () => {const createBaseRequest = (overrides: Partial<any> = {}) =>({method: 'GET',- user: { id: 1, login: 'test-user' },+ user: { id: 1, login: 'test-user', fullName: 'Test User', email: '[email protected]' },dav: {url: '/webdav/test/file.txt',depth: '0',@@ -274,6 +276,7 @@ describe('WebDAVMethods', () => {return [true,{+ owner: { fullName: 'LockOwner', email: '[email protected]' },dbFilePath: _dbFile?.path,options: {lockRoot: options.lockRoot,@@ -337,6 +340,7 @@ describe('WebDAVMethods', () => {return [true,{+ owner: { fullName: 'LockOwner', email: '[email protected]' },dbFilePath: _dbFile?.path,options: {lockRoot: options.lockRoot,@@ -365,6 +369,7 @@ describe('WebDAVMethods', () => {filesLockManager.create.mockResolvedValue([false,{+ owner: { fullName: 'LockOwner', email: '[email protected]' },dbFilePath: 'file.txt',options: { lockRoot: '/webdav/locked/resource' }}@@ -517,6 +522,7 @@ describe('WebDAVMethods', () => {filesLockManager.browseLocks.mockResolvedValue({'file.txt': {+ owner: { fullName: 'LockOwner', email: '[email protected]' },options: { lockRoot: '/webdav/test/file.txt' }}} as any)@@ -545,6 +551,7 @@ describe('WebDAVMethods', () => {filesLockManager.browseParentChildLocks.mockResolvedValue({'file.txt': {+ owner: { fullName: 'LockOwner', email: '[email protected]' },options: { lockRoot: '/webdav/test/file.txt' }}} as any)diff --git a/backend/src/applications/webdav/services/webdav-methods.service.ts b/backend/src/applications/webdav/services/webdav-methods.service.tsindex 71805d87..4a4229cb 100644--- a/backend/src/applications/webdav/services/webdav-methods.service.ts+++ b/backend/src/applications/webdav/services/webdav-methods.service.ts@@ -12,15 +12,17 @@ import { FileError } from '../../files/models/file-error'import { LockConflict } from '../../files/models/file-lock-error'import { FilesLockManager } from '../../files/services/files-lock-manager.service'import { FilesManager } from '../../files/services/files-manager.service'-import { dirName, genEtag, isPathExists } from '../../files/utils/files'+import { dirName, fileName, genEtag, isPathExists, isPathIsDir } from '../../files/utils/files'import { SPACE_OPERATION, SPACE_REPOSITORY } from '../../spaces/constants/spaces'import { SpaceEnv } from '../../spaces/models/space-env.model'import { dbFileFromSpace } from '../../spaces/utils/paths'import { haveSpaceEnvPermissions } from '../../spaces/utils/permissions'import {DEPTH,+ HEADER,LOCK_DISCOVERY_PROP,NS_PREFIX,+ OPTIONS_HEADERS,PRECONDITION,PROPPATCH_METHOD,PROPPATCH_MODIFIED_PROPS,@@ -50,6 +52,15 @@ export class WebDAVMethods {async headOrGet(req: FastifyDAVRequest, res: FastifyReply, repository: string): Promise<StreamableFile> {if (repository === SPACE_REPOSITORY.FILES && !req.space.inSharesList) {+ if ((await isPathExists(req.space.realPath)) && (await isPathIsDir(req.space.realPath))) {+ // Directory case+ return res+ .header('DAV', OPTIONS_HEADERS.DAV)+ .header('Content-Type', 'httpd/unix-directory')+ .header('Content-Length', '0')+ .status(HttpStatus.OK)+ .send()+ }const sendFile = this.filesManager.sendFileFromSpace(req.space)try {await sendFile.checks()@@ -108,13 +119,16 @@ export class WebDAVMethods {}const lockProp = LOCK_PROP([fileLock])return res- .header('lock-token', `<${lockOptions.lockToken}>`)+ .header(HEADER.LOCK_TOKEN, `<${lockOptions.lockToken}>`).type(XML_CONTENT_TYPE).status(rExists ? HttpStatus.OK : HttpStatus.CREATED).send(xmlBuild(lockProp))- } else {- return DAV_ERROR_RES(HttpStatus.LOCKED, PRECONDITION.LOCK_CONFLICT, res, fileLock.options?.lockRoot || fileLock.dbFilePath)}+ if (fileLock) {+ const lockProp = LOCK_PROP([fileLock])+ return res.type(XML_CONTENT_TYPE).status(HttpStatus.LOCKED).send(xmlBuild(lockProp))+ }+ return DAV_ERROR_RES(HttpStatus.LOCKED, PRECONDITION.LOCK_CONFLICT, res, fileLock.options?.lockRoot || fileLock.dbFilePath)}@IfHeaderDecorator()@@ -176,7 +190,19 @@ export class WebDAVMethods {for (const p of requestedProps) {let fP: anyif (p === LOCK_DISCOVERY_PROP) {- fP = repository === SPACE_REPOSITORY.FILES && f.name in locks ? LOCK_DISCOVERY([locks[f.name]]) : null+ let lockDiscovery: any[] = null+ if (repository === SPACE_REPOSITORY.FILES) {+ if (f.name in locks) {+ lockDiscovery = LOCK_DISCOVERY([locks[f.name]])+ } else {+ // The lock name may correspond to the original file at the space root.+ const fName = fileName(req.space.dbFile.path)+ if (fName in locks) {+ lockDiscovery = LOCK_DISCOVERY([locks[fName]])+ }+ }+ }+ fP = lockDiscovery} else {fP = f[p]}diff --git a/backend/src/applications/webdav/utils/webdav.ts b/backend/src/applications/webdav/utils/webdav.tsindex 9623bea7..181c023d 100644--- a/backend/src/applications/webdav/utils/webdav.ts+++ b/backend/src/applications/webdav/utils/webdav.ts@@ -72,7 +72,7 @@ export function LOCK_DISCOVERY(locks: FileLock[]) {[`${NS_PREFIX}:lockscope`]: { [`${NS_PREFIX}:${lock.options?.lockScope || LOCK_SCOPE.EXCLUSIVE}`]: null },[`${NS_PREFIX}:locktoken`]: { [`${NS_PREFIX}:href`]: lock.options?.lockToken || SERVER_NAME },[`${NS_PREFIX}:lockroot`]: { [`${NS_PREFIX}:href`]: encodeUrl(lock.options?.lockRoot || lock.dbFilePath) },- [`${NS_PREFIX}:owner`]: lock.options?.lockInfo,+ [`${NS_PREFIX}:owner`]: formatLockOwner(lock),[`${NS_PREFIX}:timeout`]: `Second-${Math.floor(lock.expiration - currentTimeStamp())}`,[`${NS_PREFIX}:depth`]: lock.depth}@@ -94,3 +94,8 @@ export function DAV_ERROR(error: string, href?: string): string {export function DAV_ERROR_RES(code: number, error: string, res: FastifyReply, href?: string): FastifyReply {return res.status(code).type(XML_CONTENT_TYPE).send(DAV_ERROR(error, href))}++function formatLockOwner(lock: FileLock) {+ const lockInfo = `${lock.options.lockInfo ? `${lock.options.lockInfo}` : ''}${lock.app ? ` ${lock.app}` : ''}`+ return `${lock.owner.fullName} (${lock.owner.email})${lockInfo ? ` - ${lockInfo}` : ''}`+}diff --git a/backend/src/applications/webdav/webdav.controller.ts b/backend/src/applications/webdav/webdav.controller.tsindex ac21f6d1..75027345 100644--- a/backend/src/applications/webdav/webdav.controller.ts+++ b/backend/src/applications/webdav/webdav.controller.ts@@ -21,7 +21,7 @@ export class WebDAVController {@Options()serverOptions() {- // OPTIONS method is handled in the `DavProtocolGuard`, return empty response with headers+ // OPTIONS method is handled in the `WebDAVProtocolGuard`, return empty response with headersreturn}@@ -32,7 +32,7 @@ export class WebDAVController {@Options(WEBDAV_BASE_PATH)webdavOptions() {- // OPTIONS method is handled in the `DavProtocolGuard`, return empty response with headers+ // OPTIONS method is handled in the `WebDAVProtocolGuard`, return empty response with headersreturn}@@ -43,7 +43,7 @@ export class WebDAVController {@Options(`${WEBDAV_BASE_PATH}/:repository(^(${WEBDAV_NS.SPACES}|${WEBDAV_NS.TRASH})$)`)repositoriesOptions() {- // OPTIONS method is handled in the `DavProtocolGuard`+ // OPTIONS method is handled in the `WebDAVProtocolGuard`return}@@ -55,7 +55,7 @@ export class WebDAVController {@All(`${WEBDAV_BASE_PATH}/*`)@UseGuards(SpaceGuard)async files(@Req() req: FastifyDAVRequest, @Res({ passthrough: true }) res: FastifyReply) {- // OPTIONS method is handled in the `DavProtocolGuard`+ // OPTIONS method is handled in the `WebDAVProtocolGuard`switch (req.method) {case HTTP_METHOD.PROPFIND:return this.webdavMethods.propfind(req, res, SPACE_REPOSITORY.FILES)diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-collabora-online.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-collabora-online.component.tsindex 7c5e8b86..d862fa31 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-collabora-online.component.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-collabora-online.component.ts@@ -32,10 +32,10 @@ import { fileLockPropsToString } from '../utils/file-lock.utils'styles: [`.collabora-scaling {- transform: scale(0.85);+ transform: scale(0.9);transform-origin: 0 0;- width: calc(100% / 0.85);- height: calc(100% / 0.85);+ width: calc(100% / 0.9);+ height: calc(100% / 0.9);}`]