mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-17 18:19:50 +00:00
Merge remote-tracking branch 'origin/main' into feat/gateway-v2
This commit is contained in:
@@ -225,6 +225,11 @@ import { kmsServiceFactory } from "@app/services/kms/kms-service";
|
||||
import { microsoftTeamsIntegrationDALFactory } from "@app/services/microsoft-teams/microsoft-teams-integration-dal";
|
||||
import { microsoftTeamsServiceFactory } from "@app/services/microsoft-teams/microsoft-teams-service";
|
||||
import { projectMicrosoftTeamsConfigDALFactory } from "@app/services/microsoft-teams/project-microsoft-teams-config-dal";
|
||||
import { notificationQueueServiceFactory } from "@app/services/notification/notification-queue";
|
||||
import { notificationServiceFactory } from "@app/services/notification/notification-service";
|
||||
import { userNotificationDALFactory } from "@app/services/notification/user-notification-dal";
|
||||
import { offlineUsageReportDALFactory } from "@app/services/offline-usage-report/offline-usage-report-dal";
|
||||
import { offlineUsageReportServiceFactory } from "@app/services/offline-usage-report/offline-usage-report-service";
|
||||
import { incidentContactDALFactory } from "@app/services/org/incident-contacts-dal";
|
||||
import { orgBotDALFactory } from "@app/services/org/org-bot-dal";
|
||||
import { orgDALFactory } from "@app/services/org/org-dal";
|
||||
@@ -298,8 +303,6 @@ import { TSmtpService } from "@app/services/smtp/smtp-service";
|
||||
import { invalidateCacheQueueFactory } from "@app/services/super-admin/invalidate-cache-queue";
|
||||
import { TSuperAdminDALFactory } from "@app/services/super-admin/super-admin-dal";
|
||||
import { getServerCfg, superAdminServiceFactory } from "@app/services/super-admin/super-admin-service";
|
||||
import { offlineUsageReportDALFactory } from "@app/services/offline-usage-report/offline-usage-report-dal";
|
||||
import { offlineUsageReportServiceFactory } from "@app/services/offline-usage-report/offline-usage-report-service";
|
||||
import { telemetryDALFactory } from "@app/services/telemetry/telemetry-dal";
|
||||
import { telemetryQueueServiceFactory } from "@app/services/telemetry/telemetry-queue";
|
||||
import { telemetryServiceFactory } from "@app/services/telemetry/telemetry-service";
|
||||
@@ -429,6 +432,7 @@ export const registerRoutes = async (
|
||||
const telemetryDAL = telemetryDALFactory(db);
|
||||
const appConnectionDAL = appConnectionDALFactory(db);
|
||||
const secretSyncDAL = secretSyncDALFactory(db, folderDAL);
|
||||
const userNotificationDAL = userNotificationDALFactory(db);
|
||||
|
||||
// ee db layer ops
|
||||
const permissionDAL = permissionDALFactory(db);
|
||||
@@ -581,6 +585,13 @@ export const registerRoutes = async (
|
||||
auditLogStreamService
|
||||
});
|
||||
|
||||
const notificationQueue = await notificationQueueServiceFactory({
|
||||
userNotificationDAL,
|
||||
queueService
|
||||
});
|
||||
|
||||
const notificationService = notificationServiceFactory({ notificationQueue, userNotificationDAL });
|
||||
|
||||
const auditLogService = auditLogServiceFactory({ auditLogDAL, permissionService, auditLogQueue });
|
||||
const secretApprovalPolicyService = secretApprovalPolicyServiceFactory({
|
||||
projectEnvDAL,
|
||||
@@ -1414,7 +1425,8 @@ export const registerRoutes = async (
|
||||
kmsService,
|
||||
groupDAL,
|
||||
microsoftTeamsService,
|
||||
projectMicrosoftTeamsConfigDAL
|
||||
projectMicrosoftTeamsConfigDAL,
|
||||
notificationService
|
||||
});
|
||||
|
||||
const secretReplicationService = secretReplicationServiceFactory({
|
||||
@@ -1718,7 +1730,8 @@ export const registerRoutes = async (
|
||||
secretVersionV2DAL: secretVersionV2BridgeDAL,
|
||||
identityUniversalAuthClientSecretDAL: identityUaClientSecretDAL,
|
||||
serviceTokenService,
|
||||
orgService
|
||||
orgService,
|
||||
userNotificationDAL
|
||||
});
|
||||
|
||||
const dailyReminderQueueService = dailyReminderQueueServiceFactory({
|
||||
@@ -2143,6 +2156,8 @@ export const registerRoutes = async (
|
||||
kmip: kmipService,
|
||||
kmipOperation: kmipOperationService,
|
||||
gateway: gatewayService,
|
||||
relay: relayService,
|
||||
gatewayV2: gatewayV2Service,
|
||||
secretRotationV2: secretRotationV2Service,
|
||||
microsoftTeams: microsoftTeamsService,
|
||||
assumePrivileges: assumePrivilegeService,
|
||||
@@ -2152,8 +2167,7 @@ export const registerRoutes = async (
|
||||
reminder: reminderService,
|
||||
bus: eventBusService,
|
||||
sse: sseService,
|
||||
relay: relayService,
|
||||
gatewayV2: gatewayV2Service
|
||||
notification: notificationService
|
||||
});
|
||||
|
||||
const cronJobs: CronJob[] = [];
|
||||
|
||||
@@ -33,6 +33,7 @@ import { registerIntegrationAuthRouter } from "./integration-auth-router";
|
||||
import { registerIntegrationRouter } from "./integration-router";
|
||||
import { registerInviteOrgRouter } from "./invite-org-router";
|
||||
import { registerMicrosoftTeamsRouter } from "./microsoft-teams-router";
|
||||
import { registerNotificationRouter } from "./notification-router";
|
||||
import { registerOrgAdminRouter } from "./org-admin-router";
|
||||
import { registerOrgRouter } from "./organization-router";
|
||||
import { registerPasswordRouter } from "./password-router";
|
||||
@@ -83,6 +84,7 @@ export const registerV1Routes = async (server: FastifyZodProvider) => {
|
||||
await server.register(registerAdminRouter, { prefix: "/admin" });
|
||||
await server.register(registerOrgAdminRouter, { prefix: "/organization-admin" });
|
||||
await server.register(registerUserRouter, { prefix: "/user" });
|
||||
await server.register(registerNotificationRouter, { prefix: "/notifications" });
|
||||
await server.register(registerInviteOrgRouter, { prefix: "/invite-org" });
|
||||
await server.register(registerUserActionRouter, { prefix: "/user-action" });
|
||||
await server.register(registerSecretImportRouter, { prefix: "/secret-imports" });
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { UserNotificationsSchema } from "@app/db/schemas/user-notifications";
|
||||
import { UnauthorizedError } from "@app/lib/errors";
|
||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
|
||||
export const registerNotificationRouter = async (server: FastifyZodProvider) => {
|
||||
server.route({
|
||||
url: "/user",
|
||||
config: {
|
||||
rateLimit: readLimit
|
||||
},
|
||||
method: "GET",
|
||||
schema: {
|
||||
response: {
|
||||
200: z.object({
|
||||
notifications: UserNotificationsSchema.array()
|
||||
})
|
||||
}
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.authMode !== AuthMode.JWT) {
|
||||
throw new UnauthorizedError({ message: "This endpoint can only be accessed by users" });
|
||||
}
|
||||
|
||||
const notifications = await server.services.notification.listUserNotifications({
|
||||
userId: req.auth.userId,
|
||||
orgId: req.auth.orgId
|
||||
});
|
||||
|
||||
return { notifications };
|
||||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
url: "/user/:notificationId",
|
||||
config: {
|
||||
rateLimit: writeLimit
|
||||
},
|
||||
method: "DELETE",
|
||||
schema: {
|
||||
params: z.object({
|
||||
notificationId: z.string()
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
notification: UserNotificationsSchema
|
||||
})
|
||||
}
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.authMode !== AuthMode.JWT) {
|
||||
throw new UnauthorizedError({ message: "This endpoint can only be accessed by users" });
|
||||
}
|
||||
|
||||
const notification = await server.services.notification.deleteUserNotification({
|
||||
notificationId: req.params.notificationId,
|
||||
userId: req.auth.userId
|
||||
});
|
||||
|
||||
return { notification };
|
||||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
url: "/user/:notificationId",
|
||||
config: {
|
||||
rateLimit: writeLimit
|
||||
},
|
||||
method: "PATCH",
|
||||
schema: {
|
||||
params: z.object({
|
||||
notificationId: z.string()
|
||||
}),
|
||||
body: z.object({
|
||||
isRead: z.boolean()
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
notification: UserNotificationsSchema
|
||||
})
|
||||
}
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.authMode !== AuthMode.JWT) {
|
||||
throw new UnauthorizedError({ message: "This endpoint can only be accessed by users" });
|
||||
}
|
||||
|
||||
const notification = await server.services.notification.updateUserNotification({
|
||||
notificationId: req.params.notificationId,
|
||||
userId: req.auth.userId,
|
||||
...req.body
|
||||
});
|
||||
|
||||
return { notification };
|
||||
}
|
||||
});
|
||||
|
||||
// Mark all user notifications as read
|
||||
server.route({
|
||||
url: "/user/mark-as-read",
|
||||
config: {
|
||||
rateLimit: writeLimit
|
||||
},
|
||||
method: "POST",
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
handler: async (req) => {
|
||||
if (req.auth.authMode !== AuthMode.JWT) {
|
||||
throw new UnauthorizedError({ message: "This endpoint can only be accessed by users" });
|
||||
}
|
||||
|
||||
await server.services.notification.markUserNotificationsAsRead({
|
||||
userId: req.auth.userId,
|
||||
orgId: req.auth.orgId
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user