mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-02 21:25:45 +00:00
feat(notifications): project access request notification
This commit is contained in:
@@ -1231,7 +1231,8 @@ export const registerRoutes = async (
|
|||||||
projectTemplateService,
|
projectTemplateService,
|
||||||
groupProjectDAL,
|
groupProjectDAL,
|
||||||
smtpService,
|
smtpService,
|
||||||
reminderService
|
reminderService,
|
||||||
|
notificationService
|
||||||
});
|
});
|
||||||
|
|
||||||
const projectEnvService = projectEnvServiceFactory({
|
const projectEnvService = projectEnvServiceFactory({
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ export enum NotificationType {
|
|||||||
IMPORT_STARTED = "import-started",
|
IMPORT_STARTED = "import-started",
|
||||||
IMPORT_SUCCESSFUL = "import-successful",
|
IMPORT_SUCCESSFUL = "import-successful",
|
||||||
IMPORT_FAILED = "import-failed",
|
IMPORT_FAILED = "import-failed",
|
||||||
DIRECT_PROJECT_ACCESS_ISSUED_TO_ADMIN = "direct-project-access-issued-to-admin"
|
DIRECT_PROJECT_ACCESS_ISSUED_TO_ADMIN = "direct-project-access-issued-to-admin",
|
||||||
|
PROJECT_ACCESS_REQUEST = "project-access-request"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TCreateUserNotificationDTO {
|
export interface TCreateUserNotificationDTO {
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ import { TKmsServiceFactory } from "../kms/kms-service";
|
|||||||
import { validateMicrosoftTeamsChannelsSchema } from "../microsoft-teams/microsoft-teams-fns";
|
import { validateMicrosoftTeamsChannelsSchema } from "../microsoft-teams/microsoft-teams-fns";
|
||||||
import { TMicrosoftTeamsIntegrationDALFactory } from "../microsoft-teams/microsoft-teams-integration-dal";
|
import { TMicrosoftTeamsIntegrationDALFactory } from "../microsoft-teams/microsoft-teams-integration-dal";
|
||||||
import { TProjectMicrosoftTeamsConfigDALFactory } from "../microsoft-teams/project-microsoft-teams-config-dal";
|
import { TProjectMicrosoftTeamsConfigDALFactory } from "../microsoft-teams/project-microsoft-teams-config-dal";
|
||||||
|
import { TNotificationServiceFactory } from "../notification/notification-service";
|
||||||
|
import { NotificationType } from "../notification/notification-types";
|
||||||
import { TOrgDALFactory } from "../org/org-dal";
|
import { TOrgDALFactory } from "../org/org-dal";
|
||||||
import { TPkiAlertDALFactory } from "../pki-alert/pki-alert-dal";
|
import { TPkiAlertDALFactory } from "../pki-alert/pki-alert-dal";
|
||||||
import { TPkiCollectionDALFactory } from "../pki-collection/pki-collection-dal";
|
import { TPkiCollectionDALFactory } from "../pki-collection/pki-collection-dal";
|
||||||
@@ -183,6 +185,7 @@ type TProjectServiceFactoryDep = {
|
|||||||
>;
|
>;
|
||||||
projectTemplateService: TProjectTemplateServiceFactory;
|
projectTemplateService: TProjectTemplateServiceFactory;
|
||||||
reminderService: Pick<TReminderServiceFactory, "deleteReminderBySecretId">;
|
reminderService: Pick<TReminderServiceFactory, "deleteReminderBySecretId">;
|
||||||
|
notificationService: Pick<TNotificationServiceFactory, "createUserNotifications">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TProjectServiceFactory = ReturnType<typeof projectServiceFactory>;
|
export type TProjectServiceFactory = ReturnType<typeof projectServiceFactory>;
|
||||||
@@ -227,7 +230,8 @@ export const projectServiceFactory = ({
|
|||||||
projectTemplateService,
|
projectTemplateService,
|
||||||
groupProjectDAL,
|
groupProjectDAL,
|
||||||
smtpService,
|
smtpService,
|
||||||
reminderService
|
reminderService,
|
||||||
|
notificationService
|
||||||
}: TProjectServiceFactoryDep) => {
|
}: TProjectServiceFactoryDep) => {
|
||||||
/*
|
/*
|
||||||
* Create workspace. Make user the admin
|
* Create workspace. Make user the admin
|
||||||
@@ -1924,6 +1928,21 @@ export const projectServiceFactory = ({
|
|||||||
projectTypeUrl = "cert-management";
|
projectTypeUrl = "cert-management";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const callbackPath = `/projects/${projectTypeUrl}/${project.id}/access-management?selectedTab=members&requesterEmail=${userDetails.email}`;
|
||||||
|
|
||||||
|
await notificationService.createUserNotifications(
|
||||||
|
projectMembers
|
||||||
|
.filter((member) => member.roles.some((role) => role.role === ProjectMembershipRole.Admin))
|
||||||
|
.map((member) => ({
|
||||||
|
userId: member.userId,
|
||||||
|
orgId: project.orgId,
|
||||||
|
type: NotificationType.PROJECT_ACCESS_REQUEST,
|
||||||
|
title: "Project Access Request",
|
||||||
|
body: `**${userDetails.firstName} ${userDetails.lastName}** (${userDetails.email}) has requested access to the project **${project.name}**.`,
|
||||||
|
link: callbackPath
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
template: SmtpTemplates.ProjectAccessRequest,
|
template: SmtpTemplates.ProjectAccessRequest,
|
||||||
recipients: filteredProjectMembers,
|
recipients: filteredProjectMembers,
|
||||||
@@ -1934,7 +1953,7 @@ export const projectServiceFactory = ({
|
|||||||
projectName: project?.name,
|
projectName: project?.name,
|
||||||
orgName: org?.name,
|
orgName: org?.name,
|
||||||
note: comment,
|
note: comment,
|
||||||
callback_url: `${appCfg.SITE_URL}/projects/${projectTypeUrl}/${project.id}/access-management?selectedTab=members&requesterEmail=${userDetails.email}`
|
callback_url: `${appCfg.SITE_URL}${callbackPath}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user