(params: OrgScopeParams)
| 96 | * and system events (null actor). |
| 97 | */ |
| 98 | export 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 | |
| 129 | function buildCursorCondition(cursor: string): SQL<unknown> | null { |
| 130 | const cursorData = decodeCursor(cursor) |
no test coverage detected