Add user to card collaborators when card created in personal space (#8487)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / uitest-workspaces (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2025-04-07 18:45:02 +04:00 committed by GitHub
parent 9e2baac3d8
commit 5125f67471
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 23 deletions

View File

@ -44,6 +44,7 @@
"@hcengineering/platform": "^0.6.11",
"@hcengineering/server-core": "^0.6.1",
"@hcengineering/communication-sdk-types": "0.1.155",
"@hcengineering/server-contact": "^0.6.1"
"@hcengineering/server-contact": "^0.6.1",
"@hcengineering/contact": "^0.6.24"
}
}

View File

@ -15,6 +15,7 @@
import card, { Card, MasterTag, Tag } from '@hcengineering/card'
import core, {
AccountUuid,
AnyAttribute,
Data,
Doc,
@ -23,6 +24,7 @@ import core, {
Mixin,
Ref,
splitMixinUpdate,
systemAccount,
Tx,
TxCreateDoc,
TxMixin,
@ -34,7 +36,8 @@ import { TriggerControl } from '@hcengineering/server-core'
import setting from '@hcengineering/setting'
import view from '@hcengineering/view'
import { RequestEventType } from '@hcengineering/communication-sdk-types'
import { getEmployee } from '@hcengineering/server-contact'
import { getEmployee, getPersonSpaces } from '@hcengineering/server-contact'
import contact from '@hcengineering/contact'
async function OnAttribute (ctx: TxCreateDoc<AnyAttribute>[], control: TriggerControl): Promise<Tx[]> {
const attr = TxProcessor.createDoc2Doc(ctx[0])
@ -379,23 +382,44 @@ async function OnCardCreate (ctx: TxCreateDoc<Card>[], control: TriggerControl):
}
}
const { communicationApi } = control
if (communicationApi == null) return []
for (const tx of ctx) {
const employee = await getEmployee(control, tx.modifiedBy)
if (employee?.personUuid == null || !employee.active) continue
// TODO: add account
void communicationApi.event({} as any, {
type: RequestEventType.AddCollaborators,
card: tx.objectId,
collaborators: [employee.personUuid]
})
}
await updateCollaborators(control, ctx)
return res
}
async function updateCollaborators (control: TriggerControl, ctx: TxCreateDoc<Card>[]): Promise<void> {
const { communicationApi } = control
if (communicationApi == null) return
for (const tx of ctx) {
const modifier = await getEmployee(control, tx.modifiedBy)
const collaborators: AccountUuid[] = []
if (modifier?.personUuid != null && modifier.active) {
collaborators.push(modifier.personUuid)
}
const personSpaces = await getPersonSpaces(control)
const personSpace = personSpaces.find((it) => it._id === tx.objectSpace)
if (personSpace != null && personSpace.person !== modifier?._id) {
const spacePerson = (await control.findAll(control.ctx, contact.class.Person, { _id: personSpace.person }))[0]
if (spacePerson?.personUuid != null) {
collaborators.push(spacePerson.personUuid as AccountUuid)
}
}
if (collaborators.length === 0) continue
void communicationApi.event(
{ account: systemAccount },
{
type: RequestEventType.AddCollaborators,
card: tx.objectId,
collaborators
}
)
}
}
export async function OnCardTag (ctx: TxMixin<Card, Card>[], control: TriggerControl): Promise<Tx[]> {
const res: Tx[] = []
for (const tx of ctx) {

View File

@ -14,7 +14,13 @@
//
import { TriggerControl } from '@hcengineering/server-core'
import contact, { Employee, type Person, pickPrimarySocialId, SocialIdentityRef } from '@hcengineering/contact'
import contact, {
Employee,
type Person,
PersonSpace,
pickPrimarySocialId,
SocialIdentityRef
} from '@hcengineering/contact'
import { AccountUuid, parseSocialIdString, PersonId, type Ref, toIdMap } from '@hcengineering/core'
export async function getCurrentPerson (control: TriggerControl): Promise<Person | undefined> {
@ -259,3 +265,7 @@ export async function getAccountBySocialKey (control: TriggerControl, socialKey:
return employee[0]?.personUuid ?? null
}
export async function getPersonSpaces (control: TriggerControl): Promise<Pick<PersonSpace, '_id' | 'person'>[]> {
return await control.queryFind(control.ctx, contact.class.PersonSpace, {}, { projection: { _id: 1, person: 1 } })
}

View File

@ -20,7 +20,6 @@ import contact, {
formatName,
includesAny,
Person,
PersonSpace,
SocialIdentity,
SocialIdentityRef
} from '@hcengineering/contact'
@ -70,6 +69,7 @@ import { encodeObjectURI } from '@hcengineering/view'
import { workbenchId } from '@hcengineering/workbench'
import { NotifyResult } from './types'
import { getPersonSpaces } from '@hcengineering/server-contact'
/**
* @public
@ -472,12 +472,7 @@ export async function getReceiversInfo (
)
if (employees.length === 0) return []
const spaces: Pick<PersonSpace, '_id' | 'person'>[] = await control.queryFind(
ctx,
contact.class.PersonSpace,
{},
{ projection: { _id: 1, person: 1 } }
)
const spaces = await getPersonSpaces(control)
if (spaces.length === 0) return []
const socialIds: Pick<SocialIdentity, '_id' | 'attachedTo'>[] = await control.findAll(