-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(ee): add enterprise audit logs settings page #4111
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f2ef7d7
feat(ee): add enterprise audit logs settings page with server-side se…
waleedlatif1 1d13c4d
lint
waleedlatif1 3eb6b30
fix(ee): fix build error and address PR review comments
waleedlatif1 36a1aa4
lint
waleedlatif1 b9ea27d
fix(ee): fix type error with unknown metadata in JSX expression
waleedlatif1 01dfe81
fix(ee): align skeleton filter width with actual component layout
waleedlatif1 bc4788a
lint
waleedlatif1 a325138
feat(audit): add audit logging for passwords, credentials, and schedules
waleedlatif1 18352d9
fix(audit): align metadata with established recordAudit patterns
waleedlatif1 e0ab844
fix(testing): sync audit mock with new AuditAction and AuditResourceT…
waleedlatif1 6c2495b
refactor(audit-logs): derive resource type filter from AuditResourceType
waleedlatif1 4021cb2
feat(audit): enrich all recordAudit calls with structured metadata
waleedlatif1 e7d1d0c
fix(audit): remove redundant metadata fields duplicating top-level au…
waleedlatif1 231df15
fix(audit): split audit types from server-only log module
waleedlatif1 6f60475
fix(audit): escape LIKE wildcards in audit log search query
waleedlatif1 bb514a6
fix(audit): use actual deletedCount in bulk API key revoke description
waleedlatif1 4a996f4
fix(audit-logs): fix OAuth label displaying as "Oauth" in filter drop…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { NextResponse } from 'next/server' | ||
| import { getSession } from '@/lib/auth' | ||
| import { validateEnterpriseAuditAccess } from '@/app/api/v1/audit-logs/auth' | ||
| import { formatAuditLogEntry } from '@/app/api/v1/audit-logs/format' | ||
| import { | ||
| buildFilterConditions, | ||
| buildOrgScopeCondition, | ||
| queryAuditLogs, | ||
| } from '@/app/api/v1/audit-logs/query' | ||
|
|
||
| const logger = createLogger('AuditLogsAPI') | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| export async function GET(request: Request) { | ||
| try { | ||
| const session = await getSession() | ||
| if (!session?.user?.id) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
| } | ||
|
|
||
| const authResult = await validateEnterpriseAuditAccess(session.user.id) | ||
| if (!authResult.success) { | ||
| return authResult.response | ||
| } | ||
|
|
||
| const { orgMemberIds } = authResult.context | ||
|
|
||
| const { searchParams } = new URL(request.url) | ||
| const search = searchParams.get('search')?.trim() || undefined | ||
| const startDate = searchParams.get('startDate') || undefined | ||
| const endDate = searchParams.get('endDate') || undefined | ||
| const includeDeparted = searchParams.get('includeDeparted') === 'true' | ||
| const limit = Math.min(Math.max(Number(searchParams.get('limit')) || 50, 1), 100) | ||
| const cursor = searchParams.get('cursor') || undefined | ||
|
|
||
| if (startDate && Number.isNaN(Date.parse(startDate))) { | ||
| return NextResponse.json({ error: 'Invalid startDate format' }, { status: 400 }) | ||
| } | ||
| if (endDate && Number.isNaN(Date.parse(endDate))) { | ||
| return NextResponse.json({ error: 'Invalid endDate format' }, { status: 400 }) | ||
| } | ||
|
|
||
| const scopeCondition = await buildOrgScopeCondition(orgMemberIds, includeDeparted) | ||
| const filterConditions = buildFilterConditions({ | ||
| action: searchParams.get('action') || undefined, | ||
| resourceType: searchParams.get('resourceType') || undefined, | ||
| actorId: searchParams.get('actorId') || undefined, | ||
| search, | ||
| startDate, | ||
| endDate, | ||
| }) | ||
|
|
||
| const { data, nextCursor } = await queryAuditLogs( | ||
| [scopeCondition, ...filterConditions], | ||
| limit, | ||
| cursor | ||
| ) | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| data: data.map(formatAuditLogEntry), | ||
| nextCursor, | ||
| }) | ||
| } catch (error: unknown) { | ||
| const message = error instanceof Error ? error.message : 'Unknown error' | ||
| logger.error('Audit logs fetch error', { error: message }) | ||
| return NextResponse.json({ error: 'Internal server error' }, { status: 500 }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.