From 2612cd5b13683dcfaeb49b30b6a2567d37bc96be Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Thu, 17 Mar 2022 11:05:30 +0600 Subject: [PATCH] Spaces in domain (#1151) Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- dev/generator/src/recruit.ts | 2 +- dev/tool/src/importer.ts | 2 +- models/all/src/migration.ts | 19 ++++-- models/chunter/src/index.ts | 16 +---- models/chunter/src/migration.ts | 66 +++++++++++++++++++ models/contact/src/index.ts | 13 ---- models/contact/src/migration.ts | 24 ++++++- models/core/src/migration.ts | 49 +++++++++++++- models/core/src/security.ts | 6 +- models/gmail/src/index.ts | 15 +---- models/gmail/src/migration.ts | 43 ++++++++++++ models/lead/src/index.ts | 12 ---- models/lead/src/migration.ts | 21 ++++++ models/recruit/src/index.ts | 12 ---- models/recruit/src/migration.ts | 23 +++++++ models/tags/src/index.ts | 13 ---- models/tags/src/migration.ts | 20 ++++++ models/task/src/index.ts | 26 -------- models/task/src/migration.ts | 42 ++++++++++++ models/telegram/src/index.ts | 15 +---- models/telegram/src/migration.ts | 42 ++++++++++++ models/templates/src/index.ts | 15 +---- models/templates/src/migration.ts | 42 ++++++++++++ packages/core/src/component.ts | 3 +- .../src/components/CreateChannel.svelte | 2 +- .../src/components/CreateOrganizations.svelte | 2 +- .../src/components/CreatePersons.svelte | 2 +- .../src/components/CreateFunnel.svelte | 2 +- .../src/components/CreateVacancy.svelte | 2 +- .../review/CreateReviewCategory.svelte | 2 +- .../src/components/CreateProject.svelte | 2 +- .../notification-resources/src/index.ts | 13 +--- server/account/src/index.ts | 2 +- server/tool/src/index.ts | 1 + 34 files changed, 409 insertions(+), 162 deletions(-) create mode 100644 models/chunter/src/migration.ts create mode 100644 models/gmail/src/migration.ts create mode 100644 models/telegram/src/migration.ts create mode 100644 models/templates/src/migration.ts diff --git a/dev/generator/src/recruit.ts b/dev/generator/src/recruit.ts index 1ca1aa6f6a..a7930bf276 100644 --- a/dev/generator/src/recruit.ts +++ b/dev/generator/src/recruit.ts @@ -97,7 +97,7 @@ async function genVacansyApplicants ( // Update or create candidate await ctx.with('update', {}, (ctx) => - findOrUpdate(ctx, client, core.space.Model, recruit.class.Vacancy, vacancyId, vacancy) + findOrUpdate(ctx, client, core.space.Space, recruit.class.Vacancy, vacancyId, vacancy) ) console.log('Vacandy generated', vacancy.name) diff --git a/dev/tool/src/importer.ts b/dev/tool/src/importer.ts index 11cbea5e73..b3d7930757 100644 --- a/dev/tool/src/importer.ts +++ b/dev/tool/src/importer.ts @@ -246,7 +246,7 @@ async function createUpdateVacancy (client: TxOperations, statuses: any): Promis console.log('Creating vacancy', vacancy.name) // Update or create candidate - await findOrUpdate(client, core.space.Model, recruit.class.Vacancy, vacancyId, vacancy) + await findOrUpdate(client, core.space.Space, recruit.class.Vacancy, vacancyId, vacancy) const states = await createUpdateSpaceKanban(vacancyId, client, statuses) diff --git a/models/all/src/migration.ts b/models/all/src/migration.ts index c84681ba76..d8d43a1c95 100644 --- a/models/all/src/migration.ts +++ b/models/all/src/migration.ts @@ -13,22 +13,29 @@ // limitations under the License. // -import { MigrateOperation } from '@anticrm/model' - // Import migrate operations. -import { coreOperation } from '@anticrm/model-core' -import { taskOperation } from '@anticrm/model-task' +import { MigrateOperation } from '@anticrm/model' import { attachmentOperation } from '@anticrm/model-attachment' +import { chunterOperation } from '@anticrm/model-chunter' +import { contactOperation } from '@anticrm/model-contact' +import { coreOperation } from '@anticrm/model-core' +import { gmailOperation } from '@anticrm/model-gmail' import { leadOperation } from '@anticrm/model-lead' import { notificationOperation } from '@anticrm/model-notification' import { settingOperation } from '@anticrm/model-setting' import { recruitOperation } from '@anticrm/model-recruit' -import { viewOperation } from '@anticrm/model-view' -import { contactOperation } from '@anticrm/model-contact' import { tagsOperation } from '@anticrm/model-tags' +import { taskOperation } from '@anticrm/model-task' +import { telegramOperation } from '@anticrm/model-telegram' +import { templatesOperation } from '@anticrm/model-templates' +import { viewOperation } from '@anticrm/model-view' export const migrateOperations: MigrateOperation[] = [ coreOperation, + chunterOperation, + gmailOperation, + templatesOperation, + telegramOperation, taskOperation, attachmentOperation, leadOperation, diff --git a/models/chunter/src/index.ts b/models/chunter/src/index.ts index f75c815df5..ed442b326b 100644 --- a/models/chunter/src/index.ts +++ b/models/chunter/src/index.ts @@ -99,20 +99,6 @@ export function createModel (builder: Builder): void { ] } }, chunter.app.Chunter) - builder.createDoc(chunter.class.Channel, core.space.Model, { - name: 'general', - description: 'General Channel', - private: false, - archived: false, - members: [] - }, chunter.space.General) - builder.createDoc(chunter.class.Channel, core.space.Model, { - name: 'random', - description: 'Random Talks', - private: false, - archived: false, - members: [] - }, chunter.space.Random) builder.mixin(chunter.class.Comment, core.class.Class, view.mixin.AttributePresenter, { presenter: chunter.component.CommentPresenter @@ -164,4 +150,6 @@ export function createModel (builder: Builder): void { }, chunter.ids.TxBacklinkRemove) } +export { chunterOperation } from './migration' + export default chunter diff --git a/models/chunter/src/migration.ts b/models/chunter/src/migration.ts new file mode 100644 index 0000000000..6cdcb12a57 --- /dev/null +++ b/models/chunter/src/migration.ts @@ -0,0 +1,66 @@ +// +// Copyright © 2022 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import type { Client } from '@anticrm/core' +import core, { TxOperations } from '@anticrm/core' +import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' +import chunter from './plugin' + +export async function createDeps (client: Client): Promise { + const tx = new TxOperations(client, core.account.System) + + await createGeneral(tx) + await createRandom(tx) +} + +export async function createGeneral (tx: TxOperations): Promise { + const createTx = await tx.findOne(core.class.TxCreateDoc, { + objectId: chunter.space.General + }) + if (createTx === undefined) { + await tx.createDoc(chunter.class.Channel, core.space.Space, { + name: 'general', + description: 'General Channel', + private: false, + archived: false, + members: [] + }, chunter.space.General) + } +} + +export async function createRandom (tx: TxOperations): Promise { + const createTx = await tx.findOne(core.class.TxCreateDoc, { + objectId: chunter.space.Random + }) + if (createTx === undefined) { + await tx.createDoc(chunter.class.Channel, core.space.Space, { + name: 'random', + description: 'Random Talks', + private: false, + archived: false, + members: [] + }, chunter.space.Random) + } +} + +export const chunterOperation: MigrateOperation = { + async migrate (client: MigrationClient): Promise { + }, + async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + await createGeneral(tx) + await createRandom(tx) + } +} diff --git a/models/contact/src/index.ts b/models/contact/src/index.ts index bff3f3c010..0374058147 100644 --- a/models/contact/src/index.ts +++ b/models/contact/src/index.ts @@ -224,19 +224,6 @@ export function createModel (builder: Builder): void { contact.channelProvider.Facebook ) - builder.createDoc( - core.class.Space, - core.space.Model, - { - name: 'Employees', - description: 'Employees', - private: false, - archived: false, - members: [] - }, - contact.space.Employee - ) - builder.mixin(contact.class.Person, core.class.Class, view.mixin.AttributePresenter, { presenter: contact.component.PersonPresenter }) diff --git a/models/contact/src/migration.ts b/models/contact/src/migration.ts index 324363df29..3f06f303d7 100644 --- a/models/contact/src/migration.ts +++ b/models/contact/src/migration.ts @@ -15,7 +15,7 @@ // import { Channel, ChannelProvider, Contact } from '@anticrm/contact' -import { Class, DOMAIN_TX, generateId, Ref, SortingOrder, TxCreateDoc, TxCUD, TxRemoveDoc, TxUpdateDoc } from '@anticrm/core' +import { Class, DOMAIN_TX, generateId, Ref, SortingOrder, TxCreateDoc, TxCUD, TxOperations, TxRemoveDoc, TxUpdateDoc } from '@anticrm/core' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' import core from '@anticrm/model-core' import contact, { DOMAIN_CHANNEL, DOMAIN_CONTACT } from './index' @@ -207,6 +207,26 @@ async function migrateChannelsDomain (client: MigrationClient): Promise { await client.move(DOMAIN_CONTACT, { _class: contact.class.Channel }, DOMAIN_CHANNEL) } +async function createSpace (tx: TxOperations): Promise { + const current = await tx.findOne(core.class.Space, { + _id: contact.space.Employee + }) + if (current === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Employees', + description: 'Employees', + private: false, + archived: false, + members: [] + }, + contact.space.Employee + ) + } +} + export const contactOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise { const classes = [contact.class.Contact, contact.class.Person, contact.class.Employee, contact.class.Organization] @@ -214,5 +234,7 @@ export const contactOperation: MigrateOperation = { await migrateChannelsDomain(client) }, async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + await createSpace(tx) } } diff --git a/models/core/src/migration.ts b/models/core/src/migration.ts index 4e62e04ef2..3b51360cdd 100644 --- a/models/core/src/migration.ts +++ b/models/core/src/migration.ts @@ -13,17 +13,58 @@ // limitations under the License. // -import { TxOperations } from '@anticrm/core' +import { DOMAIN_TX, TxOperations } from '@anticrm/core' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' - import core from './component' +async function migrateSpaces (client: MigrationUpgradeClient): Promise { + const currentSpaces = (await client.findAll(core.class.Space, {})).map((s) => s._id) + const descendants = client.getHierarchy().getDescendants(core.class.Space) + const removedSpaces = (await client.findAll(core.class.TxRemoveDoc, { objectClass: { $in: descendants } })).map((s) => s.objectId) + let createTxes = await client.findAll(core.class.TxCreateDoc, { + objectClass: { $in: descendants }, + objectId: { $nin: [...currentSpaces, ...removedSpaces] } + }) + + // TXes already stored, avoid dublicate id error + createTxes = createTxes.map((p) => { + return { + ...p, + space: core.space.DerivedTx + } + }) + await Promise.all(createTxes.map(async (tx) => await client.tx(tx))) + let updateTxes = await client.findAll(core.class.TxUpdateDoc, { + objectClass: { $in: descendants }, + objectId: { $nin: [...currentSpaces, ...removedSpaces] } + }) + // TXes already stored, avoid dublicate id error + updateTxes = updateTxes.map((p) => { + return { + ...p, + space: core.space.DerivedTx + } + }) + await Promise.all(updateTxes.map(async (tx) => await client.tx(tx))) +} + export const coreOperation: MigrateOperation = { - async migrate (client: MigrationClient): Promise {}, + async migrate (client: MigrationClient): Promise { + await client.update(DOMAIN_TX, { + objectSpace: core.space.Model, + objectClass: { + $in: ['core:class:Space', 'contact:class:Organizations', 'contact:class:Persons', + 'chunter:class:Channel', 'task:class:SpaceWithStates', 'task:class:Project', 'recruit:class:ReviewCategory', + 'recruit:class:Candidates', 'recruit:class:Vacancy', 'lead:class:Funnel'] + } + }, { + objectSpace: core.space.Space + }) + }, async upgrade (client: MigrationUpgradeClient): Promise { const targetSpaces = (await client.findAll(core.class.Space, {})) .filter((space) => space.archived == null) @@ -32,5 +73,7 @@ export const coreOperation: MigrateOperation = { await Promise.all(targetSpaces.map( (space) => new TxOperations(client, space.modifiedBy).updateDoc(space._class, space.space, space._id, { archived: false }) )).catch((e) => console.error(e)) + + await migrateSpaces(client) } } diff --git a/models/core/src/security.ts b/models/core/src/security.ts index 32b10b6141..b3ea7b6d36 100644 --- a/models/core/src/security.ts +++ b/models/core/src/security.ts @@ -13,14 +13,16 @@ // limitations under the License. // -import { Account, Arr, DOMAIN_MODEL, IndexKind, Ref, Space } from '@anticrm/core' +import { Account, Arr, Domain, DOMAIN_MODEL, IndexKind, Ref, Space } from '@anticrm/core' import { Index, Model, Prop, TypeBoolean, TypeString } from '@anticrm/model' import core from './component' import { TDoc } from './core' +export const DOMAIN_SPACE = 'space' as Domain + // S P A C E -@Model(core.class.Space, core.class.Doc, DOMAIN_MODEL) +@Model(core.class.Space, core.class.Doc, DOMAIN_SPACE) export class TSpace extends TDoc implements Space { @Prop(TypeString(), core.string.Name) @Index(IndexKind.FullText) diff --git a/models/gmail/src/index.ts b/models/gmail/src/index.ts index 9b88c0c3f8..093292a624 100644 --- a/models/gmail/src/index.ts +++ b/models/gmail/src/index.ts @@ -132,19 +132,6 @@ export function createModel (builder: Builder): void { gmail.integrationType.Gmail ) - builder.createDoc( - core.class.Space, - core.space.Model, - { - name: 'Gmail', - description: 'Space for all gmail messages', - private: false, - archived: false, - members: [] - }, - gmail.space.Gmail - ) - builder.createDoc( activity.class.TxViewlet, core.space.Model, @@ -159,3 +146,5 @@ export function createModel (builder: Builder): void { gmail.ids.TxSharedCreate ) } + +export { gmailOperation } from './migration' diff --git a/models/gmail/src/migration.ts b/models/gmail/src/migration.ts new file mode 100644 index 0000000000..4a842e9432 --- /dev/null +++ b/models/gmail/src/migration.ts @@ -0,0 +1,43 @@ +// +// Copyright © 2022 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import core, { TxOperations } from '@anticrm/core' +import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' +import gmail from './plugin' + +export const gmailOperation: MigrateOperation = { + async migrate (client: MigrationClient): Promise { + }, + async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + const current = await tx.findOne(core.class.Space, { + _id: gmail.space.Gmail + }) + if (current === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Gmail', + description: 'Space for all gmail messages', + private: false, + archived: false, + members: [] + }, + gmail.space.Gmail + ) + } + } +} diff --git a/models/lead/src/index.ts b/models/lead/src/index.ts index 0c9a49d0f0..b66c6659e3 100644 --- a/models/lead/src/index.ts +++ b/models/lead/src/index.ts @@ -104,18 +104,6 @@ export function createModel (builder: Builder): void { }, lead.app.Lead ) - builder.createDoc( - lead.class.Funnel, - core.space.Model, - { - name: 'Funnel', - description: 'Default funnel', - private: false, - archived: false, - members: [] - }, - lead.space.DefaultFunnel - ) builder.createDoc(view.class.Viewlet, core.space.Model, { attachTo: lead.mixin.Customer, diff --git a/models/lead/src/migration.ts b/models/lead/src/migration.ts index 474acf5a1f..cf365afa68 100644 --- a/models/lead/src/migration.ts +++ b/models/lead/src/migration.ts @@ -29,6 +29,26 @@ function logInfo (msg: string, result: MigrationResult): void { } } +async function createSpace (tx: TxOperations): Promise { + const current = await tx.findOne(core.class.Space, { + _id: lead.space.DefaultFunnel + }) + if (current === undefined) { + await tx.createDoc( + lead.class.Funnel, + core.space.Space, + { + name: 'Funnel', + description: 'Default funnel', + private: false, + archived: false, + members: [] + }, + lead.space.DefaultFunnel + ) + } +} + export const leadOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise { // Update done states for tasks @@ -52,6 +72,7 @@ export const leadOperation: MigrateOperation = { console.log('Lead: Performing model upgrades') const ops = new TxOperations(client, core.account.System) + await createSpace(ops) const leads = await client.findAll(lead.class.Lead, {}) for (const lead of leads) { diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index 08f20ea67a..78b7ee5faf 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -191,18 +191,6 @@ export function createModel (builder: Builder): void { }, recruit.app.Recruit ) - builder.createDoc( - recruit.class.Candidates, - core.space.Model, - { - name: 'public', - description: 'Public Candidates', - private: false, - members: [], - archived: false - }, - recruit.space.CandidatesPublic - ) builder.createDoc(view.class.Viewlet, core.space.Model, { attachTo: recruit.mixin.Candidate, diff --git a/models/recruit/src/migration.ts b/models/recruit/src/migration.ts index cd9218c290..ce64bb78d2 100644 --- a/models/recruit/src/migration.ts +++ b/models/recruit/src/migration.ts @@ -161,6 +161,8 @@ export const recruitOperation: MigrateOperation = { async upgrade (client: MigrationUpgradeClient): Promise { const tx = new TxOperations(client, core.account.System) + await createSpace(tx) + await createOrUpdate( tx, tags.class.TagCategory, @@ -206,6 +208,27 @@ export const recruitOperation: MigrateOperation = { await createSequence(tx, recruit.class.Opinion) } } + +async function createSpace (tx: TxOperations): Promise { + const current = await tx.findOne(core.class.Space, { + _id: recruit.space.CandidatesPublic + }) + if (current === undefined) { + await tx.createDoc( + recruit.class.Candidates, + core.space.Space, + { + name: 'public', + description: 'Public Candidates', + private: false, + members: [], + archived: false + }, + recruit.space.CandidatesPublic + ) + } +} + async function migrateUpdateCandidateToPersonAndMixin (client: MigrationClient): Promise { const updateCandidates = await client.find(DOMAIN_TX, { _class: core.class.TxUpdateDoc, diff --git a/models/tags/src/index.ts b/models/tags/src/index.ts index bb4ca99d1f..c6bed58ea3 100644 --- a/models/tags/src/index.ts +++ b/models/tags/src/index.ts @@ -84,19 +84,6 @@ export class TTagCategory extends TDoc implements TagCategory { export function createModel (builder: Builder): void { builder.createModel(TTagElement, TTagReference, TTagCategory) - builder.createDoc( - core.class.Space, - core.space.Model, - { - name: 'Tags', - description: 'Space for all tags', - private: true, - archived: false, - members: [] - }, - tags.space.Tags - ) - builder.mixin(tags.class.TagReference, core.class.Class, view.mixin.AttributeEditor, { editor: tags.component.Tags }) diff --git a/models/tags/src/migration.ts b/models/tags/src/migration.ts index 152318d857..835f0fc170 100644 --- a/models/tags/src/migration.ts +++ b/models/tags/src/migration.ts @@ -1,7 +1,27 @@ +import core, { TxOperations } from '@anticrm/core' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' +import tags from './plugin' export const tagsOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise {}, async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + const current = await tx.findOne(core.class.Space, { + _id: tags.space.Tags + }) + if (current === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Tags', + description: 'Space for all tags', + private: true, + archived: false, + members: [] + }, + tags.space.Tags + ) + } } } diff --git a/models/task/src/index.ts b/models/task/src/index.ts index 32c99afeff..4f1253d25a 100644 --- a/models/task/src/index.ts +++ b/models/task/src/index.ts @@ -330,19 +330,6 @@ export function createModel (builder: Builder): void { card: task.component.KanbanCard }) - builder.createDoc( - task.class.Project, - core.space.Model, - { - name: 'public', - description: 'Public tasks', - private: false, - archived: false, - members: [] - }, - task.space.TasksPublic - ) - builder.createDoc( task.class.KanbanTemplateSpace, core.space.Model, @@ -433,19 +420,6 @@ export function createModel (builder: Builder): void { task.viewlet.Kanban ) - builder.createDoc( - core.class.Space, - core.space.Model, - { - name: 'Sequences', - description: 'Internal space to store sequence numbers', - members: [], - private: false, - archived: false - }, - task.space.Sequence - ) - builder.mixin(task.class.DoneState, core.class.Class, view.mixin.AttributePresenter, { presenter: task.component.DoneStatePresenter }) diff --git a/models/task/src/migration.ts b/models/task/src/migration.ts index cac689fbad..908c52432c 100644 --- a/models/task/src/migration.ts +++ b/models/task/src/migration.ts @@ -52,6 +52,46 @@ async function migrateClass ( ) } +async function createDefaultProject (tx: TxOperations): Promise { + const createTx = await tx.findOne(core.class.TxCreateDoc, { + objectId: task.space.TasksPublic + }) + if (createTx === undefined) { + await tx.createDoc( + task.class.Project, + core.space.Space, + { + name: 'public', + description: 'Public tasks', + private: false, + archived: false, + members: [] + }, + task.space.TasksPublic + ) + } +} + +async function createDefaultSequence (tx: TxOperations): Promise { + const current = await tx.findOne(core.class.Space, { + _id: task.space.Sequence + }) + if (current === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Sequences', + description: 'Internal space to store sequence numbers', + members: [], + private: false, + archived: false + }, + task.space.Sequence + ) + } +} + export const taskOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise { // Since we should not have Task class instances, we convert them all to Issue. @@ -138,6 +178,8 @@ export const taskOperation: MigrateOperation = { } const tx = new TxOperations(client, core.account.System) + await createDefaultSequence(tx) + await createDefaultProject(tx) // To not depend on ui package let's use inlined ones one time const colors = new Map([ diff --git a/models/telegram/src/index.ts b/models/telegram/src/index.ts index 5b222e7b0d..a85a34b4a7 100644 --- a/models/telegram/src/index.ts +++ b/models/telegram/src/index.ts @@ -97,19 +97,6 @@ export function createModel (builder: Builder): void { telegram.integrationType.Telegram ) - builder.createDoc( - core.class.Space, - core.space.Model, - { - name: 'Telegram', - description: 'Space for all telegram messages', - private: false, - archived: false, - members: [] - }, - telegram.space.Telegram - ) - builder.createDoc( activity.class.TxViewlet, core.space.Model, @@ -124,3 +111,5 @@ export function createModel (builder: Builder): void { telegram.ids.TxSharedCreate ) } + +export { telegramOperation } from './migration' diff --git a/models/telegram/src/migration.ts b/models/telegram/src/migration.ts new file mode 100644 index 0000000000..49dd4652a3 --- /dev/null +++ b/models/telegram/src/migration.ts @@ -0,0 +1,42 @@ +// +// Copyright © 2022 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import core, { TxOperations } from '@anticrm/core' +import telegram from './plugin' +import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' + +export const telegramOperation: MigrateOperation = { + async migrate (client: MigrationClient): Promise {}, + async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + const current = await tx.findOne(core.class.Space, { + _id: telegram.space.Telegram + }) + if (current === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Telegram', + description: 'Space for all telegram messages', + private: false, + archived: false, + members: [] + }, + telegram.space.Telegram + ) + } + } +} diff --git a/models/templates/src/index.ts b/models/templates/src/index.ts index 841750aa95..bfdb77ed8d 100644 --- a/models/templates/src/index.ts +++ b/models/templates/src/index.ts @@ -38,19 +38,6 @@ export class TMessageTemplate extends TDoc implements MessageTemplate { export function createModel (builder: Builder): void { builder.createModel(TMessageTemplate) - builder.createDoc( - core.class.Space, - core.space.Model, - { - name: 'Templates', - description: 'Space for all templates', - private: true, - archived: false, - members: [] - }, - templates.space.Templates - ) - builder.createDoc(setting.class.SettingsCategory, core.space.Model, { name: 'message-templates', label: templates.string.Templates, @@ -66,3 +53,5 @@ export function createModel (builder: Builder): void { order: 1500 }, templates.ids.TemplatePopupAction) } + +export { templatesOperation } from './migration' diff --git a/models/templates/src/migration.ts b/models/templates/src/migration.ts new file mode 100644 index 0000000000..a30506b74b --- /dev/null +++ b/models/templates/src/migration.ts @@ -0,0 +1,42 @@ +// +// Copyright © 2022 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import core, { TxOperations } from '@anticrm/core' +import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' +import templates from './plugin' + +export const templatesOperation: MigrateOperation = { + async migrate (client: MigrationClient): Promise {}, + async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + const current = await tx.findOne(core.class.Space, { + _id: templates.space.Templates + }) + if (current === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Templates', + description: 'Space for all templates', + private: true, + archived: false, + members: [] + }, + templates.space.Templates + ) + } + } +} diff --git a/packages/core/src/component.ts b/packages/core/src/component.ts index 47e55ad554..fa98292580 100644 --- a/packages/core/src/component.ts +++ b/packages/core/src/component.ts @@ -58,7 +58,8 @@ export default plugin(coreId, { space: { Tx: '' as Ref, DerivedTx: '' as Ref, - Model: '' as Ref + Model: '' as Ref, + Space: '' as Ref }, account: { System: '' as Ref diff --git a/plugins/chunter-resources/src/components/CreateChannel.svelte b/plugins/chunter-resources/src/components/CreateChannel.svelte index 148bd3a969..7e5124e739 100644 --- a/plugins/chunter-resources/src/components/CreateChannel.svelte +++ b/plugins/chunter-resources/src/components/CreateChannel.svelte @@ -32,7 +32,7 @@ const client = getClient() function createChannel() { - client.createDoc(chunter.class.Channel, core.space.Model, { + client.createDoc(chunter.class.Channel, core.space.Space, { name, description, private: false, diff --git a/plugins/contact-resources/src/components/CreateOrganizations.svelte b/plugins/contact-resources/src/components/CreateOrganizations.svelte index 68e927cec0..31bf37a0b6 100644 --- a/plugins/contact-resources/src/components/CreateOrganizations.svelte +++ b/plugins/contact-resources/src/components/CreateOrganizations.svelte @@ -32,7 +32,7 @@ const client = getClient() function createChannel () { - client.createDoc(contact.class.Organizations, core.space.Model, { + client.createDoc(contact.class.Organizations, core.space.Space, { name, description, private: false, diff --git a/plugins/contact-resources/src/components/CreatePersons.svelte b/plugins/contact-resources/src/components/CreatePersons.svelte index d28a6988ce..5282de6667 100644 --- a/plugins/contact-resources/src/components/CreatePersons.svelte +++ b/plugins/contact-resources/src/components/CreatePersons.svelte @@ -32,7 +32,7 @@ const client = getClient() function createChannel () { - client.createDoc(contact.class.Persons, core.space.Model, { + client.createDoc(contact.class.Persons, core.space.Space, { name, description, private: false, diff --git a/plugins/lead-resources/src/components/CreateFunnel.svelte b/plugins/lead-resources/src/components/CreateFunnel.svelte index c42f7a2da0..b3f4db8dd6 100644 --- a/plugins/lead-resources/src/components/CreateFunnel.svelte +++ b/plugins/lead-resources/src/components/CreateFunnel.svelte @@ -40,7 +40,7 @@ const id = await client.createDoc( lead.class.Funnel, - core.space.Model, + core.space.Space, { name, description, diff --git a/plugins/recruit-resources/src/components/CreateVacancy.svelte b/plugins/recruit-resources/src/components/CreateVacancy.svelte index 405baa2266..9d742bbd12 100644 --- a/plugins/recruit-resources/src/components/CreateVacancy.svelte +++ b/plugins/recruit-resources/src/components/CreateVacancy.svelte @@ -40,7 +40,7 @@ throw Error(`Failed to find target kanban template: ${templateId}`) } - const id = await client.createDoc(recruit.class.Vacancy, core.space.Model, { + const id = await client.createDoc(recruit.class.Vacancy, core.space.Space, { name, description, private: false, diff --git a/plugins/recruit-resources/src/components/review/CreateReviewCategory.svelte b/plugins/recruit-resources/src/components/review/CreateReviewCategory.svelte index 3db785d210..50e9c35aa8 100644 --- a/plugins/recruit-resources/src/components/review/CreateReviewCategory.svelte +++ b/plugins/recruit-resources/src/components/review/CreateReviewCategory.svelte @@ -40,7 +40,7 @@ throw Error(`Failed to find target kanban template: ${templateId}`) } - const id = await client.createDoc(recruit.class.ReviewCategory, core.space.Model, { + const id = await client.createDoc(recruit.class.ReviewCategory, core.space.Space, { name, description, private: false, diff --git a/plugins/task-resources/src/components/CreateProject.svelte b/plugins/task-resources/src/components/CreateProject.svelte index 6fb131ddb8..2086ab0e18 100644 --- a/plugins/task-resources/src/components/CreateProject.svelte +++ b/plugins/task-resources/src/components/CreateProject.svelte @@ -40,7 +40,7 @@ const id = await client.createDoc( task.class.Project, - core.space.Model, + core.space.Space, { name, description, diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index e19c514a4b..f5ecd66e62 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -199,16 +199,9 @@ async function getEmailTx (ptx: TxCollectionCUD, control: Trigger } const receiver = attached.email - let doc: Doc | undefined - if (hierarchy.isDerived(backlink.backlinkClass, core.class.Space)) { - doc = (await control.modelDb.findAll(backlink.backlinkClass, { - _id: backlink.backlinkId - }, { limit: 1 }))[0] - } else { - doc = (await control.findAll(backlink.backlinkClass, { - _id: backlink.backlinkId - }, { limit: 1 }))[0] - } + const doc = (await control.findAll(backlink.backlinkClass, { + _id: backlink.backlinkId + }, { limit: 1 }))[0] if (doc === undefined) return undefined const TextPresenter = getTextPresenter(doc._class, hierarchy) diff --git a/server/account/src/index.ts b/server/account/src/index.ts index 405715903f..f0a5f183e8 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and -// limitations under the License. +// limitations under the f. // import contact, { combineName } from '@anticrm/contact' diff --git a/server/tool/src/index.ts b/server/tool/src/index.ts index 1638ed916a..50bc5a6bc0 100644 --- a/server/tool/src/index.ts +++ b/server/tool/src/index.ts @@ -126,6 +126,7 @@ export async function upgradeModel ( dbName: string ): Promise { const { mongodbUri, txes } = prepareTools() + if (txes.some((tx) => tx.objectSpace !== core.space.Model)) { throw Error('Model txes must target only core.space.Model') }