mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-08 17:00:47 +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/model": "^0.6.2",
|
||||
"@hcengineering/platform": "^0.6.8",
|
||||
"@hcengineering/setting": "^0.6.5",
|
||||
"@hcengineering/server-notification": "^0.6.0",
|
||||
"@hcengineering/server-setting": "^0.6.0",
|
||||
"@hcengineering/server-core": "^0.6.1"
|
||||
}
|
||||
|
@ -17,13 +17,18 @@
|
||||
import { Builder } from '@hcengineering/model'
|
||||
|
||||
import core from '@hcengineering/core'
|
||||
import serverCore from '@hcengineering/server-core'
|
||||
import serverNotification from '@hcengineering/server-notification'
|
||||
import serverSetting from '@hcengineering/server-setting'
|
||||
import setting from '@hcengineering/setting'
|
||||
|
||||
export { serverSettingId } from '@hcengineering/server-setting'
|
||||
|
||||
export function createModel (builder: Builder): void {
|
||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||
trigger: serverSetting.trigger.OnIntegrationDisable
|
||||
builder.mixin(setting.class.Integration, core.class.Class, serverNotification.mixin.HTMLPresenter, {
|
||||
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
|
||||
)
|
||||
|
||||
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.
|
||||
//
|
||||
|
||||
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 setting from './plugin'
|
||||
import { DOMAIN_SETTING } from '.'
|
||||
import notification, { Collaborators } from '@hcengineering/notification'
|
||||
|
||||
async function migrateIntegrationsSpace (client: MigrationClient): Promise<void> {
|
||||
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 = {
|
||||
async migrate (client: MigrationClient): Promise<void> {
|
||||
await migrateIntegrationsSpace(client)
|
||||
@ -73,5 +105,6 @@ export const settingOperation: MigrateOperation = {
|
||||
async upgrade (client: MigrationUpgradeClient): Promise<void> {
|
||||
const tx = new TxOperations(client, core.account.System)
|
||||
await createSpace(tx)
|
||||
await fillMigrationCollaborator(tx)
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import setting from '@hcengineering/setting-resources/src/plugin'
|
||||
import { AnyComponent } from '@hcengineering/ui'
|
||||
import { Action, ActionCategory, ViewAction } from '@hcengineering/view'
|
||||
import { TemplateFieldFunc } from '@hcengineering/templates'
|
||||
import { NotificationGroup, NotificationType } from '@hcengineering/notification'
|
||||
|
||||
export default mergeIds(settingId, setting, {
|
||||
activity: {
|
||||
@ -29,7 +30,9 @@ export default mergeIds(settingId, setting, {
|
||||
ids: {
|
||||
TxIntegrationDisable: '' as Ref<TxViewlet>,
|
||||
EnumSetting: '' as Ref<Doc>,
|
||||
Configure: '' as Ref<Doc>
|
||||
Configure: '' as Ref<Doc>,
|
||||
SettingNotificationGroup: '' as Ref<NotificationGroup>,
|
||||
IntegrationDisabledNotification: '' as Ref<NotificationType>
|
||||
},
|
||||
component: {
|
||||
EnumSetting: '' as AnyComponent,
|
||||
|
@ -214,12 +214,10 @@ async function createEmailNotificationTxes (
|
||||
): Promise<Tx | undefined> {
|
||||
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]
|
||||
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)
|
||||
|
||||
|
@ -13,72 +13,33 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import core, {
|
||||
Account,
|
||||
Data,
|
||||
Doc,
|
||||
generateId,
|
||||
Ref,
|
||||
Tx,
|
||||
TxCollectionCUD,
|
||||
TxCreateDoc,
|
||||
TxUpdateDoc
|
||||
} from '@hcengineering/core'
|
||||
import { Doc } from '@hcengineering/core'
|
||||
import { translate } from '@hcengineering/platform'
|
||||
import type { TriggerControl } from '@hcengineering/server-core'
|
||||
import setting, { Integration } from '@hcengineering/setting'
|
||||
import contact, { EmployeeAccount } from '@hcengineering/contact'
|
||||
import notification, { Notification, NotificationStatus } from '@hcengineering/notification'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function OnIntegrationDisable (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
||||
if (!control.hierarchy.isDerived(tx._class, core.class.TxUpdateDoc)) return []
|
||||
const ctx = tx as TxUpdateDoc<Integration>
|
||||
if (!control.hierarchy.isDerived(ctx.objectClass, setting.class.Integration)) return []
|
||||
if (ctx.operations.disabled === true) {
|
||||
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 []
|
||||
export async function integrationHTMLPresenter (doc: Doc, control: TriggerControl): Promise<string> {
|
||||
const integration = doc as Integration
|
||||
const type = (await control.modelDb.findAll(setting.class.IntegrationType, { _id: integration.type }))[0]
|
||||
if (type === undefined) return ''
|
||||
return await translate(type.label, {})
|
||||
}
|
||||
|
||||
const createTx: TxCreateDoc<Notification> = {
|
||||
objectClass: notification.class.Notification,
|
||||
objectSpace: notification.space.Notifications,
|
||||
objectId: generateId(),
|
||||
modifiedOn: ctx.modifiedOn,
|
||||
modifiedBy: ctx.modifiedBy,
|
||||
space: ctx.space,
|
||||
_id: generateId(),
|
||||
_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 []
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function integrationTextPresenter (doc: Doc, control: TriggerControl): Promise<string> {
|
||||
const integration = doc as Integration
|
||||
const type = (await control.modelDb.findAll(setting.class.IntegrationType, { _id: integration.type }))[0]
|
||||
if (type === undefined) return ''
|
||||
return await translate(type.label, {})
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export default async () => ({
|
||||
trigger: {
|
||||
OnIntegrationDisable
|
||||
}
|
||||
IntegrationHTMLPresenter: integrationHTMLPresenter,
|
||||
IntegrationTextPresenter: integrationTextPresenter
|
||||
})
|
||||
|
@ -29,6 +29,7 @@
|
||||
"dependencies": {
|
||||
"@hcengineering/core": "^0.6.23",
|
||||
"@hcengineering/platform": "^0.6.8",
|
||||
"@hcengineering/server-notification": "^0.6.0",
|
||||
"@hcengineering/server-core": "^0.6.1"
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import type { Plugin, Resource } from '@hcengineering/platform'
|
||||
import { plugin } from '@hcengineering/platform'
|
||||
import type { TriggerFunc } from '@hcengineering/server-core'
|
||||
import { Presenter } from '@hcengineering/server-notification'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@ -26,7 +26,8 @@ export const serverSettingId = 'server-setting' as Plugin
|
||||
* @public
|
||||
*/
|
||||
export default plugin(serverSettingId, {
|
||||
trigger: {
|
||||
OnIntegrationDisable: '' as Resource<TriggerFunc>
|
||||
function: {
|
||||
IntegrationHTMLPresenter: '' as Resource<Presenter>,
|
||||
IntegrationTextPresenter: '' as Resource<Presenter>
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user