Skip to content

Conversation

@supalarry
Copy link
Contributor

Fixes CAL-6074

@supalarry supalarry requested a review from a team September 4, 2025 11:44
@supalarry supalarry requested a review from a team as a code owner September 4, 2025 11:44
@linear
Copy link

linear bot commented Sep 4, 2025

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

The PR makes GET /v2/event-types optional-auth aware and threads an optional auth user through controller → service to enforce visibility: hidden event types are returned only to their owner. BookingFields filtering is moved from the controller into OutputEventTypesService. Service methods were refactored to accept params objects and accept optional authUser. A repository helper to fetch public (non-hidden) user event types was added. Swagger docs now document optional auth headers. E2E tests were updated to use API keys and cover hidden/owner/non-owner behaviors.

Assessment against linked issues

Objective Addressed Explanation
Don’t return hidden event types in the public endpoint (CAL-6074)
If auth is provided return all event types for the owner; otherwise return only non-hidden ones (CAL-6074)
Add tests verifying owner vs non-owner vs unauthenticated visibility (CAL-6074)

Out-of-scope changes

No out-of-scope functional code changes were identified relevant to the objectives in the linked issue.

Possibly related PRs


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5a0de63 and f312571.

📒 Files selected for processing (1)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Install dependencies / Yarn install & cache
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-v2-hidden-event-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@graphite-app graphite-app bot requested a review from a team September 4, 2025 11:44
@keithwillcode keithwillcode added core area: core, team members only platform Anything related to our platform plan labels Sep 4, 2025
@dosubot dosubot bot added event-types area: event types, event-types 🐛 bug Something isn't working labels Sep 4, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts (1)

2368-2371: Syntax error: stray “+” before expect

This will break the test file parsing.

Apply this fix:

-        +expect(updatedEventType.hidden).toBe(false);
+        expect(updatedEventType.hidden).toBe(false);
🧹 Nitpick comments (7)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts (1)

349-356: Naming nit: avoid confusion with “hidden” event types.

These helpers filter hidden booking fields, not hidden event types. Consider filterHiddenBookingFields / filterHiddenBookingFieldsInList for clarity.

apps/api/v2/swagger/documentation.json (2)

9861-9861: Clarify owner-only behavior and default exclusion in description

The current phrasing is ambiguous. Recommend explicitly stating exclusion by default and owner-only inclusion when authenticated.

-        "description": "Hidden event types are returned only if authentication is provided and it belongs to the event type owner.",
+        "description": "Hidden event types are excluded unless the request is authenticated as the owner of the event type; in that case, the owner's hidden event types are included.",

9917-9944: Tighten auth header docs and add examples

  • Update the Authorization header description: capitalize “API key,” clarify token formats, and add
    "example": "Bearer cal_xxxxxxxxxxxxxxxxx".
  • Mark x-cal-secret-key as a password ("format": "password") and add
    "example": "sk_live_xxxxxxxxxxxxxxxxx".
  • Add "example": "client_abc123" for x-cal-client-id.
    Optionally model these via components.securitySchemes in a follow-up to avoid duplicating header parameters.
apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts (2)

207-227: Objective #2 gap: “all event types for the authenticated user” not exposed

Today, when no username, eventSlug, or usernames are provided, you return []. If the product intent is to add an authenticated endpoint for “my event types,” consider either adding a dedicated route (e.g., GET /v2/me/event-types) or a safe fallback here when authUser is present.

