From cd5db6a9c3faeb1a6862bdec2777d2358a0e8bfe Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Tue, 2 Jul 2024 15:12:39 +0400 Subject: [PATCH] ezqms-1057: fix images in branded workspaces (#5979) --- pods/server/src/server.ts | 4 ++-- server/core/src/server/storage.ts | 3 +++ server/core/src/types.ts | 2 +- server/server/src/backup.ts | 7 +++---- server/ws/src/__tests__/server.test.ts | 4 ++-- server/ws/src/client.ts | 23 ++++++----------------- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/pods/server/src/server.ts b/pods/server/src/server.ts index e21b6b1ad9..8cac008e5f 100644 --- a/pods/server/src/server.ts +++ b/pods/server/src/server.ts @@ -56,9 +56,9 @@ export function start ( const pipelineFactory = createServerPipeline(metrics, dbUrl, { ...opt, externalStorage }) const sessionFactory = (token: Token, pipeline: Pipeline): Session => { if (token.extra?.mode === 'backup') { - return new BackupClientSession(token, pipeline, opt.brandingMap) + return new BackupClientSession(token, pipeline) } - return new ClientSession(token, pipeline, opt.brandingMap) + return new ClientSession(token, pipeline) } const onClose = startJsonRpc(getMetricsContext(), { diff --git a/server/core/src/server/storage.ts b/server/core/src/server/storage.ts index 85b837305a..26f97db464 100644 --- a/server/core/src/server/storage.ts +++ b/server/core/src/server/storage.ts @@ -24,6 +24,7 @@ import core, { TxProcessor, cutObjectArray, toFindResult, + type Branding, type Account, type AttachedDoc, type Class, @@ -87,6 +88,7 @@ export class TServerStorage implements ServerStorage { triggerData = new Map, any>() liveQuery: LQ + branding: Branding | null domainInfo = new Map< Domain, @@ -119,6 +121,7 @@ export class TServerStorage implements ServerStorage { this.liveQuery = new LQ(this.newCastClient(hierarchy, modelDb, metrics)) this.hierarchy = hierarchy this.fulltext = indexFactory(this) + this.branding = options.branding this.setModel(model) } diff --git a/server/core/src/types.ts b/server/core/src/types.ts index 8e59d664ff..bde223b5ce 100644 --- a/server/core/src/types.ts +++ b/server/core/src/types.ts @@ -69,7 +69,7 @@ export interface ServerStorage extends LowLevelStorage { close: () => Promise loadModel: (last: Timestamp, hash?: string) => Promise workspaceId: WorkspaceIdWithUrl - branding?: string + branding: Branding | null storageAdapter: StorageAdapter } diff --git a/server/server/src/backup.ts b/server/server/src/backup.ts index 74cc1c3e92..1d2d539f8a 100644 --- a/server/server/src/backup.ts +++ b/server/server/src/backup.ts @@ -1,4 +1,4 @@ -import { type BrandingMap, Doc, DocInfo, Domain, Ref, StorageIterator } from '@hcengineering/core' +import { Doc, DocInfo, Domain, Ref, StorageIterator } from '@hcengineering/core' import { Pipeline, estimateDocSize } from '@hcengineering/server-core' import { Token } from '@hcengineering/server-token' import { ClientSession, Session, type ClientSessionCtx } from '@hcengineering/server-ws' @@ -30,10 +30,9 @@ export interface BackupSession extends Session { export class BackupClientSession extends ClientSession implements BackupSession { constructor ( protected readonly token: Token, - protected readonly _pipeline: Pipeline, - protected readonly brandingMap: BrandingMap + protected readonly _pipeline: Pipeline ) { - super(token, _pipeline, brandingMap) + super(token, _pipeline) } idIndex = 0 diff --git a/server/ws/src/__tests__/server.test.ts b/server/ws/src/__tests__/server.test.ts index ea68546417..3c99b2e51a 100644 --- a/server/ws/src/__tests__/server.test.ts +++ b/server/ws/src/__tests__/server.test.ts @@ -82,7 +82,7 @@ describe('server', () => { return { docs: [] } } }), - sessionFactory: (token, pipeline) => new ClientSession(token, pipeline, {}), + sessionFactory: (token, pipeline) => new ClientSession(token, pipeline), port: 3335, productId: '', brandingMap: {}, @@ -183,7 +183,7 @@ describe('server', () => { return { docs: [] } } }), - sessionFactory: (token, pipeline) => new ClientSession(token, pipeline, {}), + sessionFactory: (token, pipeline) => new ClientSession(token, pipeline), port: 3336, productId: '', brandingMap: {}, diff --git a/server/ws/src/client.ts b/server/ws/src/client.ts index b9aeb8fd00..dec8eb28b3 100644 --- a/server/ws/src/client.ts +++ b/server/ws/src/client.ts @@ -32,9 +32,7 @@ import core, { type Tx, type TxApplyIf, type TxApplyResult, - type TxCUD, - type Branding, - type BrandingMap + type TxCUD } from '@hcengineering/core' import { SessionContextImpl, createBroadcastEvent, type Pipeline } from '@hcengineering/server-core' import { type Token } from '@hcengineering/server-token' @@ -58,8 +56,7 @@ export class ClientSession implements Session { constructor ( protected readonly token: Token, - protected readonly _pipeline: Pipeline, - protected readonly brandingMap: BrandingMap + protected readonly _pipeline: Pipeline ) {} getUser (): string { @@ -78,14 +75,6 @@ export class ClientSession implements Session { return this._pipeline } - getBranding (brandingKey?: string): Branding | null { - if (brandingKey === undefined) { - return null - } - - return this.brandingMap[brandingKey] ?? null - } - async ping (ctx: ClientSessionCtx): Promise { // console.log('ping') this.lastRequest = Date.now() @@ -127,7 +116,7 @@ export class ClientSession implements Session { this.token.extra?.admin === 'true', [], this._pipeline.storage.workspaceId, - this.getBranding(this._pipeline.storage.branding) + this._pipeline.storage.branding ) await this._pipeline.tx(context, createTx) const acc = TxProcessor.createDoc2Doc(createTx) @@ -157,7 +146,7 @@ export class ClientSession implements Session { this.token.extra?.admin === 'true', [], this._pipeline.storage.workspaceId, - this.getBranding(this._pipeline.storage.branding) + this._pipeline.storage.branding ) return await this._pipeline.findAll(context, _class, query, options) } @@ -180,7 +169,7 @@ export class ClientSession implements Session { this.token.extra?.admin === 'true', [], this._pipeline.storage.workspaceId, - this.getBranding(this._pipeline.storage.branding) + this._pipeline.storage.branding ) await ctx.sendResponse(await this._pipeline.searchFulltext(context, query, options)) } @@ -196,7 +185,7 @@ export class ClientSession implements Session { this.token.extra?.admin === 'true', [], this._pipeline.storage.workspaceId, - this.getBranding(this._pipeline.storage.branding) + this._pipeline.storage.branding ) const result = await this._pipeline.tx(context, tx)