Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(backend:files): ensure locks are visible on anchored and shared files

johaven64453339e1ae
diff --git a/backend/src/applications/files/interfaces/file-props.interface.ts b/backend/src/applications/files/interfaces/file-props.interface.ts
index a3acc836..a08e4bc0 100644
--- a/backend/src/applications/files/interfaces/file-props.interface.ts
+++ b/backend/src/applications/files/interfaces/file-props.interface.ts
@@ -28,7 +28,15 @@ export interface FileProps extends Omit<File, 'ownerId' | 'spaceId' | 'spaceExte
mime: string
inTrash?: boolean
// used with shares
- origin?: { ownerLogin: string; spaceAlias: string; spaceRootExternalPath?: string }
+ origin?: {
+ ownerId: number
+ ownerLogin: string
+ spaceId: number
+ spaceAlias: string
+ spaceExternalRootId: number
+ spaceRootExternalPath: string
+ shareExternalId: number
+ }
// root can be a share or a space root
// enabled, and description are only used for shares
root?: Pick<SpaceRoot, 'id' | 'alias' | 'permissions'> &
diff --git a/backend/src/applications/shares/services/shares-queries.service.ts b/backend/src/applications/shares/services/shares-queries.service.ts
index 4dd51564..a4885d0a 100644
--- a/backend/src/applications/shares/services/shares-queries.service.ts
+++ b/backend/src/applications/shares/services/shares-queries.service.ts
@@ -663,10 +663,14 @@ export class SharesQueries {
ctime: files.ctime,
mtime: files.mtime,
mime: files.mime,
+ originOwnerId: sql`${originOwner.id}`.as('originOwnerId'),
originOwnerLogin: sql`${originOwner.login}`.as('originOwnerLogin'),
+ originSpaceId: sql`${spaces.id}`.as('originSpaceId'),
originSpaceAlias: sql`${spaces.alias}`.as('originSpaceAlias'),
+ originSpaceExternalRootId: sql`${files.spaceExternalRootId}`.as('originSpaceExternalRootId'),
originSpaceRootExternalPath: sql`IF (${spacesRoots.externalPath} IS NULL,
${shareSpaceRoot.externalPath}, ${spacesRoots.externalPath})`.as('originSpaceRootExternalPath'),
+ originShareExternalId: sql`IF (${shares.externalPath} IS NOT NULL, ${shares.parentId}, NULL)`.as('originShareExternalId'),
rootId: sql`${shares.id}`.as('rootId'),
rootAlias: shares.alias,
rootName: shares.name,
@@ -674,6 +678,7 @@ export class SharesQueries {
rootEnabled: shares.enabled,
rootExternalPath: shares.externalPath,
rootPermissions: sharesMembers.permissions,
+ rootOwnerId: sql`${users.id}`.as('rootOwnerId'),
rootOwnerLogin: sql`${users.login}`.as('rootOwnerLogin'),
rootOwnerEmail: sql`${users.email}`.as('rootOwnerEmail'),
rootOwnerFullName: userFullNameSQL(users).as('rootOwnerFullName'),
@@ -743,9 +748,13 @@ export class SharesQueries {
mtime: unionAlias.mtime,
mime: unionAlias.mime,
origin: {
+ ownerId: unionAlias.originOwnerId,
ownerLogin: unionAlias.originOwnerLogin,
+ spaceId: unionAlias.originSpaceId,
spaceAlias: unionAlias.originSpaceAlias,
- spaceRootExternalPath: unionAlias.originSpaceRootExternalPath
+ spaceExternalRootId: unionAlias.originSpaceExternalRootId,
+ spaceRootExternalPath: unionAlias.originSpaceRootExternalPath,
+ shareExternalId: unionAlias.originShareExternalId
},
root: {
id: unionAlias.rootId,
@@ -755,7 +764,12 @@ export class SharesQueries {
enabled: unionAlias.rootEnabled,
externalPath: unionAlias.rootExternalPath,
permissions: spaceGroupConcatPermissions(unionAlias.rootPermissions),
- owner: { login: unionAlias.rootOwnerLogin, email: unionAlias.rootOwnerEmail, fullName: unionAlias.rootOwnerFullName } as Owner
+ owner: {
+ id: unionAlias.rootOwnerId,
+ login: unionAlias.rootOwnerLogin,
+ email: unionAlias.rootOwnerEmail,
+ fullName: unionAlias.rootOwnerFullName
+ } satisfies Owner
},
shares: sql`IF (${sql.placeholder('withShares')}, ${concatDistinctObjectsInArray(unionAlias.childShareId, {
id: unionAlias.childShareId,
diff --git a/backend/src/applications/spaces/services/spaces-browser.service.ts b/backend/src/applications/spaces/services/spaces-browser.service.ts
index 5e2e9cc0..f6e45478 100644
--- a/backend/src/applications/spaces/services/spaces-browser.service.ts
+++ b/backend/src/applications/spaces/services/spaces-browser.service.ts
@@ -8,6 +8,7 @@ import { HttpException, Injectable, Logger } from '@nestjs/common'
import fs from 'node:fs/promises'
import path from 'node:path'
import { configuration } from '../../../configuration/config.environment'
+import { FileDBProps } from '../../files/interfaces/file-db-props.interface'
import { FileLock } from '../../files/interfaces/file-lock.interface'
import { FileProps } from '../../files/interfaces/file-props.interface'
import { FilesLockManager } from '../../files/services/files-lock-manager.service'
@@ -17,7 +18,6 @@ import { dirName, fileName, getProps } from '../../files/utils/files'
import { SharesQueries } from '../../shares/services/shares-queries.service'
import { USER_PERMISSION } from '../../users/constants/user'
import { UserModel } from '../../users/models/user.model'
-import { LOCK_SCOPE } from '../../webdav/constants/webdav'
import { SpaceFiles } from '../interfaces/space-files.interface'
import { SpaceEnv } from '../models/space-env.model'
import { IsRealPathIsDirAndExists, realPathFromRootFile } from '../utils/paths'
@@ -56,7 +56,8 @@ export class SpacesBrowser {
this.parseRootFiles(user, space, {
withShares: options.withSpacesAndShares,
withHasComments: options.withHasComments,
- withSyncs: options.withSyncs
+ withSyncs: options.withSyncs,
+ withLocks: options.withLocks
})
])
this.updateDBFiles(user, space, dbFiles, fsFiles, options)
@@ -83,6 +84,7 @@ export class SpacesBrowser {
withShares?: boolean
withHasComments?: boolean
withSyncs?: boolean
+ withLocks?: boolean
}
): Promise<FileProps[]> {
if (space.inFilesRepository && space.id && !space.root.alias) {
@@ -155,9 +157,12 @@ export class SpacesBrowser {
}
}
- private async updateRootFile(f: FileProps, options: { withShares?: boolean; withHasComments?: boolean; withSyncs?: boolean }): Promise<FileProps> {
- // get realpath
+ private async updateRootFile(
+ f: FileProps,
+ options: { withShares?: boolean; withHasComments?: boolean; withSyncs?: boolean; withLocks?: boolean }
+ ): Promise<FileProps> {
const realPath = realPathFromRootFile(f)
+ const originalPath = f.path
f.path = f.root.name
try {
const fileProps: FileProps = await getProps(realPath, f.path)
@@ -170,8 +175,28 @@ export class SpacesBrowser {
if (options.withSyncs) {
fileProps.syncs = f.syncs
}
+ if (options.withLocks && (f.origin || f.root?.owner)) {
+ // `f.origin` is used for shares
+ // `f.root.owner` is used for anchored files in spaces
+ // all other files are handled in the `enrichWithLocks` function
+ const dbFile: FileDBProps = {
+ ...(f.origin?.spaceId
+ ? { spaceId: f.origin.spaceId, ...(f.origin.spaceExternalRootId ? { spaceExternalRootId: f.origin.spaceExternalRootId } : {}) }
+ : f.origin?.shareExternalId
+ ? { shareExternalId: f.origin.shareExternalId }
+ : { ownerId: f.origin?.ownerId ?? f.root.owner.id }),
+ path: originalPath,
+ inTrash: f.inTrash
+ }
+ const locks = await this.filesLockManager.getLocksByPath(dbFile)
+ if (locks.length > 0) {
+ fileProps.lock = this.filesLockManager.convertLockToFileLockProps(locks[0])
+ }
+ }
+ // `owner.id` is only used in the `withLocks` condition
+ delete f.root.owner?.id
+ // check `f.id`; it can be null for external roots
if (f.id) {
- // f.id is null for external roots
// todo: check if a db file referenced under external roots have an id and correctly parsed here
this.filesQueries.compareAndUpdateFileProps(f, fileProps).catch((e: Error) => this.logger.error(`${this.updateRootFile.name} - ${e}`))
fileProps.id = f.id
@@ -299,13 +324,8 @@ export class SpacesBrowser {
}
const locks: Record<string, FileLock> = await this.filesLockManager.browseParentChildLocks(space.dbFile, false)
if (!Object.keys(locks).length) return
- for (const f of files.filter((f) => (f.root && f.root.alias in locks) || (!f.root && f.name in locks))) {
- const lock: FileLock = f.root ? locks[f.root.alias] : locks[f.name]
- f.lock = {
- owner: lock?.davLock?.owner || `${lock.owner.fullName} (${lock.owner.email})`,
- ownerLogin: lock.owner.login,
- isExclusive: lock?.davLock?.lockscope ? lock?.davLock?.lockscope === LOCK_SCOPE.EXCLUSIVE : true
- }
+ for (const f of files.filter((f) => !f.root && !f.origin && f.name in locks)) {
+ f.lock = this.filesLockManager.convertLockToFileLockProps(locks[f.name])
}
}
}
diff --git a/backend/src/applications/spaces/services/spaces-queries.service.ts b/backend/src/applications/spaces/services/spaces-queries.service.ts
index 3a4f84e3..441084ed 100644
--- a/backend/src/applications/spaces/services/spaces-queries.service.ts
+++ b/backend/src/applications/spaces/services/spaces-queries.service.ts
@@ -269,7 +269,7 @@ export class SpacesQueries {
name: spacesRoots.name,
externalPath: spacesRoots.externalPath,
permissions: spacesRoots.permissions,
- owner: { login: users.login, email: users.email, fullName: userFullNameSQL(users) }
+ owner: { id: users.id, login: users.login, email: users.email, fullName: userFullNameSQL(users) }
},
shares: sql`IF (${sql.placeholder('withShares')}, ${concatDistinctObjectsInArray(shares.id, {
id: shares.id,