mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-07 08:21:08 +00:00
UBERF-5304: Fix init workspace (#4524)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
889f83fc52
commit
de79b44e9f
@ -19,6 +19,7 @@
|
|||||||
import {
|
import {
|
||||||
fetchMetadataLocalStorage,
|
fetchMetadataLocalStorage,
|
||||||
getCurrentLocation,
|
getCurrentLocation,
|
||||||
|
Loading,
|
||||||
Location,
|
Location,
|
||||||
navigate,
|
navigate,
|
||||||
setMetadataLocalStorage,
|
setMetadataLocalStorage,
|
||||||
@ -117,6 +118,7 @@
|
|||||||
navigate(loc)
|
navigate(loc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let loading = true
|
||||||
|
|
||||||
async function chooseToken (time: number): Promise<void> {
|
async function chooseToken (time: number): Promise<void> {
|
||||||
if (getMetadata(presentation.metadata.Token) == null) {
|
if (getMetadata(presentation.metadata.Token) == null) {
|
||||||
@ -137,12 +139,18 @@
|
|||||||
setMetadataLocalStorage(login.metadata.LastToken, null)
|
setMetadataLocalStorage(login.metadata.LastToken, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
loading = false
|
||||||
|
} else {
|
||||||
|
loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: chooseToken($ticker)
|
$: chooseToken($ticker)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if loading}
|
||||||
|
<Loading />
|
||||||
|
{:else}
|
||||||
<Form
|
<Form
|
||||||
caption={login.string.LogIn}
|
caption={login.string.LogIn}
|
||||||
{status}
|
{status}
|
||||||
@ -152,3 +160,4 @@
|
|||||||
bottomActions={[recoveryAction]}
|
bottomActions={[recoveryAction]}
|
||||||
ignoreInitialValidation
|
ignoreInitialValidation
|
||||||
/>
|
/>
|
||||||
|
{/if}
|
||||||
|
@ -392,8 +392,6 @@ async function doIssueUpdate (
|
|||||||
Object.prototype.hasOwnProperty.call(updateTx.operations, 'estimation') ||
|
Object.prototype.hasOwnProperty.call(updateTx.operations, 'estimation') ||
|
||||||
Object.prototype.hasOwnProperty.call(updateTx.operations, 'reportedTime') ||
|
Object.prototype.hasOwnProperty.call(updateTx.operations, 'reportedTime') ||
|
||||||
(Object.prototype.hasOwnProperty.call(updateTx.operations, '$inc') &&
|
(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'))
|
Object.prototype.hasOwnProperty.call(updateTx.operations.$inc, 'reportedTime'))
|
||||||
) {
|
) {
|
||||||
const issue = await getCurrentIssue()
|
const issue = await getCurrentIssue()
|
||||||
|
@ -25,7 +25,6 @@ import contact, {
|
|||||||
} from '@hcengineering/contact'
|
} from '@hcengineering/contact'
|
||||||
import core, {
|
import core, {
|
||||||
AccountRole,
|
AccountRole,
|
||||||
BackupClient,
|
|
||||||
Client,
|
Client,
|
||||||
concatLink,
|
concatLink,
|
||||||
Data,
|
Data,
|
||||||
@ -592,14 +591,17 @@ export async function listAccounts (db: Db): Promise<Account[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const workspaceReg = /[a-z0-9]/
|
const workspaceReg = /[a-z0-9]/
|
||||||
|
const workspaceRegDigit = /[0-9]/
|
||||||
|
|
||||||
function stripId (name: string): string {
|
function stripId (name: string): string {
|
||||||
let workspaceId = ''
|
let workspaceId = ''
|
||||||
for (const c of name.toLowerCase()) {
|
for (const c of name.toLowerCase()) {
|
||||||
if (workspaceReg.test(c) || c === '-') {
|
if (workspaceReg.test(c) || c === '-') {
|
||||||
|
if (workspaceId.length > 0 || !workspaceRegDigit.test(c)) {
|
||||||
workspaceId += c
|
workspaceId += c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return workspaceId
|
return workspaceId
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,7 +696,7 @@ export async function createWorkspace (
|
|||||||
email: string,
|
email: string,
|
||||||
workspaceName: string,
|
workspaceName: string,
|
||||||
workspace?: 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
|
// We need to search for duplicate workspaceUrl
|
||||||
await searchPromise
|
await searchPromise
|
||||||
|
|
||||||
@ -702,12 +704,11 @@ export async function createWorkspace (
|
|||||||
searchPromise = generateWorkspaceRecord(db, email, productId, version, workspaceName, workspace)
|
searchPromise = generateWorkspaceRecord(db, email, productId, version, workspaceName, workspace)
|
||||||
|
|
||||||
const workspaceInfo = await searchPromise
|
const workspaceInfo = await searchPromise
|
||||||
let client: Client & BackupClient
|
let client: Client
|
||||||
try {
|
try {
|
||||||
const initWS = getMetadata(toolPlugin.metadata.InitWorkspace)
|
const initWS = getMetadata(toolPlugin.metadata.InitWorkspace)
|
||||||
const wsId = getWorkspaceId(workspaceInfo.workspace, productId)
|
const wsId = getWorkspaceId(workspaceInfo.workspace, productId)
|
||||||
if (initWS !== undefined) {
|
if (initWS !== undefined && (await getWorkspaceById(db, productId, initWS)) !== null) {
|
||||||
if ((await getWorkspaceById(db, productId, initWS)) !== null) {
|
|
||||||
client = await initModel(getTransactor(), wsId, txes, [])
|
client = await initModel(getTransactor(), wsId, txes, [])
|
||||||
await client.close()
|
await client.close()
|
||||||
await cloneWorkspace(
|
await cloneWorkspace(
|
||||||
@ -715,10 +716,10 @@ export async function createWorkspace (
|
|||||||
getWorkspaceId(initWS, productId),
|
getWorkspaceId(initWS, productId),
|
||||||
getWorkspaceId(workspaceInfo.workspace, productId)
|
getWorkspaceId(workspaceInfo.workspace, productId)
|
||||||
)
|
)
|
||||||
await upgradeModel(getTransactor(), wsId, txes, migrationOperation)
|
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) {
|
} catch (err: any) {
|
||||||
return { workspaceInfo, err, client: {} as any }
|
return { workspaceInfo, err, client: {} as any }
|
||||||
}
|
}
|
||||||
@ -765,7 +766,9 @@ export async function upgradeWorkspace (
|
|||||||
$set: { version }
|
$set: { version }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
await (
|
||||||
await upgradeModel(getTransactor(), getWorkspaceId(workspaceUrl, productId), txes, migrationOperation, logger)
|
await upgradeModel(getTransactor(), getWorkspaceId(workspaceUrl, productId), txes, migrationOperation, logger)
|
||||||
|
).close()
|
||||||
return versionStr
|
return versionStr
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -963,7 +966,7 @@ export async function setRole (
|
|||||||
workspace: string,
|
workspace: string,
|
||||||
productId: string,
|
productId: string,
|
||||||
role: AccountRole,
|
role: AccountRole,
|
||||||
client?: Client & BackupClient
|
client?: Client
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const email = cleanEmail(_email)
|
const email = cleanEmail(_email)
|
||||||
const connection = client ?? (await connect(getTransactor(), getWorkspaceId(workspace, productId)))
|
const connection = client ?? (await connect(getTransactor(), getWorkspaceId(workspace, productId)))
|
||||||
@ -994,7 +997,7 @@ export async function assignWorkspace (
|
|||||||
_email: string,
|
_email: string,
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
shouldReplaceAccount: boolean = false,
|
shouldReplaceAccount: boolean = false,
|
||||||
client?: Client & BackupClient
|
client?: Client
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const email = cleanEmail(_email)
|
const email = cleanEmail(_email)
|
||||||
const initWS = getMetadata(toolPlugin.metadata.InitWorkspace)
|
const initWS = getMetadata(toolPlugin.metadata.InitWorkspace)
|
||||||
@ -1098,14 +1101,14 @@ async function createPersonAccount (
|
|||||||
productId: string,
|
productId: string,
|
||||||
workspace: string,
|
workspace: string,
|
||||||
shouldReplaceCurrent: boolean = false,
|
shouldReplaceCurrent: boolean = false,
|
||||||
client?: Client & BackupClient
|
client?: Client
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const connection = client ?? (await connect(getTransactor(), getWorkspaceId(workspace, productId)))
|
const connection = client ?? (await connect(getTransactor(), getWorkspaceId(workspace, productId)))
|
||||||
try {
|
try {
|
||||||
const ops = new TxOperations(connection, core.account.System)
|
const ops = new TxOperations(connection, core.account.System)
|
||||||
|
|
||||||
const name = combineName(account.first, account.last)
|
const name = combineName(account.first, account.last)
|
||||||
// Check if EmployeeAccoun is not exists
|
// Check if EmployeeAccount is not exists
|
||||||
if (shouldReplaceCurrent) {
|
if (shouldReplaceCurrent) {
|
||||||
const currentAccount = await ops.findOne(contact.class.PersonAccount, {})
|
const currentAccount = await ops.findOne(contact.class.PersonAccount, {})
|
||||||
if (currentAccount !== undefined) {
|
if (currentAccount !== undefined) {
|
||||||
|
@ -116,7 +116,7 @@ export async function initModel (
|
|||||||
rawTxes: Tx[],
|
rawTxes: Tx[],
|
||||||
migrateOperations: [string, MigrateOperation][],
|
migrateOperations: [string, MigrateOperation][],
|
||||||
logger: ModelLogger = consoleModelLogger
|
logger: ModelLogger = consoleModelLogger
|
||||||
): Promise<CoreClient & BackupClient> {
|
): Promise<CoreClient> {
|
||||||
const { mongodbUri, minio, txes } = prepareTools(rawTxes)
|
const { mongodbUri, minio, txes } = prepareTools(rawTxes)
|
||||||
if (txes.some((tx) => tx.objectSpace !== core.space.Model)) {
|
if (txes.some((tx) => tx.objectSpace !== core.space.Model)) {
|
||||||
throw Error('Model txes must target only core.space.Model')
|
throw Error('Model txes must target only core.space.Model')
|
||||||
@ -128,10 +128,10 @@ export async function initModel (
|
|||||||
await client.connect()
|
await client.connect()
|
||||||
const db = getWorkspaceDB(client, workspaceId)
|
const db = getWorkspaceDB(client, workspaceId)
|
||||||
|
|
||||||
logger.log('dropping database...')
|
logger.log('dropping database...', workspaceId)
|
||||||
await db.dropDatabase()
|
await db.dropDatabase()
|
||||||
|
|
||||||
logger.log('creating model...')
|
logger.log('creating model...', workspaceId)
|
||||||
const model = txes
|
const model = txes
|
||||||
const result = await db.collection(DOMAIN_TX).insertMany(model as Document[])
|
const result = await db.collection(DOMAIN_TX).insertMany(model as Document[])
|
||||||
logger.log(`${result.insertedCount} model transactions inserted.`)
|
logger.log(`${result.insertedCount} model transactions inserted.`)
|
||||||
@ -172,7 +172,7 @@ export async function upgradeModel (
|
|||||||
rawTxes: Tx[],
|
rawTxes: Tx[],
|
||||||
migrateOperations: [string, MigrateOperation][],
|
migrateOperations: [string, MigrateOperation][],
|
||||||
logger: ModelLogger = consoleModelLogger
|
logger: ModelLogger = consoleModelLogger
|
||||||
): Promise<void> {
|
): Promise<CoreClient> {
|
||||||
const { mongodbUri, txes } = prepareTools(rawTxes)
|
const { mongodbUri, txes } = prepareTools(rawTxes)
|
||||||
|
|
||||||
if (txes.some((tx) => tx.objectSpace !== core.space.Model)) {
|
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)
|
logger.log(`${workspaceId.name}: upgrade:`, op[0], Date.now() - t)
|
||||||
}
|
}
|
||||||
|
|
||||||
await connection.close()
|
return connection
|
||||||
} finally {
|
} finally {
|
||||||
await client.close()
|
await client.close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user