Skip to content

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

refactor(backend:context): remove obsolete request context wiring

johavendb2f32c3bc59
diff --git a/backend/src/applications/comments/comments.controller.spec.ts b/backend/src/applications/comments/comments.controller.spec.ts
index 28987bb6..5d8b1d18 100644
--- a/backend/src/applications/comments/comments.controller.spec.ts
+++ b/backend/src/applications/comments/comments.controller.spec.ts
@@ -1,6 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import { Cache } from '../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../infrastructure/database/constants'
import { FilesQueries } from '../files/services/files-queries.service'
import { LinksQueries } from '../links/services/links-queries.service'
@@ -41,7 +40,6 @@ describe(CommentsController.name, () => {
{ provide: NotificationsManager, useValue: {} },
{ provide: DB_TOKEN_PROVIDER, useValue: {} },
{ provide: Cache, useValue: {} },
- ContextManager,
{ provide: CommentsManager, useValue: commentsManagerMock },
{ provide: FilesQuotaManager, useValue: {} },
CommentsQueries,
diff --git a/backend/src/applications/comments/comments.controller.ts b/backend/src/applications/comments/comments.controller.ts
index 98aca9b5..aca37682 100644
--- a/backend/src/applications/comments/comments.controller.ts
+++ b/backend/src/applications/comments/comments.controller.ts
@@ -1,5 +1,4 @@
-import { BadRequestException, Body, Controller, Delete, Get, ParseIntPipe, Patch, Post, Query, UseGuards, UseInterceptors } from '@nestjs/common'
-import { ContextInterceptor } from '../../infrastructure/context/interceptors/context.interceptor'
+import { BadRequestException, Body, Controller, Delete, Get, ParseIntPipe, Patch, Post, Query, UseGuards } from '@nestjs/common'
import { SkipSpaceGuard } from '../spaces/decorators/space-skip-guard.decorator'
import { SkipSpacePermissionsCheck } from '../spaces/decorators/space-skip-permissions.decorator'
import { GetSpace } from '../spaces/decorators/space.decorator'
@@ -26,7 +25,6 @@ export class CommentsController {
}
@Post(`${COMMENTS_ROUTE.SPACES}/*`)
- @UseInterceptors(ContextInterceptor)
createFromSpace(@GetUser() user: UserModel, @GetSpace() space: SpaceEnv, @Body() createCommentDto: CreateOrUpdateCommentDto): Promise<Comment> {
return this.commentsManager.createComment(user, space, createCommentDto)
}
diff --git a/backend/src/applications/files/editors/only-office/only-office-environment.decorator.ts b/backend/src/applications/files/editors/only-office/only-office-environment.decorator.ts
index aeeea876..190ef0bc 100644
--- a/backend/src/applications/files/editors/only-office/only-office-environment.decorator.ts
+++ b/backend/src/applications/files/editors/only-office/only-office-environment.decorator.ts
@@ -1,10 +1,9 @@
-import { applyDecorators, SetMetadata, UseGuards, UseInterceptors } from '@nestjs/common'
-import { ContextInterceptor } from '../../../../infrastructure/context/interceptors/context.interceptor'
+import { applyDecorators, SetMetadata, UseGuards } from '@nestjs/common'
import { SpaceGuard } from '../../../spaces/guards/space.guard'
import { ONLY_OFFICE_CONTEXT } from './only-office.constants'
import { OnlyOfficeGuard } from './only-office.guard'
export const OnlyOfficeContext = () => SetMetadata(ONLY_OFFICE_CONTEXT, true)
export const OnlyOfficeEnvironment = () => {
- return applyDecorators(OnlyOfficeContext(), UseInterceptors(ContextInterceptor), UseGuards(OnlyOfficeGuard, SpaceGuard))
+ return applyDecorators(OnlyOfficeContext(), UseGuards(OnlyOfficeGuard, SpaceGuard))
}
diff --git a/backend/src/applications/files/files-operations.controller.spec.ts b/backend/src/applications/files/files-operations.controller.spec.ts
index 1cdbf77f..cd94337d 100644
--- a/backend/src/applications/files/files-operations.controller.spec.ts
+++ b/backend/src/applications/files/files-operations.controller.spec.ts
@@ -1,6 +1,4 @@
import { Test, TestingModule } from '@nestjs/testing'
-import { ContextInterceptor } from '../../infrastructure/context/interceptors/context.interceptor'
-import { ContextManager } from '../../infrastructure/context/services/context-manager.service'
import { SpaceGuard } from '../spaces/guards/space.guard'
import { FILE_OPERATION } from './constants/operations'
import { FilesOperationsController } from './files-operations.controller'
@@ -39,9 +37,7 @@ describe(FilesOperationsController.name, () => {
controllers: [FilesOperationsController],
providers: [
{ provide: FilesMethods, useValue: filesMethodsMock },
- { provide: FilesTasksManager, useValue: filesTasksManagerMock },
- { provide: ContextManager, useValue: {} },
- ContextInterceptor
+ { provide: FilesTasksManager, useValue: filesTasksManagerMock }
]
})
// IMPORTANT: override the guard referenced by @UseGuards to avoid resolving its dependencies
diff --git a/backend/src/applications/files/files-operations.controller.ts b/backend/src/applications/files/files-operations.controller.ts
index 940a8685..bccca5f5 100644
--- a/backend/src/applications/files/files-operations.controller.ts
+++ b/backend/src/applications/files/files-operations.controller.ts
@@ -18,12 +18,10 @@ import {
Res,
StreamableFile,
Unlock,
- UseGuards,
- UseInterceptors
+ UseGuards
} from '@nestjs/common'
import { FastifyReply } from 'fastify'
import { webpMimeType } from '../../common/image'
-import { ContextInterceptor } from '../../infrastructure/context/interceptors/context.interceptor'
import { SkipSpacePermissionsCheck } from '../spaces/decorators/space-skip-permissions.decorator'
import { GetSpace } from '../spaces/decorators/space.decorator'
import { SpaceGuard } from '../spaces/guards/space.guard'
@@ -124,7 +122,6 @@ export class FilesOperationsController {
}
@Unlock(`${FILES_ROUTE.OPERATION}/${FILE_OPERATION.UNLOCK_REQUEST}/*`)
- @UseInterceptors(ContextInterceptor)
async unlockRequest(@GetUser() user: UserModel, @GetSpace() space: SpaceEnv): Promise<void> {
return this.filesMethods.unlockRequest(user, space)
}
diff --git a/backend/src/applications/files/services/files-methods.service.spec.ts b/backend/src/applications/files/services/files-methods.service.spec.ts
index f3347921..691e2067 100644
--- a/backend/src/applications/files/services/files-methods.service.spec.ts
+++ b/backend/src/applications/files/services/files-methods.service.spec.ts
@@ -4,7 +4,6 @@ import path from 'node:path'
import type { Mock } from 'vitest'
import { transformAndValidate } from '../../../common/functions'
import { Cache } from '../../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../../infrastructure/database/constants'
import { NotificationsManager } from '../../notifications/services/notifications-manager.service'
import { SharesManager } from '../../shares/services/shares-manager.service'
@@ -55,7 +54,6 @@ describe(FilesMethods.name, () => {
provide: Cache,
useValue: { get: () => null }
},
- { provide: ContextManager, useValue: {} },
{
provide: NotificationsManager,
useValue: {}
diff --git a/backend/src/applications/links/services/links-manager.service.spec.ts b/backend/src/applications/links/services/links-manager.service.spec.ts
index c245ead2..f7caa7fa 100644
--- a/backend/src/applications/links/services/links-manager.service.spec.ts
+++ b/backend/src/applications/links/services/links-manager.service.spec.ts
@@ -5,7 +5,6 @@ import { JwtService } from '@nestjs/jwt'
import { Test, TestingModule } from '@nestjs/testing'
import { AuthManager } from '../../../authentication/auth.service'
import { Cache } from '../../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../../infrastructure/database/constants'
import { FilesLockManager } from '../../files/services/files-lock-manager.service'
import { FilesManager } from '../../files/services/files-manager.service'
@@ -82,7 +81,6 @@ describe(LinksManager.name, () => {
provide: Cache,
useValue: {}
},
- { provide: ContextManager, useValue: {} },
{
provide: NotificationsManager,
useValue: {}
diff --git a/backend/src/applications/shares/shares.controller.spec.ts b/backend/src/applications/shares/shares.controller.spec.ts
index 4b418b61..fdad7b89 100644
--- a/backend/src/applications/shares/shares.controller.spec.ts
+++ b/backend/src/applications/shares/shares.controller.spec.ts
@@ -1,6 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import { Cache } from '../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../infrastructure/database/constants'
import { FilesQueries } from '../files/services/files-queries.service'
import { LinksQueries } from '../links/services/links-queries.service'
@@ -24,7 +23,6 @@ describe(SharesController.name, () => {
provide: Cache,
useValue: {}
},
- { provide: ContextManager, useValue: {} },
{
provide: NotificationsManager,
useValue: {}
diff --git a/backend/src/applications/shares/shares.controller.ts b/backend/src/applications/shares/shares.controller.ts
index fde363e1..0cf1c734 100644
--- a/backend/src/applications/shares/shares.controller.ts
+++ b/backend/src/applications/shares/shares.controller.ts
@@ -1,5 +1,4 @@
-import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, UseGuards, UseInterceptors } from '@nestjs/common'
-import { ContextInterceptor } from '../../infrastructure/context/interceptors/context.interceptor'
+import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, UseGuards } from '@nestjs/common'
import { LINK_TYPE } from '../links/constants/links'
import { CreateOrUpdateLinkDto } from '../links/dto/create-or-update-link.dto'
import { LinkGuest } from '../links/interfaces/link-guest.interface'
@@ -22,7 +21,6 @@ import { SharesManager } from './services/shares-manager.service'
@UserHaveRole(USER_ROLE.USER)
@UserHavePermission(USER_PERMISSION.SHARES_ADMIN)
@UseGuards(UserRolesGuard, UserPermissionsGuard)
-@UseInterceptors(ContextInterceptor)
export class SharesController {
constructor(private readonly sharesManager: SharesManager) {}
diff --git a/backend/src/applications/spaces/guards/space.guard.spec.ts b/backend/src/applications/spaces/guards/space.guard.spec.ts
index 7b4b305f..483fa75d 100644
--- a/backend/src/applications/spaces/guards/space.guard.spec.ts
+++ b/backend/src/applications/spaces/guards/space.guard.spec.ts
@@ -3,7 +3,6 @@ import { ExecutionContext, HttpException, HttpStatus } from '@nestjs/common'
import { Test, TestingModule } from '@nestjs/testing'
import { intersectPermissions } from '../../../common/shared'
import { Cache } from '../../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../../infrastructure/database/constants'
import { FilesQueries } from '../../files/services/files-queries.service'
import { LinksQueries } from '../../links/services/links-queries.service'
@@ -45,7 +44,6 @@ describe(SpaceGuard.name, () => {
provide: Cache,
useValue: {}
},
- { provide: ContextManager, useValue: {} },
{
provide: NotificationsManager,
useValue: {}
diff --git a/backend/src/applications/spaces/services/spaces-browser.service.spec.ts b/backend/src/applications/spaces/services/spaces-browser.service.spec.ts
index 6e224c51..14bfedf3 100644
--- a/backend/src/applications/spaces/services/spaces-browser.service.spec.ts
+++ b/backend/src/applications/spaces/services/spaces-browser.service.spec.ts
@@ -3,7 +3,6 @@ import { Test, TestingModule } from '@nestjs/testing'
import fs from 'node:fs/promises'
import { configuration, exportConfiguration } from '../../../configuration/config.environment'
import { Cache } from '../../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../../infrastructure/database/constants'
import { FilesQuotaManager } from '../../files/services/files-quota-manager.service'
import { FilesLockManager } from '../../files/services/files-lock-manager.service'
@@ -32,7 +31,6 @@ describe(SpacesBrowser.name, () => {
provide: Cache,
useValue: {}
},
- { provide: ContextManager, useValue: {} },
{
provide: NotificationsManager,
useValue: {}
diff --git a/backend/src/applications/spaces/spaces.controller.spec.ts b/backend/src/applications/spaces/spaces.controller.spec.ts
index 9d88d765..6465f631 100644
--- a/backend/src/applications/spaces/spaces.controller.spec.ts
+++ b/backend/src/applications/spaces/spaces.controller.spec.ts
@@ -1,6 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import { Cache } from '../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../infrastructure/database/constants'
import { FilesLockManager } from '../files/services/files-lock-manager.service'
import { FilesQueries } from '../files/services/files-queries.service'
@@ -36,7 +35,6 @@ describe(SpacesController.name, () => {
provide: FilesQuotaManager,
useValue: {}
},
- ContextManager,
SpacesManager,
SpacesQueries,
SpacesBrowser,
diff --git a/backend/src/applications/spaces/spaces.controller.ts b/backend/src/applications/spaces/spaces.controller.ts
index 4ece5874..8eb11586 100644
--- a/backend/src/applications/spaces/spaces.controller.ts
+++ b/backend/src/applications/spaces/spaces.controller.ts
@@ -14,10 +14,8 @@ import {
Put,
Query,
Search,
- UseGuards,
- UseInterceptors
+ UseGuards
} from '@nestjs/common'
-import { ContextInterceptor } from '../../infrastructure/context/interceptors/context.interceptor'
import { FileTree } from '../files/interfaces/file-tree.interface'
import { FileError } from '../files/models/file-error'
import { checkExternalPath } from '../files/utils/files'
@@ -51,7 +49,6 @@ import { SpacesManager } from './services/spaces-manager.service'
@UserHaveRole(USER_ROLE.USER)
@UserHavePermission(USER_PERMISSION.SPACES)
@UseGuards(UserRolesGuard, UserPermissionsGuard)
-@UseInterceptors(ContextInterceptor)
export class SpacesController {
constructor(
private readonly spacesManager: SpacesManager,
diff --git a/backend/src/applications/sync/sync.controller.spec.ts b/backend/src/applications/sync/sync.controller.spec.ts
index a881d4b8..ef9ecc61 100644
--- a/backend/src/applications/sync/sync.controller.spec.ts
+++ b/backend/src/applications/sync/sync.controller.spec.ts
@@ -1,6 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import { AuthRateLimitGuard } from '../../authentication/guards/auth-rate-limit.guard'
-import { ContextManager } from '../../infrastructure/context/services/context-manager.service'
import { SpacesManager } from '../spaces/services/spaces-manager.service'
import { SyncClientsManager } from './services/sync-clients-manager.service'
import { SyncManager } from './services/sync-manager.service'
@@ -14,7 +13,6 @@ describe(SyncController.name, () => {
const testingModuleBuilder = Test.createTestingModule({
controllers: [SyncController],
providers: [
- { provide: ContextManager, useValue: {} },
{ provide: SpacesManager, useValue: {} },
{ provide: SyncManager, useValue: {} },
{ provide: SyncClientsManager, useValue: {} },
diff --git a/backend/src/applications/sync/sync.controller.ts b/backend/src/applications/sync/sync.controller.ts
index 15d7232a..8dbe72c8 100644
--- a/backend/src/applications/sync/sync.controller.ts
+++ b/backend/src/applications/sync/sync.controller.ts
@@ -25,7 +25,6 @@ import { FastifyReply, FastifyRequest } from 'fastify'
import { AuthTokenSkip } from '../../authentication/decorators/auth-token-skip.decorator'
import { AuthRateLimitGuard } from '../../authentication/guards/auth-rate-limit.guard'
import { FastifyAuthenticatedRequest } from '../../authentication/interfaces/auth-request.interface'
-import { ContextInterceptor } from '../../infrastructure/context/interceptors/context.interceptor'
import { SkipSpacePermissionsCheck } from '../spaces/decorators/space-skip-permissions.decorator'
import { FastifySpaceRequest } from '../spaces/interfaces/space-request.interface'
import { USER_PERMISSION } from '../users/constants/user'
@@ -174,7 +173,6 @@ export class SyncController {
@Put(SYNC_ROUTE.PATHS)
@UserHavePermission(USER_PERMISSION.DESKTOP_APP_SYNC)
@UseGuards(UserPermissionsGuard)
- @UseInterceptors(ContextInterceptor)
updatePaths(
@GetUser() user: UserModel,
@Body(new ParseArrayPipe({ items: SyncPathDto, whitelist: true })) syncPathsDto: SyncPathDto[]
diff --git a/backend/src/infrastructure/context/services/context-manager.service.spec.ts b/backend/src/infrastructure/context/services/context-manager.service.spec.ts
index 400931dd..63069e5e 100644
--- a/backend/src/infrastructure/context/services/context-manager.service.spec.ts
+++ b/backend/src/infrastructure/context/services/context-manager.service.spec.ts
@@ -17,23 +17,18 @@ describe(ContextManager.name, () => {
expect(contextManager).toBeDefined()
})
- // Test helpers to reduce repetition and keep strong typing in one place
- const getKey = <K extends keyof ContextStore>(key: K): ContextStore[K] => contextManager.get(key) as ContextStore[K]
-
- const runWithContext = <T>(ctx: Partial<ContextStore>, fn: () => T): T => contextManager.run(ctx as ContextStore, fn) as unknown as T
+ const runWithContext = <T>(ctx: ContextStore, fn: () => T): T => contextManager.run(ctx, fn) as unknown as T
describe('Context access', () => {
- it('get() should return undefined when no context is active', () => {
- // Using a fake key ensures we don’t rely on a specific ContextStore shape
- expect(getKey('' as keyof ContextStore)).toBeUndefined()
+ it('headerOriginUrl() should return undefined when no context is active', () => {
+ expect(contextManager.headerOriginUrl()).toBeUndefined()
})
it('run() should expose context within the callback and surface return value', () => {
- const ctx = { userId: 'u1', requestId: 'r1' } as Partial<ContextStore>
+ const ctx = { headerOriginUrl: 'https://sync-in.example' }
const value = runWithContext<number>(ctx, () => {
- expect(getKey('userId' as keyof ContextStore)).toBe('u1')
- expect(getKey('requestId' as keyof ContextStore)).toBe('r1')
+ expect(contextManager.headerOriginUrl()).toBe(ctx.headerOriginUrl)
return 123
})
@@ -43,52 +38,50 @@ describe(ContextManager.name, () => {
describe('Context lifecycle', () => {
it('should restore to no context after run() completes', () => {
- const ctx = { userId: 'u2' } as Partial<ContextStore>
+ const ctx = { headerOriginUrl: 'https://sync-in.example' }
runWithContext<void>(ctx, () => {
- expect(getKey('userId' as keyof ContextStore)).toBe('u2')
+ expect(contextManager.headerOriginUrl()).toBe(ctx.headerOriginUrl)
})
- expect(getKey('userId' as keyof ContextStore)).toBeUndefined()
+ expect(contextManager.headerOriginUrl()).toBeUndefined()
})
it('should support nested contexts and restore the previous one after inner run()', () => {
- const outer = { userId: 'outer' } as Partial<ContextStore>
- const inner = { userId: 'inner' } as Partial<ContextStore>
+ const outer = { headerOriginUrl: 'https://outer.example' }
+ const inner = { headerOriginUrl: 'https://inner.example' }
runWithContext<void>(outer, () => {
- expect(getKey('userId' as keyof ContextStore)).toBe('outer')
+ expect(contextManager.headerOriginUrl()).toBe(outer.headerOriginUrl)
runWithContext<void>(inner, () => {
- expect(getKey('userId' as keyof ContextStore)).toBe('inner')
+ expect(contextManager.headerOriginUrl()).toBe(inner.headerOriginUrl)
})
- // After inner completes, outer should be visible again
- expect(getKey('userId' as keyof ContextStore)).toBe('outer')
+ expect(contextManager.headerOriginUrl()).toBe(outer.headerOriginUrl)
})
- // After outer completing, no context should be active
- expect(getKey('userId' as keyof ContextStore)).toBeUndefined()
+ expect(contextManager.headerOriginUrl()).toBeUndefined()
})
})
describe('Async propagation', () => {
it('should propagate context across microtasks (Promise)', async () => {
- const ctx = { userId: 'async-user' } as Partial<ContextStore>
+ const ctx = { headerOriginUrl: 'https://async.example' }
await runWithContext<Promise<void>>(ctx, async () => {
await Promise.resolve()
- expect(getKey('userId' as keyof ContextStore)).toBe('async-user')
+ expect(contextManager.headerOriginUrl()).toBe(ctx.headerOriginUrl)
})
})
it('should propagate context across timers (setTimeout)', async () => {
- const ctx = { requestId: 'req-timer' } as Partial<ContextStore>
+ const ctx = { headerOriginUrl: 'https://timer.example' }
await runWithContext<Promise<void>>(ctx, async () => {
await new Promise<void>((resolve) =>
setTimeout(() => {
- expect(getKey('requestId' as keyof ContextStore)).toBe('req-timer')
+ expect(contextManager.headerOriginUrl()).toBe(ctx.headerOriginUrl)
resolve()
}, 0)
)
diff --git a/backend/src/infrastructure/context/services/context-manager.service.ts b/backend/src/infrastructure/context/services/context-manager.service.ts
index c552a7dc..3675c2cf 100644
--- a/backend/src/infrastructure/context/services/context-manager.service.ts
+++ b/backend/src/infrastructure/context/services/context-manager.service.ts
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common'
import { AsyncLocalStorage } from 'node:async_hooks'
import type { Observable } from 'rxjs'
-import { ContextStore } from '../interfaces/context-store.interface'
+import type { ContextStore } from '../interfaces/context-store.interface'
@Injectable()
export class ContextManager {
@@ -15,10 +15,6 @@ export class ContextManager {
return this.storage.getStore() ? this.storage.getStore().headerOriginUrl : undefined
}
- get(key: keyof ContextStore): any {
- return this.storage.getStore() ? this.storage.getStore()[key] : undefined
- }
-
run(context: ContextStore, cb: () => unknown): Observable<unknown> {
return this.storage.run(context, cb) as Observable<unknown>
}