Skip to content

fix: return only non-hidden event types in public endpoint #22746

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

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

Conversation

BKM14
Copy link
Contributor

@BKM14 BKM14 commented Jul 25, 2025

What does this PR do?

Earlier, hidden event types were returned in the v2/event-types/ endpoint. This endpoint didn't require any authentication. Now, this endpoint only return non-hidden event types. This is implemented by adding a simple filter to the existing logic.
Additionally, hidden event types are now accessible through a separate endpoint which returns all event types associated with the authenticated user.

Image Demo:

image In the above image, we can see both eventTypes visible from the new `/v2/event-types/user` endpoint. EventType with id1 is set to hidden but is still visible. image In the above image, EventType with id1 is not visible

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Seed the database using the script and start the v2 api. Set any arbitrary eventType to hidden using the PATCH request. Now hit the /v2/event-types/ endpoint and notice that the eventType which was previously set to hidden is now not visible.

@BKM14 BKM14 requested review from a team as code owners July 25, 2025 17:51
Copy link

vercel bot commented Jul 25, 2025

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

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

Walkthrough

A new authenticated GET /user endpoint was introduced in the EventTypesController_2024_06_14 to return all event types associated with the authenticated user, requiring the EVENT_TYPE_READ permission. The public GET / endpoint was updated to exclude event types with the hidden flag set to true before transforming and returning them. Both endpoints now filter out booking fields marked as hidden in the response. No other endpoints or controller structures were changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Exclude hidden event types from the public getEventTypes endpoint (#22376, CAL-6074)
Create a new authenticated endpoint to return all event types for the authenticated user (#22376, CAL-6074)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d681d55 and a1d387a.

📒 Files selected for processing (1)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.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/controllers/event-types.controller.ts
⏰ Context from checks skipped due to timeout of 90000ms. 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

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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.

@github-actions github-actions bot added api area: API, enterprise API, access token, OAuth event-types area: event types, event-types Medium priority Created by Linear-GitHub Sync platform Anything related to our platform plan Private Created by Linear-GitHub Sync labels Jul 25, 2025
Copy link
Contributor

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "Return only non-hidden event types in public endpoint". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jul 25, 2025
@graphite-app graphite-app bot requested a review from a team July 25, 2025 17:51
@BKM14 BKM14 changed the title Return only non-hidden event types in public endpoint fix:return only non-hidden event types in public endpoint Jul 25, 2025
@BKM14 BKM14 changed the title fix:return only non-hidden event types in public endpoint fix: return only non-hidden event types in public endpoint Jul 25, 2025
Copy link

graphite-app bot commented Jul 25, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (07/25/25)

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

"Add community label" took an action on this PR • (07/25/25)

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

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: 1

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

90-123: LGTM! Consider extracting the hidden fields filtering logic to reduce duplication.

The new authenticated endpoint implementation is correct and properly secured. However, the hidden booking fields filtering logic (lines 103-117) is duplicated from the public endpoint below.

Consider extracting the filtering logic into a private helper method:

+  private filterHiddenBookingFields(eventTypes: EventTypeOutput_2024_06_14[]): EventTypeOutput_2024_06_14[] {
+    return eventTypes.map((eventType) => ({
+      ...eventType,
+      bookingFields: Array.isArray(eventType?.bookingFields)
+        ? eventType.bookingFields
+            .map((field) => {
+              if ("hidden" in field) {
+                return field.hidden !== true ? field : null;
+              }
+              return field;
+            })
+            .filter((f) => f)
+        : [],
+    })) as EventTypeOutput_2024_06_14[];
+  }

   async getEventTypesForUser(@GetUser() user: UserWithProfile): Promise<GetEventTypesOutput_2024_06_14> {
     const eventTypes = await this.eventTypesService.getUserEventTypes(user.id);
     
     if (!eventTypes || eventTypes.length === 0) {
       throw new NotFoundException(`Event types not found`);
     }

     const eventTypesFormatted = this.eventTypeResponseTransformPipe.transform(eventTypes);
-    const eventTypesWithoutHiddenFields = eventTypesFormatted.map((eventType) => {
-      return {
-        ...eventType,
-        bookingFields: Array.isArray(eventType?.bookingFields)
-          ? eventType?.bookingFields
-              .map((field) => {
-                if ("hidden" in field) {
-                  return field.hidden !== true ? field : null;
-                }
-                return field;
-              })
-              .filter((f) => f)
-          : [],
-      };
-    }) as EventTypeOutput_2024_06_14[];
+    const eventTypesWithoutHiddenFields = this.filterHiddenBookingFields(eventTypesFormatted);

     return {
       status: SUCCESS_STATUS,
       data: eventTypesWithoutHiddenFields,
     };
   }
apps/api/v2/swagger/documentation.json (1)

17742-17760: nullable: true + required: ["data"] can trip some validators

For GetEventTypeOutput_2024_06_14 the data field is both required and explicitly nullable.
A few OpenAPI generators (e.g. openapi-generator kotlin/python) flag this as contradictory and output less-friendly types.

Two options:

  1. Keep required and drop nullable, documenting an empty object when not found.
  2. Keep nullable: true and drop required, matching existing “object or null” patterns.

Pick whichever matches the API behaviour, but avoid the combination.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6a0a0f and d681d55.

📒 Files selected for processing (2)
  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts (3 hunks)
  • apps/api/v2/swagger/documentation.json (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code. Functions like .add, .diff, .isBefore, and .isAfter are slow, especially in timezone mode. Prefer .utc() for better performance. Where possible, replace with native Date and direct .valueOf() comparisons for faster execution. Recommend using native methods or Day.js .utc() consistently in hot paths like loops.

Files:

  • apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts
🧬 Code Graph Analysis (1)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts (4)
apps/api/v2/src/modules/auth/guards/api-auth/api-auth.guard.ts (1)
  • ApiAuthGuard (7-20)
apps/api/v2/src/lib/docs/headers.ts (1)
  • API_KEY_OR_ACCESS_TOKEN_HEADER (42-47)
apps/api/v2/src/modules/users/users.repository.ts (1)
  • UserWithProfile (9-12)
packages/platform/constants/api.ts (1)
  • SUCCESS_STATUS (9-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (2)
apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts (1)

155-178: LGTM! The public endpoint correctly filters out hidden event types.

The modifications properly implement the PR objective by filtering out hidden event types before transformation (line 155) while maintaining the existing hidden booking fields filtering. The variable naming accurately reflects the dual filtering operations.

The same code duplication concern mentioned in the previous comment applies here - the hidden booking fields filtering logic (lines 159-173) could benefit from the same helper method extraction.

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

17719-17735: All schema references are correct

Verified that GetEventTypeOutput_2024_06_14 appears only on the single‐resource endpoints (GET /v2/event-types/{id} and PATCH /v2/event-types/{id}) and that GetEventTypesOutput_2024_06_14 is used for collection endpoints. No dangling or incorrect references remain.

Comment on lines 9479 to 9520
"/v2/event-types/user": {
"get": {
"operationId": "EventTypesController_2024_06_14_getEventTypesForUser",
"summary": "Get all event types belonging to the authenticated user",
"parameters": [
{
"name": "cal-api-version",
"in": "header",
"description": "Must be set to 2024-06-14",
"required": true,
"schema": {
"type": "string",
"default": "2024-06-14"
}
},
{
"name": "Authorization",
"in": "header",
"description": "value must be `Bearer <token>` where `<token>` is api key prefixed with cal_ or managed user access token",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetEventTypesOutput_2024_06_14"
}
}
}
}
},
"tags": [
"Event Types"
]
}
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Prefer reusable security scheme over ad-hoc Authorization header & document error responses

The new /v2/event-types/user path embeds a hard-coded Authorization header parameter.
Across the spec we already expose authenticated endpoints via a reusable bearerAuth (or similar) security scheme – embedding the header here breaks consistency, forces duplication, and makes client generation harder.
At the same time, 4xx responses (401, 403, possibly 404) are not documented, whereas other authenticated endpoints usually list them.

-        "parameters": [
-          { … "name": "Authorization", "in": "header", … }
-        ],
+        "security": [
+          { "bearerAuth": [] }
+        ],
+        "parameters": [
+          { … "name": "cal-api-version", … }
+        ],
         "responses": {
+          "401": { "$ref": "#/components/responses/UnauthorizedError" },
+          "403": { "$ref": "#/components/responses/ForbiddenError" },
           "200": { … }
         },

Aligning with the existing pattern keeps the spec DRY and avoids confusing client SDKs.
Please adjust the path object accordingly and ensure shared error responses are referenced.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"/v2/event-types/user": {
"get": {
"operationId": "EventTypesController_2024_06_14_getEventTypesForUser",
"summary": "Get all event types belonging to the authenticated user",
"parameters": [
{
"name": "cal-api-version",
"in": "header",
"description": "Must be set to 2024-06-14",
"required": true,
"schema": {
"type": "string",
"default": "2024-06-14"
}
},
{
"name": "Authorization",
"in": "header",
"description": "value must be `Bearer <token>` where `<token>` is api key prefixed with cal_ or managed user access token",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetEventTypesOutput_2024_06_14"
}
}
}
}
},
"tags": [
"Event Types"
]
}
},
"/v2/event-types/user": {
"get": {
"operationId": "EventTypesController_2024_06_14_getEventTypesForUser",
"summary": "Get all event types belonging to the authenticated user",
"security": [
{ "bearerAuth": [] }
],
"parameters": [
{
"name": "cal-api-version",
"in": "header",
"description": "Must be set to 2024-06-14",
"required": true,
"schema": {
"type": "string",
"default": "2024-06-14"
}
}
],
"responses": {
"401": {
"$ref": "#/components/responses/UnauthorizedError"
},
"403": {
"$ref": "#/components/responses/ForbiddenError"
},
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetEventTypesOutput_2024_06_14"
}
}
}
}
},
"tags": [
"Event Types"
]
}
},
🤖 Prompt for AI Agents
In apps/api/v2/swagger/documentation.json around lines 9479 to 9520, replace the
hard-coded Authorization header parameter in the /v2/event-types/user GET
operation with a reusable security scheme reference such as "bearerAuth" to
maintain consistency and avoid duplication. Additionally, add references to the
common 4xx error responses like 401, 403, and possibly 404 to the responses
section to document authentication and authorization errors consistently with
other endpoints.