Example minimal fallback inside this method:

   async getEventTypes(queryParams: GetEventTypesQuery_2024_06_14, authUser?: AuthOptionalUser) {
     const { username, eventSlug, usernames, orgSlug, orgId } = queryParams;
+    // Optional: return authenticated user's own event types when no explicit target is provided
+    if (!username && !eventSlug && !usernames && authUser?.id) {
+      return await this.getUserEventTypes(authUser.id);
+    }

42-43: Avoid eslint-disable by typing the input sans destinationCalendar

Instead of suppressing the lint rule, consider typing createEventType input with an Omit<...,"destinationCalendar"> at the call site, or pre-omit the field before the transform step to keep this function clean.

apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts (1)

762-787: Add positive owner test for hidden eventSlug

You cover non-owner and unauth for hidden slugs; add the owner case to prevent regressions.

Suggested test:

+    it(`/GET/event-types by username and eventSlug should return hidden event type for the owner`, async () => {
+      const res = await request(app.getHttpServer())
+        .get(`/api/v2/event-types?username=${user.username}&eventSlug=${hiddenEventType.slug}`)
+        .set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
+        .set("Authorization", `Bearer ${apiKeyString}`)
+        .expect(200);
+      const body: ApiSuccessResponse<EventTypeOutput_2024_06_14[]> = res.body;
+      expect(body.data?.length).toEqual(1);
+      expect(body.data?.[0]?.id).toEqual(hiddenEventType.id);
+      expect(body.data?.[0]?.hidden).toEqual(true);
+    });
apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts (1)

176-181: Parse route param to number in Delete endpoint

@Param("eventTypeId") won’t be coerced at runtime; mirror the update route and add ParseIntPipe to avoid string IDs slipping through.

Apply:

-  async deleteEventType(
-    @Param("eventTypeId") eventTypeId: number,
+  async deleteEventType(
+    @Param("eventTypeId", ParseIntPipe) eventTypeId: number,
     @GetUser("id") userId: number
   ): Promise<DeleteEventTypeOutput_2024_06_14> {
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 34a8018 and 5a0de63.

📒 Files selected for processing (6)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts (30 hunks)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts (3 hunks)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts (1 hunks)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts (5 hunks)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts (3 hunks)
  • apps/api/v2/swagger/documentation.json (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{service,repository}.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Avoid dot-suffixes like .service.ts or .repository.ts for new files; reserve .test.ts, .spec.ts, .types.ts for their specific purposes

Files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts
🧠 Learnings (5)
📓 Common learnings
Learnt from: supalarry
PR: calcom/cal.com#23364
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/internal-to-api/internal-to-api.spec.ts:295-296
Timestamp: 2025-08-27T13:32:46.887Z
Learning: In calcom/cal.com, when transforming booking fields from internal to API format, tests in organizations-event-types.e2e-spec.ts already expect name field label and placeholder to be empty strings ("") rather than undefined. PR changes that set these to explicit empty strings are typically fixing implementation to match existing test expectations rather than breaking changes.
Learnt from: supalarry
PR: calcom/cal.com#23217
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts:93-94
Timestamp: 2025-08-21T13:44:06.805Z
Learning: In apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts, repository functions that use explicit Prisma select clauses (like getEventTypeWithSeats) are used for specific purposes and don't need to include all EventType fields like bookingRequiresAuthentication. These methods don't feed into the general OutputEventTypesService_2024_06_14 flow.
📚 Learning: 2025-08-21T13:44:06.805Z
Learnt from: supalarry
PR: calcom/cal.com#23217
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts:93-94
Timestamp: 2025-08-21T13:44:06.805Z
Learning: In apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts, repository functions that use explicit Prisma select clauses (like getEventTypeWithSeats) are used for specific purposes and don't need to include all EventType fields like bookingRequiresAuthentication. These methods don't feed into the general OutputEventTypesService_2024_06_14 flow.

Applied to files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts
📚 Learning: 2025-08-26T08:08:23.395Z
Learnt from: SinghaAnirban005
PR: calcom/cal.com#23343
File: packages/features/insights/server/trpc-router.ts:1080-1101
Timestamp: 2025-08-26T08:08:23.395Z
Learning: In packages/features/insights/server/trpc-router.ts, when filtering personal event types (userId provided, no teamId, not isAll), the query correctly uses user.id (authenticated user) instead of the input userId parameter for security reasons. This prevents users from accessing other users' personal event types by passing arbitrary user IDs.

Applied to files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/event-types.repository.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts
📚 Learning: 2025-08-27T13:32:46.887Z
Learnt from: supalarry
PR: calcom/cal.com#23364
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/internal-to-api/internal-to-api.spec.ts:295-296
Timestamp: 2025-08-27T13:32:46.887Z
Learning: In calcom/cal.com, when transforming booking fields from internal to API format, tests in organizations-event-types.e2e-spec.ts already expect name field label and placeholder to be empty strings ("") rather than undefined. PR changes that set these to explicit empty strings are typically fixing implementation to match existing test expectations rather than breaking changes.

Applied to files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts
📚 Learning: 2025-09-03T11:54:05.409Z
Learnt from: supalarry
PR: calcom/cal.com#23514
File: apps/api/v2/src/ee/bookings/2024-08-13/services/bookings.service.ts:579-582
Timestamp: 2025-09-03T11:54:05.409Z
Learning: In calcom/cal.com bookings repository methods, when Prisma select uses `eventType: true`, all eventType fields including seatsShowAttendees are automatically included in the selection. Explicit field selection is not required when using `true` for nested relations.

Applied to files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts
🧬 Code graph analysis (4)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts (1)
packages/platform/types/event-types/event-types_2024_06_14/outputs/booking-fields.output.ts (2)
  • OutputUnknownBookingField_2024_06_14 (620-629)
  • OutputBookingField_2024_06_14 (658-661)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts (1)
apps/api/v2/src/modules/auth/decorators/get-optional-user/get-optional-user.decorator.ts (1)
  • AuthOptionalUser (5-5)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts (3)
apps/api/v2/src/modules/auth/guards/optional-api-auth/optional-api-auth.guard.ts (1)
  • OptionalApiAuthGuard (4-14)
apps/api/v2/src/lib/docs/headers.ts (3)
  • OPTIONAL_X_CAL_CLIENT_ID_HEADER (5-9)
  • OPTIONAL_X_CAL_SECRET_KEY_HEADER (11-15)
  • OPTIONAL_API_KEY_OR_ACCESS_TOKEN_HEADER (49-54)
apps/api/v2/src/modules/auth/decorators/get-optional-user/get-optional-user.decorator.ts (2)
  • GetOptionalUser (7-32)
  • AuthOptionalUser (5-5)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts (3)
apps/api/v2/test/fixtures/repository/api-keys.repository.fixture.ts (1)
  • ApiKeysRepositoryFixture (6-37)
packages/platform/constants/api.ts (3)
  • CAL_API_VERSION_HEADER (72-72)
  • VERSION_2024_06_14 (56-56)
  • SUCCESS_STATUS (9-9)
packages/platform/types/api.ts (1)
  • ApiSuccessResponse (8-8)
🪛 Biome (2.1.2)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts

[error] 359-359: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

🔇 Additional comments (12)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/output-event-types.service.ts (2)

34-35: LGTM: import is correct and used below.


257-257: Good use of satisfies for type safety.

Keeps unknown booking fields well-typed without runtime cost. Ensure TS >= 4.9 in this package.

apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/event-types.service.ts (3)

98-119: Hidden event-type suppression for non-owners — LGTM

The auth-aware early return on hidden types is correct and aligns with the issue goal.


126-139: Public vs owner listing — LGTM

Branching to public-only when the requester isn’t the owner is clear and correct.


190-197: Confirm repository filter and minimal selects

Ensure getUserEventTypesPublic(userId) enforces hidden = false at the DB level and uses Prisma select (never include) per guidelines.

apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.e2e-spec.ts (5)

594-624: Hidden event-type creation test — LGTM

Good coverage to persist and assert hidden: true and ownerId.


625-674: Owner sees hidden types; hidden bookingFields filtered — LGTM

The expectations match the new visibility model and output filtering.


676-714: Non-owner and unauth cases correctly exclude hidden types — LGTM

Clear assertions on result counts and visibility flags.


715-760: eventSlug path for owner (visible case) — LGTM

End-to-end validation looks solid.


174-208: API key-based auth setup — LGTM

Nice move to real API keys; it exercises the OptionalApiAuthGuard path realistically.

apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts (2)

122-145: Optional auth + output filtering — LGTM

Guarding with OptionalApiAuthGuard and delegating hidden-field removal to the output service is clean and matches the stated behavior.


11-16: Docs: optional headers — LGTM

Good API docs for optional auth (client id/secret and bearer token).

@vercel
Copy link

vercel bot commented Sep 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 4, 2025 0:51am
cal-eu Ignored Ignored Sep 4, 2025 0:51am

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

E2E results are ready!

@supalarry supalarry merged commit ad4cf0c into main Sep 9, 2025
109 of 114 checks passed
@supalarry supalarry deleted the fix-v2-hidden-event-types branch September 9, 2025 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working core area: core, team members only event-types area: event types, event-types platform Anything related to our platform plan ready-for-e2e size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants