UBERF-7532: Bulk operations for triggers (#6023)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2024-07-09 00:04:05 +07:00
committed by GitHub
parent fa82ee1939
commit 4eac1927f0
49 changed files with 656 additions and 693 deletions
+2 -7
View File
@@ -32,7 +32,7 @@ import platform, { PlatformError, Severity, Status } from '@hcengineering/platfo
import { Middleware, SessionContext, TxMiddlewareResult, type ServerStorage } from '@hcengineering/server-core'
import { DOMAIN_PREFERENCE } from '@hcengineering/server-preference'
import { BaseMiddleware } from './base'
import { getUser, mergeTargets } from './utils'
import { getUser } from './utils'
/**
* @public
@@ -65,12 +65,7 @@ export class PrivateMiddleware extends BaseMiddleware implements Middleware {
}
}
}
const res = await this.provideTx(ctx, tx)
// Add target to all broadcasts
ctx.derived.forEach((it) => {
it.target = mergeTargets(target, it.target)
})
return res
return await this.provideTx(ctx, tx)
}
override async findAll<T extends Doc>(
+5 -5
View File
@@ -335,10 +335,8 @@ export class SpacePermissionsMiddleware extends BaseMiddleware implements Middle
await this.processPermissionsUpdatesFromTx(ctx, tx)
await this.checkPermissions(ctx, tx)
const res = await this.provideTx(ctx, tx)
for (const txd of ctx.derived) {
for (const tx of txd.derived) {
await this.processPermissionsUpdatesFromTx(ctx, tx)
}
for (const txd of ctx.derived.txes) {
await this.processPermissionsUpdatesFromTx(ctx, txd)
}
return res
}
@@ -347,7 +345,9 @@ export class SpacePermissionsMiddleware extends BaseMiddleware implements Middle
if (tx._class === core.class.TxApplyIf) {
const applyTx = tx as TxApplyIf
await Promise.all(applyTx.txes.map((t) => this.checkPermissions(ctx, t)))
for (const t of applyTx.txes) {
await this.checkPermissions(ctx, t)
}
return
}
+11 -14
View File
@@ -46,7 +46,7 @@ import core, {
import platform, { PlatformError, Severity, Status } from '@hcengineering/platform'
import { Middleware, SessionContext, TxMiddlewareResult, type ServerStorage } from '@hcengineering/server-core'
import { BaseMiddleware } from './base'
import { getUser, isOwner, isSystem, mergeTargets } from './utils'
import { getUser, isOwner, isSystem } from './utils'
type SpaceWithMembers = Pick<Space, '_id' | 'members' | 'private' | '_class'>
@@ -246,10 +246,13 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar
space: core.space.DerivedTx,
params: null
}
ctx.derived.push({
derived: [tx],
target: targets
})
ctx.derived.txes.push(tx)
ctx.derived.targets.security = (it) => {
// TODO: I'm not sure it is called
if (it._id === tx._id) {
return targets
}
}
}
private async broadcastNonMembers (ctx: SessionContext, space: SpaceWithMembers): Promise<void> {
@@ -413,17 +416,10 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
}
await this.processTx(ctx, tx)
const targets = await this.getTxTargets(ctx, tx)
const res = await this.provideTx(ctx, tx)
for (const txd of ctx.derived) {
for (const tx of txd.derived) {
await this.processTx(ctx, tx)
}
for (const txd of ctx.derived.txes) {
await this.processTx(ctx, txd)
}
ctx.derived.forEach((it) => {
it.target = mergeTargets(targets, it.target)
})
return res
}
@@ -435,6 +431,7 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar
for (const tx of txes) {
const h = this.storage.hierarchy
if (h.isDerived(tx._class, core.class.TxCUD)) {
// TODO: Do we need security check here?
const cudTx = tx as TxCUD<Doc>
await this.processTxSpaceDomain(cudTx)
} else if (tx._class === core.class.TxWorkspaceEvent) {
-12
View File
@@ -17,18 +17,6 @@ import core, { Account, AccountRole, systemAccountEmail } from '@hcengineering/c
import platform, { PlatformError, Severity, Status } from '@hcengineering/platform'
import { SessionContext, type ServerStorage } from '@hcengineering/server-core'
export function mergeTargets (current: string[] | undefined, prev: string[] | undefined): string[] | undefined {
if (current === undefined) return prev
if (prev === undefined) return current
const res: string[] = []
for (const value of current) {
if (prev.includes(value)) {
res.push(value)
}
}
return res
}
export async function getUser (storage: ServerStorage, ctx: SessionContext): Promise<Account> {
if (ctx.userEmail === undefined) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))