mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-11 12:57:59 +00:00
TSK-1349 Send notification integration disconnect (#3096)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
e319a22a72
commit
97396cc5f2
@ -28,6 +28,8 @@
|
|||||||
"@hcengineering/core": "^0.6.23",
|
"@hcengineering/core": "^0.6.23",
|
||||||
"@hcengineering/model": "^0.6.2",
|
"@hcengineering/model": "^0.6.2",
|
||||||
"@hcengineering/platform": "^0.6.8",
|
"@hcengineering/platform": "^0.6.8",
|
||||||
|
"@hcengineering/setting": "^0.6.5",
|
||||||
|
"@hcengineering/server-notification": "^0.6.0",
|
||||||
"@hcengineering/server-setting": "^0.6.0",
|
"@hcengineering/server-setting": "^0.6.0",
|
||||||
"@hcengineering/server-core": "^0.6.1"
|
"@hcengineering/server-core": "^0.6.1"
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,18 @@
|
|||||||
import { Builder } from '@hcengineering/model'
|
import { Builder } from '@hcengineering/model'
|
||||||
|
|
||||||
import core from '@hcengineering/core'
|
import core from '@hcengineering/core'
|
||||||
import serverCore from '@hcengineering/server-core'
|
import serverNotification from '@hcengineering/server-notification'
|
||||||
import serverSetting from '@hcengineering/server-setting'
|
import serverSetting from '@hcengineering/server-setting'
|
||||||
|
import setting from '@hcengineering/setting'
|
||||||
|
|
||||||
export { serverSettingId } from '@hcengineering/server-setting'
|
export { serverSettingId } from '@hcengineering/server-setting'
|
||||||
|
|
||||||
export function createModel (builder: Builder): void {
|
export function createModel (builder: Builder): void {
|
||||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
builder.mixin(setting.class.Integration, core.class.Class, serverNotification.mixin.HTMLPresenter, {
|
||||||
trigger: serverSetting.trigger.OnIntegrationDisable
|
presenter: serverSetting.function.IntegrationHTMLPresenter
|
||||||
|
})
|
||||||
|
|
||||||
|
builder.mixin(setting.class.Integration, core.class.Class, serverNotification.mixin.TextPresenter, {
|
||||||
|
presenter: serverSetting.function.IntegrationTextPresenter
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -482,4 +482,38 @@ export function createModel (builder: Builder): void {
|
|||||||
},
|
},
|
||||||
setting.templateField.OwnerPosition
|
setting.templateField.OwnerPosition
|
||||||
)
|
)
|
||||||
|
|
||||||
|
builder.createDoc(
|
||||||
|
notification.class.NotificationGroup,
|
||||||
|
core.space.Model,
|
||||||
|
{
|
||||||
|
label: setting.string.Setting,
|
||||||
|
icon: setting.icon.Setting
|
||||||
|
},
|
||||||
|
setting.ids.SettingNotificationGroup
|
||||||
|
)
|
||||||
|
|
||||||
|
builder.createDoc(
|
||||||
|
notification.class.NotificationType,
|
||||||
|
core.space.Model,
|
||||||
|
{
|
||||||
|
hidden: false,
|
||||||
|
generated: false,
|
||||||
|
label: setting.string.IntegrationDisabled,
|
||||||
|
group: setting.ids.SettingNotificationGroup,
|
||||||
|
field: 'disabled',
|
||||||
|
txClasses: [core.class.TxUpdateDoc],
|
||||||
|
objectClass: setting.class.Integration,
|
||||||
|
templates: {
|
||||||
|
textTemplate: 'Integration with {doc} was disabled',
|
||||||
|
htmlTemplate: '<p>Integration with {doc} was disabled</p>',
|
||||||
|
subjectTemplate: 'Integration with {doc} was disabled'
|
||||||
|
},
|
||||||
|
providers: {
|
||||||
|
[notification.providers.PlatformNotification]: true,
|
||||||
|
[notification.providers.EmailNotification]: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setting.ids.IntegrationDisabledNotification
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,11 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
import core, { DOMAIN_TX, TxOperations } from '@hcengineering/core'
|
import core, { DOMAIN_TX, Doc, TxOperations } from '@hcengineering/core'
|
||||||
import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@hcengineering/model'
|
import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@hcengineering/model'
|
||||||
import setting from './plugin'
|
import setting from './plugin'
|
||||||
import { DOMAIN_SETTING } from '.'
|
import { DOMAIN_SETTING } from '.'
|
||||||
|
import notification, { Collaborators } from '@hcengineering/notification'
|
||||||
|
|
||||||
async function migrateIntegrationsSpace (client: MigrationClient): Promise<void> {
|
async function migrateIntegrationsSpace (client: MigrationClient): Promise<void> {
|
||||||
const settings = await client.find(DOMAIN_SETTING, {
|
const settings = await client.find(DOMAIN_SETTING, {
|
||||||
@ -66,6 +67,37 @@ async function createSpace (tx: TxOperations): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fillMigrationCollaborator (tx: TxOperations): Promise<void> {
|
||||||
|
const h = tx.getHierarchy()
|
||||||
|
const settings = await tx.findAll(setting.class.Integration, {})
|
||||||
|
for (const value of settings) {
|
||||||
|
if (h.hasMixin(value, notification.mixin.Collaborators)) {
|
||||||
|
const collabs = h.as<Doc, Collaborators>(value, notification.mixin.Collaborators)
|
||||||
|
if (collabs.collaborators === undefined || !collabs.collaborators.includes(collabs.modifiedBy)) {
|
||||||
|
await tx.updateMixin<Doc, Collaborators>(
|
||||||
|
value._id,
|
||||||
|
value._class,
|
||||||
|
value.space,
|
||||||
|
notification.mixin.Collaborators,
|
||||||
|
{
|
||||||
|
collaborators: [collabs.createdBy ?? collabs.modifiedBy]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await tx.createMixin<Doc, Collaborators>(
|
||||||
|
value._id,
|
||||||
|
setting.class.Integration,
|
||||||
|
value.space,
|
||||||
|
notification.mixin.Collaborators,
|
||||||
|
{
|
||||||
|
collaborators: [value.createdBy ?? value.modifiedBy]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const settingOperation: MigrateOperation = {
|
export const settingOperation: MigrateOperation = {
|
||||||
async migrate (client: MigrationClient): Promise<void> {
|
async migrate (client: MigrationClient): Promise<void> {
|
||||||
await migrateIntegrationsSpace(client)
|
await migrateIntegrationsSpace(client)
|
||||||
@ -73,5 +105,6 @@ export const settingOperation: MigrateOperation = {
|
|||||||
async upgrade (client: MigrationUpgradeClient): Promise<void> {
|
async upgrade (client: MigrationUpgradeClient): Promise<void> {
|
||||||
const tx = new TxOperations(client, core.account.System)
|
const tx = new TxOperations(client, core.account.System)
|
||||||
await createSpace(tx)
|
await createSpace(tx)
|
||||||
|
await fillMigrationCollaborator(tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import setting from '@hcengineering/setting-resources/src/plugin'
|
|||||||
import { AnyComponent } from '@hcengineering/ui'
|
import { AnyComponent } from '@hcengineering/ui'
|
||||||
import { Action, ActionCategory, ViewAction } from '@hcengineering/view'
|
import { Action, ActionCategory, ViewAction } from '@hcengineering/view'
|
||||||
import { TemplateFieldFunc } from '@hcengineering/templates'
|
import { TemplateFieldFunc } from '@hcengineering/templates'
|
||||||
|
import { NotificationGroup, NotificationType } from '@hcengineering/notification'
|
||||||
|
|
||||||
export default mergeIds(settingId, setting, {
|
export default mergeIds(settingId, setting, {
|
||||||
activity: {
|
activity: {
|
||||||
@ -29,7 +30,9 @@ export default mergeIds(settingId, setting, {
|
|||||||
ids: {
|
ids: {
|
||||||
TxIntegrationDisable: '' as Ref<TxViewlet>,
|
TxIntegrationDisable: '' as Ref<TxViewlet>,
|
||||||
EnumSetting: '' as Ref<Doc>,
|
EnumSetting: '' as Ref<Doc>,
|
||||||
Configure: '' as Ref<Doc>
|
Configure: '' as Ref<Doc>,
|
||||||
|
SettingNotificationGroup: '' as Ref<NotificationGroup>,
|
||||||
|
IntegrationDisabledNotification: '' as Ref<NotificationType>
|
||||||
},
|
},
|
||||||
component: {
|
component: {
|
||||||
EnumSetting: '' as AnyComponent,
|
EnumSetting: '' as AnyComponent,
|
||||||
|
@ -214,12 +214,10 @@ async function createEmailNotificationTxes (
|
|||||||
): Promise<Tx | undefined> {
|
): Promise<Tx | undefined> {
|
||||||
const sender = (await control.modelDb.findAll(contact.class.EmployeeAccount, { _id: senderId }))[0]
|
const sender = (await control.modelDb.findAll(contact.class.EmployeeAccount, { _id: senderId }))[0]
|
||||||
|
|
||||||
if (sender === undefined) return
|
|
||||||
|
|
||||||
const receiver = (await control.modelDb.findAll(contact.class.EmployeeAccount, { _id: receiverId }))[0]
|
const receiver = (await control.modelDb.findAll(contact.class.EmployeeAccount, { _id: receiverId }))[0]
|
||||||
if (receiver === undefined) return
|
if (receiver === undefined) return
|
||||||
|
|
||||||
const senderName = formatName(sender.name)
|
const senderName = sender !== undefined ? formatName(sender.name) : ''
|
||||||
|
|
||||||
const content = await getContent(doc, senderName, type, control, data)
|
const content = await getContent(doc, senderName, type, control, data)
|
||||||
|
|
||||||
|
@ -13,72 +13,33 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
import core, {
|
import { Doc } from '@hcengineering/core'
|
||||||
Account,
|
import { translate } from '@hcengineering/platform'
|
||||||
Data,
|
|
||||||
Doc,
|
|
||||||
generateId,
|
|
||||||
Ref,
|
|
||||||
Tx,
|
|
||||||
TxCollectionCUD,
|
|
||||||
TxCreateDoc,
|
|
||||||
TxUpdateDoc
|
|
||||||
} from '@hcengineering/core'
|
|
||||||
import type { TriggerControl } from '@hcengineering/server-core'
|
import type { TriggerControl } from '@hcengineering/server-core'
|
||||||
import setting, { Integration } from '@hcengineering/setting'
|
import setting, { Integration } from '@hcengineering/setting'
|
||||||
import contact, { EmployeeAccount } from '@hcengineering/contact'
|
|
||||||
import notification, { Notification, NotificationStatus } from '@hcengineering/notification'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export async function OnIntegrationDisable (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
export async function integrationHTMLPresenter (doc: Doc, control: TriggerControl): Promise<string> {
|
||||||
if (!control.hierarchy.isDerived(tx._class, core.class.TxUpdateDoc)) return []
|
const integration = doc as Integration
|
||||||
const ctx = tx as TxUpdateDoc<Integration>
|
const type = (await control.modelDb.findAll(setting.class.IntegrationType, { _id: integration.type }))[0]
|
||||||
if (!control.hierarchy.isDerived(ctx.objectClass, setting.class.Integration)) return []
|
if (type === undefined) return ''
|
||||||
if (ctx.operations.disabled === true) {
|
return await translate(type.label, {})
|
||||||
const account = (
|
}
|
||||||
await control.modelDb.findAll(core.class.Account, { _id: ctx.objectSpace as string as Ref<Account> })
|
|
||||||
)[0]
|
|
||||||
if (account === undefined) return []
|
|
||||||
const employeeRef = (account as EmployeeAccount).employee
|
|
||||||
if (employeeRef === undefined) return []
|
|
||||||
|
|
||||||
const createTx: TxCreateDoc<Notification> = {
|
/**
|
||||||
objectClass: notification.class.Notification,
|
* @public
|
||||||
objectSpace: notification.space.Notifications,
|
*/
|
||||||
objectId: generateId(),
|
export async function integrationTextPresenter (doc: Doc, control: TriggerControl): Promise<string> {
|
||||||
modifiedOn: ctx.modifiedOn,
|
const integration = doc as Integration
|
||||||
modifiedBy: ctx.modifiedBy,
|
const type = (await control.modelDb.findAll(setting.class.IntegrationType, { _id: integration.type }))[0]
|
||||||
space: ctx.space,
|
if (type === undefined) return ''
|
||||||
_id: generateId(),
|
return await translate(type.label, {})
|
||||||
_class: core.class.TxCreateDoc,
|
|
||||||
attributes: {
|
|
||||||
tx: ctx._id,
|
|
||||||
status: NotificationStatus.New
|
|
||||||
} as unknown as Data<Notification>
|
|
||||||
}
|
|
||||||
|
|
||||||
const createNotificationTx: TxCollectionCUD<Doc, Notification> = {
|
|
||||||
objectId: employeeRef,
|
|
||||||
objectClass: contact.class.Employee,
|
|
||||||
objectSpace: contact.space.Employee,
|
|
||||||
modifiedOn: ctx.modifiedOn,
|
|
||||||
space: core.space.Tx,
|
|
||||||
_class: core.class.TxCollectionCUD,
|
|
||||||
modifiedBy: ctx.modifiedBy,
|
|
||||||
_id: generateId(),
|
|
||||||
collection: 'notifications',
|
|
||||||
tx: createTx
|
|
||||||
}
|
|
||||||
return [createNotificationTx]
|
|
||||||
}
|
|
||||||
return []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||||
export default async () => ({
|
export default async () => ({
|
||||||
trigger: {
|
IntegrationHTMLPresenter: integrationHTMLPresenter,
|
||||||
OnIntegrationDisable
|
IntegrationTextPresenter: integrationTextPresenter
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hcengineering/core": "^0.6.23",
|
"@hcengineering/core": "^0.6.23",
|
||||||
"@hcengineering/platform": "^0.6.8",
|
"@hcengineering/platform": "^0.6.8",
|
||||||
|
"@hcengineering/server-notification": "^0.6.0",
|
||||||
"@hcengineering/server-core": "^0.6.1"
|
"@hcengineering/server-core": "^0.6.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import type { Plugin, Resource } from '@hcengineering/platform'
|
import type { Plugin, Resource } from '@hcengineering/platform'
|
||||||
import { plugin } from '@hcengineering/platform'
|
import { plugin } from '@hcengineering/platform'
|
||||||
import type { TriggerFunc } from '@hcengineering/server-core'
|
import { Presenter } from '@hcengineering/server-notification'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -26,7 +26,8 @@ export const serverSettingId = 'server-setting' as Plugin
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export default plugin(serverSettingId, {
|
export default plugin(serverSettingId, {
|
||||||
trigger: {
|
function: {
|
||||||
OnIntegrationDisable: '' as Resource<TriggerFunc>
|
IntegrationHTMLPresenter: '' as Resource<Presenter>,
|
||||||
|
IntegrationTextPresenter: '' as Resource<Presenter>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user