UBERF-5304: Fix init workspace (#4524)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-02-05 18:46:21 +07:00 committed by GitHub
parent 889f83fc52
commit de79b44e9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 37 deletions

View File

@ -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<void> {
if (getMetadata(presentation.metadata.Token) == null) {
@ -137,18 +139,25 @@
setMetadataLocalStorage(login.metadata.LastToken, null)
}
}
loading = false
} else {
loading = false
}
}
$: chooseToken($ticker)
</script>
<Form
caption={login.string.LogIn}
{status}
{fields}
{object}
{action}
bottomActions={[recoveryAction]}
ignoreInitialValidation
/>
{#if loading}
<Loading />
{:else}
<Form
caption={login.string.LogIn}
{status}
{fields}
{object}
{action}
bottomActions={[recoveryAction]}
ignoreInitialValidation
/>
{/if}

View File

@ -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()

View File

@ -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<Account[]> {
}
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<void> {
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<void> {
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<void> {
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) {

View File

@ -116,7 +116,7 @@ export async function initModel (
rawTxes: Tx[],
migrateOperations: [string, MigrateOperation][],
logger: ModelLogger = consoleModelLogger
): Promise<CoreClient & BackupClient> {
): Promise<CoreClient> {
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<void> {
): Promise<CoreClient> {
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()
}