From d749a9621f8682c1c7d2b538c5ac1c60a3050f41 Mon Sep 17 00:00:00 2001 From: sidwebworks <58144379+sidwebworks@users.noreply.github.com> Date: Fri, 1 Aug 2025 17:14:51 +0530 Subject: [PATCH] fix: make the conditions optional in casl check --- backend/src/ee/services/event/event-sse-stream.ts | 8 ++++++-- backend/src/lib/api-docs/constants.ts | 10 +++++++++- backend/src/server/routes/v1/event-router.ts | 9 +++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/src/ee/services/event/event-sse-stream.ts b/backend/src/ee/services/event/event-sse-stream.ts index d73eccb42..0b7607ee5 100644 --- a/backend/src/ee/services/event/event-sse-stream.ts +++ b/backend/src/ee/services/event/event-sse-stream.ts @@ -71,8 +71,12 @@ export function createEventStreamClient(redis: Redis, options: IEventStreamClien action: "subscribe", conditions: { eventType: r.event, - secretPath: r.conditions?.secretPath ?? "/", - environment: r.conditions?.environmentSlug + ...(r.conditions + ? { + secretPath: r.conditions?.secretPath, + environment: r.conditions?.environmentSlug + } + : {}) } })); diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts index 72b283a0f..17f13d3c2 100644 --- a/backend/src/lib/api-docs/constants.ts +++ b/backend/src/lib/api-docs/constants.ts @@ -69,7 +69,8 @@ export enum ApiDocsTags { SecretScanning = "Secret Scanning", OidcSso = "OIDC SSO", SamlSso = "SAML SSO", - LdapSso = "LDAP SSO" + LdapSso = "LDAP SSO", + Events = "Event Subscriptions" } export const GROUPS = { @@ -2869,3 +2870,10 @@ export const LdapSso = { caCert: "The CA certificate to use when verifying the LDAP server certificate." } }; + +export const EventSubscriptions = { + SUBSCRIBE_PROJECT_EVENTS: { + projectId: "The ID of the project the group belongs to.", + register: "List of events you want to subscribe to" + } +}; diff --git a/backend/src/server/routes/v1/event-router.ts b/backend/src/server/routes/v1/event-router.ts index b8a043db5..dd6932c9a 100644 --- a/backend/src/server/routes/v1/event-router.ts +++ b/backend/src/server/routes/v1/event-router.ts @@ -7,6 +7,7 @@ import { ActionProjectType, ProjectType } from "@app/db/schemas"; import { getServerSentEventsHeaders } from "@app/ee/services/event/event-sse-stream"; import { EventRegisterSchema } from "@app/ee/services/event/types"; import { ProjectPermissionSecretActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission"; +import { ApiDocsTags, EventSubscriptions } from "@app/lib/api-docs"; import { BadRequestError, ForbiddenRequestError, RateLimitError } from "@app/lib/errors"; import { readLimit } from "@app/server/config/rateLimiter"; import { verifyAuth } from "@app/server/plugins/auth/verify-auth"; @@ -20,10 +21,14 @@ export const registerEventRouter = async (server: FastifyZodProvider) => { rateLimit: readLimit }, schema: { + hide: false, + tags: [ApiDocsTags.Events], + description: "Subscribe to project events", body: z.object({ - projectId: z.string().trim(), + projectId: z.string().trim().describe(EventSubscriptions.SUBSCRIBE_PROJECT_EVENTS.projectId), register: z.array(EventRegisterSchema).max(10) - }) + }), + produces: ["text/event-stream"] }, onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), handler: async (req, reply) => {