-
Notifications
You must be signed in to change notification settings - Fork 12.1k
fix: strip avatar and profile from children payload in managed event type updates #28239
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
alishaz-polymath
merged 3 commits into
main
from
devin/1772450657-strip-avatar-from-children-payload
Mar 2, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
53611cf
fix: strip avatar and profile from children payload in managed event …
devin-ai-integration[bot] bf66acd
refactor: extract stripChildrenForPayload into shared utility instead…
devin-ai-integration[bot] 7b54ced
fix: remove unused @ts-expect-error directive in useEventTypeForm
devin-ai-integration[bot] 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
167 changes: 167 additions & 0 deletions
167
packages/platform/atoms/event-types/hooks/useEventTypeForm.test.ts
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,167 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
|
|
||
| import type { ChildrenEventType } from "@calcom/features/eventtypes/lib/childrenEventType"; | ||
| import { MembershipRole } from "@calcom/prisma/enums"; | ||
|
|
||
| /** | ||
| * Extracts only the fields needed by the server from a ChildrenEventType array. | ||
| * This mirrors the stripping logic in useEventTypeForm's handleSubmit to ensure | ||
| * that display-only fields (avatar, profile, etc.) are not sent in the payload. | ||
| */ | ||
| function stripChildrenForPayload(children: ChildrenEventType[]) { | ||
| return children.map((child) => ({ | ||
| hidden: child.hidden, | ||
| owner: { | ||
| id: child.owner.id, | ||
| name: child.owner.name, | ||
| email: child.owner.email, | ||
| eventTypeSlugs: child.owner.eventTypeSlugs, | ||
| }, | ||
| })); | ||
| } | ||
|
|
||
| describe("useEventTypeForm - children payload stripping", () => { | ||
| it("should strip avatar, profile, username, and membership from children payload", () => { | ||
| const children: ChildrenEventType[] = [ | ||
| { | ||
| value: "1", | ||
| label: "Alice", | ||
| created: true, | ||
| slug: "test-event", | ||
| hidden: false, | ||
| owner: { | ||
| id: 1, | ||
| name: "Alice", | ||
| email: "alice@example.com", | ||
| username: "alice", | ||
| avatar: "data:image/png;base64," + "A".repeat(50000), // Large base64 avatar | ||
| membership: MembershipRole.MEMBER, | ||
| eventTypeSlugs: ["meeting", "consultation"], | ||
| profile: { | ||
| id: 1, | ||
| username: "alice", | ||
| upId: "usr_1", | ||
| organizationId: null, | ||
| organization: null, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| value: "2", | ||
| label: "Bob", | ||
| created: false, | ||
| slug: "test-event", | ||
| hidden: true, | ||
| owner: { | ||
| id: 2, | ||
| name: "Bob", | ||
| email: "bob@example.com", | ||
| username: "bob", | ||
| avatar: "https://example.com/avatars/bob.png", | ||
| membership: MembershipRole.OWNER, | ||
| eventTypeSlugs: [], | ||
| profile: { | ||
| id: 2, | ||
| username: "bob", | ||
| upId: "usr_2", | ||
| organizationId: 10, | ||
| organization: { | ||
| id: 10, | ||
| slug: "org", | ||
| name: "Org", | ||
| calVideoLogo: null, | ||
| bannerUrl: "", | ||
| isPlatform: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| const stripped = stripChildrenForPayload(children); | ||
|
|
||
| // Should only contain server-needed fields | ||
| expect(stripped).toEqual([ | ||
| { | ||
| hidden: false, | ||
| owner: { | ||
| id: 1, | ||
| name: "Alice", | ||
| email: "alice@example.com", | ||
| eventTypeSlugs: ["meeting", "consultation"], | ||
| }, | ||
| }, | ||
| { | ||
| hidden: true, | ||
| owner: { | ||
| id: 2, | ||
| name: "Bob", | ||
| email: "bob@example.com", | ||
| eventTypeSlugs: [], | ||
| }, | ||
| }, | ||
| ]); | ||
|
|
||
| // Verify avatar is not present | ||
| for (const child of stripped) { | ||
| expect(child.owner).not.toHaveProperty("avatar"); | ||
| expect(child.owner).not.toHaveProperty("profile"); | ||
| expect(child.owner).not.toHaveProperty("username"); | ||
| expect(child.owner).not.toHaveProperty("membership"); | ||
| } | ||
| }); | ||
|
|
||
| it("should significantly reduce payload size for large teams", () => { | ||
| // Simulate 85 users with base64 avatars (~10KB each) | ||
| const largeBase64Avatar = "data:image/png;base64," + "A".repeat(10000); | ||
|
|
||
| const children: ChildrenEventType[] = Array.from({ length: 85 }, (_, i) => ({ | ||
| value: String(i + 1), | ||
| label: `User ${i + 1}`, | ||
| created: true, | ||
| slug: "managed-event", | ||
| hidden: false, | ||
| owner: { | ||
| id: i + 1, | ||
| name: `User ${i + 1}`, | ||
| email: `user${i + 1}@example.com`, | ||
| username: `user${i + 1}`, | ||
| avatar: largeBase64Avatar, | ||
| membership: MembershipRole.MEMBER, | ||
| eventTypeSlugs: ["event-a", "event-b"], | ||
| profile: { | ||
| id: i + 1, | ||
| username: `user${i + 1}`, | ||
| upId: `usr_${i + 1}`, | ||
| organizationId: 1, | ||
| organization: { | ||
| id: 1, | ||
| slug: "org", | ||
| name: "Large Org", | ||
| calVideoLogo: null, | ||
| bannerUrl: "", | ||
| isPlatform: false, | ||
| }, | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| const fullPayloadSize = JSON.stringify(children).length; | ||
| const strippedPayloadSize = JSON.stringify(stripChildrenForPayload(children)).length; | ||
|
|
||
| // The stripped payload should be dramatically smaller | ||
| expect(strippedPayloadSize).toBeLessThan(fullPayloadSize * 0.1); | ||
|
|
||
| // Full payload with 85 users and 10KB avatars should be around 850KB+ | ||
| expect(fullPayloadSize).toBeGreaterThan(800000); | ||
|
|
||
| // Stripped payload should be well under 1MB | ||
| expect(strippedPayloadSize).toBeLessThan(100000); | ||
| }); | ||
|
|
||
| it("should handle undefined children gracefully", () => { | ||
| const children: ChildrenEventType[] = []; | ||
| const stripped = stripChildrenForPayload(children); | ||
| expect(stripped).toEqual([]); | ||
| }); | ||
| }); | ||
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.
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.