Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix links co-authors notifications #7802

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions models/controlled-documents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,11 @@ export function defineNotifications (builder: Builder): void {
'effectiveDate',
'plannedEffectiveDate',
'changeControl',
'coAuthors'
'coAuthors',
'reviewers',
'approvers'
],
['owner', 'comments', 'reviewers', 'approvers']
['owner', 'comments']
)
}

Expand Down
3 changes: 1 addition & 2 deletions models/controlled-documents/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default mergeIds(documentsId, documents, {
notification: {
DocumentsNotificationGroup: '' as Ref<NotificationGroup>,
ContentNotification: '' as Ref<NotificationType>,
StateNotification: '' as Ref<NotificationType>,
CoAuthorsNotification: '' as Ref<NotificationType>
StateNotification: '' as Ref<NotificationType>
}
})
9 changes: 5 additions & 4 deletions models/server-controlled-documents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
10 changes: 10 additions & 0 deletions models/server-controlled-documents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
}
)
}
4 changes: 4 additions & 0 deletions plugins/controlled-documents/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import type {
Sequence,
ControlledDocumentSnapshot
} from './types'
import type { NotificationType } from '@hcengineering/notification'

/**
* @public
Expand Down Expand Up @@ -307,6 +308,9 @@ export const documentsPlugin = plugin(documentsId, {
},
template: {
ProductChangeControl: '' as Ref<DocumentTemplate>
},
notification: {
CoAuthorsNotification: '' as Ref<NotificationType>
}
})

Expand Down
9 changes: 5 additions & 4 deletions server-plugins/controlled-documents-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
34 changes: 32 additions & 2 deletions server-plugins/controlled-documents-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -421,6 +425,31 @@ export async function documentTextPresenter (doc: ControlledDocument): Promise<s
return doc.title
}

function CoAuthorsTypeMatch (
originTx: TxCUD<ControlledDocument>,
_doc: Doc,
accounts: Ref<Account>[],
_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<ControlledDocument>
const employees = Array.isArray(tx.operations.coAuthors)
? tx.operations.coAuthors ?? []
: (combineAttributes([tx.operations], 'coAuthors', '$push', '$each') as Ref<Employee>[])
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<ControlledDocument>
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: {
Expand All @@ -431,6 +460,7 @@ export default async () => ({
OnWorkspaceOwnerAdded
},
function: {
ControlledDocumentTextPresenter: documentTextPresenter
ControlledDocumentTextPresenter: documentTextPresenter,
CoAuthorsTypeMatch
}
})
5 changes: 3 additions & 2 deletions server-plugins/controlled-documents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +25,7 @@ export default plugin(serverDocumentsId, {
OnWorkspaceOwnerAdded: '' as Resource<TriggerFunc>
},
function: {
ControlledDocumentTextPresenter: '' as Resource<Presenter>
ControlledDocumentTextPresenter: '' as Resource<Presenter>,
CoAuthorsTypeMatch: '' as TypeMatchFunc
}
})
1 change: 1 addition & 0 deletions server-plugins/gmail-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions server-plugins/gmail-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//

import contact, { Channel, formatName } from '@hcengineering/contact'
import {
import core, {
Account,
Class,
concatLink,
Expand All @@ -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
Expand Down Expand Up @@ -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 []
}

Expand Down
Loading