mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 23:32:14 +00:00
TSK-1263 fix (#3087)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
6d99032f2d
commit
b2f098c71c
@ -334,6 +334,7 @@ export function generateClassNotificationTypes (
|
|||||||
: [core.class.TxCreateDoc, core.class.TxRemoveDoc]
|
: [core.class.TxCreateDoc, core.class.TxRemoveDoc]
|
||||||
const data: Data<NotificationType> = {
|
const data: Data<NotificationType> = {
|
||||||
attribute: attribute._id,
|
attribute: attribute._id,
|
||||||
|
field: attribute.name,
|
||||||
group,
|
group,
|
||||||
generated: true,
|
generated: true,
|
||||||
objectClass,
|
objectClass,
|
||||||
|
@ -208,6 +208,7 @@ async function createCustomFieldTypes (client: MigrationUpgradeClient): Promise<
|
|||||||
: [core.class.TxCreateDoc, core.class.TxRemoveDoc]
|
: [core.class.TxCreateDoc, core.class.TxRemoveDoc]
|
||||||
const data: Data<NotificationType> = {
|
const data: Data<NotificationType> = {
|
||||||
attribute: attribute._id,
|
attribute: attribute._id,
|
||||||
|
field: attribute.name,
|
||||||
group: group._id,
|
group: group._id,
|
||||||
generated: true,
|
generated: true,
|
||||||
objectClass,
|
objectClass,
|
||||||
|
@ -37,7 +37,7 @@ export function createModel (builder: Builder): void {
|
|||||||
notification.class.NotificationType,
|
notification.class.NotificationType,
|
||||||
serverNotification.mixin.TypeMatch,
|
serverNotification.mixin.TypeMatch,
|
||||||
{
|
{
|
||||||
func: serverNotification.function.IsUserInFieldValue
|
func: serverNotification.function.IsUserEmployeeInFieldValue
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ export function createModel (builder: Builder): void {
|
|||||||
notification.class.NotificationType,
|
notification.class.NotificationType,
|
||||||
serverNotification.mixin.TypeMatch,
|
serverNotification.mixin.TypeMatch,
|
||||||
{
|
{
|
||||||
func: serverNotification.function.IsUserInFieldValue
|
func: serverNotification.function.IsUserEmployeeInFieldValue
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ export function createModel (builder: Builder): void {
|
|||||||
notification.class.NotificationType,
|
notification.class.NotificationType,
|
||||||
serverNotification.mixin.TypeMatch,
|
serverNotification.mixin.TypeMatch,
|
||||||
{
|
{
|
||||||
func: serverNotification.function.IsUserInFieldValue
|
func: serverNotification.function.IsUserEmployeeInFieldValue
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -407,11 +407,12 @@ function isTypeMatched (
|
|||||||
tx: TxCUD<Doc>,
|
tx: TxCUD<Doc>,
|
||||||
extractedTx: TxCUD<Doc>
|
extractedTx: TxCUD<Doc>
|
||||||
): boolean {
|
): boolean {
|
||||||
const targetClass = control.hierarchy.getBaseClass(type.objectClass)
|
const h = control.hierarchy
|
||||||
|
const targetClass = h.getBaseClass(type.objectClass)
|
||||||
if (!type.txClasses.includes(extractedTx._class)) return false
|
if (!type.txClasses.includes(extractedTx._class)) return false
|
||||||
if (!control.hierarchy.isDerived(extractedTx.objectClass, targetClass)) return false
|
if (!control.hierarchy.isDerived(h.getBaseClass(extractedTx.objectClass), targetClass)) return false
|
||||||
if (tx._class === core.class.TxCollectionCUD && type.attachedToClass !== undefined) {
|
if (tx._class === core.class.TxCollectionCUD && type.attachedToClass !== undefined) {
|
||||||
if (!control.hierarchy.isDerived(tx.objectClass, type.attachedToClass)) return false
|
if (!control.hierarchy.isDerived(h.getBaseClass(tx.objectClass), h.getBaseClass(type.attachedToClass))) return false
|
||||||
}
|
}
|
||||||
if (type.field !== undefined) {
|
if (type.field !== undefined) {
|
||||||
if (extractedTx._class === core.class.TxUpdateDoc) {
|
if (extractedTx._class === core.class.TxUpdateDoc) {
|
||||||
@ -779,6 +780,30 @@ export async function isUserInFieldValue (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export async function isUserEmployeeInFieldValue (
|
||||||
|
tx: Tx,
|
||||||
|
doc: Doc,
|
||||||
|
user: Ref<Account>,
|
||||||
|
type: NotificationType,
|
||||||
|
control: TriggerControl
|
||||||
|
): Promise<boolean> {
|
||||||
|
if (type.field === undefined) return false
|
||||||
|
const value = (doc as any)[type.field]
|
||||||
|
if (value === undefined) return false
|
||||||
|
const employee = (
|
||||||
|
await control.modelDb.findAll(contact.class.EmployeeAccount, { _id: user as Ref<EmployeeAccount> })
|
||||||
|
)[0]
|
||||||
|
if (employee === undefined) return false
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.includes(employee.employee)
|
||||||
|
} else {
|
||||||
|
return value === employee.employee
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -797,7 +822,9 @@ export async function OnAttributeCreate (tx: Tx, control: TriggerControl): Promi
|
|||||||
? [control.hierarchy.isMixin(attribute.attributeOf) ? core.class.TxMixin : core.class.TxUpdateDoc]
|
? [control.hierarchy.isMixin(attribute.attributeOf) ? core.class.TxMixin : core.class.TxUpdateDoc]
|
||||||
: [core.class.TxCreateDoc, core.class.TxRemoveDoc]
|
: [core.class.TxCreateDoc, core.class.TxRemoveDoc]
|
||||||
const data: Data<NotificationType> = {
|
const data: Data<NotificationType> = {
|
||||||
|
attribute: attribute._id,
|
||||||
group: group._id,
|
group: group._id,
|
||||||
|
field: attribute.name,
|
||||||
generated: true,
|
generated: true,
|
||||||
objectClass,
|
objectClass,
|
||||||
txClasses,
|
txClasses,
|
||||||
@ -846,6 +873,7 @@ export default async () => ({
|
|||||||
OnAttributeUpdate
|
OnAttributeUpdate
|
||||||
},
|
},
|
||||||
function: {
|
function: {
|
||||||
IsUserInFieldValue: isUserInFieldValue
|
IsUserInFieldValue: isUserInFieldValue,
|
||||||
|
IsUserEmployeeInFieldValue: isUserEmployeeInFieldValue
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -199,6 +199,7 @@ export default plugin(serverNotificationId, {
|
|||||||
OnAttributeUpdate: '' as Resource<TriggerFunc>
|
OnAttributeUpdate: '' as Resource<TriggerFunc>
|
||||||
},
|
},
|
||||||
function: {
|
function: {
|
||||||
IsUserInFieldValue: '' as TypeMatchFunc
|
IsUserInFieldValue: '' as TypeMatchFunc,
|
||||||
|
IsUserEmployeeInFieldValue: '' as TypeMatchFunc
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user