From df9115b75a99340c06c6baab2f3a9ed3e04b8374 Mon Sep 17 00:00:00 2001 From: Anna No Date: Mon, 30 May 2022 22:59:14 +0700 Subject: [PATCH] Board: Update server-plugin for task to subscribe to updates on create & update (#1925) Signed-off-by: Anna No --- changelog.md | 1 + .../attachment-resources/src/index.ts | 9 +-------- server-plugins/gmail-resources/src/index.ts | 20 +------------------ .../inventory-resources/src/index.ts | 20 ++----------------- .../notification-resources/src/index.ts | 17 +--------------- server-plugins/tags-resources/src/index.ts | 20 +------------------ server-plugins/task-resources/src/index.ts | 12 ++++++----- .../telegram-resources/src/index.ts | 20 +------------------ server/core/src/index.ts | 1 + server/core/src/storage.ts | 14 +++---------- server/core/src/utils.ts | 20 +++++++++++++++++++ 11 files changed, 39 insertions(+), 115 deletions(-) create mode 100644 server/core/src/utils.ts diff --git a/changelog.md b/changelog.md index 49b0c57442..5c7aa574cd 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ Platform: +- Fix subscribe to updates on Task create / update - Fix popup window layouts - Fix table two loading spinners - Improve full text search performance diff --git a/server-plugins/attachment-resources/src/index.ts b/server-plugins/attachment-resources/src/index.ts index 3af99a090b..e10a2e9c86 100644 --- a/server-plugins/attachment-resources/src/index.ts +++ b/server-plugins/attachment-resources/src/index.ts @@ -16,18 +16,11 @@ import type { Doc, Ref, Tx, TxCollectionCUD, TxCreateDoc, TxRemoveDoc } from '@anticrm/core' import type { TriggerControl } from '@anticrm/server-core' +import { extractTx } from '@anticrm/server-core' import type { Attachment } from '@anticrm/attachment' import attachment from '@anticrm/attachment' import core, { TxProcessor } from '@anticrm/core' -const extractTx = (tx: Tx): Tx => { - if (tx._class === core.class.TxCollectionCUD) { - return (tx as TxCollectionCUD).tx - } - - return tx -} - const findCreateTx = async ( id: Ref, findAll: TriggerControl['findAll'] diff --git a/server-plugins/gmail-resources/src/index.ts b/server-plugins/gmail-resources/src/index.ts index 77fcb2e6fe..4ed2e826b4 100644 --- a/server-plugins/gmail-resources/src/index.ts +++ b/server-plugins/gmail-resources/src/index.ts @@ -15,7 +15,6 @@ import contact, { Channel } from '@anticrm/contact' import core, { - AttachedDoc, Class, Doc, DocumentQuery, @@ -24,28 +23,11 @@ import core, { Hierarchy, Ref, Tx, - TxCollectionCUD, TxCreateDoc, TxProcessor } from '@anticrm/core' import gmail, { Message } from '@anticrm/gmail' -import { TriggerControl } from '@anticrm/server-core' - -const extractTx = (tx: Tx): Tx => { - if (tx._class === core.class.TxCollectionCUD) { - const ctx = tx as TxCollectionCUD - if (ctx.tx._class === core.class.TxCreateDoc) { - const create = ctx.tx as TxCreateDoc - create.attributes.attachedTo = ctx.objectId - create.attributes.attachedToClass = ctx.objectClass - create.attributes.collection = ctx.collection - return create - } - return ctx.tx - } - - return tx -} +import { extractTx, TriggerControl } from '@anticrm/server-core' /** * @public diff --git a/server-plugins/inventory-resources/src/index.ts b/server-plugins/inventory-resources/src/index.ts index 0f3993372f..8a824d6c07 100644 --- a/server-plugins/inventory-resources/src/index.ts +++ b/server-plugins/inventory-resources/src/index.ts @@ -13,31 +13,15 @@ // limitations under the License. // -import core, { AttachedDoc, Doc, Tx, TxCollectionCUD, TxCreateDoc, TxProcessor, TxUpdateDoc } from '@anticrm/core' +import core, { Doc, Tx, TxCreateDoc, TxProcessor, TxUpdateDoc } from '@anticrm/core' import inventory, { Product } from '@anticrm/inventory' import login from '@anticrm/login' import { getMetadata } from '@anticrm/platform' -import { TriggerControl } from '@anticrm/server-core' +import { extractTx, TriggerControl } from '@anticrm/server-core' import { getUpdateLastViewTx } from '@anticrm/server-notification' import view from '@anticrm/view' import workbench from '@anticrm/workbench' -const extractTx = (tx: Tx): Tx => { - if (tx._class === core.class.TxCollectionCUD) { - const ctx = tx as TxCollectionCUD - if (ctx.tx._class === core.class.TxCreateDoc) { - const create = ctx.tx as TxCreateDoc - create.attributes.attachedTo = ctx.objectId - create.attributes.attachedToClass = ctx.objectClass - create.attributes.collection = ctx.collection - return create - } - return ctx.tx - } - - return tx -} - /** * @public */ diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index dc134c4f34..807d2ea87b 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -35,25 +35,10 @@ import core, { import notification, { EmailNotification, Notification, NotificationStatus } from '@anticrm/notification' import { getResource } from '@anticrm/platform' import type { TriggerControl } from '@anticrm/server-core' +import { extractTx } from '@anticrm/server-core' import { getUpdateLastViewTx } from '@anticrm/server-notification' import view, { HTMLPresenter, TextPresenter } from '@anticrm/view' -const extractTx = (tx: Tx): Tx => { - if (tx._class === core.class.TxCollectionCUD) { - const ctx = tx as TxCollectionCUD - if (ctx.tx._class === core.class.TxCreateDoc) { - const create = ctx.tx as TxCreateDoc - create.attributes.attachedTo = ctx.objectId - create.attributes.attachedToClass = ctx.objectClass - create.attributes.collection = ctx.collection - return create - } - return ctx.tx - } - - return tx -} - /** * @public */ diff --git a/server-plugins/tags-resources/src/index.ts b/server-plugins/tags-resources/src/index.ts index bec338f513..e710b22beb 100644 --- a/server-plugins/tags-resources/src/index.ts +++ b/server-plugins/tags-resources/src/index.ts @@ -14,7 +14,6 @@ // import core, { - AttachedDoc, Class, Doc, DocumentQuery, @@ -23,31 +22,14 @@ import core, { Hierarchy, Ref, Tx, - TxCollectionCUD, TxCreateDoc, TxCUD, TxProcessor, TxRemoveDoc } from '@anticrm/core' -import { TriggerControl } from '@anticrm/server-core' +import { extractTx, TriggerControl } from '@anticrm/server-core' import tags, { TagElement, TagReference } from '@anticrm/tags' -const extractTx = (tx: Tx): Tx => { - if (tx._class === core.class.TxCollectionCUD) { - const ctx = tx as TxCollectionCUD - if (ctx.tx._class === core.class.TxCreateDoc) { - const create = ctx.tx as TxCreateDoc - create.attributes.attachedTo = ctx.objectId - create.attributes.attachedToClass = ctx.objectClass - create.attributes.collection = ctx.collection - return create - } - return ctx.tx - } - - return tx -} - /** * @public */ diff --git a/server-plugins/task-resources/src/index.ts b/server-plugins/task-resources/src/index.ts index eebb3ad0b9..8c0ff24d6c 100644 --- a/server-plugins/task-resources/src/index.ts +++ b/server-plugins/task-resources/src/index.ts @@ -16,7 +16,7 @@ import core, { Doc, Tx, TxCreateDoc, TxProcessor, TxUpdateDoc } from '@anticrm/core' import login from '@anticrm/login' import { getMetadata } from '@anticrm/platform' -import { TriggerControl } from '@anticrm/server-core' +import { extractTx, TriggerControl } from '@anticrm/server-core' import { getUpdateLastViewTx } from '@anticrm/server-notification' import task, { Issue, Task } from '@anticrm/task' import view from '@anticrm/view' @@ -43,11 +43,12 @@ export function issueTextPresenter (doc: Doc): string { * @public */ export async function OnTaskCreate (tx: Tx, control: TriggerControl): Promise { - if (tx._class !== core.class.TxCreateDoc) { + const actualTx = extractTx(tx) + if (actualTx._class !== core.class.TxCreateDoc) { return [] } - const createTx = tx as TxCreateDoc + const createTx = actualTx as TxCreateDoc if (!control.hierarchy.isDerived(createTx.objectClass, task.class.Task)) { return [] @@ -89,11 +90,12 @@ export async function OnTaskCreate (tx: Tx, control: TriggerControl): Promise { - if (tx._class !== core.class.TxUpdateDoc) { + const actualTx = extractTx(tx) + if (actualTx._class !== core.class.TxUpdateDoc) { return [] } - const updateTx = tx as TxUpdateDoc + const updateTx = actualTx as TxUpdateDoc if (!control.hierarchy.isDerived(updateTx.objectClass, task.class.Task)) { return [] diff --git a/server-plugins/telegram-resources/src/index.ts b/server-plugins/telegram-resources/src/index.ts index fc94d3d439..df60637a71 100644 --- a/server-plugins/telegram-resources/src/index.ts +++ b/server-plugins/telegram-resources/src/index.ts @@ -15,7 +15,6 @@ import contact, { Channel } from '@anticrm/contact' import core, { - AttachedDoc, Class, Doc, DocumentQuery, @@ -24,29 +23,12 @@ import core, { Hierarchy, Ref, Tx, - TxCollectionCUD, TxCreateDoc, TxProcessor } from '@anticrm/core' -import { TriggerControl } from '@anticrm/server-core' +import { extractTx, TriggerControl } from '@anticrm/server-core' import telegram, { TelegramMessage } from '@anticrm/telegram' -const extractTx = (tx: Tx): Tx => { - if (tx._class === core.class.TxCollectionCUD) { - const ctx = tx as TxCollectionCUD - if (ctx.tx._class === core.class.TxCreateDoc) { - const create = ctx.tx as TxCreateDoc - create.attributes.attachedTo = ctx.objectId - create.attributes.attachedToClass = ctx.objectClass - create.attributes.collection = ctx.collection - return create - } - return ctx.tx - } - - return tx -} - /** * @public */ diff --git a/server/core/src/index.ts b/server/core/src/index.ts index 27d7bcd011..fb9e0ef103 100644 --- a/server/core/src/index.ts +++ b/server/core/src/index.ts @@ -19,4 +19,5 @@ export * from './types' export * from './fulltext' export * from './storage' export * from './pipeline' +export * from './utils' export { default } from './plugin' diff --git a/server/core/src/storage.ts b/server/core/src/storage.ts index e5610a2b1c..64d3915332 100644 --- a/server/core/src/storage.ts +++ b/server/core/src/storage.ts @@ -52,6 +52,7 @@ import { FullTextIndex } from './fulltext' import serverCore from './plugin' import { Triggers } from './triggers' import type { FullTextAdapter, FullTextAdapterFactory, ObjectDDParticipant } from './types' +import { extractTx } from './utils' /** * @public @@ -230,17 +231,8 @@ class TServerStorage implements ServerStorage { return doc } - extractTx (tx: Tx): Tx { - if (tx._class === core.class.TxCollectionCUD) { - const ctx = tx as TxCollectionCUD - return ctx.tx - } - - return tx - } - async processRemove (ctx: MeasureContext, tx: Tx): Promise { - const actualTx = this.extractTx(tx) + const actualTx = extractTx(tx) if (!this.hierarchy.isDerived(actualTx._class, core.class.TxRemoveDoc)) return [] const rtx = actualTx as TxRemoveDoc const result: Tx[] = [] @@ -316,7 +308,7 @@ class TServerStorage implements ServerStorage { } async processMove (ctx: MeasureContext, tx: Tx): Promise { - const actualTx = this.extractTx(tx) + const actualTx = extractTx(tx) if (!this.hierarchy.isDerived(actualTx._class, core.class.TxUpdateDoc)) return [] const rtx = actualTx as TxUpdateDoc if (rtx.operations.space === undefined || rtx.operations.space === rtx.objectSpace) return [] diff --git a/server/core/src/utils.ts b/server/core/src/utils.ts new file mode 100644 index 0000000000..941252ba81 --- /dev/null +++ b/server/core/src/utils.ts @@ -0,0 +1,20 @@ +import core, { AttachedDoc, Doc, Tx, TxCollectionCUD, TxCreateDoc } from '@anticrm/core' + +/** + * @public + */ +export function extractTx (tx: Tx): Tx { + if (tx._class === core.class.TxCollectionCUD) { + const ctx = tx as TxCollectionCUD + if (ctx.tx._class === core.class.TxCreateDoc) { + const create = ctx.tx as TxCreateDoc + create.attributes.attachedTo = ctx.objectId + create.attributes.attachedToClass = ctx.objectClass + create.attributes.collection = ctx.collection + return create + } + return ctx.tx + } + + return tx +}