From 53505d8c1ee17b981d64c27272fe8c4c7cc53dd0 Mon Sep 17 00:00:00 2001 From: Kristina Fefelova Date: Mon, 27 Jan 2025 18:30:22 +0400 Subject: [PATCH] Fix links co-authors notifications Signed-off-by: Kristina Fefelova --- models/controlled-documents/src/index.ts | 6 ++-- models/controlled-documents/src/plugin.ts | 3 +- .../server-controlled-documents/package.json | 9 ++--- .../server-controlled-documents/src/index.ts | 10 ++++++ plugins/controlled-documents/src/plugin.ts | 4 +++ .../package.json | 9 ++--- .../src/index.ts | 34 +++++++++++++++++-- .../controlled-documents/src/index.ts | 5 +-- server-plugins/gmail-resources/package.json | 1 + server-plugins/gmail-resources/src/index.ts | 9 +++-- 10 files changed, 72 insertions(+), 18 deletions(-) diff --git a/models/controlled-documents/src/index.ts b/models/controlled-documents/src/index.ts index f7659ab4697..2f4ebf8dbc1 100644 --- a/models/controlled-documents/src/index.ts +++ b/models/controlled-documents/src/index.ts @@ -898,9 +898,11 @@ export function defineNotifications (builder: Builder): void { 'effectiveDate', 'plannedEffectiveDate', 'changeControl', - 'coAuthors' + 'coAuthors', + 'reviewers', + 'approvers' ], - ['owner', 'comments', 'reviewers', 'approvers'] + ['owner', 'comments'] ) } diff --git a/models/controlled-documents/src/plugin.ts b/models/controlled-documents/src/plugin.ts index f155e919ec1..892d439f7e0 100644 --- a/models/controlled-documents/src/plugin.ts +++ b/models/controlled-documents/src/plugin.ts @@ -76,7 +76,6 @@ export default mergeIds(documentsId, documents, { notification: { DocumentsNotificationGroup: '' as Ref, ContentNotification: '' as Ref, - StateNotification: '' as Ref, - CoAuthorsNotification: '' as Ref + StateNotification: '' as Ref } }) diff --git a/models/server-controlled-documents/package.json b/models/server-controlled-documents/package.json index 9876b3c1fea..ba1a3216495 100644 --- a/models/server-controlled-documents/package.json +++ b/models/server-controlled-documents/package.json @@ -28,15 +28,16 @@ "typescript": "^5.3.3" }, "dependencies": { + "@hcengineering/contact": "^0.6.24", + "@hcengineering/controlled-documents": "^0.1.0", "@hcengineering/core": "^0.6.32", "@hcengineering/model": "^0.6.11", - "@hcengineering/platform": "^0.6.11", - "@hcengineering/server-core": "^0.6.1", "@hcengineering/model-core": "^0.6.0", + "@hcengineering/notification": "^0.6.23", + "@hcengineering/platform": "^0.6.11", "@hcengineering/request": "^0.6.14", - "@hcengineering/contact": "^0.6.24", - "@hcengineering/controlled-documents": "^0.1.0", "@hcengineering/server-controlled-documents": "^0.1.0", + "@hcengineering/server-core": "^0.6.1", "@hcengineering/server-notification": "^0.6.1" } } diff --git a/models/server-controlled-documents/src/index.ts b/models/server-controlled-documents/src/index.ts index 535e3a0b4f0..23fa2dbc80d 100644 --- a/models/server-controlled-documents/src/index.ts +++ b/models/server-controlled-documents/src/index.ts @@ -9,6 +9,7 @@ import documents, { DocumentState } from '@hcengineering/controlled-documents' import serverDocuments from '@hcengineering/server-controlled-documents' import contact from '@hcengineering/contact' import serverNotification from '@hcengineering/server-notification' +import notification from '@hcengineering/notification' export { serverDocumentsId } from '@hcengineering/server-controlled-documents/src/index' @@ -66,4 +67,13 @@ export function createModel (builder: Builder): void { builder.mixin(documents.class.ControlledDocument, core.class.Class, serverNotification.mixin.TextPresenter, { presenter: serverDocuments.function.ControlledDocumentTextPresenter }) + + builder.mixin( + documents.notification.CoAuthorsNotification, + notification.class.NotificationType, + serverNotification.mixin.TypeMatch, + { + func: serverDocuments.function.CoAuthorsTypeMatch + } + ) } diff --git a/plugins/controlled-documents/src/plugin.ts b/plugins/controlled-documents/src/plugin.ts index 49aaaef79ff..f3a5af320ee 100644 --- a/plugins/controlled-documents/src/plugin.ts +++ b/plugins/controlled-documents/src/plugin.ts @@ -41,6 +41,7 @@ import type { Sequence, ControlledDocumentSnapshot } from './types' +import type { NotificationType } from '@hcengineering/notification' /** * @public @@ -307,6 +308,9 @@ export const documentsPlugin = plugin(documentsId, { }, template: { ProductChangeControl: '' as Ref + }, + notification: { + CoAuthorsNotification: '' as Ref } }) diff --git a/server-plugins/controlled-documents-resources/package.json b/server-plugins/controlled-documents-resources/package.json index e2281172d71..a4acf3426f6 100644 --- a/server-plugins/controlled-documents-resources/package.json +++ b/server-plugins/controlled-documents-resources/package.json @@ -38,15 +38,16 @@ "@types/node": "~20.11.16" }, "dependencies": { + "@hcengineering/chunter": "^0.6.20", "@hcengineering/contact": "^0.6.24", + "@hcengineering/controlled-documents": "^0.1.0", "@hcengineering/core": "^0.6.32", + "@hcengineering/notification": "^0.6.23", "@hcengineering/platform": "^0.6.11", + "@hcengineering/request": "^0.6.14", + "@hcengineering/server-chunter-resources": "^0.6.0", "@hcengineering/server-core": "^0.6.1", "@hcengineering/server-token": "^0.6.11", - "@hcengineering/chunter": "^0.6.20", - "@hcengineering/server-chunter-resources": "^0.6.0", - "@hcengineering/request": "^0.6.14", - "@hcengineering/controlled-documents": "^0.1.0", "@hcengineering/training": "^0.1.0" } } diff --git a/server-plugins/controlled-documents-resources/src/index.ts b/server-plugins/controlled-documents-resources/src/index.ts index e2c90a4f825..2349ca95ac2 100644 --- a/server-plugins/controlled-documents-resources/src/index.ts +++ b/server-plugins/controlled-documents-resources/src/index.ts @@ -25,11 +25,15 @@ import core, { TxUpdateDoc, type Account, type RolesAssignment, - type Timestamp + type Timestamp, + Doc, + combineAttributes, + TxCUD } from '@hcengineering/core' import { RequestStatus } from '@hcengineering/request' import { TriggerControl } from '@hcengineering/server-core' import training, { TrainingState, type TrainingRequest } from '@hcengineering/training' +import { NotificationType } from '@hcengineering/notification' async function getDocs ( control: TriggerControl, @@ -421,6 +425,31 @@ export async function documentTextPresenter (doc: ControlledDocument): Promise, + _doc: Doc, + accounts: Ref[], + _type: NotificationType, + control: TriggerControl +): boolean { + if (accounts.some((it) => originTx.modifiedBy === it)) return false + if (originTx._class === core.class.TxUpdateDoc) { + const tx = originTx as TxUpdateDoc + const employees = Array.isArray(tx.operations.coAuthors) + ? tx.operations.coAuthors ?? [] + : (combineAttributes([tx.operations], 'coAuthors', '$push', '$each') as Ref[]) + const employeeAccounts = employees.flatMap((it) => control.modelDb.getAccountByPersonId(it)).map((it) => it._id) + return accounts.some((it) => employeeAccounts.includes(it)) + } else if (originTx._class === core.class.TxCreateDoc) { + const tx = originTx as TxCreateDoc + const employees = tx.attributes.coAuthors + const coAuthorAccounts = employees.flatMap((it) => control.modelDb.getAccountByPersonId(it)).map((it) => it._id) + return accounts.some((it) => coAuthorAccounts.includes(it)) + } + + return false +} + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => ({ trigger: { @@ -431,6 +460,7 @@ export default async () => ({ OnWorkspaceOwnerAdded }, function: { - ControlledDocumentTextPresenter: documentTextPresenter + ControlledDocumentTextPresenter: documentTextPresenter, + CoAuthorsTypeMatch } }) diff --git a/server-plugins/controlled-documents/src/index.ts b/server-plugins/controlled-documents/src/index.ts index 96d08696e78..09bbb091a3e 100644 --- a/server-plugins/controlled-documents/src/index.ts +++ b/server-plugins/controlled-documents/src/index.ts @@ -6,7 +6,7 @@ import type { Plugin, Resource } from '@hcengineering/platform' import { plugin } from '@hcengineering/platform' import { TriggerFunc } from '@hcengineering/server-core' -import { Presenter } from '@hcengineering/server-notification' +import { Presenter, TypeMatchFunc } from '@hcengineering/server-notification' /** * @public @@ -25,6 +25,7 @@ export default plugin(serverDocumentsId, { OnWorkspaceOwnerAdded: '' as Resource }, function: { - ControlledDocumentTextPresenter: '' as Resource + ControlledDocumentTextPresenter: '' as Resource, + CoAuthorsTypeMatch: '' as TypeMatchFunc } }) diff --git a/server-plugins/gmail-resources/package.json b/server-plugins/gmail-resources/package.json index eefd78bced2..58f01eb5e90 100644 --- a/server-plugins/gmail-resources/package.json +++ b/server-plugins/gmail-resources/package.json @@ -38,6 +38,7 @@ }, "dependencies": { "@hcengineering/activity": "^0.6.0", + "@hcengineering/ai-bot": "^0.6.0", "@hcengineering/contact": "^0.6.24", "@hcengineering/core": "^0.6.32", "@hcengineering/gmail": "^0.6.22", diff --git a/server-plugins/gmail-resources/src/index.ts b/server-plugins/gmail-resources/src/index.ts index 5e76c20003b..6869330ade3 100644 --- a/server-plugins/gmail-resources/src/index.ts +++ b/server-plugins/gmail-resources/src/index.ts @@ -14,7 +14,7 @@ // import contact, { Channel, formatName } from '@hcengineering/contact' -import { +import core, { Account, Class, concatLink, @@ -40,6 +40,7 @@ import serverNotification, { import { getContentByTemplate } from '@hcengineering/server-notification-resources' import { getMetadata } from '@hcengineering/platform' import { ActivityMessage } from '@hcengineering/activity' +import aiBot from '@hcengineering/ai-bot' /** * @public @@ -171,7 +172,11 @@ const SendEmailNotifications: NotificationProviderFunc = async ( return [] } - if (!receiver.person.active) { + if ( + !receiver.person.active || + receiver.account._id === core.account.System || + receiver.account._id === aiBot.account.AIBot + ) { return [] }