diff --git a/dev/tool/src/workspace.ts b/dev/tool/src/workspace.ts index b389057634..1db9e8b7d4 100644 --- a/dev/tool/src/workspace.ts +++ b/dev/tool/src/workspace.ts @@ -114,6 +114,7 @@ export async function restoreWorkspace ( elasticUrl: string, transactorUrl: string ): Promise { + console.log('Restoring workspace', mongoUrl, dbName, fileName) const client = new MongoClient(mongoUrl) try { await client.connect() @@ -161,7 +162,7 @@ export async function restoreWorkspace ( } } - await upgradeModel(dbName, transactorUrl) + await upgradeModel(transactorUrl, dbName) await rebuildElastic(mongoUrl, dbName, minio, elasticUrl) } finally { diff --git a/models/all/src/index.ts b/models/all/src/index.ts index 9d0441e157..d0b41cc8b9 100644 --- a/models/all/src/index.ts +++ b/models/all/src/index.ts @@ -36,8 +36,6 @@ import { createModel as templatesModel } from '@anticrm/model-templates' import { createModel as textEditorModel } from '@anticrm/model-text-editor' import { createModel as viewModel } from '@anticrm/model-view' import { createModel as workbenchModel } from '@anticrm/model-workbench' -import { readFileSync } from 'fs' -import { join } from 'path' const builder = new Builder() @@ -70,14 +68,11 @@ const builders = [ for (const b of builders) { b(builder) } -const packageFile = readFileSync(join(__dirname, '..', 'package.json')).toString() -const json = JSON.parse(packageFile) -const packageVersion = json.version.split('.') export const version: Data = { - major: parseInt(packageVersion[0]), - minor: parseInt(packageVersion[1]), - patch: parseInt(packageVersion[2]) + major: 0, + minor: 6, + patch: 0 } builder.createDoc(core.class.Version, core.space.Model, version, core.version.Model) diff --git a/server/account/src/index.ts b/server/account/src/index.ts index ae8191fdb0..178e44a5af 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -391,10 +391,10 @@ async function getWorkspaceAndAccount ( export async function assignWorkspace (db: Db, email: string, workspace: string): Promise { const { workspaceId, accountId } = await getWorkspaceAndAccount(db, email, workspace) // Add account into workspace. - await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: workspaceId }, { $push: { accounts: accountId } }) + await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: workspaceId }, { $addToSet: { accounts: accountId } }) // Add workspace to account - await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: accountId }, { $push: { workspaces: workspaceId } }) + await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: accountId }, { $addToSet: { workspaces: workspaceId } }) const account = await db.collection(ACCOUNT_COLLECTION).findOne({ _id: accountId }) @@ -408,17 +408,33 @@ async function createEmployeeAccount (account: Account, workspace: string): Prom const name = combineName(account.first, account.last) - const employee = await ops.createDoc(contact.class.Employee, contact.space.Employee, { - name, - city: '', - channels: [] - }) + // Check if EmployeeAccoun is not exists + const existingAccount = await ops.findOne(contact.class.EmployeeAccount, { email: account.email }) - await ops.createDoc(contact.class.EmployeeAccount, core.space.Model, { - email: account.email, - employee, - name - }) + if (existingAccount === undefined) { + const employee = await ops.createDoc(contact.class.Employee, contact.space.Employee, { + name, + city: '', + channels: [] + }) + + await ops.createDoc(contact.class.EmployeeAccount, core.space.Model, { + email: account.email, + employee, + name + }) + } else { + const employee = await ops.findOne(contact.class.Employee, { _id: existingAccount.employee }) + if (employee === undefined) { + // Employee was deleted, let's restore it. + const employeeId = await ops.createDoc(contact.class.Employee, contact.space.Employee, { + name, + city: '', + channels: [] + }) + await ops.updateDoc(contact.class.EmployeeAccount, existingAccount.space, existingAccount._id, { employee: employeeId }) + } + } } finally { await connection.close() }