MCPcopy Index your code
hub / github.com/simstudioai/sim / buildOrgScopeCondition

Function buildOrgScopeCondition

apps/sim/app/api/v1/audit-logs/query.ts:98–127  ·  view source on GitHub ↗
(params: OrgScopeParams)

Source from the content-addressed store, hash-verified

96 * and system events (null actor).
97 */
98export function buildOrgScopeCondition(params: OrgScopeParams): SQL<unknown> {
99 const { organizationId, orgWorkspaceIds, orgMemberIds, includeDeparted } = params
100
101 const orgLevelCondition = and(
102 isNull(auditLog.workspaceId),
103 or(
104 sql`${auditLog.metadata}->>'organizationId' = ${organizationId}`,
105 and(
106 eq(auditLog.resourceType, AuditResourceType.ORGANIZATION),
107 eq(auditLog.resourceId, organizationId)
108 )
109 )
110 )!
111
112 const orgScope =
113 orgWorkspaceIds.length > 0
114 ? or(inArray(auditLog.workspaceId, orgWorkspaceIds), orgLevelCondition)!
115 : orgLevelCondition
116
117 if (includeDeparted) {
118 return orgScope
119 }
120
121 const currentActorCondition =
122 orgMemberIds.length > 0
123 ? or(inArray(auditLog.actorId, orgMemberIds), isNull(auditLog.actorId))!
124 : isNull(auditLog.actorId)
125
126 return and(orgScope, currentActorCondition)!
127}
128
129function buildCursorCondition(cursor: string): SQL<unknown> | null {
130 const cursorData = decodeCursor(cursor)

Callers 4

route.tsFile · 0.90
query.test.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90

Calls 1

eqFunction · 0.50

Tested by

no test coverage detected