-
Notifications
You must be signed in to change notification settings - Fork 100
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
Audit log GraphQL API #5530
Open
TuvalSimha
wants to merge
4
commits into
main
Choose a base branch
from
tuval/audit-log-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,265
−8
Open
Audit log GraphQL API #5530
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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,41 @@ | ||
import { graphql } from 'testkit/gql'; | ||
import { execute } from '../../../testkit/graphql'; | ||
import { initSeed } from '../../../testkit/seed'; | ||
|
||
describe('Audit Logs Creation', () => { | ||
describe('Organization', () => { | ||
const query = graphql(` | ||
query MyQuery($selector: OrganizationSelectorInput!) { | ||
auditLogs(selector: $selector) { | ||
nodes { | ||
eventTime | ||
id | ||
__typename | ||
} | ||
} | ||
} | ||
`); | ||
test.concurrent( | ||
'Should be only one audit log for organization creation', | ||
async ({ expect }) => { | ||
const { ownerToken, createOrg } = await initSeed().createOwner(); | ||
const { organization } = await createOrg(); | ||
|
||
const result = await execute({ | ||
document: query, | ||
variables: { | ||
selector: { | ||
organization: organization.id, | ||
}, | ||
}, | ||
authToken: ownerToken, | ||
}); | ||
expect(result.rawBody.data?.auditLogs.nodes).not.toBeNull(); | ||
expect(result.rawBody.data?.auditLogs.nodes.length).toBeGreaterThan(0); | ||
expect(result.rawBody.data?.auditLogs.nodes[0].__typename).toBe( | ||
'OrganizationCreatedAuditLog', | ||
); | ||
}, | ||
); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/migrations/src/clickhouse-actions/011-audit-logs.ts
This file contains 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,20 @@ | ||
import type { Action } from '../clickhouse'; | ||
|
||
export const action: Action = async exec => { | ||
await exec(` | ||
CREATE TABLE IF NOT EXISTS "audit_log" | ||
( | ||
"id" UUID DEFAULT generateUUIDv4() CODEC(ZSTD(1)), | ||
"event_time" DateTime CODEC(ZSTD(1)), | ||
"user_id" String CODEC(ZSTD(1)), | ||
"user_email" String CODEC(ZSTD(1)), | ||
"organization_id" String CODEC(ZSTD(1)), | ||
"event_action" String CODEC(ZSTD(1)), | ||
"metadata" String CODEC(ZSTD(1)) | ||
) | ||
ENGINE = ReplacingMergeTree | ||
ORDER BY ("event_time", "user_id", "organization_id") | ||
TTL event_time + INTERVAL 1 YEAR | ||
TuvalSimha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SETTINGS index_granularity = 8192 | ||
`); | ||
}; |
This file contains 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 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 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 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,13 @@ | ||
import { createModule } from 'graphql-modules'; | ||
import { ClickHouse } from '../operations/providers/clickhouse-client'; | ||
import { AuditLogManager } from './providers/audit-logs-manager'; | ||
import { resolvers } from './resolvers.generated'; | ||
import { typeDefs } from './module.graphql'; | ||
|
||
export const auditLogsModule = createModule({ | ||
id: 'audit-logs', | ||
dirname: __dirname, | ||
typeDefs, | ||
resolvers, | ||
providers: [AuditLogManager, ClickHouse], | ||
}); |
52 changes: 52 additions & 0 deletions
52
packages/services/api/src/modules/audit-logs/module.graphql.mappers.ts
This file contains 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,52 @@ | ||
import { AuditLogModel } from './providers/audit-logs-manager'; | ||
|
||
export type AuditLogMapper = AuditLogModel; | ||
TuvalSimha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Schema | ||
export type SchemaPolicySettingsUpdatedAuditLogMapper = AuditLogModel; | ||
export type SchemaCheckedAuditLogMapper = AuditLogModel; | ||
export type SchemaPublishAuditLogMapper = AuditLogModel; | ||
export type ServiceDeletedAuditLogMapper = AuditLogModel; | ||
// Organization | ||
export type OrganizationSettingsUpdatedAuditLogMapper = AuditLogModel; | ||
export type OrganizationTransferredAuditLogMapper = AuditLogModel; | ||
export type OrganizationTransferredRequestAuditLogMapper = AuditLogModel; | ||
export type OrganizationCreatedAuditLogMapper = AuditLogModel; | ||
export type OrganizationDeletedAuditLogMapper = AuditLogModel; | ||
export type OrganizationUpdatedIntegrationAuditLogMapper = AuditLogModel; | ||
// Project | ||
export type ProjectCreatedAuditLogMapper = AuditLogModel; | ||
export type ProjectSettingsUpdatedAuditLogMapper = AuditLogModel; | ||
export type ProjectDeletedAuditLogMapper = AuditLogModel; | ||
// User Role | ||
export type RoleCreatedAuditLogMapper = AuditLogModel; | ||
export type RoleAssignedAuditLogMapper = AuditLogModel; | ||
export type RoleDeletedAuditLogMapper = AuditLogModel; | ||
export type RoleUpdatedAuditLogMapper = AuditLogModel; | ||
// Support | ||
export type SupportTicketCreatedAuditLogMapper = AuditLogModel; | ||
export type SupportTicketUpdatedAuditLogMapper = AuditLogModel; | ||
// Laboratory Collection | ||
export type CollectionCreatedAuditLogMapper = AuditLogModel; | ||
export type CollectionDeletedAuditLogMapper = AuditLogModel; | ||
export type CollectionUpdatedAuditLogMapper = AuditLogModel; | ||
// Laboratory Collection Operation | ||
export type OperationInDocumentCollectionCreatedAuditLogMapper = AuditLogModel; | ||
export type OperationInDocumentCollectionUpdatedAuditLogMapper = AuditLogModel; | ||
export type OperationInDocumentCollectionDeletedAuditLogMapper = AuditLogModel; | ||
// User | ||
export type UserInvitedAuditLogMapper = AuditLogModel; | ||
export type UserJoinedAuditLogMapper = AuditLogModel; | ||
export type UserRemovedAuditLogMapper = AuditLogModel; | ||
export type UserSettingsUpdatedAuditLogMapper = AuditLogModel; | ||
// Target | ||
export type TargetCreatedAuditLogMapper = AuditLogModel; | ||
export type TargetSettingsUpdatedAuditLogMapper = AuditLogModel; | ||
export type TargetDeletedAuditLogMapper = AuditLogModel; | ||
// Subscription | ||
export type SubscriptionCreatedAuditLogMapper = AuditLogModel; | ||
export type SubscriptionUpdatedAuditLogMapper = AuditLogModel; | ||
export type SubscriptionCanceledAuditLogMapper = AuditLogModel; | ||
// App Deployment | ||
export type AppDeploymentCreatedAuditLogMapper = AuditLogModel; | ||
export type AppDeploymentUpdatedAuditLogMapper = AuditLogModel; | ||
export type AppDeploymentPublishedAuditLogMapper = AuditLogModel; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to configure indexing?
@TuvalSimha please confirm what queries are you making here, and @kamilkisiela can help with the indexes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reminder of this one