Remove notification subscriptions when an employee is deactivated (#7089)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-11-02 22:12:32 +05:00 committed by GitHub
parent bf9ed35c87
commit 8bd4590816
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 51 additions and 2 deletions

View File

@ -76,6 +76,15 @@ export function createModel (builder: Builder): void {
}
})
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverHr.trigger.OnEmployeeDeactivate,
isAsync: true,
txMatch: {
_class: core.class.TxMixin,
mixin: contact.mixin.Employee
}
})
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverHr.trigger.OnPublicHolidayCreate,
txMatch: {

View File

@ -30,6 +30,7 @@
"dependencies": {
"@hcengineering/activity": "^0.6.0",
"@hcengineering/core": "^0.6.32",
"@hcengineering/contact": "^0.6.24",
"@hcengineering/model": "^0.6.11",
"@hcengineering/model-chunter": "^0.6.0",
"@hcengineering/model-core": "^0.6.0",

View File

@ -33,6 +33,7 @@ import serverNotification, {
type TypeMatch,
type TypeMatchFunc
} from '@hcengineering/server-notification'
import contact from '@hcengineering/contact'
export { serverNotificationId } from '@hcengineering/server-notification'
@ -90,4 +91,13 @@ export function createModel (builder: Builder): void {
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverNotification.trigger.OnDocRemove
})
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverNotification.trigger.OnEmployeeDeactivate,
isAsync: true,
txMatch: {
_class: core.class.TxMixin,
mixin: contact.mixin.Employee
}
})
}

View File

@ -29,6 +29,7 @@ export const serverHrId = 'server-hr' as Plugin
export default plugin(serverHrId, {
trigger: {
OnEmployee: '' as Resource<TriggerFunc>,
OnEmployeeDeactivate: '' as Resource<TriggerFunc>,
OnDepartmentStaff: '' as Resource<TriggerFunc>,
OnDepartmentRemove: '' as Resource<TriggerFunc>,
OnRequestCreate: '' as Resource<TriggerFunc>,

View File

@ -17,6 +17,7 @@
import activity, { ActivityMessage, DocUpdateMessage } from '@hcengineering/activity'
import chunter, { ChatMessage } from '@hcengineering/chunter'
import contact, {
Employee,
getAvatarProviderId,
getGravatarUrl,
Person,
@ -1908,6 +1909,31 @@ async function OnActivityMessageRemove (message: ActivityMessage, control: Trigg
return res
}
async function OnEmployeeDeactivate (tx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> {
const actualTx = TxProcessor.extractTx(tx)
if (core.class.TxMixin !== actualTx._class) {
return []
}
const ctx = actualTx as TxMixin<Person, Employee>
if (ctx.mixin !== contact.mixin.Employee || ctx.attributes.active !== false) {
return []
}
const targetAccount = control.modelDb.getAccountByPersonId(ctx.objectId) as PersonAccount[]
if (targetAccount.length === 0) return []
const res: Tx[] = []
for (const acc of targetAccount) {
const subscriptions = await control.findAll(control.ctx, notification.class.PushSubscription, {
user: acc._id
})
for (const sub of subscriptions) {
res.push(control.txFactory.createTxRemoveDoc(sub._class, sub.space, sub._id))
}
}
return res
}
async function OnDocRemove (originTx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> {
const tx = TxProcessor.extractTx(originTx) as TxRemoveDoc<Doc>
@ -1949,7 +1975,8 @@ export default async () => ({
trigger: {
OnAttributeCreate,
OnAttributeUpdate,
OnDocRemove
OnDocRemove,
OnEmployeeDeactivate
},
function: {
IsUserInFieldValueTypeMatch: isUserInFieldValueTypeMatch,

View File

@ -168,7 +168,8 @@ export default plugin(serverNotificationId, {
OnAttributeCreate: '' as Resource<TriggerFunc>,
OnAttributeUpdate: '' as Resource<TriggerFunc>,
OnReactionChanged: '' as Resource<TriggerFunc>,
OnDocRemove: '' as Resource<TriggerFunc>
OnDocRemove: '' as Resource<TriggerFunc>,
OnEmployeeDeactivate: '' as Resource<TriggerFunc>
},
function: {
IsUserInFieldValueTypeMatch: '' as TypeMatchFunc,