From de79b44e9fbc714c86c4c6ee6e3740675a766566 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Mon, 5 Feb 2024 18:46:21 +0700 Subject: [PATCH] UBERF-5304: Fix init workspace (#4524) Signed-off-by: Andrey Sobolev --- .../src/components/LoginForm.svelte | 27 +++++++---- server-plugins/tracker-resources/src/index.ts | 2 - server/account/src/index.ts | 45 ++++++++++--------- server/tool/src/index.ts | 10 ++--- 4 files changed, 47 insertions(+), 37 deletions(-) diff --git a/plugins/login-resources/src/components/LoginForm.svelte b/plugins/login-resources/src/components/LoginForm.svelte index 3f06c662a2..2c7aa383f0 100644 --- a/plugins/login-resources/src/components/LoginForm.svelte +++ b/plugins/login-resources/src/components/LoginForm.svelte @@ -19,6 +19,7 @@ import { fetchMetadataLocalStorage, getCurrentLocation, + Loading, Location, navigate, setMetadataLocalStorage, @@ -117,6 +118,7 @@ navigate(loc) } } + let loading = true async function chooseToken (time: number): Promise { if (getMetadata(presentation.metadata.Token) == null) { @@ -137,18 +139,25 @@ setMetadataLocalStorage(login.metadata.LastToken, null) } } + loading = false + } else { + loading = false } } $: chooseToken($ticker) -
+{#if loading} + +{:else} + +{/if} diff --git a/server-plugins/tracker-resources/src/index.ts b/server-plugins/tracker-resources/src/index.ts index 462bbd748f..d38edef8d9 100644 --- a/server-plugins/tracker-resources/src/index.ts +++ b/server-plugins/tracker-resources/src/index.ts @@ -392,8 +392,6 @@ async function doIssueUpdate ( Object.prototype.hasOwnProperty.call(updateTx.operations, 'estimation') || Object.prototype.hasOwnProperty.call(updateTx.operations, 'reportedTime') || (Object.prototype.hasOwnProperty.call(updateTx.operations, '$inc') && - Object.prototype.hasOwnProperty.call(updateTx.operations.$inc, 'reportedTime')) || - (Object.prototype.hasOwnProperty.call(updateTx.operations, '$dec') && Object.prototype.hasOwnProperty.call(updateTx.operations.$inc, 'reportedTime')) ) { const issue = await getCurrentIssue() diff --git a/server/account/src/index.ts b/server/account/src/index.ts index 084084b9df..4567a11380 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -25,7 +25,6 @@ import contact, { } from '@hcengineering/contact' import core, { AccountRole, - BackupClient, Client, concatLink, Data, @@ -592,12 +591,15 @@ export async function listAccounts (db: Db): Promise { } const workspaceReg = /[a-z0-9]/ +const workspaceRegDigit = /[0-9]/ function stripId (name: string): string { let workspaceId = '' for (const c of name.toLowerCase()) { if (workspaceReg.test(c) || c === '-') { - workspaceId += c + if (workspaceId.length > 0 || !workspaceRegDigit.test(c)) { + workspaceId += c + } } } return workspaceId @@ -694,7 +696,7 @@ export async function createWorkspace ( email: string, workspaceName: string, workspace?: string -): Promise<{ workspaceInfo: Workspace, err?: any, client?: Client & BackupClient }> { +): Promise<{ workspaceInfo: Workspace, err?: any, client?: Client }> { // We need to search for duplicate workspaceUrl await searchPromise @@ -702,23 +704,22 @@ export async function createWorkspace ( searchPromise = generateWorkspaceRecord(db, email, productId, version, workspaceName, workspace) const workspaceInfo = await searchPromise - let client: Client & BackupClient + let client: Client try { const initWS = getMetadata(toolPlugin.metadata.InitWorkspace) const wsId = getWorkspaceId(workspaceInfo.workspace, productId) - if (initWS !== undefined) { - if ((await getWorkspaceById(db, productId, initWS)) !== null) { - client = await initModel(getTransactor(), wsId, txes, []) - await client.close() - await cloneWorkspace( - getTransactor(), - getWorkspaceId(initWS, productId), - getWorkspaceId(workspaceInfo.workspace, productId) - ) - await upgradeModel(getTransactor(), wsId, txes, migrationOperation) - } + if (initWS !== undefined && (await getWorkspaceById(db, productId, initWS)) !== null) { + client = await initModel(getTransactor(), wsId, txes, []) + await client.close() + await cloneWorkspace( + getTransactor(), + getWorkspaceId(initWS, productId), + getWorkspaceId(workspaceInfo.workspace, productId) + ) + client = await upgradeModel(getTransactor(), wsId, txes, migrationOperation) + } else { + client = await initModel(getTransactor(), wsId, txes, migrationOperation) } - client = await initModel(getTransactor(), wsId, txes, migrationOperation) } catch (err: any) { return { workspaceInfo, err, client: {} as any } } @@ -765,7 +766,9 @@ export async function upgradeWorkspace ( $set: { version } } ) - await upgradeModel(getTransactor(), getWorkspaceId(workspaceUrl, productId), txes, migrationOperation, logger) + await ( + await upgradeModel(getTransactor(), getWorkspaceId(workspaceUrl, productId), txes, migrationOperation, logger) + ).close() return versionStr } @@ -963,7 +966,7 @@ export async function setRole ( workspace: string, productId: string, role: AccountRole, - client?: Client & BackupClient + client?: Client ): Promise { const email = cleanEmail(_email) const connection = client ?? (await connect(getTransactor(), getWorkspaceId(workspace, productId))) @@ -994,7 +997,7 @@ export async function assignWorkspace ( _email: string, workspaceId: string, shouldReplaceAccount: boolean = false, - client?: Client & BackupClient + client?: Client ): Promise { const email = cleanEmail(_email) const initWS = getMetadata(toolPlugin.metadata.InitWorkspace) @@ -1098,14 +1101,14 @@ async function createPersonAccount ( productId: string, workspace: string, shouldReplaceCurrent: boolean = false, - client?: Client & BackupClient + client?: Client ): Promise { const connection = client ?? (await connect(getTransactor(), getWorkspaceId(workspace, productId))) try { const ops = new TxOperations(connection, core.account.System) const name = combineName(account.first, account.last) - // Check if EmployeeAccoun is not exists + // Check if EmployeeAccount is not exists if (shouldReplaceCurrent) { const currentAccount = await ops.findOne(contact.class.PersonAccount, {}) if (currentAccount !== undefined) { diff --git a/server/tool/src/index.ts b/server/tool/src/index.ts index 15d089f8d1..858558107b 100644 --- a/server/tool/src/index.ts +++ b/server/tool/src/index.ts @@ -116,7 +116,7 @@ export async function initModel ( rawTxes: Tx[], migrateOperations: [string, MigrateOperation][], logger: ModelLogger = consoleModelLogger -): Promise { +): Promise { const { mongodbUri, minio, txes } = prepareTools(rawTxes) if (txes.some((tx) => tx.objectSpace !== core.space.Model)) { throw Error('Model txes must target only core.space.Model') @@ -128,10 +128,10 @@ export async function initModel ( await client.connect() const db = getWorkspaceDB(client, workspaceId) - logger.log('dropping database...') + logger.log('dropping database...', workspaceId) await db.dropDatabase() - logger.log('creating model...') + logger.log('creating model...', workspaceId) const model = txes const result = await db.collection(DOMAIN_TX).insertMany(model as Document[]) logger.log(`${result.insertedCount} model transactions inserted.`) @@ -172,7 +172,7 @@ export async function upgradeModel ( rawTxes: Tx[], migrateOperations: [string, MigrateOperation][], logger: ModelLogger = consoleModelLogger -): Promise { +): Promise { const { mongodbUri, txes } = prepareTools(rawTxes) if (txes.some((tx) => tx.objectSpace !== core.space.Model)) { @@ -231,7 +231,7 @@ export async function upgradeModel ( logger.log(`${workspaceId.name}: upgrade:`, op[0], Date.now() - t) } - await connection.close() + return connection } finally { await client.close() }