@emrysal
Copy link
Contributor

emrysal commented Jul 25, 2025

Thank you for the contribution, requesting clarification on the addition of /event-types/user for getting authed user event types. The fix itself is good.

@emrysal emrysal marked this pull request as draft July 25, 2025 22:36
@BKM14
Copy link
Contributor Author

BKM14 commented Jul 26, 2025

Thank you for the contribution, requesting clarification on the addition of /event-types/user for getting authed user event types. The fix itself is good.

The issue suggested moving fetching all eventTypes(including hidden eventTypes) for the authenticated user. The /event-types/user endpoint serves this purpose. It gets the user based on the token and then fetches all eventTypes associated to that user.

@emrysal Marking this as ready for review now

@BKM14 BKM14 marked this pull request as ready for review July 26, 2025 02:39
@dosubot dosubot bot added the 🐛 bug Something isn't working label Jul 26, 2025
@BKM14 BKM14 requested a review from kart1ka August 4, 2025 08:33
Copy link
Contributor

@kart1ka kart1ka left a comment

Choose a reason for hiding this comment

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

LGTM

@supalarry
Copy link
Contributor

Thank you for the contribution, requesting clarification on the addition of /event-types/user for getting authed user event types. The fix itself is good.

I am not sure if we can deploy it because it's kind of a breaking change. On the one hand hidden event types should be hidden and its in a way a fix, but it also means that people who rely on these endpoints for managing user's event types would result in a user not seeing the hidden event types anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api area: API, enterprise API, access token, OAuth 🐛 bug Something isn't working community Created by Linear-GitHub Sync event-types area: event types, event-types Medium priority Created by Linear-GitHub Sync platform Anything related to our platform plan Private Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: v2 api don't return hidden event types in public endpoint
4 participants