From 5a1d9d10d887b4cb680ead6f8e4e0eb26c712dfb Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Thu, 22 Aug 2024 17:21:13 +0400 Subject: [PATCH] uberf-7927: get rid of product id Signed-off-by: Alexey Zinoviev Signed-off-by: Alexey Zinoviev --- dev/doc-import-tool/package.json | 2 +- dev/tool/src/__start.ts | 2 +- dev/tool/src/benchmark.ts | 2 +- dev/tool/src/clean.ts | 7 +- dev/tool/src/index.ts | 172 +++++----- dev/tool/src/openai.ts | 3 +- dev/tool/src/renameAccount.ts | 13 +- packages/core/src/classes.ts | 1 - packages/core/src/component.ts | 3 +- packages/core/src/utils.ts | 13 +- packages/platform/lang/en.json | 1 - packages/platform/lang/es.json | 1 - packages/platform/lang/fr.json | 1 - packages/platform/lang/pt.json | 1 - packages/platform/lang/ru.json | 1 - packages/platform/lang/zh.json | 1 - packages/platform/src/platform.ts | 1 - packages/storage/src/index.ts | 4 +- pods/account/src/__start.ts | 2 +- pods/authProviders/src/github.ts | 19 +- pods/authProviders/src/google.ts | 14 +- pods/authProviders/src/index.ts | 6 +- pods/authProviders/src/token.ts | 3 +- pods/server/src/__start.ts | 1 - pods/server/src/server.ts | 2 - .../ai-bot-resources/src/adapter.ts | 9 +- server-plugins/ai-bot/src/types.ts | 1 - server/account-service/src/index.ts | 9 +- .../src/__tests__/account.test_skip.ts | 34 +- server/account/src/operations.ts | 305 ++++++------------ server/account/src/service.ts | 27 +- server/backup-service/src/index.ts | 2 +- server/backup/src/backup.ts | 3 - server/backup/src/service.ts | 6 +- server/core/src/__tests__/aggregator.spec.ts | 2 +- server/core/src/__tests__/memAdapters.ts | 6 +- server/core/src/server/aggregator.ts | 4 +- server/core/src/storage.ts | 2 +- server/datalake/src/index.ts | 2 +- server/elastic/src/__tests__/adapter.test.ts | 2 +- server/front/src/index.ts | 2 +- server/minio/src/__tests__/minio.test.ts | 10 +- server/minio/src/index.ts | 17 +- server/mongo/src/__tests__/storage.test.ts | 4 +- server/s3/src/__tests__/s3.test.ts | 10 +- server/s3/src/index.ts | 17 +- server/s3/src/perfTest.ts | 4 +- server/token/src/token.ts | 6 +- server/tool/src/index.ts | 3 +- server/ws/src/__tests__/server.test.ts | 6 +- server/ws/src/factories.ts | 14 +- server/ws/src/server.ts | 6 +- server/ws/src/server_http.ts | 11 +- server/ws/src/server_u.ts | 6 - server/ws/src/types.ts | 2 - services/ai-bot/pod-ai-bot/src/config.ts | 3 - services/ai-bot/pod-ai-bot/src/controller.ts | 13 +- .../pod-calendar/src/workspaceClient.ts | 2 +- services/github/pod-github/src/client.ts | 4 +- services/github/pod-github/src/config.ts | 7 - services/github/pod-github/src/platform.ts | 10 +- services/github/pod-github/src/types.ts | 1 - services/github/pod-github/src/worker.ts | 2 +- .../gmail/pod-gmail/src/workspaceClient.ts | 4 +- services/love/src/main.ts | 4 +- services/love/src/workspaceClient.ts | 2 +- services/sign/pod-sign/src/signController.ts | 3 +- .../telegram/pod-telegram/src/workspace.ts | 13 +- 68 files changed, 314 insertions(+), 562 deletions(-) diff --git a/dev/doc-import-tool/package.json b/dev/doc-import-tool/package.json index aa81d7c8b6a..87f0604b970 100644 --- a/dev/doc-import-tool/package.json +++ b/dev/doc-import-tool/package.json @@ -15,7 +15,7 @@ "build:watch": "compile", "_phase:bundle": "rushx bundle", "bundle": "mkdir -p bundle && node esbuild.js", - "run-local": "cross-env SERVER_SECRET=secret MONGO_URL=mongodb://localhost:27017 COLLABORATOR_URL=ws://localhost:3078 STORAGE_CONFIG=minio|minio?accessKey=minioadmin&secretKey=minioadmin PRODUCT_ID=ezqms node --nolazy -r ts-node/register ./src/__start.ts", + "run-local": "cross-env SERVER_SECRET=secret MONGO_URL=mongodb://localhost:27017 COLLABORATOR_URL=ws://localhost:3078 STORAGE_CONFIG=minio|minio?accessKey=minioadmin&secretKey=minioadmin node --nolazy -r ts-node/register ./src/__start.ts", "run": "cross-env node -r ts-node/register --max-old-space-size=8000 ./src/__start.ts", "format": "format src", "test": "jest --passWithNoTests --silent", diff --git a/dev/tool/src/__start.ts b/dev/tool/src/__start.ts index 5ba341d8eda..c3a43ea79c5 100644 --- a/dev/tool/src/__start.ts +++ b/dev/tool/src/__start.ts @@ -84,4 +84,4 @@ function prepareTools (): { console.log(`tools git_version: ${process.env.GIT_REVISION ?? ''} model_version: ${process.env.MODEL_VERSION ?? ''}`) -devTool(prepareTools, process.env.PRODUCT_ID ?? '') +devTool(prepareTools) diff --git a/dev/tool/src/benchmark.ts b/dev/tool/src/benchmark.ts index 90e443c9723..dfa440535f6 100644 --- a/dev/tool/src/benchmark.ts +++ b/dev/tool/src/benchmark.ts @@ -481,7 +481,7 @@ export async function stressBenchmark (transactor: string, mode: StressBenchmark try { counter++ console.log('Attempt', counter) - const token = generateToken(generateId(), { name: generateId(), productId: '' }) + const token = generateToken(generateId(), { name: generateId() }) await rate.add(async () => { try { const ws = new WebSocket(concatLink(transactor, token)) diff --git a/dev/tool/src/clean.ts b/dev/tool/src/clean.ts index afd0d8d72f9..9e8e6a3a937 100644 --- a/dev/tool/src/clean.ts +++ b/dev/tool/src/clean.ts @@ -1056,7 +1056,6 @@ export async function removeDuplicateIds ( ctx: MeasureContext, mongodbUri: string, storageAdapter: StorageAdapter, - productId: string, accountsUrl: string, initWorkspacesStr: string ): Promise { @@ -1066,13 +1065,13 @@ export async function removeDuplicateIds ( // disable spaces while change hardocded ids const skippedDomains: string[] = [DOMAIN_DOC_INDEX_STATE, DOMAIN_BENCHMARK, DOMAIN_TX, DOMAIN_SPACE] try { - const workspaces = await listWorkspacesRaw(_client.db(ACCOUNT_DB), productId) + const workspaces = await listWorkspacesRaw(_client.db(ACCOUNT_DB)) workspaces.sort((a, b) => b.lastVisit - a.lastVisit) const initWorkspaces = initWorkspacesStr.split(';') const initWS = workspaces.filter((p) => initWorkspaces.includes(p.workspace)) const ids = new Map() for (const workspace of initWS) { - const workspaceId = getWorkspaceId(workspace.workspace, productId) + const workspaceId = getWorkspaceId(workspace.workspace) const db = getWorkspaceDB(_client, workspaceId) const txex = await db.collection(DOMAIN_TX).find>({}).toArray() @@ -1125,7 +1124,7 @@ export async function removeDuplicateIds ( if (initWorkspaces.includes(workspace.workspace)) continue ctx.info(`Processing workspace ${workspace.workspaceName ?? workspace.workspace}`) - const workspaceId = getWorkspaceId(workspace.workspace, productId) + const workspaceId = getWorkspaceId(workspace.workspace) const db = getWorkspaceDB(_client, workspaceId) const check = await db.collection(DOMAIN_MIGRATION).findOne({ state, plugin: workspace.workspace }) if (check != null) continue diff --git a/dev/tool/src/index.ts b/dev/tool/src/index.ts index 7069995c1fe..16c23b3b0ef 100644 --- a/dev/tool/src/index.ts +++ b/dev/tool/src/index.ts @@ -119,7 +119,6 @@ export function devTool ( version: Data migrateOperations: [string, MigrateOperation][] }, - productId: string, extendProgram?: (prog: Command) => void ): void { const toolCtx = new MeasureMetricsContext('tool', {}) @@ -200,7 +199,7 @@ export function devTool ( const { mongodbUri } = prepareTools() await withDatabase(mongodbUri, async (db) => { console.log(`creating account ${cmd.first as string} ${cmd.last as string} (${email})...`) - await createAcc(toolCtx, db, productId, null, email, cmd.password, cmd.first, cmd.last, true) + await createAcc(toolCtx, db, null, email, cmd.password, cmd.first, cmd.last, true) }) }) @@ -212,7 +211,7 @@ export function devTool ( const { mongodbUri } = prepareTools() await withDatabase(mongodbUri, async (db) => { console.log(`update account ${email} ${cmd.first as string} ${cmd.last as string}...`) - await replacePassword(db, productId, email, cmd.password) + await replacePassword(db, email, cmd.password) }) }) @@ -223,7 +222,7 @@ export function devTool ( const { mongodbUri } = prepareTools() await withDatabase(mongodbUri, async (db) => { console.log(`update account ${email} to ${newEmail}`) - await renameAccount(toolCtx, db, productId, accountsUrl, email, newEmail) + await renameAccount(toolCtx, db, accountsUrl, email, newEmail) }) }) @@ -234,7 +233,7 @@ export function devTool ( const { mongodbUri } = prepareTools() await withDatabase(mongodbUri, async (db) => { console.log(`update account ${email} to ${newEmail}`) - await fixAccountEmails(toolCtx, db, productId, accountsUrl, email, newEmail) + await fixAccountEmails(toolCtx, db, accountsUrl, email, newEmail) }) }) @@ -248,13 +247,13 @@ export function devTool ( console.log('compacting db ...') let gtotal: number = 0 try { - const workspaces = await listWorkspacesPure(db, productId) + const workspaces = await listWorkspacesPure(db) for (const workspace of workspaces) { if (cmd.workspace !== '' && workspace.workspace !== cmd.workspace) { continue } let total: number = 0 - const wsDb = getWorkspaceDB(client, { name: workspace.workspace, productId }) + const wsDb = getWorkspaceDB(client, { name: workspace.workspace }) const collections = wsDb.listCollections() while (true) { const collInfo = await collections.next() @@ -282,11 +281,11 @@ export function devTool ( await withDatabase(mongodbUri, async (db, client) => { console.log(`assigning user ${email} to ${workspace}...`) try { - const workspaceInfo = await getWorkspaceById(db, productId, workspace) + const workspaceInfo = await getWorkspaceById(db, workspace) if (workspaceInfo === null) { throw new Error(`workspace ${workspace} not found`) } - const token = generateToken(systemAccountEmail, { name: workspaceInfo.workspace, productId }) + const token = generateToken(systemAccountEmail, { name: workspaceInfo.workspace }) const endpoint = await getTransactorEndpoint(token, 'external') console.log('assigning to workspace', workspaceInfo, endpoint) const client = await createClient(endpoint, token) @@ -294,7 +293,6 @@ export function devTool ( await assignWorkspace( toolCtx, db, - productId, null, email, workspaceInfo.workspace, @@ -324,9 +322,9 @@ export function devTool ( cmd: { token: string, host: string, enable: string, tokenLimit: string, embeddings: string } ) => { console.log(`enabling OpenAI for workspace ${workspace}...`) - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') - await openAIConfig(endpoint, workspace, productId, { + await openAIConfig(endpoint, workspace, { token: cmd.token, endpoint: cmd.host, enabled: cmd.enable === 'true', @@ -363,7 +361,6 @@ export function devTool ( txes, migrateOperations, db, - productId, cmd.init !== undefined || cmd.branding !== undefined ? { initWorkspace: cmd.init, key: cmd.branding ?? 'huly' } : null, @@ -381,15 +378,15 @@ export function devTool ( const { mongodbUri } = prepareTools() console.log(`set user ${email} role for ${workspace}...`) await withDatabase(mongodbUri, async (db) => { - const workspaceInfo = await getWorkspaceById(db, productId, workspace) + const workspaceInfo = await getWorkspaceById(db, workspace) if (workspaceInfo === null) { throw new Error(`workspace ${workspace} not found`) } console.log('assigning to workspace', workspaceInfo) - const token = generateToken(systemAccountEmail, { name: workspaceInfo.workspace, productId }) + const token = generateToken(systemAccountEmail, { name: workspaceInfo.workspace }) const endpoint = await getTransactorEndpoint(token, 'external') const client = await createClient(endpoint, token) - await setRole(toolCtx, db, email, workspace, productId, role, client) + await setRole(toolCtx, db, email, workspace, role, client) await client.close() }) }) @@ -413,7 +410,7 @@ export function devTool ( .action(async (workspace, cmd: { force: boolean, indexes: boolean }) => { const { mongodbUri, version, txes, migrateOperations } = prepareTools() await withDatabase(mongodbUri, async (db) => { - const info = await getWorkspaceById(db, productId, workspace) + const info = await getWorkspaceById(db, workspace) if (info === null) { throw new Error(`workspace ${workspace} not found`) } @@ -425,7 +422,6 @@ export function devTool ( version, txes, migrateOperations, - productId, db, info.workspaceUrl ?? info.workspace, consoleModelLogger, @@ -461,7 +457,7 @@ export function devTool ( }) => { const { mongodbUri, version, txes, migrateOperations } = prepareTools() await withDatabase(mongodbUri, async (db, client) => { - const worker = new UpgradeWorker(db, client, version, txes, migrateOperations, productId) + const worker = new UpgradeWorker(db, client, version, txes, migrateOperations) await worker.upgradeAll(toolCtx, { errorHandler: async (ws, err) => {}, force: cmd.force, @@ -484,7 +480,7 @@ export function devTool ( .action(async (cmd: { remove: boolean, disable: boolean, exclude: string, timeout: string }) => { const { mongodbUri } = prepareTools() await withDatabase(mongodbUri, async (db, client) => { - const workspaces = new Map((await listWorkspacesPure(db, productId)).map((p) => [p._id.toString(), p])) + const workspaces = new Map((await listWorkspacesPure(db)).map((p) => [p._id.toString(), p])) const accounts = await listAccounts(db) @@ -516,7 +512,7 @@ export function devTool ( lastVisitDays }) if (cmd.remove) { - await dropWorkspaceFull(toolCtx, db, client, productId, null, ws.workspace, adapter) + await dropWorkspaceFull(toolCtx, db, client, null, ws.workspace, adapter) } } else { toolCtx.warn(' +++ used', { @@ -542,15 +538,15 @@ export function devTool ( await withStorage(mongodbUri, async (storageAdapter) => { await withDatabase(mongodbUri, async (db, client) => { - const ws = await getWorkspaceById(db, productId, workspace) + const ws = await getWorkspaceById(db, workspace) if (ws === null) { console.log('no workspace exists') return } if (cmd.full) { - await dropWorkspaceFull(toolCtx, db, client, productId, null, workspace, storageAdapter) + await dropWorkspaceFull(toolCtx, db, client, null, workspace, storageAdapter) } else { - await dropWorkspace(toolCtx, db, productId, null, workspace) + await dropWorkspace(toolCtx, db, null, workspace) } }) }) @@ -564,11 +560,11 @@ export function devTool ( const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (storageAdapter) => { await withDatabase(mongodbUri, async (db, client) => { - for (const workspace of await listWorkspacesByAccount(db, productId, email)) { + for (const workspace of await listWorkspacesByAccount(db, email)) { if (cmd.full) { - await dropWorkspaceFull(toolCtx, db, client, productId, null, workspace.workspace, storageAdapter) + await dropWorkspaceFull(toolCtx, db, client, null, workspace.workspace, storageAdapter) } else { - await dropWorkspace(toolCtx, db, productId, null, workspace.workspace) + await dropWorkspace(toolCtx, db, null, workspace.workspace) } } }) @@ -581,7 +577,7 @@ export function devTool ( .action(async (email, cmd: { full: boolean }) => { const { mongodbUri } = prepareTools() await withDatabase(mongodbUri, async (db, client) => { - for (const workspace of await listWorkspacesByAccount(db, productId, email)) { + for (const workspace of await listWorkspacesByAccount(db, email)) { console.log(workspace.workspace, workspace.workspaceUrl, workspace.workspaceName) } }) @@ -595,11 +591,11 @@ export function devTool ( await withStorage(mongodbUri, async (storageAdapter) => { await withDatabase(mongodbUri, async (db, client) => { - const workspacesJSON = await listWorkspacesPure(db, productId) + const workspacesJSON = await listWorkspacesPure(db) for (const ws of workspacesJSON) { const lastVisit = Math.floor((Date.now() - ws.lastVisit) / 1000 / 3600 / 24) if (lastVisit > 30) { - await dropWorkspaceFull(toolCtx, db, client, productId, null, ws.workspace, storageAdapter) + await dropWorkspaceFull(toolCtx, db, client, null, ws.workspace, storageAdapter) } } }) @@ -613,7 +609,7 @@ export function devTool ( .action(async (cmd: { expired: boolean }) => { const { mongodbUri, version } = prepareTools() await withDatabase(mongodbUri, async (db) => { - const workspacesJSON = await listWorkspacesPure(db, productId) + const workspacesJSON = await listWorkspacesPure(db) for (const ws of workspacesJSON) { let lastVisit = Math.floor((Date.now() - ws.lastVisit) / 1000 / 3600 / 24) if (cmd.expired && lastVisit <= 7) { @@ -653,9 +649,9 @@ export function devTool ( program.command('fix-person-accounts').action(async () => { const { mongodbUri, version } = prepareTools() await withDatabase(mongodbUri, async (db, client) => { - const ws = await listWorkspacesPure(db, productId) + const ws = await listWorkspacesPure(db) for (const w of ws) { - const wsDb = getWorkspaceDB(client, { name: w.workspace, productId }) + const wsDb = getWorkspaceDB(client, { name: w.workspace }) await wsDb.collection('tx').updateMany( { objectClass: contact.class.PersonAccount, @@ -675,7 +671,7 @@ export function devTool ( .action(async () => { const { mongodbUri } = prepareTools() await withDatabase(mongodbUri, async (db) => { - const workspaces = await listWorkspacesPure(db, productId) + const workspaces = await listWorkspacesPure(db) const accounts = await listAccounts(db) for (const a of accounts) { const wss = a.workspaces.map((it) => it.toString()) @@ -694,7 +690,7 @@ export function devTool ( .action(async (email: string, cmd) => { const { mongodbUri } = prepareTools() await withDatabase(mongodbUri, async (db) => { - await dropAccount(toolCtx, db, productId, null, email) + await dropAccount(toolCtx, db, null, email) }) }) @@ -727,7 +723,7 @@ export function devTool ( } ) => { const storage = await createFileBackupStorage(dirName) - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await backup(toolCtx, endpoint, wsid, storage, { force: cmd.force, @@ -778,7 +774,7 @@ export function devTool ( cmd: { merge: boolean, parallel: string, recheck: boolean, include: string, skip: string } ) => { const storage = await createFileBackupStorage(dirName) - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await restore(toolCtx, endpoint, wsid, storage, { date: parseInt(date ?? '-1'), @@ -805,13 +801,8 @@ export function devTool ( .action(async (bucketName: string, dirName: string, workspace: string, cmd) => { const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { - const storage = await createStorageBackupStorage( - toolCtx, - adapter, - getWorkspaceId(bucketName, productId), - dirName - ) - const wsid = getWorkspaceId(workspace, productId) + const storage = await createStorageBackupStorage(toolCtx, adapter, getWorkspaceId(bucketName), dirName) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await backup(toolCtx, endpoint, wsid, storage) }) @@ -824,12 +815,7 @@ export function devTool ( .action(async (bucketName: string, dirName: string, cmd: { force: boolean }) => { const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { - const storage = await createStorageBackupStorage( - toolCtx, - adapter, - getWorkspaceId(bucketName, productId), - dirName - ) + const storage = await createStorageBackupStorage(toolCtx, adapter, getWorkspaceId(bucketName), dirName) await compactBackup(toolCtx, storage, cmd.force) }) }) @@ -843,13 +829,8 @@ export function devTool ( await withDatabase(mongodbUri, async (db) => { const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { - const storage = await createStorageBackupStorage( - toolCtx, - adapter, - getWorkspaceId(bucketName, productId), - dirName - ) - const workspaces = await listWorkspacesPure(db, productId) + const storage = await createStorageBackupStorage(toolCtx, adapter, getWorkspaceId(bucketName), dirName) + const workspaces = await listWorkspacesPure(db) for (const w of workspaces) { console.log(`clearing ${w.workspace} history:`) @@ -865,7 +846,7 @@ export function devTool ( const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { const storage = await createStorageBackupStorage(toolCtx, adapter, getWorkspaceId(bucketName), dirName) - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await restore(toolCtx, endpoint, wsid, storage, { date: parseInt(date ?? '-1') @@ -878,12 +859,7 @@ export function devTool ( .action(async (bucketName: string, dirName: string, cmd) => { const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { - const storage = await createStorageBackupStorage( - toolCtx, - adapter, - getWorkspaceId(bucketName, productId), - dirName - ) + const storage = await createStorageBackupStorage(toolCtx, adapter, getWorkspaceId(bucketName), dirName) await backupList(storage) }) }) @@ -908,7 +884,7 @@ export function devTool ( .description('restore workspace transactions and minio resources from previous dump.') .action(async (workspace: string, cmd) => { const { mongodbUri, txes } = prepareTools() - await diffWorkspace(mongodbUri, getWorkspaceId(workspace, productId), txes) + await diffWorkspace(mongodbUri, getWorkspaceId(workspace), txes) }) program @@ -926,7 +902,7 @@ export function devTool ( } console.log(`clearing ${workspace} history:`) - await clearTelegramHistory(toolCtx, mongodbUri, getWorkspaceId(workspace, productId), telegramDB, adapter) + await clearTelegramHistory(toolCtx, mongodbUri, getWorkspaceId(workspace), telegramDB, adapter) }) }) }) @@ -944,21 +920,21 @@ export function devTool ( process.exit(1) } - const workspaces = await listWorkspacesPure(db, productId) + const workspaces = await listWorkspacesPure(db) for (const w of workspaces) { console.log(`clearing ${w.workspace} history:`) - await clearTelegramHistory(toolCtx, mongodbUri, getWorkspaceId(w.workspace, productId), telegramDB, adapter) + await clearTelegramHistory(toolCtx, mongodbUri, getWorkspaceId(w.workspace), telegramDB, adapter) } }) }) }) program - .command('generate-token ') + .command('generate-token ') .description('generate token') - .action(async (name: string, workspace: string, productId) => { - console.log(generateToken(name, getWorkspaceId(workspace, productId))) + .action(async (name: string, workspace: string) => { + console.log(generateToken(name, getWorkspaceId(workspace))) }) program .command('decode-token ') @@ -977,7 +953,7 @@ export function devTool ( const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { await withDatabase(mongodbUri, async (db) => { - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await cleanWorkspace(toolCtx, mongodbUri, wsid, adapter, getElasticUrl(), endpoint, cmd) }) @@ -986,7 +962,7 @@ export function devTool ( program.command('clean-empty-buckets').action(async (cmd: any) => { const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { - const buckets = await adapter.listBuckets(toolCtx, productId) + const buckets = await adapter.listBuckets(toolCtx) for (const ws of buckets) { const l = await ws.list() if ((await l.next()) === undefined) { @@ -1006,8 +982,7 @@ export function devTool ( const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { const wsId: WorkspaceId = { - name: workspace, - productId + name: workspace } const token = generateToken(systemAccountEmail, wsId) const endpoint = await getTransactorEndpoint(token) @@ -1023,8 +998,7 @@ export function devTool ( const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { const wsId: WorkspaceId = { - name: workspace, - productId + name: workspace } const token = generateToken(systemAccountEmail, wsId) const endpoint = await getTransactorEndpoint(token) @@ -1057,13 +1031,13 @@ export function devTool ( console.log('moving files to storage provider', exAdapter.defaultAdapter) - const workspaces = await listWorkspacesPure(db, productId) + const workspaces = await listWorkspacesPure(db) for (const workspace of workspaces) { if (cmd.workspace !== '' && workspace.workspace !== cmd.workspace) { continue } - const wsId = getWorkspaceId(workspace.workspace, productId) + const wsId = getWorkspaceId(workspace.workspace) await moveFiles(toolCtx, wsId, exAdapter, parseInt(cmd.blobLimit)) } } catch (err: any) { @@ -1076,7 +1050,7 @@ export function devTool ( program.command('fix-bw-workspace ').action(async (workspace: string) => { const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { - await fixMinioBW(toolCtx, getWorkspaceId(workspace, productId), adapter) + await fixMinioBW(toolCtx, getWorkspaceId(workspace), adapter) }) }) @@ -1084,7 +1058,7 @@ export function devTool ( .command('clean-removed-transactions ') .description('clean removed transactions') .action(async (workspace: string, cmd: any) => { - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const token = generateToken(systemAccountEmail, wsid) const endpoint = await getTransactorEndpoint(token) await cleanRemovedTransactions(wsid, endpoint) @@ -1094,7 +1068,7 @@ export function devTool ( .command('clean-archived-spaces ') .description('clean archived spaces') .action(async (workspace: string, cmd: any) => { - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const token = generateToken(systemAccountEmail, wsid) const endpoint = await getTransactorEndpoint(token) await cleanArchivedSpaces(wsid, endpoint) @@ -1104,7 +1078,7 @@ export function devTool ( .command('chunter-fix-comments ') .description('chunter-fix-comments') .action(async (workspace: string, cmd: any) => { - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const token = generateToken(systemAccountEmail, wsid) const endpoint = await getTransactorEndpoint(token) await fixCommentDoubleIdCreate(wsid, endpoint) @@ -1117,7 +1091,7 @@ export function devTool ( .option('--property ', 'Property name', '') .option('--detail ', 'Show details', false) .action(async (workspace: string, cmd: { detail: boolean, mixin: string, property: string }) => { - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const token = generateToken(systemAccountEmail, wsid) const endpoint = await getTransactorEndpoint(token) await showMixinForeignAttributes(wsid, endpoint, cmd) @@ -1130,7 +1104,7 @@ export function devTool ( .option('--property ', 'Property name', '') .action(async (workspace: string, cmd: { mixin: string, property: string }) => { const { mongodbUri } = prepareTools() - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const token = generateToken(systemAccountEmail, wsid) const endpoint = await getTransactorEndpoint(token) await fixMixinForeignAttributes(mongodbUri, wsid, endpoint, cmd) @@ -1144,7 +1118,7 @@ export function devTool ( .option('--list', 'List plugin states', false) .action(async (workspace: string, cmd: { enable: string, disable: string, list: boolean }) => { console.log(JSON.stringify(cmd)) - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await changeConfiguration(wsid, endpoint, cmd) }) @@ -1160,10 +1134,10 @@ export function devTool ( await withDatabase(mongodbUri, async (db) => { console.log('configure all workspaces') console.log(JSON.stringify(cmd)) - const workspaces = await listWorkspacesRaw(db, productId) + const workspaces = await listWorkspacesRaw(db) for (const ws of workspaces) { console.log('configure', ws.workspaceName ?? ws.workspace) - const wsid = getWorkspaceId(ws.workspace, productId) + const wsid = getWorkspaceId(ws.workspace) const token = generateToken(systemAccountEmail, wsid) const endpoint = await getTransactorEndpoint(token) await changeConfiguration(wsid, endpoint, cmd) @@ -1176,7 +1150,7 @@ export function devTool ( .description('optimize model') .action(async (workspace: string, cmd: { enable: string, disable: string, list: boolean }) => { console.log(JSON.stringify(cmd)) - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const token = generateToken(systemAccountEmail, wsid) const endpoint = await getTransactorEndpoint(token) await optimizeModel(wsid, endpoint) @@ -1212,17 +1186,17 @@ export function devTool ( return } - const allWorkspacesPure = Array.from(await listWorkspacesPure(db, productId)) + const allWorkspacesPure = Array.from(await listWorkspacesPure(db)) const allWorkspaces = new Map(allWorkspacesPure.map((it) => [it.workspace, it])) let workspaces = cmd.workspaces .split(',') .map((it) => it.trim()) .filter((it) => it.length > 0) - .map((it) => getWorkspaceId(it, productId)) + .map((it) => getWorkspaceId(it)) if (cmd.workspaces.length === 0) { - workspaces = allWorkspacesPure.map((it) => getWorkspaceId(it.workspace, productId)) + workspaces = allWorkspacesPure.map((it) => getWorkspaceId(it.workspace)) } const accounts = new Map(Array.from(await listAccounts(db)).map((it) => [it._id.toString(), it.email])) @@ -1269,7 +1243,7 @@ export function devTool ( .description('fix skills for workspace') .action(async (workspace: string, step: string) => { const { mongodbUri } = prepareTools() - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const token = generateToken(systemAccountEmail, wsid) const endpoint = await getTransactorEndpoint(token) await fixSkills(mongodbUri, wsid, endpoint, step) @@ -1281,7 +1255,7 @@ export function devTool ( .action(async (workspace: string) => { const { mongodbUri } = prepareTools() console.log('Restoring recruiting task types in workspace ', workspace, '...') - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await restoreRecruitingTaskTypes(mongodbUri, wsid, endpoint) }) @@ -1292,7 +1266,7 @@ export function devTool ( .action(async (workspace: string) => { const { mongodbUri } = prepareTools() console.log('Restoring recruiting task types in workspace ', workspace, '...') - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await restoreHrTaskTypesFromUpdates(mongodbUri, wsid, endpoint) }) @@ -1312,7 +1286,7 @@ export function devTool ( cmd: { objectId: string, objectClass: string, type: string, attribute: string, value: string, domain: string } ) => { const { mongodbUri } = prepareTools() - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await updateField(mongodbUri, wsid, endpoint, cmd) } @@ -1323,7 +1297,7 @@ export function devTool ( .description('reindex workspace to elastic') .action(async (workspace: string) => { const { mongodbUri } = prepareTools() - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await recreateElastic(mongodbUri, wsid, endpoint) }) @@ -1334,7 +1308,7 @@ export function devTool ( .action(async (workspace: string) => { const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { - const wsid = getWorkspaceId(workspace, productId) + const wsid = getWorkspaceId(workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external') await fixJsonMarkup(toolCtx, mongodbUri, adapter, wsid, endpoint) }) @@ -1346,7 +1320,7 @@ export function devTool ( .action(async (workspaces: string) => { const { mongodbUri } = prepareTools() await withStorage(mongodbUri, async (adapter) => { - await removeDuplicateIds(toolCtx, mongodbUri, adapter, productId, accountsUrl, workspaces) + await removeDuplicateIds(toolCtx, mongodbUri, adapter, accountsUrl, workspaces) }) }) diff --git a/dev/tool/src/openai.ts b/dev/tool/src/openai.ts index 81d627a5f7e..b69478d45b7 100644 --- a/dev/tool/src/openai.ts +++ b/dev/tool/src/openai.ts @@ -5,10 +5,9 @@ import { connect } from '@hcengineering/server-tool' export async function openAIConfig ( transactorUrl: string, workspace: string, - productId: string, opt: { endpoint: string, token: string, enabled: boolean, tokenLimit: number, embeddings: boolean } ): Promise { - const connection = await connect(transactorUrl, getWorkspaceId(workspace, productId), '#configurator@hc.engineering') + const connection = await connect(transactorUrl, getWorkspaceId(workspace), '#configurator@hc.engineering') try { const ops = new TxOperations(connection, core.account.System) diff --git a/dev/tool/src/renameAccount.ts b/dev/tool/src/renameAccount.ts index 21f734b0b6f..421400305fa 100644 --- a/dev/tool/src/renameAccount.ts +++ b/dev/tool/src/renameAccount.ts @@ -9,7 +9,6 @@ import { type Db } from 'mongodb' export async function renameAccount ( ctx: MeasureContext, db: Db, - productId: string, accountsUrl: string, oldEmail: string, newEmail: string @@ -26,13 +25,12 @@ export async function renameAccount ( await changeEmail(ctx, db, account, newEmail) - await fixWorkspaceEmails(account, db, productId, accountsUrl, oldEmail, newEmail) + await fixWorkspaceEmails(account, db, accountsUrl, oldEmail, newEmail) } export async function fixAccountEmails ( ctx: MeasureContext, db: Db, - productId: string, transactorUrl: string, oldEmail: string, newEmail: string @@ -42,26 +40,25 @@ export async function fixAccountEmails ( throw new Error("Account does'n exists") } - await fixWorkspaceEmails(account, db, productId, transactorUrl, oldEmail, newEmail) + await fixWorkspaceEmails(account, db, transactorUrl, oldEmail, newEmail) } async function fixWorkspaceEmails ( account: Account, db: Db, - productId: string, accountsUrl: string, oldEmail: string, newEmail: string ): Promise { const accountWorkspaces = account.workspaces.map((it) => it.toString()) // We need to update all workspaces - const workspaces = await listWorkspacesPure(db, productId) + const workspaces = await listWorkspacesPure(db) for (const ws of workspaces) { if (!accountWorkspaces.includes(ws._id.toString())) { continue } console.log('checking workspace', ws.workspaceName, ws.workspace) - const wsid = getWorkspaceId(ws.workspace, productId) + const wsid = getWorkspaceId(ws.workspace) const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid)) // Let's connect and update account information. @@ -75,7 +72,7 @@ async function fixEmailInWorkspace ( oldEmail: string, newEmail: string ): Promise { - const connection = await connect(transactorUrl, { name: ws.workspace, productId: ws.productId }, undefined, { + const connection = await connect(transactorUrl, { name: ws.workspace }, undefined, { mode: 'backup', model: 'upgrade', // Required for force all clients reload after operation will be complete. admin: 'true' diff --git a/packages/core/src/classes.ts b/packages/core/src/classes.ts index b8e42732c00..e847294dfee 100644 --- a/packages/core/src/classes.ts +++ b/packages/core/src/classes.ts @@ -654,7 +654,6 @@ export interface DomainIndexConfiguration extends Doc { export interface BaseWorkspaceInfo { workspace: string // An uniq workspace name, Database names - productId: string disabled?: boolean version?: Data branding?: string diff --git a/packages/core/src/component.ts b/packages/core/src/component.ts index d751649ae91..2b26d1e5a68 100644 --- a/packages/core/src/component.ts +++ b/packages/core/src/component.ts @@ -162,8 +162,7 @@ export default plugin(coreId, { }, status: { ObjectNotFound: '' as StatusCode<{ _id: Ref }>, - ItemNotFound: '' as StatusCode<{ _id: Ref, _localId: string }>, - InvalidProduct: '' as StatusCode<{ productId: string }> + ItemNotFound: '' as StatusCode<{ _id: Ref, _localId: string }> }, version: { Model: '' as Ref diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 895d1b0e1a6..c8fc702086b 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -122,7 +122,6 @@ export function toFindResult (docs: T[], total?: number, lookupMa */ export interface WorkspaceId { name: string - productId: string } /** @@ -136,20 +135,20 @@ export interface WorkspaceIdWithUrl extends WorkspaceId { /** * @public * - * Combine workspace with productId, if not equal '' + * Previously was combining workspace with productId, if not equal '' + * Now just returning workspace as is. Keeping it to simplify further refactoring of ws id. */ -export function getWorkspaceId (workspace: string, productId: string = ''): WorkspaceId { +export function getWorkspaceId (workspace: string): WorkspaceId { return { - name: workspace, - productId + name: workspace } } /** * @public */ -export function toWorkspaceString (id: WorkspaceId, sep = '@'): string { - return id.name + (id.productId === '' ? '' : sep + id.productId) +export function toWorkspaceString (id: WorkspaceId): string { + return id.name } const attributesPrefix = 'attributes.' diff --git a/packages/platform/lang/en.json b/packages/platform/lang/en.json index 5e01432a6ee..b5ddbaf8f36 100644 --- a/packages/platform/lang/en.json +++ b/packages/platform/lang/en.json @@ -18,7 +18,6 @@ "WorkspaceRateLimit": "Server is busy, Please wait a bit and try again", "AccountAlreadyConfirmed": "Account already confirmed", "WorkspaceAlreadyExists": "Workspace already exists", - "ProductIdMismatch": "Product Mismatch", "InvalidOtp": "Invalid code" } } diff --git a/packages/platform/lang/es.json b/packages/platform/lang/es.json index 04c6ec0b1da..e008c8eb477 100644 --- a/packages/platform/lang/es.json +++ b/packages/platform/lang/es.json @@ -18,7 +18,6 @@ "WorkspaceRateLimit": "El servidor está ocupado. Espere un momento e inténtelo de nuevo", "AccountAlreadyConfirmed": "La cuenta ya está confirmada", "WorkspaceAlreadyExists": "El espacio de trabajo ya existe", - "ProductIdMismatch": "Desajuste de producto", "InvalidOtp": "Código no válido" } } \ No newline at end of file diff --git a/packages/platform/lang/fr.json b/packages/platform/lang/fr.json index 09ae879b641..60e421c310d 100644 --- a/packages/platform/lang/fr.json +++ b/packages/platform/lang/fr.json @@ -18,7 +18,6 @@ "WorkspaceRateLimit": "Le serveur est occupé, veuillez patienter un moment et réessayer", "AccountAlreadyConfirmed": "Compte déjà confirmé", "WorkspaceAlreadyExists": "L'espace de travail existe déjà", - "ProductIdMismatch": "Incompatibilité de produit", "InvalidOtp": "Code invalide" } } \ No newline at end of file diff --git a/packages/platform/lang/pt.json b/packages/platform/lang/pt.json index ece77184371..603a90a8ad5 100644 --- a/packages/platform/lang/pt.json +++ b/packages/platform/lang/pt.json @@ -18,7 +18,6 @@ "WorkspaceRateLimit": "O servidor está ocupado. Por favor, espere um pouco e tente novamente", "AccountAlreadyConfirmed": "Conta já confirmada", "WorkspaceAlreadyExists": "Espaço de trabalho já existe", - "ProductIdMismatch": "Discrepância de produto", "InvalidOtp": "Código inválido" } } \ No newline at end of file diff --git a/packages/platform/lang/ru.json b/packages/platform/lang/ru.json index 7b5759a1593..7772a8efb1e 100644 --- a/packages/platform/lang/ru.json +++ b/packages/platform/lang/ru.json @@ -18,7 +18,6 @@ "WorkspaceRateLimit": "Сервер перегружен, пожалуйста, подождите", "AccountAlreadyConfirmed": "Аккаунт уже подтвержден", "WorkspaceAlreadyExists": "Рабочее пространство уже существует", - "ProductIdMismatch": "Продукт не соответствует", "InvalidOtp": "Неверный код" } } diff --git a/packages/platform/lang/zh.json b/packages/platform/lang/zh.json index b153e213859..062c41d319a 100644 --- a/packages/platform/lang/zh.json +++ b/packages/platform/lang/zh.json @@ -18,7 +18,6 @@ "WorkspaceRateLimit": "服务器繁忙,请稍后再试", "AccountAlreadyConfirmed": "账户已确认", "WorkspaceAlreadyExists": "工作区已存在", - "ProductIdMismatch": "产品不匹配", "InvalidOtp": "无效的代码" } } diff --git a/packages/platform/src/platform.ts b/packages/platform/src/platform.ts index eb9c7843062..b4b7b2503cc 100644 --- a/packages/platform/src/platform.ts +++ b/packages/platform/src/platform.ts @@ -153,7 +153,6 @@ export default plugin(platformId, { AccountAlreadyConfirmed: '' as StatusCode<{ account: string }>, WorkspaceAlreadyExists: '' as StatusCode<{ workspace: string }>, WorkspaceRateLimit: '' as StatusCode<{ workspace: string }>, - ProductIdMismatch: '' as StatusCode<{ productId: string }>, InvalidOtp: '' as StatusCode }, metadata: { diff --git a/packages/storage/src/index.ts b/packages/storage/src/index.ts index f4183dff349..5d3744fdc55 100644 --- a/packages/storage/src/index.ts +++ b/packages/storage/src/index.ts @@ -43,7 +43,7 @@ export interface StorageAdapter { make: (ctx: MeasureContext, workspaceId: WorkspaceId) => Promise delete: (ctx: MeasureContext, workspaceId: WorkspaceId) => Promise - listBuckets: (ctx: MeasureContext, productId: string) => Promise + listBuckets: (ctx: MeasureContext) => Promise remove: (ctx: MeasureContext, workspaceId: WorkspaceId, objectNames: string[]) => Promise listStream: (ctx: MeasureContext, workspaceId: WorkspaceId, prefix?: string) => Promise stat: (ctx: MeasureContext, workspaceId: WorkspaceId, objectName: string) => Promise @@ -104,7 +104,7 @@ export class DummyStorageAdapter implements StorageAdapter, StorageAdapterEx { } } - async listBuckets (ctx: MeasureContext, productId: string): Promise { + async listBuckets (ctx: MeasureContext): Promise { return [] } diff --git a/pods/account/src/__start.ts b/pods/account/src/__start.ts index 11e9ec066c8..dd0dbfb33e0 100644 --- a/pods/account/src/__start.ts +++ b/pods/account/src/__start.ts @@ -43,6 +43,6 @@ const intTimer = setInterval(() => { const brandingPath = process.env.BRANDING_PATH -serveAccount(metricsContext, getModelVersion(), txes, migrateOperations, '', loadBrandingMap(brandingPath), () => { +serveAccount(metricsContext, getModelVersion(), txes, migrateOperations, loadBrandingMap(brandingPath), () => { clearInterval(intTimer) }) diff --git a/pods/authProviders/src/github.ts b/pods/authProviders/src/github.ts index 237aae04b81..cde9d123682 100644 --- a/pods/authProviders/src/github.ts +++ b/pods/authProviders/src/github.ts @@ -13,7 +13,6 @@ export function registerGithub ( router: Router, accountsUrl: string, db: Db, - productId: string, frontUrl: string, brandings: BrandingMap ): string | undefined { @@ -71,21 +70,11 @@ export function registerGithub ( const state = safeParseAuthState(ctx.query?.state) const branding = getBranding(brandings, state?.branding) if (state.inviteId != null && state.inviteId !== '') { - loginInfo = await joinWithProvider( - measureCtx, - db, - productId, - null, - email, - first, - last, - state.inviteId as any, - { - githubId: ctx.state.user.id - } - ) + loginInfo = await joinWithProvider(measureCtx, db, null, email, first, last, state.inviteId as any, { + githubId: ctx.state.user.id + }) } else { - loginInfo = await loginWithProvider(measureCtx, db, productId, null, email, first, last, { + loginInfo = await loginWithProvider(measureCtx, db, null, email, first, last, { githubId: ctx.state.user.id }) } diff --git a/pods/authProviders/src/google.ts b/pods/authProviders/src/google.ts index cfda04830cd..5241440acd4 100644 --- a/pods/authProviders/src/google.ts +++ b/pods/authProviders/src/google.ts @@ -13,7 +13,6 @@ export function registerGoogle ( router: Router, accountsUrl: string, db: Db, - productId: string, frontUrl: string, brandings: BrandingMap ): string | undefined { @@ -76,18 +75,9 @@ export function registerGoogle ( const state = safeParseAuthState(ctx.query?.state) const branding = getBranding(brandings, state?.branding) if (state.inviteId != null && state.inviteId !== '') { - loginInfo = await joinWithProvider( - measureCtx, - db, - productId, - null, - email, - first, - last, - state.inviteId as any - ) + loginInfo = await joinWithProvider(measureCtx, db, null, email, first, last, state.inviteId as any) } else { - loginInfo = await loginWithProvider(measureCtx, db, productId, null, email, first, last) + loginInfo = await loginWithProvider(measureCtx, db, null, email, first, last) } const origin = concatLink(branding?.front ?? frontUrl, '/login/auth') diff --git a/pods/authProviders/src/index.ts b/pods/authProviders/src/index.ts index a66177059eb..0ab49993c06 100644 --- a/pods/authProviders/src/index.ts +++ b/pods/authProviders/src/index.ts @@ -16,7 +16,6 @@ export type AuthProvider = ( router: Router, accountsUrl: string, db: Db, - productId: string, frontUrl: string, brandings: BrandingMap ) => string | undefined @@ -26,7 +25,6 @@ export function registerProviders ( app: Koa, router: Router, db: Db, - productId: string, serverSecret: string, frontUrl: string | undefined, brandings: BrandingMap @@ -59,12 +57,12 @@ export function registerProviders ( }) }) - registerToken(ctx, passport, router, accountsUrl, db, productId, frontUrl, brandings) + registerToken(ctx, passport, router, accountsUrl, db, frontUrl, brandings) const res: string[] = [] const providers: AuthProvider[] = [registerGoogle, registerGithub] for (const provider of providers) { - const value = provider(ctx, passport, router, accountsUrl, db, productId, frontUrl, brandings) + const value = provider(ctx, passport, router, accountsUrl, db, frontUrl, brandings) if (value !== undefined) res.push(value) } diff --git a/pods/authProviders/src/token.ts b/pods/authProviders/src/token.ts index 568160e7ac0..0f7b0b4bc1e 100644 --- a/pods/authProviders/src/token.ts +++ b/pods/authProviders/src/token.ts @@ -13,7 +13,6 @@ export function registerToken ( router: Router, accountsUrl: string, db: Db, - productId: string, frontUrl: string, brandings: BrandingMap ): string | undefined { @@ -22,7 +21,7 @@ export function registerToken ( new CustomStrategy(function (req: any, done: any) { const token = req.body.token ?? req.query.token - getAccountInfoByToken(measureCtx, db, productId, null, token) + getAccountInfoByToken(measureCtx, db, null, token) .then((user: any) => done(null, user)) .catch((err: any) => done(err)) }) diff --git a/pods/server/src/__start.ts b/pods/server/src/__start.ts index a3306be78cf..ba2027d9780 100644 --- a/pods/server/src/__start.ts +++ b/pods/server/src/__start.ts @@ -66,7 +66,6 @@ const shutdown = start(config.url, { serverFactory, indexParallel: 2, indexProcessing: 500, - productId: '', brandingMap: loadBrandingMap(config.brandingPath), accountsUrl: config.accountsUrl, enableCompression: config.enableCompression diff --git a/pods/server/src/server.ts b/pods/server/src/server.ts index 870d96f0ebd..aea3ba6f5c6 100644 --- a/pods/server/src/server.ts +++ b/pods/server/src/server.ts @@ -37,7 +37,6 @@ export function start ( storageConfig: StorageConfiguration rekoniUrl: string port: number - productId: string brandingMap: BrandingMap serverFactory: ServerFactory @@ -80,7 +79,6 @@ export function start ( pipelineFactory, sessionFactory, port: opt.port, - productId: opt.productId, brandingMap: opt.brandingMap, serverFactory: opt.serverFactory, enableCompression: opt.enableCompression, diff --git a/server-plugins/ai-bot-resources/src/adapter.ts b/server-plugins/ai-bot-resources/src/adapter.ts index 0ad6f9f5fb9..9668f3534d9 100644 --- a/server-plugins/ai-bot-resources/src/adapter.ts +++ b/server-plugins/ai-bot-resources/src/adapter.ts @@ -38,19 +38,14 @@ class AIBotAdapter implements AIBotServiceAdapter { return } const existsRecord = await this.workspacesInfoCollection.findOne({ - workspace: workspace.name, - productId: workspace.productId + workspace: workspace.name }) if (existsRecord != null && !existsRecord.active) { - await this.workspacesInfoCollection.updateOne( - { workspace: workspace.name, productId: workspace.productId }, - { $set: { active: true } } - ) + await this.workspacesInfoCollection.updateOne({ workspace: workspace.name }, { $set: { active: true } }) } else if (existsRecord == null) { const record: WorkspaceInfoRecord = { workspace: workspace.name, - productId: workspace.productId, active: true } diff --git a/server-plugins/ai-bot/src/types.ts b/server-plugins/ai-bot/src/types.ts index 89d45b440ae..96ae3e5dba6 100644 --- a/server-plugins/ai-bot/src/types.ts +++ b/server-plugins/ai-bot/src/types.ts @@ -22,7 +22,6 @@ export interface AIBotServiceAdapter extends ServiceAdapter { export interface WorkspaceInfoRecord { workspace: string - productId: string active: boolean avatarPath?: string avatarLastModified?: number diff --git a/server/account-service/src/index.ts b/server/account-service/src/index.ts index 4a5b7430d56..8aec25fc28a 100644 --- a/server/account-service/src/index.ts +++ b/server/account-service/src/index.ts @@ -46,7 +46,6 @@ export function serveAccount ( version: Data, txes: Tx[], migrateOperations: [string, MigrateOperation][], - productId: string, brandings: BrandingMap, onClose?: () => void ): void { @@ -124,10 +123,10 @@ export function serveAccount ( void client.getClient().then(async (p: MongoClient) => { const db = p.db(ACCOUNT_DB) - registerProviders(measureCtx, app, router, db, productId, serverSecret, frontURL, brandings) + registerProviders(measureCtx, app, router, db, serverSecret, frontURL, brandings) // We need to clean workspace with creating === true, since server is restarted. - void cleanInProgressWorkspaces(db, productId) + void cleanInProgressWorkspaces(db) setInterval( () => { @@ -139,7 +138,7 @@ export function serveAccount ( const performUpgrade = (process.env.PERFORM_UPGRADE ?? 'true') === 'true' if (performUpgrade) { await measureCtx.with('upgrade-all-models', {}, async (ctx) => { - worker = new UpgradeWorker(db, p, version, txes, migrateOperations, productId) + worker = new UpgradeWorker(db, p, version, txes, migrateOperations) await worker.upgradeAll(ctx, { errorHandler: async (ws, err) => { Analytics.handleError(err) @@ -253,7 +252,7 @@ export function serveAccount ( const result = await measureCtx.with( request.method, {}, - async (ctx) => await method(ctx, db, productId, branding, request, token) + async (ctx) => await method(ctx, db, branding, request, token) ) worker?.updateResponseStatistics(result) diff --git a/server/account/src/__tests__/account.test_skip.ts b/server/account/src/__tests__/account.test_skip.ts index da40c99894d..f9ca52adc30 100644 --- a/server/account/src/__tests__/account.test_skip.ts +++ b/server/account/src/__tests__/account.test_skip.ts @@ -51,7 +51,7 @@ describe('server', () => { params: [workspace, 'ООО Рога и Копыта'] } - const result = await methods.createWorkspace(metricsContext, db, '', null, request) + const result = await methods.createWorkspace(metricsContext, db, null, request) expect(result.result).toBeDefined() workspace = result.result as string }) @@ -62,12 +62,12 @@ describe('server', () => { params: ['andrey2', '123'] } - const result = await methods.createAccount(metricsContext, db, '', null, request) + const result = await methods.createAccount(metricsContext, db, null, request) expect(result.result).toBeDefined() }) it('should not create, duplicate account', async () => { - await methods.createAccount(metricsContext, db, '', null, { + await methods.createAccount(metricsContext, db, null, { method: 'createAccount', params: ['andrey', '123'] }) @@ -77,20 +77,20 @@ describe('server', () => { params: ['andrey', '123'] } - const result = await methods.createAccount(metricsContext, db, '', null, request) + const result = await methods.createAccount(metricsContext, db, null, request) expect(result.error).toBeDefined() }) it('should login', async () => { - await methods.createAccount(metricsContext, db, '', null, { + await methods.createAccount(metricsContext, db, null, { method: 'createAccount', params: ['andrey', '123'] }) - await methods.createWorkspace(metricsContext, db, '', null, { + await methods.createWorkspace(metricsContext, db, null, { method: 'createWorkspace', params: [workspace, 'ООО Рога и Копыта'] }) - await methods.assignWorkspace(metricsContext, db, '', null, { + await methods.assignWorkspace(metricsContext, db, null, { method: 'assignWorkspace', params: ['andrey', workspace] }) @@ -100,7 +100,7 @@ describe('server', () => { params: ['andrey', '123', workspace] } - const result = await methods.login(metricsContext, db, '', null, request) + const result = await methods.login(metricsContext, db, null, request) expect(result.result).toBeDefined() }) @@ -110,7 +110,7 @@ describe('server', () => { params: ['andrey', '123555', workspace] } - const result = await methods.login(metricsContext, db, '', null, request) + const result = await methods.login(metricsContext, db, null, request) expect(result.error).toBeDefined() }) @@ -120,7 +120,7 @@ describe('server', () => { params: ['andrey1', '123555', workspace] } - const result = await methods.login(metricsContext, db, '', null, request) + const result = await methods.login(metricsContext, db, null, request) expect(result.error).toBeDefined() }) @@ -130,34 +130,34 @@ describe('server', () => { params: ['andrey', '123', 'non-existent-workspace'] } - const result = await methods.login(metricsContext, db, '', null, request) + const result = await methods.login(metricsContext, db, null, request) expect(result.error).toBeDefined() }) it('do remove workspace', async () => { - await methods.createAccount(metricsContext, db, '', null, { + await methods.createAccount(metricsContext, db, null, { method: 'createAccount', params: ['andrey', '123'] }) - await methods.createWorkspace(metricsContext, db, '', null, { + await methods.createWorkspace(metricsContext, db, null, { method: 'createWorkspace', params: [workspace, 'ООО Рога и Копыта'] }) - await methods.assignWorkspace(metricsContext, db, '', null, { + await methods.assignWorkspace(metricsContext, db, null, { method: 'assignWorkspace', params: ['andrey', workspace] }) // Check we had one expect((await getAccount(db, 'andrey'))?.workspaces.length).toEqual(1) - expect((await getWorkspaceByUrl(db, '', workspace))?.accounts.length).toEqual(1) + expect((await getWorkspaceByUrl(db, workspace))?.accounts.length).toEqual(1) - await methods.removeWorkspace(metricsContext, db, '', null, { + await methods.removeWorkspace(metricsContext, db, null, { method: 'removeWorkspace', params: ['andrey', workspace] }) expect((await getAccount(db, 'andrey'))?.workspaces.length).toEqual(0) - expect((await getWorkspaceByUrl(db, '', workspace))?.accounts.length).toEqual(0) + expect((await getWorkspaceByUrl(db, workspace))?.accounts.length).toEqual(0) }) afterAll(async () => { diff --git a/server/account/src/operations.ts b/server/account/src/operations.ts index ecc8182d73b..29917bc0863 100644 --- a/server/account/src/operations.ts +++ b/server/account/src/operations.ts @@ -230,7 +230,6 @@ export interface LoginInfo { */ export interface WorkspaceLoginInfo extends LoginInfo { workspace: string - productId: string workspaceId: string @@ -297,31 +296,21 @@ export async function setAccountAdmin (db: Db, email: string, admin: boolean): P await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: account._id }, { $set: { admin } }) } -function withProductId (productId: string, query: Filter): Filter { - return productId === '' - ? { - $or: [ - { productId: '', ...query }, - { productId: { $exists: false }, ...query } - ] - } - : { productId, ...query } -} /** * @public * @param db - * @param workspaceUrl - * @returns */ -export async function getWorkspaceByUrl (db: Db, productId: string, workspaceUrl: string): Promise { - const res = await db.collection(WORKSPACE_COLLECTION).findOne(withProductId(productId, { workspaceUrl })) +export async function getWorkspaceByUrl (db: Db, workspaceUrl: string): Promise { + const res = await db.collection(WORKSPACE_COLLECTION).findOne({ workspaceUrl }) if (res != null) { return res } // Fallback to old workspaces. return await db .collection(WORKSPACE_COLLECTION) - .findOne(withProductId(productId, { workspace: workspaceUrl, workspaceUrl: { $exists: false } })) + .findOne({ workspace: workspaceUrl, workspaceUrl: { $exists: false } }) } /** @@ -330,8 +319,8 @@ export async function getWorkspaceByUrl (db: Db, productId: string, workspaceUrl * @param workspace - * @returns */ -export async function getWorkspaceById (db: Db, productId: string, workspace: string): Promise { - return await db.collection(WORKSPACE_COLLECTION).findOne(withProductId(productId, { workspace })) +export async function getWorkspaceById (db: Db, workspace: string): Promise { + return await db.collection(WORKSPACE_COLLECTION).findOne({ workspace }) } function toAccountInfo (account: Account): AccountInfo { @@ -343,7 +332,6 @@ function toAccountInfo (account: Account): AccountInfo { async function getAccountInfo ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, email: string, password: string @@ -393,7 +381,6 @@ async function sendOtpEmail (branding: Branding | null, otp: string, email: stri export async function getAccountInfoByToken ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string ): Promise { @@ -412,12 +399,12 @@ export async function getAccountInfoByToken ( } const info = toAccountInfo(account) - const workspaceInfo = await getWorkspaceById(db, productId, workspace.name) + const workspaceInfo = await getWorkspaceById(db, workspace.name) const result = { endpoint: workspaceInfo != null ? getEndpoint(ctx, workspaceInfo, EndpointKind.External) : '', email, confirmed: info.confirmed ?? true, - token: generateToken(email, getWorkspaceId('', productId), getExtra(info)) + token: generateToken(email, getWorkspaceId(''), getExtra(info)) } return result } @@ -433,25 +420,24 @@ export async function getAccountInfoByToken ( export async function login ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string, password: string ): Promise { const email = cleanEmail(_email) try { - const info = await getAccountInfo(ctx, db, productId, branding, email, password) + const info = await getAccountInfo(ctx, db, branding, email, password) const result = { endpoint: '', email, confirmed: info.confirmed ?? true, - token: generateToken(email, getWorkspaceId('', productId), getExtra(info)) + token: generateToken(email, getWorkspaceId(''), getExtra(info)) } - ctx.info('login success', { email, productId }) + ctx.info('login success', { email }) return result } catch (err: any) { Analytics.handleError(err) - ctx.error('login failed', { email, productId, _email, err }) + ctx.error('login failed', { email, _email, err }) throw err } } @@ -478,7 +464,6 @@ async function getNewOtp (db: Db): Promise { export async function sendOtp ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string ): Promise { @@ -526,7 +511,6 @@ async function isOtpValid (db: Db, account: Account, otp: string): Promise(OTP_COLLECTION).deleteMany({ account: account._id }) - ctx.info('otp login success', { email, productId }) + ctx.info('otp login success', { email }) return result } catch (err: any) { Analytics.handleError(err) - ctx.error('otp login failed', { email, productId, _email, err }) + ctx.error('otp login failed', { email, _email, err }) throw err } } @@ -612,7 +596,6 @@ function decodeToken (ctx: MeasureContext, token: string): Token { export async function selectWorkspace ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, workspaceUrl: string, @@ -625,7 +608,7 @@ export async function selectWorkspace ( const endpointKind = kind === 'external' ? EndpointKind.External : EndpointKind.Internal if (email === guestAccountEmail && decodedToken.extra?.guest === 'true') { - const workspaceInfo = await getWorkspaceByUrl(db, productId, workspaceUrl) + const workspaceInfo = await getWorkspaceByUrl(db, workspaceUrl) if (workspaceInfo == null) { throw new PlatformError( new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace: workspaceUrl }) @@ -638,7 +621,6 @@ export async function selectWorkspace ( token, workspace: workspaceUrl, workspaceId: workspaceInfo.workspace, - productId, creating: workspaceInfo.creating, createProgress: workspaceInfo.createProgress } @@ -656,9 +638,9 @@ export async function selectWorkspace ( let workspaceInfo: Workspace | null if (workspaceUrl === '') { // Find from token - workspaceInfo = await getWorkspaceById(db, decodedToken.workspace.productId, decodedToken.workspace.name) + workspaceInfo = await getWorkspaceById(db, decodedToken.workspace.name) } else { - workspaceInfo = await getWorkspaceByUrl(db, productId, workspaceUrl) + workspaceInfo = await getWorkspaceByUrl(db, workspaceUrl) } if (workspaceInfo == null) { throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace: workspaceUrl })) @@ -668,10 +650,9 @@ export async function selectWorkspace ( return { endpoint: getEndpoint(ctx, workspaceInfo, endpointKind), email, - token: generateToken(email, getWorkspaceId(workspaceInfo.workspace, productId), getExtra(accountInfo)), + token: generateToken(email, getWorkspaceId(workspaceInfo.workspace), getExtra(accountInfo)), workspace: workspaceUrl, workspaceId: workspaceInfo.workspace, - productId, creating: workspaceInfo.creating, createProgress: workspaceInfo.createProgress } @@ -691,10 +672,9 @@ export async function selectWorkspace ( const result = { endpoint: getEndpoint(ctx, workspaceInfo, endpointKind), email, - token: generateToken(email, getWorkspaceId(workspaceInfo.workspace, productId), getExtra(accountInfo)), + token: generateToken(email, getWorkspaceId(workspaceInfo.workspace), getExtra(accountInfo)), workspace: workspaceUrl, workspaceId: workspaceInfo.workspace, - productId, creating: workspaceInfo.creating, createProgress: workspaceInfo.createProgress } @@ -749,7 +729,6 @@ export async function useInvite (db: Db, inviteId: ObjectId): Promise { export async function join ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string, password: string, @@ -762,7 +741,6 @@ export async function join ( const ws = await assignWorkspace( ctx, db, - productId, branding, email, workspace.name, @@ -770,8 +748,8 @@ export async function join ( invite?.personId ) - const token = (await login(ctx, db, productId, branding, email, password)).token - const result = await selectWorkspace(ctx, db, productId, branding, token, ws.workspaceUrl ?? ws.workspace, 'external') + const token = (await login(ctx, db, branding, email, password)).token + const result = await selectWorkspace(ctx, db, branding, token, ws.workspaceUrl ?? ws.workspace, 'external') await useInvite(db, inviteId) return result } @@ -802,7 +780,6 @@ export async function confirmEmail (db: Db, _email: string): Promise { export async function confirm ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string ): Promise { @@ -814,17 +791,17 @@ export async function confirm ( } const email = cleanEmail(_email) const account = await confirmEmail(db, email) - const workspaceInfo = await getWorkspaceById(db, productId, decode.workspace.name) + const workspaceInfo = await getWorkspaceById(db, decode.workspace.name) const result = { endpoint: workspaceInfo != null ? getEndpoint(ctx, workspaceInfo, EndpointKind.External) : '', email, - token: generateToken(email, getWorkspaceId('', productId), getExtra(account)) + token: generateToken(email, getWorkspaceId(''), getExtra(account)) } - ctx.info('confirm success', { email, productId }) + ctx.info('confirm success', { email }) return result } -async function sendConfirmation (productId: string, branding: Branding | null, account: Account): Promise { +async function sendConfirmation (branding: Branding | null, account: Account): Promise { const sesURL = getMetadata(accountPlugin.metadata.SES_URL) if (sesURL === undefined || sesURL === '') { console.info('Please provide email service url to enable email confirmations.') @@ -837,7 +814,7 @@ async function sendConfirmation (productId: string, branding: Branding | null, a const token = generateToken( '@confirm', - getWorkspaceId('', productId), + getWorkspaceId(''), getExtra(account, { confirm: account.email }) @@ -874,7 +851,6 @@ async function sendConfirmation (productId: string, branding: Branding | null, a export async function signUpJoin ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string, password: string, @@ -890,7 +866,6 @@ export async function signUpJoin ( await createAcc( ctx, db, - productId, branding, email, password, @@ -901,7 +876,6 @@ export async function signUpJoin ( const ws = await assignWorkspace( ctx, db, - productId, branding, email, workspace.name, @@ -909,8 +883,8 @@ export async function signUpJoin ( invite?.personId ) - const token = (await login(ctx, db, productId, branding, email, password)).token - const result = await selectWorkspace(ctx, db, productId, branding, token, ws.workspaceUrl ?? ws.workspace, 'external') + const token = (await login(ctx, db, branding, email, password)).token + const result = await selectWorkspace(ctx, db, branding, token, ws.workspaceUrl ?? ws.workspace, 'external') await useInvite(db, inviteId) return result } @@ -921,7 +895,6 @@ export async function signUpJoin ( export async function createAcc ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string, password: string | null, @@ -966,7 +939,7 @@ export async function createAcc ( const sesURL = getMetadata(accountPlugin.metadata.SES_URL) if (!confirmed && shouldConfirm) { if (sesURL !== undefined && sesURL !== '') { - await sendConfirmation(productId, branding, newAccount) + await sendConfirmation(branding, newAccount) } else { ctx.info('Please provide email service url to enable email confirmations.') await confirmEmail(db, email) @@ -982,7 +955,6 @@ export async function createAcc ( export async function createAccount ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string, password: string, @@ -994,7 +966,6 @@ export async function createAccount ( const account = await createAcc( ctx, db, - productId, branding, email, password, @@ -1006,7 +977,7 @@ export async function createAccount ( const result = { endpoint: '', email, - token: generateToken(email, getWorkspaceId('', productId), getExtra(account)) + token: generateToken(email, getWorkspaceId(''), getExtra(account)) } return result } @@ -1017,7 +988,6 @@ export async function createAccount ( export async function signUpOtp ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string ): Promise { @@ -1025,9 +995,9 @@ export async function signUpOtp ( const first = email.split('@', 1)[0] ?? '' const last = '' - await createAcc(ctx, db, productId, branding, email, null, first, last, false, false) + await createAcc(ctx, db, branding, email, null, first, last, false, false) - return await sendOtp(ctx, db, productId, branding, _email) + return await sendOtp(ctx, db, branding, _email) } /** @@ -1036,13 +1006,11 @@ export async function signUpOtp ( export async function listWorkspaces ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string ): Promise { decodeToken(ctx, token) // Just verify token is valid - return (await db.collection(WORKSPACE_COLLECTION).find(withProductId(productId, {})).toArray()) - .map((it) => ({ ...it, productId })) + return (await db.collection(WORKSPACE_COLLECTION).find({}).toArray()) .filter((it) => it.disabled !== true) .map(trimWorkspaceInfo) } @@ -1050,15 +1018,14 @@ export async function listWorkspaces ( /** * @public */ -export async function listWorkspacesByAccount (db: Db, productId: string, email: string): Promise { +export async function listWorkspacesByAccount (db: Db, email: string): Promise { const account = await getAccount(db, email) return ( await db .collection(WORKSPACE_COLLECTION) - .find(withProductId(productId, { _id: { $in: account?.workspaces } })) + .find({ _id: { $in: account?.workspaces } }) .toArray() ) - .map((it) => ({ ...it, productId })) .filter((it) => it.disabled !== true) .map(trimWorkspaceInfo) } @@ -1066,19 +1033,15 @@ export async function listWorkspacesByAccount (db: Db, productId: string, email: /** * @public */ -export async function listWorkspacesRaw (db: Db, productId: string): Promise { - return (await db.collection(WORKSPACE_COLLECTION).find(withProductId(productId, {})).toArray()) - .map((it) => ({ ...it, productId })) - .filter((it) => it.disabled !== true) +export async function listWorkspacesRaw (db: Db): Promise { + return (await db.collection(WORKSPACE_COLLECTION).find({}).toArray()).filter((it) => it.disabled !== true) } /** * @public */ -export async function listWorkspacesPure (db: Db, productId: string): Promise { - return (await db.collection(WORKSPACE_COLLECTION).find(withProductId(productId, {})).toArray()).map( - (it) => ({ ...it, productId }) - ) +export async function listWorkspacesPure (db: Db): Promise { + return await db.collection(WORKSPACE_COLLECTION).find({}).toArray() } /** * @public @@ -1087,16 +1050,12 @@ export async function setWorkspaceDisabled (db: Db, workspaceId: Workspace['_id' await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: workspaceId }, { $set: { disabled } }) } -export async function cleanInProgressWorkspaces (db: Db, productId: string): Promise { - const toDelete = ( - await db - .collection(WORKSPACE_COLLECTION) - .find(withProductId(productId, { creating: true })) - .toArray() - ).map((it) => ({ ...it, productId })) +export async function cleanInProgressWorkspaces (db: Db): Promise { + const toDelete = await db.collection(WORKSPACE_COLLECTION).find({ creating: true }).toArray() + const ctx = new MeasureMetricsContext('clean', {}) for (const d of toDelete) { - await dropWorkspace(ctx, db, productId, null, d.workspace) + await dropWorkspace(ctx, db, null, d.workspace) } } @@ -1107,15 +1066,17 @@ export async function cleanExpiredOtp (db: Db): Promise { /** * @public */ -export async function updateWorkspace ( - db: Db, - productId: string, - info: Workspace, - ops: Partial -): Promise { +export async function updateWorkspace (db: Db, info: Workspace, ops: Partial): Promise { await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: info._id }, { $set: { ...info, ...ops } }) } +/** + * @public + */ +export async function clearWorkspaceProductId (db: Db, info: Workspace): Promise { + await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: info._id }, { $unset: { productId: '' } }) +} + /** * @public */ @@ -1145,7 +1106,6 @@ function getEmailName (email: string): string { async function generateWorkspaceRecord ( db: Db, email: string, - productId: string, version: Data, branding: Branding | null, workspaceName: string, @@ -1155,7 +1115,7 @@ async function generateWorkspaceRecord ( const brandingKey = branding?.key ?? 'huly' if (fixedWorkspace !== undefined) { const ws = await coll.find({ workspaceUrl: fixedWorkspace }).toArray() - if ((await getWorkspaceById(db, productId, fixedWorkspace)) !== null || ws.length > 0) { + if ((await getWorkspaceById(db, fixedWorkspace)) !== null || ws.length > 0) { throw new PlatformError( new Status(Severity.ERROR, platform.status.WorkspaceAlreadyExists, { workspace: fixedWorkspace }) ) @@ -1163,7 +1123,6 @@ async function generateWorkspaceRecord ( const data = { workspace: fixedWorkspace, workspaceUrl: fixedWorkspace, - productId, version, branding: brandingKey, workspaceName, @@ -1196,7 +1155,6 @@ async function generateWorkspaceRecord ( const data = { workspace, workspaceUrl, - productId, version, branding: brandingKey, workspaceName, @@ -1242,7 +1200,6 @@ export async function createWorkspace ( txes: Tx[], migrationOperation: [string, MigrateOperation][], db: Db, - productId: string, branding: Branding | null, email: string, workspaceName: string, @@ -1254,7 +1211,7 @@ export async function createWorkspace ( await searchPromise // Safe generate workspace record. - searchPromise = generateWorkspaceRecord(db, email, productId, version, branding, workspaceName, workspace) + searchPromise = generateWorkspaceRecord(db, email, version, branding, workspaceName, workspace) const workspaceInfo = await searchPromise @@ -1283,12 +1240,11 @@ export async function createWorkspace ( try { const wsUrl: WorkspaceIdWithUrl = { name: workspaceInfo.workspace, - productId: workspaceInfo.productId, workspaceName: workspaceInfo.workspaceName ?? '', workspaceUrl: workspaceInfo.workspaceUrl ?? '' } - const wsId = getWorkspaceId(workspaceInfo.workspace, productId) + const wsId = getWorkspaceId(workspaceInfo.workspace) await childLogger.withLog('init-workspace', {}, async (ctx) => { await initModel(ctx, wsId, txes, ctxModellogger, async (value) => { @@ -1418,22 +1374,16 @@ export async function upgradeWorkspace ( version: Data, txes: Tx[], migrationOperation: [string, MigrateOperation][], - productId: string, db: Db, workspaceUrl: string, logger: ModelLogger = consoleModelLogger, forceUpdate: boolean = true, forceIndexes: boolean = false ): Promise { - const ws = await getWorkspaceByUrl(db, productId, workspaceUrl) + const ws = await getWorkspaceByUrl(db, workspaceUrl) if (ws === null) { throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace: workspaceUrl })) } - if (ws.productId !== productId) { - if (productId !== '' || ws.productId !== undefined) { - throw new PlatformError(new Status(Severity.ERROR, platform.status.ProductIdMismatch, { productId })) - } - } const versionStr = versionToString(version) if (ws?.version !== undefined && !forceUpdate && versionStr === versionToString(ws.version)) { @@ -1448,7 +1398,7 @@ export async function upgradeWorkspace ( await upgradeModel( ctx, getEndpoint(ctx, ws, EndpointKind.Internal), - getWorkspaceId(ws.workspace, productId), + getWorkspaceId(ws.workspace), txes, migrationOperation, logger, @@ -1474,7 +1424,6 @@ export const createUserWorkspace = async ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, workspaceName: string @@ -1507,7 +1456,6 @@ export const createUserWorkspace = txes, migrationOperation, db, - productId, branding, email, workspaceName, @@ -1518,7 +1466,7 @@ export const createUserWorkspace = const shouldUpdateAccount = initWS !== undefined const client = await connect( getEndpoint(ctx, workspace, EndpointKind.Internal), - getWorkspaceId(workspace.workspace, productId), + getWorkspaceId(workspace.workspace), undefined, { admin: 'true' @@ -1529,7 +1477,6 @@ export const createUserWorkspace = await assignWorkspace( ctx, db, - productId, branding, email, workspace.workspace, @@ -1576,8 +1523,7 @@ export const createUserWorkspace = const result = { endpoint: getEndpoint(ctx, workspaceInfo, EndpointKind.External), email, - token: generateToken(email, getWorkspaceId(workspaceInfo.workspace, productId), getExtra(info)), - productId, + token: generateToken(email, getWorkspaceId(workspaceInfo.workspace), getExtra(info)), workspace: workspaceInfo.workspaceUrl } ctx.info('Creating user side done', { workspaceName, email }) @@ -1590,7 +1536,6 @@ export const createUserWorkspace = export async function getInviteLink ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, exp: number, @@ -1600,7 +1545,7 @@ export async function getInviteLink ( personId?: Ref ): Promise { const { workspace, email } = decodeToken(ctx, token) - const wsPromise = await getWorkspaceById(db, productId, workspace.name) + const wsPromise = await getWorkspaceById(db, workspace.name) if (wsPromise === null) { ctx.error('workspace not found', { workspace, email }) throw new PlatformError( @@ -1648,7 +1593,6 @@ function trimWorkspaceInfo (ws: Workspace): WorkspaceInfo { export async function getUserWorkspaces ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string ): Promise { @@ -1661,7 +1605,7 @@ export async function getUserWorkspaces ( return ( await db .collection(WORKSPACE_COLLECTION) - .find(withProductId(productId, account.admin === true ? {} : { _id: { $in: account.workspaces } })) + .find(account.admin === true ? {} : { _id: { $in: account.workspaces } }) .sort({ lastVisit: -1 }) .toArray() ) @@ -1675,7 +1619,6 @@ export async function getUserWorkspaces ( export async function getWorkspaceInfo ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, _updateLastVisit: boolean = false @@ -1689,7 +1632,7 @@ export async function getWorkspaceInfo ( if (email !== systemAccountEmail && !guest) { account = await ctx.with('get-account', {}, async () => await getAccount(db, email)) if (account === null) { - ctx.error('no account', { email, productId, token }) + ctx.error('no account', { email, token }) throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {})) } } else if (guest) { @@ -1709,7 +1652,7 @@ export async function getWorkspaceInfo ( } const [ws] = await ctx.with('get-workspace', {}, async () => - (await db.collection(WORKSPACE_COLLECTION).find(withProductId(productId, query)).toArray()).filter( + (await db.collection(WORKSPACE_COLLECTION).find(query).toArray()).filter( (it) => it.disabled !== true || account?.admin === true || it.creating === true ) ) @@ -1740,12 +1683,11 @@ async function updateLastVisit (db: Db, ws: Workspace, account: Account): Promis async function getWorkspaceAndAccount ( ctx: MeasureContext, db: Db, - productId: string, _email: string, workspaceUrl: string ): Promise<{ account: Account, workspace: Workspace }> { const email = cleanEmail(_email) - const wsPromise = await getWorkspaceById(db, productId, workspaceUrl) + const wsPromise = await getWorkspaceById(db, workspaceUrl) if (wsPromise === null) { throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace: workspaceUrl })) } @@ -1764,19 +1706,17 @@ export async function setRole ( db: Db, _email: string, workspace: string, - productId: string, role: AccountRole, client?: Client ): Promise { if (!Object.values(AccountRole).includes(role)) return const email = cleanEmail(_email) - const workspaceInfo = await getWorkspaceById(db, productId, workspace) + const workspaceInfo = await getWorkspaceById(db, workspace) if (workspaceInfo == null) { throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace })) } const connection = - client ?? - (await connect(getEndpoint(ctx, workspaceInfo, EndpointKind.Internal), getWorkspaceId(workspace, productId))) + client ?? (await connect(getEndpoint(ctx, workspaceInfo, EndpointKind.Internal), getWorkspaceId(workspace))) try { const ops = new TxOperations(connection, core.account.System) @@ -1800,19 +1740,18 @@ export async function setRole ( export async function createMissingEmployee ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string ): Promise { const { email } = decodeToken(ctx, token) - const wsInfo = await getWorkspaceInfo(ctx, db, productId, branding, token) + const wsInfo = await getWorkspaceInfo(ctx, db, branding, token) const account = await getAccount(db, email) if (account === null) { throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, { account: email })) } - await createPersonAccount(ctx, db, account, productId, wsInfo.workspaceId, AccountRole.Guest) + await createPersonAccount(ctx, db, account, wsInfo.workspaceId, AccountRole.Guest) } /** @@ -1821,7 +1760,6 @@ export async function createMissingEmployee ( export async function assignWorkspace ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string, workspaceId: string, @@ -1838,14 +1776,13 @@ export async function assignWorkspace ( ctx.error('assign-workspace failed', { email, workspaceId, reason: 'initWs === workspaceId' }) throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {})) } - const workspaceInfo = await getWorkspaceAndAccount(ctx, db, productId, email, workspaceId) + const workspaceInfo = await getWorkspaceAndAccount(ctx, db, email, workspaceId) if (workspaceInfo.account !== null) { await createPersonAccount( ctx, db, workspaceInfo.account, - productId, workspaceId, role, personId, @@ -1967,7 +1904,6 @@ async function createPersonAccount ( ctx: MeasureContext, db: Db, account: Account, - productId: string, workspace: string, role: AccountRole, personId?: Ref, @@ -1975,13 +1911,12 @@ async function createPersonAccount ( client?: Client, personAccountId?: Ref ): Promise { - const workspaceInfo = await getWorkspaceById(db, productId, workspace) + const workspaceInfo = await getWorkspaceById(db, workspace) if (workspaceInfo == null) { throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace })) } const connection = - client ?? - (await connect(getEndpoint(ctx, workspaceInfo, EndpointKind.Internal), getWorkspaceId(workspace, productId))) + client ?? (await connect(getEndpoint(ctx, workspaceInfo, EndpointKind.Internal), getWorkspaceId(workspace))) try { const ops = new TxOperations(connection, core.account.System).apply('create-person' + generateId()) @@ -2047,14 +1982,13 @@ async function createPersonAccount ( export async function changePassword ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, oldPassword: string, password: string ): Promise { const { email } = decodeToken(ctx, token) - const account = await getAccountInfo(ctx, db, productId, branding, email, oldPassword) + const account = await getAccountInfo(ctx, db, branding, email, oldPassword) const salt = randomBytes(32) const hash = hashWithSalt(password, salt) @@ -2074,7 +2008,7 @@ export async function changeEmail (ctx: MeasureContext, db: Db, account: Account /** * @public */ -export async function replacePassword (db: Db, productId: string, email: string, password: string): Promise { +export async function replacePassword (db: Db, email: string, password: string): Promise { const account = await getAccount(db, email) if (account === null) { @@ -2092,7 +2026,6 @@ export async function replacePassword (db: Db, productId: string, email: string, export async function requestPassword ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string ): Promise { @@ -2115,7 +2048,7 @@ export async function requestPassword ( const token = generateToken( '@restore', - getWorkspaceId('', productId), + getWorkspaceId(''), getExtra(account, { restore: email }) @@ -2149,7 +2082,6 @@ export async function requestPassword ( export async function restorePassword ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, password: string @@ -2167,7 +2099,7 @@ export async function restorePassword ( await updatePassword(db, account, password) - return await login(ctx, db, productId, branding, email, password) + return await login(ctx, db, branding, email, password) } async function updatePassword (db: Db, account: Account, password: string | null): Promise { @@ -2183,12 +2115,11 @@ async function updatePassword (db: Db, account: Account, password: string | null export async function removeWorkspace ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, email: string, workspaceId: string ): Promise { - const { workspace, account } = await getWorkspaceAndAccount(ctx, db, productId, email, workspaceId) + const { workspace, account } = await getWorkspaceAndAccount(ctx, db, email, workspaceId) // Add account into workspace. await db @@ -2208,7 +2139,6 @@ export async function removeWorkspace ( export async function checkJoin ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, inviteId: ObjectId @@ -2216,14 +2146,14 @@ export async function checkJoin ( const { email } = decodeToken(ctx, token) const invite = await getInvite(db, inviteId) const workspace = await checkInvite(ctx, invite, email) - const ws = await getWorkspaceById(db, productId, workspace.name) + const ws = await getWorkspaceById(db, workspace.name) if (ws === null) { ctx.error('workspace not found', { name: workspace.name, email, inviteId }) throw new PlatformError( new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace: workspace.name }) ) } - return await selectWorkspace(ctx, db, productId, branding, token, ws?.workspaceUrl ?? ws.workspace, 'external', false) + return await selectWorkspace(ctx, db, branding, token, ws?.workspaceUrl ?? ws.workspace, 'external', false) } /** @@ -2232,11 +2162,10 @@ export async function checkJoin ( export async function dropWorkspace ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, workspaceId: string ): Promise { - const ws = await getWorkspaceById(db, productId, workspaceId) + const ws = await getWorkspaceById(db, workspaceId) if (ws === null) { throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace: workspaceId })) } @@ -2256,15 +2185,14 @@ export async function dropWorkspaceFull ( ctx: MeasureContext, db: Db, client: MongoClient, - productId: string, branding: Branding | null, workspaceId: string, storageAdapter?: StorageAdapter ): Promise { - const ws = await dropWorkspace(ctx, db, productId, branding, workspaceId) + const ws = await dropWorkspace(ctx, db, branding, workspaceId) const workspaceDb = client.db(ws.workspace) await workspaceDb.dropDatabase() - const wspace = getWorkspaceId(workspaceId, productId) + const wspace = getWorkspaceId(workspaceId) const hasBucket = await storageAdapter?.exists(ctx, wspace) if (storageAdapter !== undefined && hasBucket === true) { await storageAdapter.delete(ctx, wspace) @@ -2278,7 +2206,6 @@ export async function dropWorkspaceFull ( export async function dropAccount ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, email: string ): Promise { @@ -2289,12 +2216,12 @@ export async function dropAccount ( const workspaces = await db .collection(WORKSPACE_COLLECTION) - .find(withProductId(productId, { _id: { $in: account.workspaces } })) + .find({ _id: { $in: account.workspaces } }) .toArray() await Promise.all( workspaces.map(async (ws) => { - await deactivatePersonAccount(ctx, db, account.email, ws.workspace, productId) + await deactivatePersonAccount(ctx, db, account.email, ws.workspace) }) ) @@ -2311,7 +2238,6 @@ export async function dropAccount ( export async function leaveWorkspace ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, email: string @@ -2323,14 +2249,14 @@ export async function leaveWorkspace ( throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, { account: tokenData.email })) } - const workspace = await getWorkspaceById(db, productId, tokenData.workspace.name) + const workspace = await getWorkspaceById(db, tokenData.workspace.name) if (workspace === null) { throw new PlatformError( new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace: tokenData.workspace.name }) ) } - await deactivatePersonAccount(ctx, db, email, workspace.workspace, workspace.productId) + await deactivatePersonAccount(ctx, db, email, workspace.workspace) const account = tokenData.email !== email ? await getAccount(db, email) : currentAccount if (account !== null) { @@ -2350,7 +2276,6 @@ export async function leaveWorkspace ( export async function sendInvite ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, email: string, @@ -2363,7 +2288,7 @@ export async function sendInvite ( throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, { account: tokenData.email })) } - const workspace = await getWorkspaceById(db, productId, tokenData.workspace.name) + const workspace = await getWorkspaceById(db, tokenData.workspace.name) if (workspace === null) { throw new PlatformError( new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace: tokenData.workspace.name }) @@ -2386,7 +2311,7 @@ export async function sendInvite ( const expHours = 48 const exp = expHours * 60 * 60 * 1000 - const inviteId = await getInviteLink(ctx, db, productId, branding, token, exp, email, 1) + const inviteId = await getInviteLink(ctx, db, branding, token, exp, email, 1) const link = concatLink(front, `/login/join?inviteId=${inviteId.toString()}`) const ws = workspace.workspaceName ?? workspace.workspace @@ -2411,21 +2336,12 @@ export async function sendInvite ( ctx.info('Invite sent', { email, workspace, link }) } -async function deactivatePersonAccount ( - ctx: MeasureContext, - db: Db, - email: string, - workspace: string, - productId: string -): Promise { - const workspaceInfo = await getWorkspaceById(db, productId, workspace) +async function deactivatePersonAccount (ctx: MeasureContext, db: Db, email: string, workspace: string): Promise { + const workspaceInfo = await getWorkspaceById(db, workspace) if (workspaceInfo == null) { throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspace })) } - const connection = await connect( - getEndpoint(ctx, workspaceInfo, EndpointKind.Internal), - getWorkspaceId(workspace, productId) - ) + const connection = await connect(getEndpoint(ctx, workspaceInfo, EndpointKind.Internal), getWorkspaceId(workspace)) try { const ops = new TxOperations(connection, core.account.System) @@ -2451,31 +2367,23 @@ async function deactivatePersonAccount ( export type AccountMethod = ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, request: any, token?: string ) => Promise function wrap ( - accountMethod: ( - ctx: MeasureContext, - db: Db, - productId: string, - branding: Branding | null, - ...args: any[] - ) => Promise + accountMethod: (ctx: MeasureContext, db: Db, branding: Branding | null, ...args: any[]) => Promise ): AccountMethod { return async function ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, request: any, token?: string ): Promise { if (token !== undefined) request.params.unshift(token) - return await accountMethod(ctx, db, productId, branding, ...request.params) + return await accountMethod(ctx, db, branding, ...request.params) .then((result) => ({ id: request.id, result })) .catch((err) => { const status = @@ -2505,7 +2413,6 @@ function wrap ( export async function joinWithProvider ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string, first: string, @@ -2530,8 +2437,8 @@ export async function joinWithProvider ( await updatePassword(db, account, null) } - const token = generateToken(email, getWorkspaceId('', productId), getExtra(account)) - const ws = await getWorkspaceById(db, productId, workspace.name) + const token = generateToken(email, getWorkspaceId(''), getExtra(account)) + const ws = await getWorkspaceById(db, workspace.name) if (ws != null && ws.accounts.includes(account._id)) { const result = { @@ -2545,7 +2452,6 @@ export async function joinWithProvider ( const wsRes = await assignWorkspace( ctx, db, - productId, branding, email, workspace.name, @@ -2555,7 +2461,6 @@ export async function joinWithProvider ( const result = await selectWorkspace( ctx, db, - productId, branding, token, wsRes.workspaceUrl ?? wsRes.workspace, @@ -2566,28 +2471,18 @@ export async function joinWithProvider ( await useInvite(db, inviteId) return result } - const newAccount = await createAcc(ctx, db, productId, branding, email, null, first, last, true, true, extra) - const token = generateToken(email, getWorkspaceId('', productId), getExtra(newAccount)) + const newAccount = await createAcc(ctx, db, branding, email, null, first, last, true, true, extra) + const token = generateToken(email, getWorkspaceId(''), getExtra(newAccount)) const ws = await assignWorkspace( ctx, db, - productId, branding, email, workspace.name, invite?.role ?? AccountRole.User, invite?.personId ) - const result = await selectWorkspace( - ctx, - db, - productId, - branding, - token, - ws.workspaceUrl ?? ws.workspace, - 'external', - false - ) + const result = await selectWorkspace(ctx, db, branding, token, ws.workspaceUrl ?? ws.workspace, 'external', false) await useInvite(db, inviteId) @@ -2602,7 +2497,6 @@ export async function joinWithProvider ( export async function loginWithProvider ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, _email: string, first: string, @@ -2626,16 +2520,16 @@ export async function loginWithProvider ( const result = { endpoint: '', email, - token: generateToken(email, getWorkspaceId('', productId), getExtra(account)) + token: generateToken(email, getWorkspaceId(''), getExtra(account)) } return result } - const newAccount = await createAcc(ctx, db, productId, branding, email, null, first, last, true, true, extra) + const newAccount = await createAcc(ctx, db, branding, email, null, first, last, true, true, extra) const result = { endpoint: '', email, - token: generateToken(email, getWorkspaceId('', productId), getExtra(newAccount)) + token: generateToken(email, getWorkspaceId(''), getExtra(newAccount)) } return result } catch (err: any) { @@ -2651,7 +2545,6 @@ export async function loginWithProvider ( export async function changeUsername ( ctx: MeasureContext, db: Db, - productId: string, branding: Branding | null, token: string, first: string, diff --git a/server/account/src/service.ts b/server/account/src/service.ts index 3658054c372..7a44382da96 100644 --- a/server/account/src/service.ts +++ b/server/account/src/service.ts @@ -18,7 +18,14 @@ import { MigrateOperation, ModelLogger } from '@hcengineering/model' import { FileModelLogger } from '@hcengineering/server-tool' import { Db, MongoClient } from 'mongodb' import path from 'path' -import { Workspace, WorkspaceInfo, listWorkspacesRaw, updateWorkspace, upgradeWorkspace } from './operations' +import { + Workspace, + WorkspaceInfo, + listWorkspacesRaw, + updateWorkspace, + upgradeWorkspace, + clearWorkspaceProductId +} from './operations' import { Analytics } from '@hcengineering/analytics' export type UpgradeErrorHandler = (workspace: BaseWorkspaceInfo, error: any) => Promise @@ -39,8 +46,7 @@ export class UpgradeWorker { readonly client: MongoClient, readonly version: Data, readonly txes: Tx[], - readonly migrationOperation: [string, MigrateOperation][], - readonly productId: string + readonly migrationOperation: [string, MigrateOperation][] ) {} canceled = false @@ -94,7 +100,6 @@ export class UpgradeWorker { this.version, this.txes, this.migrationOperation, - this.productId, this.db, ws.workspaceUrl ?? ws.workspace, logger, @@ -128,15 +133,11 @@ export class UpgradeWorker { } async upgradeAll (ctx: MeasureContext, opt: UpgradeOptions): Promise { - const workspaces = await ctx.with( - 'retrieve-workspaces', - {}, - async (ctx) => await listWorkspacesRaw(this.db, this.productId) - ) + const workspaces = await ctx.with('retrieve-workspaces', {}, async (ctx) => await listWorkspacesRaw(this.db)) workspaces.sort((a, b) => b.lastVisit - a.lastVisit) - // We need to update workspaces with missing workspaceUrl for (const ws of workspaces) { + // We need to update workspaces with missing workspaceUrl if (ws.workspaceUrl == null) { const upd: Partial = { workspaceUrl: ws.workspace @@ -144,7 +145,11 @@ export class UpgradeWorker { if (ws.workspaceName == null) { upd.workspaceName = ws.workspace } - await updateWorkspace(this.db, this.productId, ws, upd) + await updateWorkspace(this.db, ws, upd) + } + // We need to drop productId from workspace + if ((ws as any).productId !== undefined) { + await clearWorkspaceProductId(this.db, ws) } } diff --git a/server/backup-service/src/index.ts b/server/backup-service/src/index.ts index a7a66fa15b1..4412f6ce0e2 100644 --- a/server/backup-service/src/index.ts +++ b/server/backup-service/src/index.ts @@ -39,7 +39,7 @@ export function startBackup ( const pipelineFactory = pipelineFactoryFactory(config.MongoURL, workspaceStorageAdapter) // A token to access account service - const token = generateToken(systemAccountEmail, { name: 'backup', productId: '' }) + const token = generateToken(systemAccountEmail, { name: 'backup' }) const shutdown = backupService(ctx, storageAdapter, { ...config, Token: token }, pipelineFactory) diff --git a/server/backup/src/backup.ts b/server/backup/src/backup.ts index bf9bf3d7ea3..8ae6740c4a4 100644 --- a/server/backup/src/backup.ts +++ b/server/backup/src/backup.ts @@ -116,7 +116,6 @@ export interface BackupSnapshot { export interface BackupInfo { workspace: string version: string - productId: string snapshots: BackupSnapshot[] snapshotsIndex?: number lastTxId?: string @@ -566,7 +565,6 @@ export async function backup ( let backupInfo: BackupInfo = { workspace: workspaceId.name, - productId: workspaceId.productId, version: '0.6.2', snapshots: [] } @@ -581,7 +579,6 @@ export async function backup ( backupInfo.version = '0.6.2' backupInfo.workspace = workspaceId.name - backupInfo.productId = workspaceId.productId // Skip backup if there is no transaction changes. const lastTx = await connection.findOne( diff --git a/server/backup/src/service.ts b/server/backup/src/service.ts index 34d6230af33..64e45578dfa 100644 --- a/server/backup/src/service.ts +++ b/server/backup/src/service.ts @@ -99,7 +99,6 @@ class BackupWorker { index++ rootCtx.info('\n\nBACKUP WORKSPACE ', { workspace: ws.workspace, - productId: ws.productId, index, total: workspaces.length }) @@ -112,19 +111,18 @@ class BackupWorker { const storage = await createStorageBackupStorage( ctx, this.storageAdapter, - getWorkspaceId(this.config.BucketName, ws.productId), + getWorkspaceId(this.config.BucketName), ws.workspace ) const wsUrl: WorkspaceIdWithUrl = { name: ws.workspace, - productId: ws.productId, workspaceName: ws.workspaceName ?? '', workspaceUrl: ws.workspaceUrl ?? '' } const pipeline = await this.pipelineFactory(ctx, wsUrl, true, () => {}, null) await ctx.with('backup', { workspace: ws.workspace }, async (ctx) => { - await backup(ctx, ws.endpoint, getWorkspaceId(ws.workspace, ws.productId), storage, { + await backup(ctx, ws.endpoint, getWorkspaceId(ws.workspace), storage, { skipDomains: [], force: false, recheck: false, diff --git a/server/core/src/__tests__/aggregator.spec.ts b/server/core/src/__tests__/aggregator.spec.ts index 3c80a02ee10..e85f46a584f 100644 --- a/server/core/src/__tests__/aggregator.spec.ts +++ b/server/core/src/__tests__/aggregator.spec.ts @@ -21,7 +21,7 @@ describe('aggregator tests', () => { const aggr = new AggregatorStorageAdapter(adapters, 'mem2', blobs) const testCtx = new MeasureMetricsContext('test', {}) - const ws1: WorkspaceId = { name: 'ws1', productId: '' } + const ws1: WorkspaceId = { name: 'ws1' } return { mem1, mem2, aggr, ws1, testCtx } } it('not reuse existing storage', async () => { diff --git a/server/core/src/__tests__/memAdapters.ts b/server/core/src/__tests__/memAdapters.ts index 3910c35a6e1..56aa32435b2 100644 --- a/server/core/src/__tests__/memAdapters.ts +++ b/server/core/src/__tests__/memAdapters.ts @@ -35,14 +35,14 @@ export class MemStorageAdapter implements StorageAdapter { async delete (ctx: MeasureContext, workspaceId: WorkspaceId): Promise {} - async listBuckets (ctx: MeasureContext, productId: string): Promise { + async listBuckets (ctx: MeasureContext): Promise { const workspaces = new Set(Array.from(this.files.values()).map((it) => it.workspace)) return Array.from(workspaces).map((it) => ({ name: it, delete: async () => { - await this.delete(ctx, { name: it, productId: '' }) + await this.delete(ctx, { name: it }) }, - list: () => this.listStream(ctx, { name: it, productId: '' }) + list: () => this.listStream(ctx, { name: it }) })) } diff --git a/server/core/src/server/aggregator.ts b/server/core/src/server/aggregator.ts index 6ed1b3139e9..d11c2546ac8 100644 --- a/server/core/src/server/aggregator.ts +++ b/server/core/src/server/aggregator.ts @@ -186,10 +186,10 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE } @withContext('aggregator-listBuckets', {}) - async listBuckets (ctx: MeasureContext, productId: string): Promise { + async listBuckets (ctx: MeasureContext): Promise { const result: BucketInfo[] = [] for (const a of this.adapters.values()) { - result.push(...(await a.listBuckets(ctx, productId))) + result.push(...(await a.listBuckets(ctx))) } return result } diff --git a/server/core/src/storage.ts b/server/core/src/storage.ts index dc6a69f809c..0f3cef77a56 100644 --- a/server/core/src/storage.ts +++ b/server/core/src/storage.ts @@ -17,7 +17,7 @@ export * from '@hcengineering/storage' * @public */ export function getBucketId (workspaceId: WorkspaceId): string { - return toWorkspaceString(workspaceId, '.') + return toWorkspaceString(workspaceId) } const chunkSize = 2 * 1024 * 1024 diff --git a/server/datalake/src/index.ts b/server/datalake/src/index.ts index 2a77f4f8621..7746512e7ac 100644 --- a/server/datalake/src/index.ts +++ b/server/datalake/src/index.ts @@ -54,7 +54,7 @@ export class DatalakeService implements StorageAdapter { // workspace/buckets not supported, assume that always exist } - async listBuckets (ctx: MeasureContext, productId: string): Promise { + async listBuckets (ctx: MeasureContext): Promise { return [] } diff --git a/server/elastic/src/__tests__/adapter.test.ts b/server/elastic/src/__tests__/adapter.test.ts index fdb1f699d54..2c54fc93eab 100644 --- a/server/elastic/src/__tests__/adapter.test.ts +++ b/server/elastic/src/__tests__/adapter.test.ts @@ -25,7 +25,7 @@ describe('Elastic Adapter', () => { beforeEach(async () => { adapter = await createElasticAdapter( process.env.ELASTIC_URL ?? 'http://localhost:9200/', - getWorkspaceId('ws1', ''), + getWorkspaceId('ws1'), new MeasureMetricsContext('-', {}) ) }) diff --git a/server/front/src/index.ts b/server/front/src/index.ts index 4e6b9f00b6e..1554dc89ae3 100644 --- a/server/front/src/index.ts +++ b/server/front/src/index.ts @@ -374,7 +374,7 @@ export function start ( 'handle-file', {}, async (ctx) => { - let payload: Token = { email: 'guest', workspace: { name: req.query.workspace as string, productId: '' } } + let payload: Token = { email: 'guest', workspace: { name: req.query.workspace as string } } try { const cookies = ((req?.headers?.cookie as string) ?? '').split(';').map((it) => it.trim().split('=')) diff --git a/server/minio/src/__tests__/minio.test.ts b/server/minio/src/__tests__/minio.test.ts index 6feb66ed240..e421dbe4e0a 100644 --- a/server/minio/src/__tests__/minio.test.ts +++ b/server/minio/src/__tests__/minio.test.ts @@ -30,7 +30,7 @@ describe('minio operations', () => { jest.setTimeout(50000) const minioService = new MinioService({ ...(config.storages[0] as MinioConfig), rootBucket: 'test-bucket' }) - let existingTestBuckets = await minioService.listBuckets(toolCtx, '') + let existingTestBuckets = await minioService.listBuckets(toolCtx) // Delete old buckets for (const b of existingTestBuckets) { await b.delete() @@ -41,8 +41,8 @@ describe('minio operations', () => { expect(genWorkspaceId1).not.toEqual(genWorkspaceId2) - const ws1 = { name: genWorkspaceId1, productId: '' } - const ws2 = { name: genWorkspaceId2, productId: '' } + const ws1 = { name: genWorkspaceId1 } + const ws2 = { name: genWorkspaceId2 } await minioService.make(toolCtx, ws1) await minioService.make(toolCtx, ws2) @@ -66,13 +66,13 @@ describe('minio operations', () => { expect('obj1').toEqual(data.toString()) - existingTestBuckets = await minioService.listBuckets(toolCtx, '') + existingTestBuckets = await minioService.listBuckets(toolCtx) expect(existingTestBuckets.length).toEqual(2) // Delete old buckets for (const b of existingTestBuckets) { await b.delete() } - existingTestBuckets = await minioService.listBuckets(toolCtx, '') + existingTestBuckets = await minioService.listBuckets(toolCtx) expect(existingTestBuckets.length).toEqual(0) }) }) diff --git a/server/minio/src/index.ts b/server/minio/src/index.ts index e9403f7058b..fcad03afec6 100644 --- a/server/minio/src/index.ts +++ b/server/minio/src/index.ts @@ -73,11 +73,11 @@ export class MinioService implements StorageAdapter { * @public */ getBucketId (workspaceId: WorkspaceId): string { - return this.opt.rootBucket ?? (this.opt.bucketPrefix ?? '') + toWorkspaceString(workspaceId, '.') + return this.opt.rootBucket ?? (this.opt.bucketPrefix ?? '') + toWorkspaceString(workspaceId) } getBucketFolder (workspaceId: WorkspaceId): string { - return toWorkspaceString(workspaceId, '.') + return toWorkspaceString(workspaceId) } async close (): Promise {} @@ -97,7 +97,7 @@ export class MinioService implements StorageAdapter { } } - async listBuckets (ctx: MeasureContext, productId: string): Promise { + async listBuckets (ctx: MeasureContext): Promise { if (this.opt.rootBucket !== undefined) { const info = new Map() const stream = this.client.listObjects(this.opt.rootBucket, '', false) @@ -117,9 +117,9 @@ export class MinioService implements StorageAdapter { info.set(wsName, { name: wsName, delete: async () => { - await this.delete(ctx, { name: wsName, productId }) + await this.delete(ctx, { name: wsName }) }, - list: async () => await this.listStream(ctx, { name: wsName, productId }) + list: async () => await this.listStream(ctx, { name: wsName }) }) } }) @@ -128,8 +128,7 @@ export class MinioService implements StorageAdapter { return Array.from(info.values()) } else { const productPostfix = this.getBucketFolder({ - name: '', - productId + name: '' }) const buckets = await this.client.listBuckets() return buckets @@ -140,9 +139,9 @@ export class MinioService implements StorageAdapter { return { name, delete: async () => { - await this.delete(ctx, { name, productId }) + await this.delete(ctx, { name }) }, - list: async () => await this.listStream(ctx, { name, productId }) + list: async () => await this.listStream(ctx, { name }) } }) } diff --git a/server/mongo/src/__tests__/storage.test.ts b/server/mongo/src/__tests__/storage.test.ts index b92d445daca..ce3761bf96a 100644 --- a/server/mongo/src/__tests__/storage.test.ts +++ b/server/mongo/src/__tests__/storage.test.ts @@ -128,7 +128,7 @@ describe('mongo operations', () => { new MeasureMetricsContext('', {}), hierarchy, mongodbUri, - getWorkspaceId(dbId, ''), + getWorkspaceId(dbId), model ) @@ -174,7 +174,7 @@ describe('mongo operations', () => { }, serviceAdapters: {}, defaultContentAdapter: 'default', - workspace: { ...getWorkspaceId(dbId, ''), workspaceName: '', workspaceUrl: '' }, + workspace: { ...getWorkspaceId(dbId), workspaceName: '', workspaceUrl: '' }, storageFactory: createNullStorageFactory() } const ctx = new MeasureMetricsContext('client', {}) diff --git a/server/s3/src/__tests__/s3.test.ts b/server/s3/src/__tests__/s3.test.ts index 609512d3b38..1db8b6b5cd5 100644 --- a/server/s3/src/__tests__/s3.test.ts +++ b/server/s3/src/__tests__/s3.test.ts @@ -30,7 +30,7 @@ describe('s3 operations', () => { jest.setTimeout(50000) const minioService = new S3Service({ ...(config.storages[0] as S3Config), rootBucket: 'haiodo-test-bucket' }) - let existingTestBuckets = await minioService.listBuckets(toolCtx, '') + let existingTestBuckets = await minioService.listBuckets(toolCtx) // Delete old buckets for (const b of existingTestBuckets) { await b.delete() @@ -41,8 +41,8 @@ describe('s3 operations', () => { expect(genWorkspaceId1).not.toEqual(genWorkspaceId2) - const ws1 = { name: genWorkspaceId1, productId: '' } - const ws2 = { name: genWorkspaceId2, productId: '' } + const ws1 = { name: genWorkspaceId1 } + const ws2 = { name: genWorkspaceId2 } await minioService.make(toolCtx, ws1) await minioService.make(toolCtx, ws2) @@ -66,13 +66,13 @@ describe('s3 operations', () => { expect('obj1').toEqual(data.toString()) - existingTestBuckets = await minioService.listBuckets(toolCtx, '') + existingTestBuckets = await minioService.listBuckets(toolCtx) expect(existingTestBuckets.length).toEqual(2) // Delete old buckets for (const b of existingTestBuckets) { await b.delete() } - existingTestBuckets = await minioService.listBuckets(toolCtx, '') + existingTestBuckets = await minioService.listBuckets(toolCtx) expect(existingTestBuckets.length).toEqual(0) }) }) diff --git a/server/s3/src/index.ts b/server/s3/src/index.ts index 0d6d48bc589..08040f9a762 100644 --- a/server/s3/src/index.ts +++ b/server/s3/src/index.ts @@ -82,11 +82,11 @@ export class S3Service implements StorageAdapter { * @public */ getBucketId (workspaceId: WorkspaceId): string { - return this.opt.rootBucket ?? (this.opt.bucketPrefix ?? '') + toWorkspaceString(workspaceId, '.') + return this.opt.rootBucket ?? (this.opt.bucketPrefix ?? '') + toWorkspaceString(workspaceId) } getBucketFolder (workspaceId: WorkspaceId): string { - return toWorkspaceString(workspaceId, '.') + return toWorkspaceString(workspaceId) } async close (): Promise {} @@ -121,7 +121,7 @@ export class S3Service implements StorageAdapter { } } - async listBuckets (ctx: MeasureContext, productId: string): Promise { + async listBuckets (ctx: MeasureContext): Promise { try { if (this.opt.rootBucket !== undefined) { const info = new Map() @@ -140,9 +140,9 @@ export class S3Service implements StorageAdapter { info.set(wsName, { name: wsName, delete: async () => { - await this.delete(ctx, { name: wsName, productId }) + await this.delete(ctx, { name: wsName }) }, - list: async () => await this.listStream(ctx, { name: wsName, productId }) + list: async () => await this.listStream(ctx, { name: wsName }) }) } } @@ -155,8 +155,7 @@ export class S3Service implements StorageAdapter { return Array.from(info.values()) } else { const productPostfix = this.getBucketFolder({ - name: '', - productId + name: '' }) const buckets = await this.client.listBuckets() return (buckets.Buckets ?? []) @@ -167,9 +166,9 @@ export class S3Service implements StorageAdapter { return { name, delete: async () => { - await this.delete(ctx, { name, productId }) + await this.delete(ctx, { name }) }, - list: async () => await this.listStream(ctx, { name, productId }) + list: async () => await this.listStream(ctx, { name }) } }) } diff --git a/server/s3/src/perfTest.ts b/server/s3/src/perfTest.ts index 694a4d672fe..a1fed0f6ce9 100644 --- a/server/s3/src/perfTest.ts +++ b/server/s3/src/perfTest.ts @@ -15,7 +15,7 @@ const toolCtx = new MeasureMetricsContext('test', {}) const storageService = new S3Service({ ...(config.storages[0] as S3Config), rootBucket: 'haiodo-test-bucket' }) async function doTest (): Promise { - const existingTestBuckets = await storageService.listBuckets(toolCtx, '') + const existingTestBuckets = await storageService.listBuckets(toolCtx) // Delete old buckets for (const b of existingTestBuckets) { await b.delete() @@ -23,7 +23,7 @@ async function doTest (): Promise { const genWorkspaceId1 = generateId() - const ws1 = { name: genWorkspaceId1, productId: '' } + const ws1 = { name: genWorkspaceId1 } await storageService.make(toolCtx, ws1) /// /////// Uploads let st1 = Date.now() diff --git a/server/token/src/token.ts b/server/token/src/token.ts index b64c677a4c2..2a7517edd74 100644 --- a/server/token/src/token.ts +++ b/server/token/src/token.ts @@ -20,7 +20,7 @@ const getSecret = (): string => { * @public */ export function generateToken (email: string, workspace: WorkspaceId, extra?: Record): string { - return encode({ ...(extra ?? {}), email, workspace: workspace.name, productId: workspace.productId }, getSecret()) + return encode({ ...(extra ?? {}), email, workspace: workspace.name }, getSecret()) } /** @@ -28,6 +28,6 @@ export function generateToken (email: string, workspace: WorkspaceId, extra?: Re */ export function decodeToken (token: string, verify: boolean = true): Token { const value = decode(token, getSecret(), !verify) - const { email, workspace, productId, ...extra } = value - return { email, workspace: getWorkspaceId(workspace, productId), extra } + const { email, workspace, ...extra } = value + return { email, workspace: getWorkspaceId(workspace), extra } } diff --git a/server/tool/src/index.ts b/server/tool/src/index.ts index dd20545f8d7..f29c8f38e55 100644 --- a/server/tool/src/index.ts +++ b/server/tool/src/index.ts @@ -432,8 +432,7 @@ export async function upgradeModel ( const serverEndpoint = transactorUrl.replaceAll('wss://', 'https://').replace('ws://', 'http://') const token = generateToken(systemAccountEmail, workspaceId, { admin: 'true' }) await fetch( - serverEndpoint + - `/api/v1/manage?token=${token}&operation=force-close&wsId=${toWorkspaceString(workspaceId, '@')}`, + serverEndpoint + `/api/v1/manage?token=${token}&operation=force-close&wsId=${toWorkspaceString(workspaceId)}`, { method: 'PUT' } diff --git a/server/ws/src/__tests__/server.test.ts b/server/ws/src/__tests__/server.test.ts index aff86da0896..afa4d8d4659 100644 --- a/server/ws/src/__tests__/server.test.ts +++ b/server/ws/src/__tests__/server.test.ts @@ -86,7 +86,6 @@ describe('server', () => { }), sessionFactory: (token, pipeline) => new ClientSession(token, pipeline), port: 3335, - productId: '', brandingMap: {}, serverFactory: startHttpServer, accountsUrl: '', @@ -94,7 +93,7 @@ describe('server', () => { }) function connect (): WebSocket { - const token: string = generateToken('', getWorkspaceId('latest', '')) + const token: string = generateToken('', getWorkspaceId('latest')) return new WebSocket(`ws://localhost:3335/${token}`) } @@ -188,7 +187,6 @@ describe('server', () => { }), sessionFactory: (token, pipeline) => new ClientSession(token, pipeline), port: 3336, - productId: '', brandingMap: {}, serverFactory: startHttpServer, accountsUrl: '', @@ -244,7 +242,7 @@ describe('server', () => { try { // - const token: string = generateToken('my@email.com', getWorkspaceId('latest', '')) + const token: string = generateToken('my@email.com', getWorkspaceId('latest')) let clearTo: any const timeoutPromise = new Promise((resolve) => { clearTo = setTimeout(resolve, 4000) diff --git a/server/ws/src/factories.ts b/server/ws/src/factories.ts index 375abcdf2e1..51401b5402b 100644 --- a/server/ws/src/factories.ts +++ b/server/ws/src/factories.ts @@ -5,17 +5,7 @@ import { type ServerFactory } from './types' */ export const serverFactories: Record = { ws: startHttpServer, - uweb: ( - sessions, - handleRequest, - ctx, - pipelineFactory, - port, - productId, - enableCompression, - accountsUrl, - externalStorage - ) => { + uweb: (sessions, handleRequest, ctx, pipelineFactory, port, enableCompression, accountsUrl, externalStorage) => { try { // eslint-disable-next-line @typescript-eslint/no-var-requires const serverHttp = require('./server_u') @@ -25,7 +15,6 @@ export const serverFactories: Record = { ctx, pipelineFactory, port, - productId, enableCompression, accountsUrl, externalStorage @@ -38,7 +27,6 @@ export const serverFactories: Record = { ctx, pipelineFactory, port, - productId, enableCompression, accountsUrl, externalStorage diff --git a/server/ws/src/server.ts b/server/ws/src/server.ts index beeae39ec59..c73baae141e 100644 --- a/server/ws/src/server.ts +++ b/server/ws/src/server.ts @@ -271,7 +271,6 @@ class TSessionManager implements SessionManager { token: Token, rawToken: string, pipelineFactory: PipelineFactory, - productId: string, sessionId: string | undefined, accountsUrl: string ): Promise< @@ -279,7 +278,7 @@ class TSessionManager implements SessionManager { | { upgrade: true, upgradeInfo?: WorkspaceLoginInfo['upgrade'] } | { error: any } > { - const wsString = toWorkspaceString(token.workspace, '@') + const wsString = toWorkspaceString(token.workspace) let workspaceInfo: WorkspaceLoginInfo | undefined try { @@ -429,7 +428,6 @@ class TSessionManager implements SessionManager { createdBy: '', createdOn: Date.now(), lastVisit: Date.now(), - productId: '', createProgress: 100, creating: false, disabled: false, @@ -983,7 +981,6 @@ export function start ( port: number pipelineFactory: PipelineFactory sessionFactory: (token: Token, pipeline: Pipeline) => Session - productId: string brandingMap: BrandingMap serverFactory: ServerFactory enableCompression?: boolean @@ -1008,7 +1005,6 @@ export function start ( ctx, opt.pipelineFactory, opt.port, - opt.productId, opt.enableCompression ?? false, opt.accountsUrl, opt.externalStorage diff --git a/server/ws/src/server_http.ts b/server/ws/src/server_http.ts index 96c91ab9183..dbe9d351187 100644 --- a/server/ws/src/server_http.ts +++ b/server/ws/src/server_http.ts @@ -46,7 +46,6 @@ export function startHttpServer ( ctx: MeasureContext, pipelineFactory: PipelineFactory, port: number, - productId: string, enableCompression: boolean, accountsUrl: string, externalStorage: StorageAdapter @@ -54,7 +53,6 @@ export function startHttpServer ( if (LOGGING_ENABLED) { ctx.info('starting server on', { port, - productId, enableCompression, accountsUrl, parallel: os.availableParallelism() @@ -271,7 +269,7 @@ export function startHttpServer ( connectionSocket: cs, payload: token, token: rawToken, - session: sessions.addSession(ctx, cs, token, rawToken, pipelineFactory, productId, sessionId, accountsUrl), + session: sessions.addSession(ctx, cs, token, rawToken, pipelineFactory, sessionId, accountsUrl), url: '' } @@ -362,13 +360,6 @@ export function startHttpServer ( const payload = decodeToken(token ?? '') const sessionId = url.searchParams.get('sessionId') - if (payload.workspace.productId !== productId) { - if (LOGGING_ENABLED) { - ctx.error('invalid product', { required: payload.workspace.productId, productId }) - } - throw new Error('Invalid workspace product') - } - wss.handleUpgrade(request, socket, head, (ws) => { void handleConnection(ws, request, payload, token, sessionId ?? undefined) }) diff --git a/server/ws/src/server_u.ts b/server/ws/src/server_u.ts index c390817b1d2..6e3469811ee 100644 --- a/server/ws/src/server_u.ts +++ b/server/ws/src/server_u.ts @@ -49,7 +49,6 @@ export function startUWebsocketServer ( ctx: MeasureContext, pipelineFactory: PipelineFactory, port: number, - productId: string, enableCompression: boolean, accountsUrl: string, externalStorage: StorageAdapter @@ -82,10 +81,6 @@ export function startUWebsocketServer ( try { const payload = decodeToken(token ?? '') - if (payload.workspace.productId !== productId) { - throw new Error('Invalid workspace product') - } - /* You MUST copy data out of req here, as req is only valid within this immediate callback */ const url = req.getUrl() const secWebSocketKey = req.getHeader('sec-websocket-key') @@ -132,7 +127,6 @@ export function startUWebsocketServer ( ws.getUserData().payload, ws.getUserData().token, pipelineFactory, - productId, undefined, accountsUrl ) diff --git a/server/ws/src/types.ts b/server/ws/src/types.ts index 8d997c19a56..97539dbef11 100644 --- a/server/ws/src/types.ts +++ b/server/ws/src/types.ts @@ -153,7 +153,6 @@ export interface SessionManager { token: Token, rawToken: string, pipelineFactory: PipelineFactory, - productId: string, sessionId: string | undefined, accountsUrl: string ) => Promise @@ -197,7 +196,6 @@ export type ServerFactory = ( ctx: MeasureContext, pipelineFactory: PipelineFactory, port: number, - productId: string, enableCompression: boolean, accountsUrl: string, externalStorage: StorageAdapter diff --git a/services/ai-bot/pod-ai-bot/src/config.ts b/services/ai-bot/pod-ai-bot/src/config.ts index 784a2ac1ab3..860d50aa1c3 100644 --- a/services/ai-bot/pod-ai-bot/src/config.ts +++ b/services/ai-bot/pod-ai-bot/src/config.ts @@ -17,7 +17,6 @@ interface Config { AccountsURL: string ConfigurationDB: string MongoURL: string - ProductID: string ServerSecret: string ServiceID: string SupportWorkspace: string @@ -33,7 +32,6 @@ const envMap: { [key in keyof Config]: string } = { AccountsURL: 'ACCOUNTS_URL', ConfigurationDB: 'CONFIGURATION_DB', MongoURL: 'MONGO_URL', - ProductID: 'PRODUCT_ID', ServerSecret: 'SERVER_SECRET', ServiceID: 'SERVICE_ID', SupportWorkspace: 'SUPPORT_WORKSPACE', @@ -50,7 +48,6 @@ const config: Config = (() => { AccountsURL: process.env[envMap.AccountsURL], ConfigurationDB: process.env[envMap.ConfigurationDB] ?? '%ai-bot', MongoURL: process.env[envMap.MongoURL], - ProductID: process.env[envMap.ProductID] ?? '', ServerSecret: process.env[envMap.ServerSecret], ServiceID: process.env[envMap.ServiceID] ?? 'ai-bot-service', SupportWorkspace: process.env[envMap.SupportWorkspace], diff --git a/services/ai-bot/pod-ai-bot/src/controller.ts b/services/ai-bot/pod-ai-bot/src/controller.ts index 9568d13fdea..f663ee459b5 100644 --- a/services/ai-bot/pod-ai-bot/src/controller.ts +++ b/services/ai-bot/pod-ai-bot/src/controller.ts @@ -57,7 +57,7 @@ export class AIBotController { const activeRecords = await this.workspacesInfoCollection.find({ active: true }).toArray() for (const record of activeRecords) { - const id: WorkspaceId = { name: record.workspace, productId: record.productId } + const id: WorkspaceId = { name: record.workspace } const ws = toWorkspaceString(id) @@ -85,10 +85,7 @@ export class AIBotController { this.closeWorkspaceTimeouts.delete(workspace) } - await this.workspacesInfoCollection.updateOne( - { workspace: workspaceId.name, productId: workspaceId.productId }, - { $set: { active: false } } - ) + await this.workspacesInfoCollection.updateOne({ workspace: workspaceId.name }, { $set: { active: false } }) const client = this.workspaces.get(workspace) @@ -183,9 +180,7 @@ export class AIBotController { async transfer (event: AIBotTransferEvent): Promise { const workspaceId = getWorkspaceId(event.toWorkspace) - const info = await this.workspacesInfoCollection - .find({ workspace: workspaceId.name, productId: workspaceId.productId }) - .toArray() + const info = await this.workspacesInfoCollection.find({ workspace: workspaceId.name }).toArray() await this.initWorkspaceClient(workspaceId, info[0]) @@ -211,7 +206,7 @@ export class AIBotController { async updateAvatarInfo (workspace: WorkspaceId, path: string, lastModified: number): Promise { await this.workspacesInfoCollection.updateOne( - { workspace: workspace.name, productId: workspace.productId }, + { workspace: workspace.name }, { $set: { avatarPath: path, avatarLastModified: lastModified } } ) } diff --git a/services/calendar/pod-calendar/src/workspaceClient.ts b/services/calendar/pod-calendar/src/workspaceClient.ts index d19ca286f70..90accd098fc 100644 --- a/services/calendar/pod-calendar/src/workspaceClient.ts +++ b/services/calendar/pod-calendar/src/workspaceClient.ts @@ -157,7 +157,7 @@ export class WorkspaceClient { } private async initClient (workspace: string): Promise { - const token = generateToken(config.SystemEmail, { name: workspace, productId: '' }) + const token = generateToken(config.SystemEmail, { name: workspace }) const client = await getClient(token) client.notify = (...tx: Tx[]) => { void this.txHandler(...tx) diff --git a/services/github/pod-github/src/client.ts b/services/github/pod-github/src/client.ts index 789761d3338..02813d1dad0 100644 --- a/services/github/pod-github/src/client.ts +++ b/services/github/pod-github/src/client.ts @@ -17,7 +17,6 @@ import config from './config' */ export async function createPlatformClient ( workspace: string, - productId: string, timeout: number, reconnect?: (event: ClientConnectEvent) => void ): Promise { @@ -33,8 +32,7 @@ export async function createPlatformClient ( const token = generateToken( config.SystemEmail, { - name: workspace, - productId + name: workspace }, { mode: 'github' } ) diff --git a/services/github/pod-github/src/config.ts b/services/github/pod-github/src/config.ts index 30655c171c6..3422220baa8 100644 --- a/services/github/pod-github/src/config.ts +++ b/services/github/pod-github/src/config.ts @@ -26,8 +26,6 @@ interface Config { CollaboratorURL: string - ProductID: string - BotName: string SentryDSN: string @@ -56,8 +54,6 @@ const envMap: { [key in keyof Config]: string } = { CollaboratorURL: 'COLLABORATOR_URL', - ProductID: 'PRODUCT_ID', - SentryDSN: 'SENTRY_DSN', BrandingPath: 'BRANDING_PATH' } @@ -78,7 +74,6 @@ const required: Array = [ 'CollaboratorURL', - 'ProductID', 'BotName' ] @@ -106,8 +101,6 @@ const config: Config = (() => { CollaboratorURL: process.env[envMap.CollaboratorURL], - ProductID: process.env[envMap.ProductID] ?? '', - SentryDSN: process.env[envMap.SentryDSN], BrandingPath: process.env[envMap.BrandingPath] ?? '' } diff --git a/services/github/pod-github/src/platform.ts b/services/github/pod-github/src/platform.ts index 046db1e59c5..c2aed038a3c 100644 --- a/services/github/pod-github/src/platform.ts +++ b/services/github/pod-github/src/platform.ts @@ -221,7 +221,7 @@ export class PlatformWorker { } else { let client: Client | undefined try { - client = await createPlatformClient(oldWorkspace, config.ProductID, 30000) + client = await createPlatformClient(oldWorkspace, 30000) await this.removeInstallationFromWorkspace(oldWorker, installationId) await client.close() } catch (err: any) { @@ -290,7 +290,7 @@ export class PlatformWorker { } else { let client: Client | undefined try { - client = await createPlatformClient(workspace, config.ProductID, 30000) + client = await createPlatformClient(workspace, 30000) await GithubWorker.checkIntegrations(client, this.installations) await client.close() } catch (err: any) { @@ -388,7 +388,7 @@ export class PlatformWorker { platformClient = this.clients.get(payload.workspace)?.client if (platformClient === undefined) { shouldClose = true - platformClient = await createPlatformClient(payload.workspace, config.ProductID, 30000) + platformClient = await createPlatformClient(payload.workspace, 30000) } const client = new TxOperations(platformClient, payload.accountId) @@ -657,8 +657,7 @@ export class PlatformWorker { const token = generateToken( config.SystemEmail, { - name: workspace, - productId: config.ProductID + name: workspace }, { mode: 'github' } ) @@ -697,7 +696,6 @@ export class PlatformWorker { this.installations, { name: workspace, - productId: config.ProductID, workspaceUrl: workspaceInfo.workspace, workspaceName: workspace }, diff --git a/services/github/pod-github/src/types.ts b/services/github/pod-github/src/types.ts index ff2e730c40c..9bc08458c35 100644 --- a/services/github/pod-github/src/types.ts +++ b/services/github/pod-github/src/types.ts @@ -50,7 +50,6 @@ export const githubDerivedSyncVersion = 'v1' export interface Workspace { _id: string workspace: string - productId: string } /** diff --git a/services/github/pod-github/src/worker.ts b/services/github/pod-github/src/worker.ts index 0d3762bb039..0f273b91ef9 100644 --- a/services/github/pod-github/src/worker.ts +++ b/services/github/pod-github/src/worker.ts @@ -1488,7 +1488,7 @@ export class GithubWorker implements IntegrationManager { ctx.info('Connecting to', { workspace: workspace.workspaceUrl, workspaceId: workspace.workspaceName }) let client: Client | undefined try { - client = await createPlatformClient(workspace.name, workspace.productId, 30000, (event: ClientConnectEvent) => { + client = await createPlatformClient(workspace.name, 30000, (event: ClientConnectEvent) => { reconnect(workspace.name, event) }) diff --git a/services/gmail/pod-gmail/src/workspaceClient.ts b/services/gmail/pod-gmail/src/workspaceClient.ts index c316c95fcc4..a3088ac1927 100644 --- a/services/gmail/pod-gmail/src/workspaceClient.ts +++ b/services/gmail/pod-gmail/src/workspaceClient.ts @@ -76,7 +76,7 @@ export class WorkspaceClient { this.mongo, this.client, this, - { name: this.workspace, productId: '' }, + { name: this.workspace }, this.storageAdapter ) this.clients.set(user.userId, newClient) @@ -125,7 +125,7 @@ export class WorkspaceClient { } private async initClient (workspace: string): Promise { - const token = generateToken(config.SystemEmail, { name: workspace, productId: '' }) + const token = generateToken(config.SystemEmail, { name: workspace }) console.log('token', token, workspace) const client = await getClient(token) client.notify = (...tx: Tx[]) => { diff --git a/services/love/src/main.ts b/services/love/src/main.ts index 7530355b4b0..eeeb5bcb4bc 100644 --- a/services/love/src/main.ts +++ b/services/love/src/main.ts @@ -192,11 +192,11 @@ const checkRecordAvailable = async (storageConfig: StorageConfig | undefined): P } function getBucket (storageConfig: any, workspaceId: WorkspaceId): string { - return storageConfig.rootBucket ?? (storageConfig.bucketPrefix ?? '') + toWorkspaceString(workspaceId, '.') + return storageConfig.rootBucket ?? (storageConfig.bucketPrefix ?? '') + toWorkspaceString(workspaceId) } function getBucketFolder (workspaceId: WorkspaceId): string { - return toWorkspaceString(workspaceId, '.') + return toWorkspaceString(workspaceId) } function getDocumentKey (storageConfig: any, workspace: WorkspaceId, name: string): string { diff --git a/services/love/src/workspaceClient.ts b/services/love/src/workspaceClient.ts index a2323db58d7..07334fd7770 100644 --- a/services/love/src/workspaceClient.ts +++ b/services/love/src/workspaceClient.ts @@ -35,7 +35,7 @@ export class WorkspaceClient { } private async initClient (workspace: string): Promise { - const token = generateToken(config.SystemEmail, { name: workspace, productId: '' }) + const token = generateToken(config.SystemEmail, { name: workspace }) const client = await getClient(token) this.client = new TxOperations(client, core.account.System) return this.client diff --git a/services/sign/pod-sign/src/signController.ts b/services/sign/pod-sign/src/signController.ts index 935b8f39b32..f72de5bc645 100644 --- a/services/sign/pod-sign/src/signController.ts +++ b/services/sign/pod-sign/src/signController.ts @@ -51,8 +51,7 @@ export class SignController { private async createPlatformClient (workspace: string): Promise { const token = generateToken(config.SystemEmail, { - name: workspace, - productId: '' + name: workspace }) const endpoint = await getTransactorEndpoint(token) const connection = await createClient(endpoint, token) diff --git a/services/telegram/pod-telegram/src/workspace.ts b/services/telegram/pod-telegram/src/workspace.ts index 0ee09c0c771..7833eb47667 100644 --- a/services/telegram/pod-telegram/src/workspace.ts +++ b/services/telegram/pod-telegram/src/workspace.ts @@ -160,7 +160,7 @@ export class WorkspaceWorker { lastMsgStorage: Collection, channelsStorage: Collection ): Promise { - const token = generateToken(config.SystemEmail, { name: workspace, productId: '' }) + const token = generateToken(config.SystemEmail, { name: workspace }) const client = await createPlatformClient(token) const worker = new WorkspaceWorker( @@ -644,7 +644,7 @@ export class WorkspaceWorker { const attachments = await this.client.findAll(attachment.class.Attachment, { attachedTo: msg._id }) const res: Buffer[] = [] for (const attachment of attachments) { - const chunks = await this.storageAdapter.read(this.ctx, { name: this.workspace, productId: '' }, attachment.file) + const chunks = await this.storageAdapter.read(this.ctx, { name: this.workspace }, attachment.file) const buffer = Buffer.concat(chunks) if (buffer.length > 0) { res.push( @@ -669,14 +669,7 @@ export class WorkspaceWorker { try { const id = uuid() file.size = file.size ?? file.file.length - await this.storageAdapter.put( - this.ctx, - { name: this.workspace, productId: '' }, - id, - file.file, - file.type, - file.size - ) + await this.storageAdapter.put(this.ctx, { name: this.workspace }, id, file.file, file.type, file.size) const tx = factory.createTxCollectionCUD( msg._class, msg._id,