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

feat: audit log #14985

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open

feat: audit log #14985

wants to merge 37 commits into from

Conversation

TaduJR
Copy link
Contributor

@TaduJR TaduJR commented May 11, 2024

What does this PR do?

This change tries to resolve #1461 by adding audit logger on v1 api, v2 api and backend.
These are the list of events handled on Teams and Organizations

Event-Types
	- Modified
		Event Setup
			Title
			Duration
			Location
	- Created
	- Delete

Bookings
	- Modified
		Reschedule
		Edit Location
	- Created
	- Cancelled

Note

This PR needs frontend integration and audit log table data fetching based on logged team

Important

I already made the common local parser. It just needs integration with the frontend.

Tip

I have an idea on where to show the Logged Events. Check this the screenshot.
302881919-7bd72ad8-1bb4-4924-b5ee-1c4ff564b6af

  • Fixes [CAL-1710] Audit log #1461 (GitHub issue number)
  • Fixes CAL-1461 (Linear issue number - should be visible at the bottom of the GitHub issue description)

Handling EventType Audit Logs
https://www.loom.com/share/07e24f0d6249494da1647ce4f9a82520

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected)
  • I have added a Docs issue here if this PR makes changes that would require a documentation change
  • I have added or modified automated tests that prove my fix is effective or that my feature works (PRs might be rejected if logical changes are not properly tested)

How should this be tested?

  • Are there environment variables that should be set? No
  • What are the minimal test data to have? Event Type, Team and User Entity Records
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR? Yes, check the Highlighted Markdowns

Checklist

Copy link

vercel bot commented May 11, 2024

@TaduJR is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label May 11, 2024
@graphite-app graphite-app bot requested review from a team May 11, 2024 09:25
@github-actions github-actions bot added ❗️ migrations contains migration files 3 points Created by SyncLinear.com enterprise area: enterprise, audit log, organisation, SAML, SSO foundation Medium priority Created by Linear-GitHub Sync organizations area: organizations, orgs ✨ feature New feature or request 🎨 needs design Before engineering kick-off, a designer needs to submit a mockup 💎 Bounty A bounty on Algora.io 🚧 wip / in the making This is currently being worked on labels May 11, 2024
Copy link
Contributor

github-actions bot commented May 11, 2024

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link.

Copy link

graphite-app bot commented May 11, 2024

Graphite Automations

"Add community label" took an action on this PR • (05/11/24)

1 label was added to this PR based on Keith Williams's automation.

"Add foundation team as reviewer" took an action on this PR • (05/11/24)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add consumer team as reviewer" took an action on this PR • (05/11/24)

1 reviewer was added to this PR based on Keith Williams's automation.

Copy link
Contributor

github-actions bot commented May 11, 2024

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@PeerRich PeerRich added High priority Created by Linear-GitHub Sync and removed Medium priority Created by Linear-GitHub Sync labels May 14, 2024
Copy link
Member

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has a lot of potential. Thank you for your contribution 🙏 I have some observations in order to ensure this is a top quality feature.

Delegate auditing logs to a background task

Since we're doing extra writing to the database for each action being taken. We should find a way to delegate all this logging off the main thread. It is expected that this will make all logged actions slower. But we should try to make this the least intrusive as possible. Some possible approaches that come to mind is using a prisma middleware to avoid polluting the code itself.

Make the feature opt-in by default

Since this codebase is shared with all self posters. We should try to make all these features opt-in by default. That way we don't suddenly introduce more unexpected DB load or side effect after an update. A possible approach would be using our current feature flags to toggle logging on or off and it is turned off by default. That way we can also switch it off without having to redeploy in case something wrong happens.

Use dependency injection pattern

This is so we can easily switch to a third party service if needed. We can disable it locally. We can unit test it. We can switch it with another one. I would try to come up with a AuditLogger abstraction and create an InternalAuditLogger as our first option. Here's a very nice video explaining the pattern if you want to dive into that.

Feel free to reach out with questions and more guidance.

​May you be well 🙏

@@ -402,6 +402,7 @@ model Team {
platformOAuthClient PlatformOAuthClient[]
smsLockState SMSLockState @default(UNLOCKED)
platformBilling PlatformBilling?
auditLog AuditLog[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the relationship needed at all? We can ditch the relationship and still query by teamId don't we?

id Int @id @default(autoincrement())
action String
actionDesc String?
actor Json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of Json can we turn this into actorId so we can query/join the user on query? We're trying to avoid Json fields as much as possible are these are harder to index and query.

action String
actionDesc String?
actor Json
target Json?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here on target. We can have a targetId: 1 and targetType: "team" instead of a Json field.

actionDesc String?
actor Json
target Json?
crud String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could/should be an enum:


enum Crud {
  CREATE
  READ
  UPDATE
  DELETE
}

@zomars
Copy link
Member

zomars commented May 14, 2024

/tip $25

Copy link

algora-pbc bot commented May 14, 2024

🎉🎈 @TaduJR has been awarded $25! 🎈🎊

@algora-pbc algora-pbc bot added the 💰 Rewarded Rewarded bounties on Algora.io label May 14, 2024
@TaduJR
Copy link
Contributor Author

TaduJR commented May 14, 2024

Hello @zomars. I will look into and fix every changes you requested and thank you so much for the tip.

@keithwillcode keithwillcode added this to the v4.2 milestone May 15, 2024
@github-actions github-actions bot added the Medium priority Created by Linear-GitHub Sync label May 25, 2024
Copy link

socket-security bot commented May 26, 2024

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 points Created by SyncLinear.com 🙋 Bounty claim 💎 Bounty A bounty on Algora.io community Created by Linear-GitHub Sync enterprise area: enterprise, audit log, organisation, SAML, SSO ✨ feature New feature or request foundation High priority Created by Linear-GitHub Sync Medium priority Created by Linear-GitHub Sync ❗️ migrations contains migration files 🎨 needs design Before engineering kick-off, a designer needs to submit a mockup organizations area: organizations, orgs 💰 Rewarded Rewarded bounties on Algora.io 🚧 wip / in the making This is currently being worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-1710] Audit log
4 participants