mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-21 07:46:24 +00:00
ezqms-798: fix role name update (#5514)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
381166ed87
commit
93192bcdbc
@ -15,7 +15,7 @@
|
||||
//
|
||||
|
||||
import { type Builder } from '@hcengineering/model'
|
||||
|
||||
import serverCore from '@hcengineering/server-core'
|
||||
import core from '@hcengineering/core'
|
||||
import serverNotification from '@hcengineering/server-notification'
|
||||
import serverSetting from '@hcengineering/server-setting'
|
||||
@ -64,4 +64,15 @@ export function createModel (builder: Builder): void {
|
||||
serverFunc: serverSetting.function.GetOwnerPosition
|
||||
}
|
||||
)
|
||||
|
||||
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
|
||||
trigger: serverSetting.trigger.OnRoleNameUpdate,
|
||||
txMatch: {
|
||||
_class: core.class.TxCollectionCUD,
|
||||
objectSpace: core.space.Model,
|
||||
collection: 'roles',
|
||||
'tx._class': core.class.TxUpdateDoc,
|
||||
'tx.objectClass': core.class.Role
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -620,11 +620,18 @@ export interface RoleAttributeBaseProps {
|
||||
export function getRoleAttributeBaseProps (data: AttachedData<Role>, roleId: Ref<Role>): RoleAttributeBaseProps {
|
||||
const name = data.name.trim()
|
||||
const label = getEmbeddedLabel(`Role: ${name}`)
|
||||
const id = `role-${roleId}` as Ref<Attribute<PropertyType>>
|
||||
const id = getRoleAttributeId(roleId)
|
||||
|
||||
return { label, id }
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function getRoleAttributeId (roleId: Ref<Role>): Ref<Attribute<PropertyType>> {
|
||||
return `role-${roleId}` as Ref<Attribute<PropertyType>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
|
@ -14,8 +14,8 @@
|
||||
//
|
||||
|
||||
import contact, { Person, PersonAccount, getFirstName, getLastName } from '@hcengineering/contact'
|
||||
import { Account, Doc, Ref } from '@hcengineering/core'
|
||||
import { translate } from '@hcengineering/platform'
|
||||
import core, { Account, Doc, Ref, Role, Tx, TxProcessor, TxUpdateDoc, getRoleAttributeId } from '@hcengineering/core'
|
||||
import { getEmbeddedLabel, translate } from '@hcengineering/platform'
|
||||
import type { TriggerControl } from '@hcengineering/server-core'
|
||||
import setting, { Integration } from '@hcengineering/setting'
|
||||
|
||||
@ -91,6 +91,24 @@ export async function getOwnerPosition (
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function OnRoleNameUpdate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
||||
const actualTx = TxProcessor.extractTx(tx)
|
||||
const updateTx = actualTx as TxUpdateDoc<Role>
|
||||
|
||||
if (updateTx.operations?.name === undefined) return []
|
||||
|
||||
// Update the related mixin attribute
|
||||
const roleAttrId = getRoleAttributeId(updateTx.objectId)
|
||||
const updAttrTx = control.txFactory.createTxUpdateDoc(core.class.Attribute, core.space.Model, roleAttrId, {
|
||||
label: getEmbeddedLabel(updateTx.operations.name)
|
||||
})
|
||||
|
||||
return [updAttrTx]
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export default async () => ({
|
||||
function: {
|
||||
@ -100,5 +118,8 @@ export default async () => ({
|
||||
GetFirstName: getOwnerFirstName,
|
||||
GetLastName: getOwnerLastName,
|
||||
GetOwnerPosition: getOwnerPosition
|
||||
},
|
||||
trigger: {
|
||||
OnRoleNameUpdate
|
||||
}
|
||||
})
|
||||
|
@ -16,6 +16,7 @@
|
||||
import type { Plugin, Resource } from '@hcengineering/platform'
|
||||
import { plugin } from '@hcengineering/platform'
|
||||
import { Presenter } from '@hcengineering/server-notification'
|
||||
import { TriggerFunc } from '@hcengineering/server-core'
|
||||
import { TemplateFieldServerFunc } from '@hcengineering/server-templates'
|
||||
|
||||
/**
|
||||
@ -34,5 +35,8 @@ export default plugin(serverSettingId, {
|
||||
GetFirstName: '' as Resource<TemplateFieldServerFunc>,
|
||||
GetLastName: '' as Resource<TemplateFieldServerFunc>,
|
||||
GetOwnerPosition: '' as Resource<TemplateFieldServerFunc>
|
||||
},
|
||||
trigger: {
|
||||
OnRoleNameUpdate: '' as Resource<TriggerFunc>
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user