mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 03:40:48 +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]
|
||||
const data: Data<NotificationType> = {
|
||||
attribute: attribute._id,
|
||||
field: attribute.name,
|
||||
group,
|
||||
generated: true,
|
||||
objectClass,
|
||||
|
@ -208,6 +208,7 @@ async function createCustomFieldTypes (client: MigrationUpgradeClient): Promise<
|
||||
: [core.class.TxCreateDoc, core.class.TxRemoveDoc]
|
||||
const data: Data<NotificationType> = {
|
||||
attribute: attribute._id,
|
||||
field: attribute.name,
|
||||
group: group._id,
|
||||
generated: true,
|
||||
objectClass,
|
||||
|
@ -37,7 +37,7 @@ export function createModel (builder: Builder): void {
|
||||
notification.class.NotificationType,
|
||||
serverNotification.mixin.TypeMatch,
|
||||
{
|
||||
func: serverNotification.function.IsUserInFieldValue
|
||||
func: serverNotification.function.IsUserEmployeeInFieldValue
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ export function createModel (builder: Builder): void {
|
||||
notification.class.NotificationType,
|
||||
serverNotification.mixin.TypeMatch,
|
||||
{
|
||||
func: serverNotification.function.IsUserInFieldValue
|
||||
func: serverNotification.function.IsUserEmployeeInFieldValue
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ export function createModel (builder: Builder): void {
|
||||
notification.class.NotificationType,
|
||||
serverNotification.mixin.TypeMatch,
|
||||
{
|
||||
func: serverNotification.function.IsUserInFieldValue
|
||||
func: serverNotification.function.IsUserEmployeeInFieldValue
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -407,11 +407,12 @@ function isTypeMatched (
|
||||
tx: TxCUD<Doc>,
|
||||
extractedTx: TxCUD<Doc>
|
||||
): 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 (!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 (!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 (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
|
||||
*/
|
||||
@ -797,7 +822,9 @@ export async function OnAttributeCreate (tx: Tx, control: TriggerControl): Promi
|
||||
? [control.hierarchy.isMixin(attribute.attributeOf) ? core.class.TxMixin : core.class.TxUpdateDoc]
|
||||
: [core.class.TxCreateDoc, core.class.TxRemoveDoc]
|
||||
const data: Data<NotificationType> = {
|
||||
attribute: attribute._id,
|
||||
group: group._id,
|
||||
field: attribute.name,
|
||||
generated: true,
|
||||
objectClass,
|
||||
txClasses,
|
||||
@ -846,6 +873,7 @@ export default async () => ({
|
||||
OnAttributeUpdate
|
||||
},
|
||||
function: {
|
||||
IsUserInFieldValue: isUserInFieldValue
|
||||
IsUserInFieldValue: isUserInFieldValue,
|
||||
IsUserEmployeeInFieldValue: isUserEmployeeInFieldValue
|
||||
}
|
||||
})
|
||||
|
@ -199,6 +199,7 @@ export default plugin(serverNotificationId, {
|
||||
OnAttributeUpdate: '' as Resource<TriggerFunc>
|
||||
},
|
||||
function: {
|
||||
IsUserInFieldValue: '' as TypeMatchFunc
|
||||
IsUserInFieldValue: '' as TypeMatchFunc,
|
||||
IsUserEmployeeInFieldValue: '' as TypeMatchFunc
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user