UBERF-8425: Global accounts (#7573)

This commit is contained in:
Alexey Zinoviev
2025-02-04 10:31:03 +07:00
committed by GitHub
parent 83e5b16392
commit 2c64ceadb8
765 changed files with 19134 additions and 17955 deletions
@@ -1,9 +1,8 @@
//
// Copyright © 2023 Hardcore Engineering Inc.
//
/* eslint-disable @typescript-eslint/no-unused-vars */
import chunter from '@hcengineering/chunter'
import contact, { PersonAccount } from '@hcengineering/contact'
import core, {
Doc,
DocumentUpdate,
@@ -15,7 +14,7 @@ import core, {
TxCUD,
TxProcessor,
TxUpdateDoc,
systemAccountEmail,
systemAccountUuid,
type Class,
type TxMixin
} from '@hcengineering/core'
@@ -32,7 +31,7 @@ export async function OnGithubBroadcast (txes: Tx[], control: TriggerControl): P
control.ctx.contextData.broadcast.targets.github = (it) => {
if (TxProcessor.isExtendsCUD(it._class)) {
if ((it as TxCUD<Doc>).objectClass === github.class.DocSyncInfo) {
return [systemAccountEmail]
return [systemAccountUuid]
}
}
}
@@ -134,52 +133,50 @@ async function updateDocSyncInfo (
cache: Map<string, any>,
toApply: Tx[]
): Promise<void> {
const checkTx = (tx: Tx): boolean =>
control.hierarchy.isDerived(tx._class, core.class.TxCUD) &&
(tx as TxCUD<Doc>).objectClass === github.class.DocSyncInfo &&
(tx as TxCUD<Doc>).objectId === cud.objectId
const txes = [...control.txes, ...control.ctx.contextData.broadcast.txes, ...toApply]
// Check already captured Txes
for (const i of txes) {
if (checkTx(i)) {
// We have sync doc create request already.
return
}
}
const [account] = control.modelDb.findAllSync(contact.class.PersonAccount, {
_id: tx.modifiedBy as Ref<PersonAccount>
})
// Do not modify state if is modified by github service.
if (account === undefined) {
return
}
const projects =
(cache.get('projects') as GithubProject[]) ??
(await control.queryFind(control.ctx, github.mixin.GithubProject, {}, { projection: { _id: 1 } }))
cache.set('projects', projects)
if (projects.some((it) => it._id === (space as Ref<GithubProject>))) {
const sdoc =
(cache.get(cud.objectId) as DocSyncInfo) ??
(
await control.findAll(control.ctx, github.class.DocSyncInfo, {
_id: cud.objectId as Ref<DocSyncInfo>
})
).shift()
// We need to check if sync doc is already exists.
if (sdoc === undefined) {
// Created by non github integration
// We need to create the doc sync info
createSyncDoc(control, cud, tx, space, toApply)
} else {
cache.set(cud.objectId, sdoc)
// We need to create the doc sync info
updateSyncDoc(control, cud, space, sdoc, toApply)
}
}
// TODO: FIXME
// throw new Error('Not implemented')
// const checkTx = (tx: Tx): boolean =>
// control.hierarchy.isDerived(tx._class, core.class.TxCUD) &&
// (tx as TxCUD<Doc>).objectClass === github.class.DocSyncInfo &&
// (tx as TxCUD<Doc>).objectId === cud.objectId
// const txes = [...control.txes, ...control.ctx.contextData.broadcast.txes, ...toApply]
// // Check already captured Txes
// for (const i of txes) {
// if (checkTx(i)) {
// // We have sync doc create request already.
// return
// }
// }
// const [account] = control.modelDb.findAllSync(contact.class.PersonAccount, {
// _id: tx.modifiedBy as PersonId
// })
// // Do not modify state if is modified by github service.
// if (account === undefined) {
// return
// }
// const projects =
// (cache.get('projects') as GithubProject[]) ??
// (await control.queryFind(control.ctx, github.mixin.GithubProject, {}, { projection: { _id: 1 } }))
// cache.set('projects', projects)
// if (projects.some((it) => it._id === (space as Ref<GithubProject>))) {
// const sdoc =
// (cache.get(cud.objectId) as DocSyncInfo) ??
// (
// await control.findAll(control.ctx, github.class.DocSyncInfo, {
// _id: cud.objectId as Ref<DocSyncInfo>
// })
// ).shift()
// // We need to check if sync doc is already exists.
// if (sdoc === undefined) {
// // Created by non github integration
// // We need to create the doc sync info
// createSyncDoc(control, cud, tx, space, toApply)
// } else {
// cache.set(cud.objectId, sdoc)
// // We need to create the doc sync info
// updateSyncDoc(control, cud, space, sdoc, toApply)
// }
// }
}
function isDocSyncUpdateRequired (h: Hierarchy, coll: TxCUD<Doc>): boolean {