Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
filter enabled channels
Thiago Araujo da Silva46ae524a9eda
diff --git a/backend/src/services/alert/alert-channel-dal.ts b/backend/src/services/alert/alert-channel-dal.tsindex 7038693e81..8b26385fc1 100644--- a/backend/src/services/alert/alert-channel-dal.ts+++ b/backend/src/services/alert/alert-channel-dal.ts@@ -76,15 +76,23 @@ export const alertChannelDALFactory = (db: TDbClient) => {}};- const findByAlertId = async (alertId: string, tx?: Knex): Promise<TAlertChannels[]> => {+ const findByAlertId = async (+ alertId: string,+ filter: { enabled?: boolean } = {},+ tx?: Knex+ ): Promise<TAlertChannels[]> => {try {- const channels = await (tx || db.replicaNode())(TableName.AlertChannel)+ const query = (tx || db.replicaNode())(TableName.AlertChannel).join(TableName.AlertChannelMembership,`${TableName.AlertChannel}.id`,`${TableName.AlertChannelMembership}.channelId`)- .where(`${TableName.AlertChannelMembership}.alertId`, alertId)+ .where(`${TableName.AlertChannelMembership}.alertId`, alertId);++ if (filter.enabled !== undefined) void query.where(`${TableName.AlertChannel}.enabled`, filter.enabled);++ const channels = await query.select(selectAllTableCols(TableName.AlertChannel)).orderBy(`${TableName.AlertChannel}.createdAt`, "asc");diff --git a/backend/src/services/alert/alert-engine.test.ts b/backend/src/services/alert/alert-engine.test.tsindex 7f51d74277..0390598090 100644--- a/backend/src/services/alert/alert-engine.test.ts+++ b/backend/src/services/alert/alert-engine.test.ts@@ -95,7 +95,10 @@ const buildEngine = (opts: {const historyWrites: Array<{ deliveries: TDelivery[]; status: string }> = [];const engine = alertEngineFactory({- alertChannelDAL: { findByAlertId: async () => opts.channels },+ alertChannelDAL: {+ findByAlertId: async (_alertId: string, filter?: { enabled?: boolean }) =>+ filter?.enabled === undefined ? opts.channels : opts.channels.filter((c) => c.enabled === filter.enabled)+ },alertChannelRecipientDAL: {// One recipient row per directed channel in the run, so each resolves its own list.findByChannelIds: async (channelIds: string[]) =>diff --git a/backend/src/services/alert/alert-engine.ts b/backend/src/services/alert/alert-engine.tsindex 063d15adfd..43b8a78608 100644--- a/backend/src/services/alert/alert-engine.ts+++ b/backend/src/services/alert/alert-engine.ts@@ -87,7 +87,7 @@ export const alertEngineFactory = ({});if (targets.length === 0) return;- const channels = (await alertChannelDAL.findByAlertId(alert.id)).filter((channel) => channel.enabled);+ const channels = await alertChannelDAL.findByAlertId(alert.id, { enabled: true });if (channels.length === 0) return;const window = provider.dedupWindowHours?.(alert.condition) ?? DEFAULT_DEDUP_WINDOW_HOURS;diff --git a/backend/src/services/alert/alert-service.ts b/backend/src/services/alert/alert-service.tsindex 4a72ff26d1..2f75cd4d4c 100644--- a/backend/src/services/alert/alert-service.ts+++ b/backend/src/services/alert/alert-service.ts@@ -190,7 +190,7 @@ export const alertServiceFactory = ({await alertChannelMembershipDAL.insertMany([{ alertId: createdAlert.id, channelId: channel.id }], tx);}- const attachedChannels = await alertChannelDAL.findByAlertId(createdAlert.id, tx);+ const attachedChannels = await alertChannelDAL.findByAlertId(createdAlert.id, {}, tx);const details = await alertChannelService.getDetailsForChannels(attachedChannels, cipher, tx);return { created: createdAlert, channels: details };});@@ -262,7 +262,7 @@ export const alertServiceFactory = ({cipher: Awaited<ReturnType<typeof getAlertChannelCipher>>,tx: Knex) => {- const existing = await alertChannelDAL.findByAlertId(alert.id, tx);+ const existing = await alertChannelDAL.findByAlertId(alert.id, {}, tx);const existingById = new Map<string, TAlertChannels>(existing.map((channel) => [channel.id, channel]));const incomingIds = new Set(incoming.filter((channel) => channel.id).map((channel) => channel.id as string));@@ -353,7 +353,7 @@ export const alertServiceFactory = ({await $reconcileChannels(alert, dto.channels, cipher, tx);}- const attachedChannels = await alertChannelDAL.findByAlertId(alert.id, tx);+ const attachedChannels = await alertChannelDAL.findByAlertId(alert.id, {}, tx);const details = await alertChannelService.getDetailsForChannels(attachedChannels, cipher, tx);return { updated: updatedAlert, channels: details };});@@ -374,7 +374,7 @@ export const alertServiceFactory = ({);await alertDAL.transaction(async (tx) => {- const channels = await alertChannelDAL.findByAlertId(alert.id, tx);+ const channels = await alertChannelDAL.findByAlertId(alert.id, {}, tx);for (const channel of channels) {// eslint-disable-next-line no-await-in-loop -- one shared tx connection; writes must be serialawait alertChannelService.deleteChannelInTx(channel.id, tx);