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
refactor(reminders): remove dead and duplicated reminder code
Calvin101682e8b3d2
diff --git a/backend/src/services/alert/alert-channel-service.ts b/backend/src/services/alert/alert-channel-service.tsindex a7b57a7933..e0636e7588 100644--- a/backend/src/services/alert/alert-channel-service.ts+++ b/backend/src/services/alert/alert-channel-service.ts@@ -79,14 +79,9 @@ export const alertChannelServiceFactory = ({groupDAL,emailDomainDAL}: TAlertChannelServiceFactoryDep) => {- const $recipientIdsByType = (recipients: TChannelRecipientInput[]) => ({- userIds: [- ...new Set(recipients.filter((r) => r.principalType === AlertPrincipalType.USER).map((r) => r.principalId))- ],- groupIds: [- ...new Set(recipients.filter((r) => r.principalType === AlertPrincipalType.GROUP).map((r) => r.principalId))- ]- });+ const $idsOfType = (recipients: TChannelRecipientInput[], principalType: AlertPrincipalType) => [+ ...new Set(recipients.filter((r) => r.principalType === principalType).map((r) => r.principalId))+ ];const $assertProjectMembersRecipients = (projectId: string | null | undefined,@@ -155,12 +150,10 @@ export const alertChannelServiceFactory = ({$assertNoDuplicateRecipients(recipients);$assertProjectMembersRecipients(projectId, recipients);- const idsOfType = (principalType: AlertPrincipalType) =>- recipients.filter((r) => r.principalType === principalType).map((r) => r.principalId);- const userIds = idsOfType(AlertPrincipalType.USER);- const groupIds = idsOfType(AlertPrincipalType.GROUP);+ const userIds = $idsOfType(recipients, AlertPrincipalType.USER);+ const groupIds = $idsOfType(recipients, AlertPrincipalType.GROUP);- await $validateEmailRecipients(orgId, idsOfType(AlertPrincipalType.EMAIL), tx);+ await $validateEmailRecipients(orgId, $idsOfType(recipients, AlertPrincipalType.EMAIL), tx);if (userIds.length === 0 && groupIds.length === 0) return;const inScope = await resolvePrincipalsInScope(@@ -318,7 +311,8 @@ export const alertChannelServiceFactory = ({recipients: TChannelRecipientInput[],tx?: Knex): Promise<TChannelRecipientInput[]> => {- const { userIds, groupIds } = $recipientIdsByType(recipients);+ const userIds = $idsOfType(recipients, AlertPrincipalType.USER);+ const groupIds = $idsOfType(recipients, AlertPrincipalType.GROUP);const inScope =userIds.length || groupIds.length? await resolvePrincipalsInScope(diff --git a/backend/src/services/reminder-recipients/reminder-recipient-dal.ts b/backend/src/services/reminder-recipients/reminder-recipient-dal.tsdeleted file mode 100644index 67988d4dbe..0000000000--- a/backend/src/services/reminder-recipients/reminder-recipient-dal.ts+++ /dev/null@@ -1,11 +0,0 @@-import { TDbClient } from "@app/db";-import { TableName } from "@app/db/schemas";-import { ormify } from "@app/lib/knex";--export type TReminderRecipientDALFactory = ReturnType<typeof reminderRecipientDALFactory>;--export const reminderRecipientDALFactory = (db: TDbClient) => {- const reminderRecipientOrm = ormify(db, TableName.ReminderRecipient);-- return { ...reminderRecipientOrm };-};diff --git a/backend/src/services/reminder/reminder-service.ts b/backend/src/services/reminder/reminder-service.tsindex a496c48ed1..857b929706 100644--- a/backend/src/services/reminder/reminder-service.ts+++ b/backend/src/services/reminder/reminder-service.ts@@ -339,6 +339,19 @@ export const reminderServiceFactory = ({logger.warn(`Stopped reaping orphaned secret reminder alerts after ${MAX_ORPHAN_REAP_BATCHES} batches`);};+ const deleteReminderBySecretId: TReminderServiceFactory["deleteReminderBySecretId"] = async (+ secretId: string,+ projectId: string,+ tx?: Knex+ ) => {+ await reminderDAL.delete({ secretId }, tx);+ await alertService.deleteAlertsForDeletedResources(+ { resourceType: SECRET_REMINDER_RESOURCE_TYPE, resourceIds: [secretId] },+ tx+ );+ await secretV2BridgeDAL.invalidateSecretCacheByProjectId(projectId);+ };+const deleteReminder: TReminderServiceFactory["deleteReminder"] = async ({actor,actorId,@@ -366,25 +379,7 @@ export const reminderServiceFactory = ({ProjectPermissionSecretActions.Edit,subject(ProjectPermissionSub.Secrets, subjectFields));- await reminderDAL.delete({ secretId });- await alertService.deleteAlertsForDeletedResources({- resourceType: SECRET_REMINDER_RESOURCE_TYPE,- resourceIds: [secretId]- });- await secretV2BridgeDAL.invalidateSecretCacheByProjectId(secret.projectId);- };-- const deleteReminderBySecretId: TReminderServiceFactory["deleteReminderBySecretId"] = async (- secretId: string,- projectId: string,- tx?: Knex- ) => {- await reminderDAL.delete({ secretId }, tx);- await alertService.deleteAlertsForDeletedResources(- { resourceType: SECRET_REMINDER_RESOURCE_TYPE, resourceIds: [secretId] },- tx- );- await secretV2BridgeDAL.invalidateSecretCacheByProjectId(projectId);+ await deleteReminderBySecretId(secretId, secret.projectId);};// A moved secret takes its reminder with it, schedule and alert, replacing any reminder the destinationdiff --git a/backend/src/services/secret/secret-queue.ts b/backend/src/services/secret/secret-queue.tsindex f487666847..2b78014b42 100644--- a/backend/src/services/secret/secret-queue.ts+++ b/backend/src/services/secret/secret-queue.ts@@ -1,5 +1,4 @@/* eslint-disable no-await-in-loop */-import { ForbiddenError } from "@casl/ability";import { AxiosError } from "axios";import { randomUUID } from "crypto";import { Knex } from "knex";@@ -20,7 +19,7 @@ import { TSecretApprovalRequestDALFactory } from "@app/ee/services/secret-approvimport { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";import { getConfig } from "@app/lib/config/env";import { crypto, SymmetricKeySize } from "@app/lib/crypto/cryptography";-import { BadRequestError, NotFoundError } from "@app/lib/errors";+import { NotFoundError } from "@app/lib/errors";import { getTimeDifferenceInSeconds, groupBy, isSamePath, unique } from "@app/lib/fn";import { logger } from "@app/lib/logger";import { requestMemoKeys } from "@app/lib/request-context/memo-keys";@@ -77,7 +76,6 @@ import { WebhookEvents } from "../webhook/webhook-types";import { TSecretDALFactory } from "./secret-dal";import { interpolateSecrets } from "./secret-fns";import {- TCreateSecretReminderDTO,TFailedIntegrationSyncEmailsPayload,THandleReminderDTO,TIntegrationSyncPayload,@@ -274,46 +272,6 @@ export const secretQueueFactory = ({.replace(":", "-");};- const addSecretReminder = async ({- oldSecret,- newSecret,- actor,- secretReminderRecipients- }: TCreateSecretReminderDTO) => {- try {- if (oldSecret.id !== newSecret.id) {- throw new BadRequestError({- name: "SecretReminderIdMismatch",- message: "Existing secret didn't match the updated secret ID."- });- }-- if (!newSecret.secretReminderRepeatDays) {- throw new BadRequestError({- name: "SecretReminderRepeatDaysMissing",- message: "Secret reminder repeat days is missing."- });- }-- await reminderService.createReminder({- ...actor,- reminder: {- secretId: newSecret.id,- message: newSecret.secretReminderNote,- repeatDays: newSecret.secretReminderRepeatDays,- recipients: secretReminderRecipients- }- });- } catch (err) {- logger.error(err, "Failed to create secret reminder.");- if (err instanceof BadRequestError || err instanceof ForbiddenError) throw err;- throw new BadRequestError({- name: "SecretReminderCreateFailed",- message: "Failed to create secret reminder."- });- }- };-const handleSecretReminder = async ({ newSecret, oldSecret, projectId, actor }: THandleReminderDTO) => {const { secretReminderRepeatDays, secretReminderNote, secretReminderRecipients } = newSecret;@@ -322,13 +280,14 @@ export const secretQueueFactory = ({(secretReminderRepeatDays && oldSecret.secretReminderRepeatDays !== secretReminderRepeatDays) ||(secretReminderNote && oldSecret.secretReminderNote !== secretReminderNote)) {- await addSecretReminder({- oldSecret,- newSecret,- projectId,- actor,- secretReminderRecipients: secretReminderRecipients ?? [],- deleteRecipients: false+ await reminderService.createReminder({+ ...actor,+ reminder: {+ secretId: newSecret.id,+ message: secretReminderNote,+ repeatDays: secretReminderRepeatDays,+ recipients: secretReminderRecipients ?? []+ }});} else if (secretReminderRepeatDays === null &&@@ -1648,7 +1607,6 @@ export const secretQueueFactory = ({syncSecrets,startSecretV2Migration,syncIntegrations,- addSecretReminder,removeSecretReminder,handleSecretReminder,replicateSecretsdiff --git a/backend/src/services/secret/secret-types.ts b/backend/src/services/secret/secret-types.tsindex 6130d4ab8d..1cf183a4b3 100644--- a/backend/src/services/secret/secret-types.ts+++ b/backend/src/services/secret/secret-types.ts@@ -454,16 +454,6 @@ export type THandleReminderDTO = {actor: TGenericPermission;};-export type TCreateSecretReminderDTO = {- oldSecret: TPartialSecret;- newSecret: TPartialSecret;- projectId: string;- actor: TGenericPermission;- secretReminderRecipients: string[];-- deleteRecipients?: boolean;-};-export type TRemoveSecretReminderDTO = {secretId: string;repeatDays: number;