mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-31 04:09:43 +02:00
Fix collaborators tests (#9331)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -14,9 +14,9 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { getCurrentEmployee } from '@hcengineering/contact'
|
||||
import { Doc, DocumentQuery, getCurrentAccount, Ref } from '@hcengineering/core'
|
||||
import core, { DocumentQuery, getCurrentAccount, Ref } from '@hcengineering/core'
|
||||
import type { IntlString, Asset } from '@hcengineering/platform'
|
||||
import { createQuery } from '@hcengineering/presentation'
|
||||
import { createQuery, getClient } from '@hcengineering/presentation'
|
||||
import type { Issue, IssueStatus } from '@hcengineering/tracker'
|
||||
import { IModeSelector, resolvedLocationStore } from '@hcengineering/ui'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
@@ -28,6 +28,8 @@
|
||||
export let config: [string, IntlString, object][] = []
|
||||
export let icon: Asset | undefined = undefined
|
||||
|
||||
const client = getClient()
|
||||
const hierarchy = client.getHierarchy()
|
||||
const socialIds = getCurrentAccount().socialIds
|
||||
const acc = getCurrentAccount().uuid
|
||||
const dispatch = createEventDispatcher()
|
||||
@@ -64,16 +66,16 @@
|
||||
|
||||
const subscribedQuery = createQuery()
|
||||
$: subscribedQuery.query(
|
||||
tracker.class.Issue,
|
||||
{ 'notification:mixin:Collaborators.collaborators': acc },
|
||||
(result) => {
|
||||
const newSub = result.map((p) => p._id as Ref<Doc> as Ref<Issue>)
|
||||
core.class.Collaborator,
|
||||
{ collaborator: acc, attachedToClass: { $in: hierarchy.getDescendants(tracker.class.Issue) } },
|
||||
(collaborators) => {
|
||||
const newSub = collaborators.map((it) => it.attachedTo as Ref<Issue>)
|
||||
const curSub = subscribed._id.$in
|
||||
if (curSub.length !== newSub.length || curSub.some((id, i) => newSub[i] !== id)) {
|
||||
subscribed = { _id: { $in: newSub } }
|
||||
}
|
||||
},
|
||||
{ sort: { _id: 1 }, projection: { _id: 1 } }
|
||||
{ sort: { attachedTo: 1 }, projection: { attachedTo: 1 } }
|
||||
)
|
||||
|
||||
$: queries = { assigned, active, backlog, created, subscribed }
|
||||
|
||||
@@ -853,6 +853,7 @@ async function getTxCollabs (
|
||||
(await control.findAll(ctx, core.class.Collaborator, {
|
||||
attachedTo: doc._id
|
||||
}))
|
||||
cache.set(doc._id, collaborators)
|
||||
const collabs = collaborators.map((c) => c.collaborator)
|
||||
const ops = isMixinTx(tx) ? tx.attributes : (tx as TxUpdateDoc<Doc>).operations
|
||||
const newCollaborators = (await getNewCollaborators(ops, mixin, doc._class, control)).filter(
|
||||
@@ -1375,45 +1376,51 @@ async function updateCollaborators (
|
||||
tx: TxCUD<Doc>,
|
||||
cache: Map<Ref<Doc>, Collaborator[]>
|
||||
): Promise<Tx[]> {
|
||||
if (tx._class !== core.class.TxCreateDoc && tx._class !== core.class.TxRemoveDoc) return []
|
||||
if (tx.objectClass !== core.class.Collaborator) return []
|
||||
if (tx._class !== core.class.TxUpdateDoc && tx._class !== core.class.TxMixin) return []
|
||||
|
||||
const hierarchy = control.hierarchy
|
||||
|
||||
const mixin = getClassCollaborators(control.modelDb, hierarchy, tx.objectClass)
|
||||
if (mixin === undefined || tx.attachedToClass === undefined || tx.attachedTo === undefined) return []
|
||||
if (hierarchy.classHierarchyMixin(tx.objectClass, activity.mixin.ActivityDoc) === undefined) return []
|
||||
|
||||
if (hierarchy.classHierarchyMixin(tx.attachedToClass, activity.mixin.ActivityDoc) === undefined) return []
|
||||
const mixin = getClassCollaborators(control.modelDb, hierarchy, tx.objectClass)
|
||||
if (mixin === undefined) return []
|
||||
|
||||
const doc = (await control.findAll(ctx, tx.objectClass, { _id: tx.objectId }, { limit: 1 }))[0]
|
||||
if (doc === undefined) return []
|
||||
|
||||
const collabsResult = await getTxCollabs(ctx, tx, control, cache, doc)
|
||||
if (collabsResult.added.length === 0 && collabsResult.removed.length === 0) return []
|
||||
|
||||
const res: Tx[] = []
|
||||
|
||||
const { txes: collabTxes } = await createSyncCollaboratorsTxes(
|
||||
ctx,
|
||||
control,
|
||||
cache,
|
||||
doc._id,
|
||||
doc._class,
|
||||
doc.space,
|
||||
collabsResult.added,
|
||||
collabsResult.removed
|
||||
)
|
||||
|
||||
res.push(...collabTxes)
|
||||
|
||||
const contexts = await control.findAll(control.ctx, notification.class.DocNotifyContext, { objectId: tx.attachedTo })
|
||||
const res: Tx[] = []
|
||||
if (tx._class === core.class.TxCreateDoc) {
|
||||
const collab = TxProcessor.createDoc2Doc(tx as TxCreateDoc<Collaborator>)
|
||||
const addedInfo = await getReceiversInfo(ctx, [collab.collaborator], control)
|
||||
const addedInfo = collabsResult.added.length > 0 ? await getReceiversInfo(ctx, collabsResult.added, control) : []
|
||||
|
||||
for (const info of addedInfo.values()) {
|
||||
const context = getDocNotifyContext(control, contexts, tx.attachedTo, info.account)
|
||||
if (context !== undefined) {
|
||||
if (context.hidden) {
|
||||
res.push(control.txFactory.createTxUpdateDoc(context._class, context.space, context._id, { hidden: false }))
|
||||
}
|
||||
for (const info of addedInfo) {
|
||||
const context = getDocNotifyContext(control, contexts, doc._id, info.account)
|
||||
if (context !== undefined) {
|
||||
if (context.hidden) {
|
||||
res.push(control.txFactory.createTxUpdateDoc(context._class, context.space, context._id, { hidden: false }))
|
||||
}
|
||||
await createNotifyContext(
|
||||
ctx,
|
||||
control,
|
||||
tx.attachedTo,
|
||||
tx.attachedToClass,
|
||||
tx.objectSpace,
|
||||
info,
|
||||
tx.modifiedBy,
|
||||
undefined,
|
||||
tx
|
||||
)
|
||||
}
|
||||
} else {
|
||||
const removed = control.removedMap.get(tx.objectId) as Collaborator
|
||||
if (removed === undefined) return []
|
||||
await removeContexts(ctx, contexts, [removed.collaborator], control)
|
||||
await createNotifyContext(ctx, control, doc._id, doc._class, doc.space, info, tx.modifiedBy, undefined, tx)
|
||||
}
|
||||
|
||||
if (collabsResult.removed.length > 0) {
|
||||
await removeContexts(ctx, contexts, collabsResult.removed, control)
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user