ezqms-798: fix role name update (#5514)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-05-06 13:10:37 +04:00 committed by GitHub
parent 381166ed87
commit 93192bcdbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 4 deletions

View File

@ -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
}
})
}

View File

@ -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
*/

View File

@ -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
}
})

View File

@ -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>
}
})