mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 09:30:09 +00:00
Minor improvements on new reminders api
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { ForbiddenError } from "@casl/ability";
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TableName } from "@app/db/schemas";
|
||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||
import { ProjectPermissionSecretActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||
import { BadRequestError } from "@app/lib/errors";
|
||||
@@ -21,7 +22,7 @@ type TReminderServiceFactoryDep = {
|
||||
smtpService: TSmtpService;
|
||||
projectMembershipDAL: Pick<TProjectMembershipDALFactory, "findAllProjectMembers">;
|
||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||
secretV2BridgeDAL: Pick<TSecretV2BridgeDALFactory, "invalidateSecretCacheByProjectId">;
|
||||
secretV2BridgeDAL: Pick<TSecretV2BridgeDALFactory, "invalidateSecretCacheByProjectId" | "findOneWithTags">;
|
||||
};
|
||||
|
||||
export const reminderServiceFactory = ({
|
||||
@@ -136,13 +137,16 @@ export const reminderServiceFactory = ({
|
||||
actorId,
|
||||
actorOrgId,
|
||||
actorAuthMethod,
|
||||
projectId,
|
||||
reminder
|
||||
}: TCreateReminderDTO) => {
|
||||
const secret = await secretV2BridgeDAL.findOneWithTags({ [`${TableName.SecretV2}.id` as "id"]: reminder.secretId });
|
||||
if (!secret) {
|
||||
throw new BadRequestError({ message: `Secret ${reminder.secretId} not found` });
|
||||
}
|
||||
const { permission } = await permissionService.getProjectPermission({
|
||||
actor,
|
||||
actorId,
|
||||
projectId,
|
||||
projectId: secret.projectId,
|
||||
actorAuthMethod,
|
||||
actorOrgId
|
||||
});
|
||||
@@ -150,30 +154,32 @@ export const reminderServiceFactory = ({
|
||||
|
||||
const response = await createReminderInternal({
|
||||
...reminder,
|
||||
projectId
|
||||
projectId: secret.projectId
|
||||
});
|
||||
return response;
|
||||
};
|
||||
|
||||
const getReminder: TReminderServiceFactory["getReminder"] = async ({
|
||||
secretId,
|
||||
projectId,
|
||||
actor,
|
||||
actorId,
|
||||
actorOrgId,
|
||||
actorAuthMethod
|
||||
}: {
|
||||
secretId: string;
|
||||
projectId: string;
|
||||
actor: ActorType;
|
||||
actorId: string;
|
||||
actorOrgId: string;
|
||||
actorAuthMethod: ActorAuthMethod;
|
||||
}) => {
|
||||
const secret = await secretV2BridgeDAL.findOneWithTags({ [`${TableName.SecretV2}.id` as "id"]: secretId });
|
||||
if (!secret) {
|
||||
throw new BadRequestError({ message: `Secret ${secretId} not found` });
|
||||
}
|
||||
const { permission } = await permissionService.getProjectPermission({
|
||||
actor,
|
||||
actorId,
|
||||
projectId,
|
||||
projectId: secret.projectId,
|
||||
actorAuthMethod,
|
||||
actorOrgId
|
||||
});
|
||||
@@ -228,40 +234,29 @@ export const reminderServiceFactory = ({
|
||||
actorId,
|
||||
actorOrgId,
|
||||
actorAuthMethod,
|
||||
secretId,
|
||||
projectId
|
||||
secretId
|
||||
}: {
|
||||
actor: ActorType;
|
||||
actorId: string;
|
||||
actorOrgId: string;
|
||||
actorAuthMethod: ActorAuthMethod;
|
||||
secretId: string;
|
||||
projectId: string;
|
||||
}) => {
|
||||
const secret = await secretV2BridgeDAL.findOneWithTags({ [`${TableName.SecretV2}.id` as "id"]: secretId });
|
||||
if (!secret) {
|
||||
throw new BadRequestError({ message: `Secret ${secretId} not found` });
|
||||
}
|
||||
const { permission } = await permissionService.getProjectPermission({
|
||||
actor,
|
||||
actorId,
|
||||
projectId,
|
||||
projectId: secret.projectId,
|
||||
actorAuthMethod,
|
||||
actorOrgId
|
||||
});
|
||||
|
||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretActions.Edit, ProjectPermissionSub.Secrets);
|
||||
await reminderDAL.delete({ secretId });
|
||||
await secretV2BridgeDAL.invalidateSecretCacheByProjectId(projectId);
|
||||
};
|
||||
|
||||
const removeReminderRecipients: TReminderServiceFactory["removeReminderRecipients"] = async (
|
||||
secretId: string,
|
||||
projectId: string,
|
||||
tx?: Knex
|
||||
) => {
|
||||
const reminder = await reminderDAL.findOne({ secretId }, tx);
|
||||
if (!reminder) {
|
||||
return;
|
||||
}
|
||||
await reminderRecipientDAL.delete({ reminderId: reminder.id }, tx);
|
||||
await secretV2BridgeDAL.invalidateSecretCacheByProjectId(projectId);
|
||||
await secretV2BridgeDAL.invalidateSecretCacheByProjectId(secret.projectId);
|
||||
};
|
||||
|
||||
const deleteReminderBySecretId: TReminderServiceFactory["deleteReminderBySecretId"] = async (
|
||||
@@ -354,7 +349,6 @@ export const reminderServiceFactory = ({
|
||||
getReminder,
|
||||
sendDailyReminders,
|
||||
deleteReminder,
|
||||
removeReminderRecipients,
|
||||
deleteReminderBySecretId,
|
||||
batchCreateReminders,
|
||||
createReminderInternal
|
||||
|
||||
@@ -17,7 +17,6 @@ export type TCreateReminderDTO = {
|
||||
actorId: string;
|
||||
actorOrgId: string;
|
||||
actorAuthMethod: ActorAuthMethod;
|
||||
projectId: string;
|
||||
reminder: {
|
||||
secretId?: string;
|
||||
message?: string | null;
|
||||
@@ -37,28 +36,19 @@ export type TBatchCreateReminderDTO = {
|
||||
}[];
|
||||
|
||||
export interface TReminderServiceFactory {
|
||||
createReminder: ({
|
||||
actor,
|
||||
actorId,
|
||||
actorOrgId,
|
||||
actorAuthMethod,
|
||||
projectId,
|
||||
reminder
|
||||
}: TCreateReminderDTO) => Promise<{
|
||||
createReminder: ({ actor, actorId, actorOrgId, actorAuthMethod, reminder }: TCreateReminderDTO) => Promise<{
|
||||
id: string;
|
||||
created: boolean;
|
||||
}>;
|
||||
|
||||
getReminder: ({
|
||||
secretId,
|
||||
projectId,
|
||||
actor,
|
||||
actorId,
|
||||
actorOrgId,
|
||||
actorAuthMethod
|
||||
}: {
|
||||
secretId: string;
|
||||
projectId: string;
|
||||
actor: ActorType;
|
||||
actorId: string;
|
||||
actorOrgId: string;
|
||||
@@ -72,19 +62,15 @@ export interface TReminderServiceFactory {
|
||||
actorId,
|
||||
actorOrgId,
|
||||
actorAuthMethod,
|
||||
secretId,
|
||||
projectId
|
||||
secretId
|
||||
}: {
|
||||
actor: ActorType;
|
||||
actorId: string;
|
||||
actorOrgId: string;
|
||||
actorAuthMethod: ActorAuthMethod;
|
||||
secretId: string;
|
||||
projectId: string;
|
||||
}) => Promise<void>;
|
||||
|
||||
removeReminderRecipients: (secretId: string, projectId: string, tx?: Knex) => Promise<void>;
|
||||
|
||||
deleteReminderBySecretId: (secretId: string, projectId: string, tx?: Knex) => Promise<void>;
|
||||
|
||||
batchCreateReminders: (
|
||||
|
||||
Reference in New Issue
Block a user