ezqms-834: fix roles ids and names (#5520)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-05-06 17:47:34 +04:00 committed by GitHub
parent d99d0c6cbb
commit 844e393460
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 65 deletions

View File

@ -15,7 +15,7 @@
import { ArrOf, Prop, TypeRef, type Builder } from '@hcengineering/model'
import { type Asset } from '@hcengineering/platform'
import { getRoleAttributeBaseProps } from '@hcengineering/core'
import { getRoleAttributeLabel } from '@hcengineering/core'
import { TSpacesTypeData } from './security'
import core from './component'
@ -30,10 +30,10 @@ const roles = [
export function defineSpaceType (builder: Builder): void {
for (const role of roles) {
const { label, id } = getRoleAttributeBaseProps(role, role._id)
const label = getRoleAttributeLabel(role.name)
const roleAssgtType = ArrOf(TypeRef(core.class.Account))
Prop(roleAssgtType, label)(TSpacesTypeData.prototype, id)
Prop(roleAssgtType, label)(TSpacesTypeData.prototype, role._id)
}
builder.createModel(TSpacesTypeData)

View File

@ -18,9 +18,7 @@ import {
Account,
AccountRole,
AnyAttribute,
AttachedData,
AttachedDoc,
Attribute,
Class,
ClassifierKind,
Collection,
@ -36,7 +34,6 @@ import {
IndexKind,
Obj,
Permission,
PropertyType,
Ref,
Role,
Space,
@ -609,27 +606,8 @@ export async function checkPermission (
/**
* @public
*/
export interface RoleAttributeBaseProps {
label: IntlString
id: Ref<Attribute<PropertyType>>
}
/**
* @public
*/
export function getRoleAttributeBaseProps (data: AttachedData<Role>, roleId: Ref<Role>): RoleAttributeBaseProps {
const name = data.name.trim()
const label = getEmbeddedLabel(`Role: ${name}`)
const id = getRoleAttributeId(roleId)
return { label, id }
}
/**
* @public
*/
export function getRoleAttributeId (roleId: Ref<Role>): Ref<Attribute<PropertyType>> {
return `role-${roleId}` as Ref<Attribute<PropertyType>>
export function getRoleAttributeLabel (roleName: string): IntlString {
return getEmbeddedLabel(`Role: ${roleName.trim()}`)
}
/**

View File

@ -18,7 +18,7 @@
import { IntlString } from '@hcengineering/platform'
import { ButtonKind, ButtonSize } from '@hcengineering/ui'
export let object: TypedSpace
export let object: TypedSpace | undefined
export let label: IntlString
export let value: Ref<Account>[]
export let onChange: ((refs: Ref<Account>[]) => void) | undefined
@ -30,13 +30,15 @@
$: members = object?.members ?? []
</script>
<AccountArrayEditor
{value}
{label}
readonly={readonly || (object.private && members.length === 0)}
includeItems={object.private ? members : undefined}
{onChange}
{size}
width={width ?? 'min-content'}
{kind}
/>
{#if object !== undefined}
<AccountArrayEditor
{value}
{label}
readonly={readonly || (object.private && members.length === 0)}
includeItems={object.private ? members : undefined}
{onChange}
{size}
width={width ?? 'min-content'}
{kind}
/>
{/if}

View File

@ -15,18 +15,16 @@
import core, {
AttachedData,
Attribute,
Class,
ClassifierKind,
Data,
PropertyType,
Ref,
Role,
Space,
SpaceType,
TxOperations,
TypeAny as TypeAnyType,
getRoleAttributeBaseProps
getRoleAttributeLabel
} from '@hcengineering/core'
import { TypeAny } from '@hcengineering/model'
import { getEmbeddedLabel, IntlString } from '@hcengineering/platform'
@ -71,18 +69,13 @@ export async function createSpaceType<T extends SpaceType> (
export interface RoleAttributeProps {
label: IntlString
roleType: TypeAnyType
id: Ref<Attribute<PropertyType>>
}
export function getRoleAttributeProps (data: AttachedData<Role>, roleId: Ref<Role>): RoleAttributeProps {
const baseProps = getRoleAttributeBaseProps(data, roleId)
const roleType = TypeAny(
setting.component.RoleAssignmentEditor,
baseProps.label,
setting.component.RoleAssignmentEditor
)
export function getRoleAttributeProps (name: string): RoleAttributeProps {
const label = getRoleAttributeLabel(name)
const roleType = TypeAny(setting.component.RoleAssignmentEditor, label, setting.component.RoleAssignmentEditor)
return { ...baseProps, roleType }
return { label, roleType }
}
export async function createSpaceTypeRole (
@ -101,19 +94,14 @@ export async function createSpaceTypeRole (
_id
)
const { label, roleType, id } = getRoleAttributeProps(data, roleId)
const { label, roleType } = getRoleAttributeProps(data.name)
await client.createDoc(
core.class.Attribute,
core.space.Model,
{
name: roleId,
attributeOf: type.targetClass,
type: roleType,
label
},
id
)
await client.createDoc(core.class.Attribute, core.space.Model, {
name: roleId,
attributeOf: type.targetClass,
type: roleType,
label
})
return roleId
}

View File

@ -14,7 +14,7 @@
//
import contact, { Person, PersonAccount, getFirstName, getLastName } from '@hcengineering/contact'
import core, { Account, Doc, Ref, Role, Tx, TxProcessor, TxUpdateDoc, getRoleAttributeId } from '@hcengineering/core'
import core, { Account, Doc, Ref, Role, Tx, TxProcessor, TxUpdateDoc } from '@hcengineering/core'
import { getEmbeddedLabel, translate } from '@hcengineering/platform'
import type { TriggerControl } from '@hcengineering/server-core'
import setting, { Integration } from '@hcengineering/setting'
@ -101,8 +101,12 @@ export async function OnRoleNameUpdate (tx: Tx, control: TriggerControl): Promis
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, {
const roleAttribute = await control.modelDb.findOne(core.class.Attribute, {
name: updateTx.objectId
})
if (roleAttribute === undefined) return []
const updAttrTx = control.txFactory.createTxUpdateDoc(core.class.Attribute, core.space.Model, roleAttribute._id, {
label: getEmbeddedLabel(updateTx.operations.name)
})