Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-7690: Skip space security for >=85% of spaces and do on result … #6338

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions server/middleware/src/spaceSecurity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import core, {
TxWorkspaceEvent,
WorkspaceEvent,
generateId,
systemAccountEmail
systemAccountEmail,
toFindResult
} from '@hcengineering/core'
import platform, { PlatformError, Severity, Status } from '@hcengineering/platform'
import { Middleware, SessionContext, TxMiddlewareResult, type ServerStorage } from '@hcengineering/server-core'
Expand Down Expand Up @@ -491,6 +492,8 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar
const isSpace = this.storage.hierarchy.isDerived(_class, core.class.Space)
const field = this.getKey(domain)

let clientFilterSpaces: Set<Ref<Space>> | undefined

if (!isSystem(account) && account.role !== AccountRole.DocGuest && domain !== DOMAIN_MODEL) {
if (!isOwner(account, ctx) || !isSpace) {
if (query[field] !== undefined) {
Expand All @@ -514,13 +517,26 @@ export class SpaceSecurityMiddleware extends BaseMiddleware implements Middlewar
} else if (spaces.result.length === 1) {
;(newQuery as any)[field] = spaces.result[0]
} else {
;(newQuery as any)[field] = { $in: spaces.result }
// Check if spaces > 85% of all domain spaces, in this case return all and filter on client.
if (spaces.result.length / spaces.domainSpaces.size > 0.85 && options?.limit === undefined) {
clientFilterSpaces = new Set(spaces.result)
delete newQuery.space
} else {
;(newQuery as any)[field] = { $in: spaces.result }
}
}
}
}
}

const findResult = await this.provideFindAll(ctx, _class, newQuery, options)
let findResult = await this.provideFindAll(ctx, _class, newQuery, options)
if (clientFilterSpaces !== undefined) {
findResult = toFindResult(
findResult.filter((it) => (clientFilterSpaces as Set<Ref<Space>>).has(it.space)),
findResult.total,
findResult.lookupMap
)
}
if (!isOwner(account, ctx) && account.role !== AccountRole.DocGuest) {
if (options?.lookup !== undefined) {
for (const object of findResult) {
Expand Down