Skip to content

Commit e9e6064

Browse files
authored
Merge pull request #646 from Dokploy/fix/notifications
fix(dokploy): filter notifications by admin
2 parents 8af5afb + 6b7712e commit e9e6064

File tree

11 files changed

+45
-10
lines changed

11 files changed

+45
-10
lines changed

apps/dokploy/server/api/routers/settings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export const settingsRouter = createTRPCRouter({
242242
await cleanUpUnusedImages(server.serverId);
243243
await cleanUpDockerBuilder(server.serverId);
244244
await cleanUpSystemPrune(server.serverId);
245-
await sendDockerCleanupNotifications();
245+
await sendDockerCleanupNotifications(server.adminId);
246246
});
247247
}
248248
} else {
@@ -278,7 +278,7 @@ export const settingsRouter = createTRPCRouter({
278278
await cleanUpUnusedImages();
279279
await cleanUpDockerBuilder();
280280
await cleanUpSystemPrune();
281-
await sendDockerCleanupNotifications();
281+
await sendDockerCleanupNotifications(admin.adminId);
282282
});
283283
} else {
284284
const currentJob = scheduledJobs["docker-cleanup"];

packages/server/src/services/application.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export const deployApplication = async ({
193193
applicationName: application.name,
194194
applicationType: "application",
195195
buildLink,
196+
adminId: application.project.adminId,
196197
});
197198
} catch (error) {
198199
await updateDeploymentStatus(deployment.deploymentId, "error");
@@ -204,6 +205,7 @@ export const deployApplication = async ({
204205
// @ts-ignore
205206
errorMessage: error?.message || "Error to build",
206207
buildLink,
208+
adminId: application.project.adminId,
207209
});
208210

209211
console.log(
@@ -314,6 +316,7 @@ export const deployRemoteApplication = async ({
314316
applicationName: application.name,
315317
applicationType: "application",
316318
buildLink,
319+
adminId: application.project.adminId,
317320
});
318321
} catch (error) {
319322
// @ts-ignore
@@ -336,6 +339,7 @@ export const deployRemoteApplication = async ({
336339
// @ts-ignore
337340
errorMessage: error?.message || "Error to build",
338341
buildLink,
342+
adminId: application.project.adminId,
339343
});
340344

341345
console.log(

packages/server/src/services/compose.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export const deployCompose = async ({
235235
applicationName: compose.name,
236236
applicationType: "compose",
237237
buildLink,
238+
adminId: compose.project.adminId,
238239
});
239240
} catch (error) {
240241
await updateDeploymentStatus(deployment.deploymentId, "error");
@@ -248,6 +249,7 @@ export const deployCompose = async ({
248249
// @ts-ignore
249250
errorMessage: error?.message || "Error to build",
250251
buildLink,
252+
adminId: compose.project.adminId,
251253
});
252254
throw error;
253255
}
@@ -353,6 +355,7 @@ export const deployRemoteCompose = async ({
353355
applicationName: compose.name,
354356
applicationType: "compose",
355357
buildLink,
358+
adminId: compose.project.adminId,
356359
});
357360
} catch (error) {
358361
// @ts-ignore
@@ -376,6 +379,7 @@ export const deployRemoteCompose = async ({
376379
// @ts-ignore
377380
errorMessage: error?.message || "Error to build",
378381
buildLink,
382+
adminId: compose.project.adminId,
379383
});
380384
throw error;
381385
}

packages/server/src/utils/backups/mariadb.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const runMariadbBackup = async (
4949
projectName: project.name,
5050
databaseType: "mariadb",
5151
type: "success",
52+
adminId: project.adminId,
5253
});
5354
} catch (error) {
5455
console.log(error);
@@ -59,6 +60,7 @@ export const runMariadbBackup = async (
5960
type: "error",
6061
// @ts-ignore
6162
errorMessage: error?.message || "Error message not provided",
63+
adminId: project.adminId,
6264
});
6365
throw error;
6466
}

packages/server/src/utils/backups/mongo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
4646
projectName: project.name,
4747
databaseType: "mongodb",
4848
type: "success",
49+
adminId: project.adminId,
4950
});
5051
} catch (error) {
5152
console.log(error);
@@ -56,6 +57,7 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
5657
type: "error",
5758
// @ts-ignore
5859
errorMessage: error?.message || "Error message not provided",
60+
adminId: project.adminId,
5961
});
6062
throw error;
6163
}

packages/server/src/utils/backups/mysql.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
4646
projectName: project.name,
4747
databaseType: "mysql",
4848
type: "success",
49+
adminId: project.adminId,
4950
});
5051
} catch (error) {
5152
console.log(error);
@@ -56,6 +57,7 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
5657
type: "error",
5758
// @ts-ignore
5859
errorMessage: error?.message || "Error message not provided",
60+
adminId: project.adminId,
5961
});
6062
throw error;
6163
}

packages/server/src/utils/backups/postgres.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const runPostgresBackup = async (
4949
projectName: project.name,
5050
databaseType: "postgres",
5151
type: "success",
52+
adminId: project.adminId,
5253
});
5354
} catch (error) {
5455
await sendDatabaseBackupNotifications({
@@ -58,6 +59,7 @@ export const runPostgresBackup = async (
5859
type: "error",
5960
// @ts-ignore
6061
errorMessage: error?.message || "Error message not provided",
62+
adminId: project.adminId,
6163
});
6264

6365
throw error;

packages/server/src/utils/notifications/build-error.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { db } from "@dokploy/server/db";
22
import { notifications } from "@dokploy/server/db/schema";
33
import BuildFailedEmail from "@dokploy/server/emails/emails/build-failed";
44
import { renderAsync } from "@react-email/components";
5-
import { eq } from "drizzle-orm";
5+
import { and, eq } from "drizzle-orm";
66
import {
77
sendDiscordNotification,
88
sendEmailNotification,
@@ -16,6 +16,7 @@ interface Props {
1616
applicationType: string;
1717
errorMessage: string;
1818
buildLink: string;
19+
adminId: string;
1920
}
2021

2122
export const sendBuildErrorNotifications = async ({
@@ -24,10 +25,14 @@ export const sendBuildErrorNotifications = async ({
2425
applicationType,
2526
errorMessage,
2627
buildLink,
28+
adminId,
2729
}: Props) => {
2830
const date = new Date();
2931
const notificationList = await db.query.notifications.findMany({
30-
where: eq(notifications.appBuildError, true),
32+
where: and(
33+
eq(notifications.appBuildError, true),
34+
eq(notifications.adminId, adminId),
35+
),
3136
with: {
3237
email: true,
3338
discord: true,

packages/server/src/utils/notifications/build-success.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { db } from "@dokploy/server/db";
22
import { notifications } from "@dokploy/server/db/schema";
33
import BuildSuccessEmail from "@dokploy/server/emails/emails/build-success";
44
import { renderAsync } from "@react-email/components";
5-
import { eq } from "drizzle-orm";
5+
import { and, eq } from "drizzle-orm";
66
import {
77
sendDiscordNotification,
88
sendEmailNotification,
@@ -15,17 +15,22 @@ interface Props {
1515
applicationName: string;
1616
applicationType: string;
1717
buildLink: string;
18+
adminId: string;
1819
}
1920

2021
export const sendBuildSuccessNotifications = async ({
2122
projectName,
2223
applicationName,
2324
applicationType,
2425
buildLink,
26+
adminId,
2527
}: Props) => {
2628
const date = new Date();
2729
const notificationList = await db.query.notifications.findMany({
28-
where: eq(notifications.appDeploy, true),
30+
where: and(
31+
eq(notifications.appDeploy, true),
32+
eq(notifications.adminId, adminId),
33+
),
2934
with: {
3035
email: true,
3136
discord: true,

packages/server/src/utils/notifications/database-backup.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { db } from "@dokploy/server/db";
22
import { notifications } from "@dokploy/server/db/schema";
33
import DatabaseBackupEmail from "@dokploy/server/emails/emails/database-backup";
44
import { renderAsync } from "@react-email/components";
5-
import { eq } from "drizzle-orm";
5+
import { and, eq } from "drizzle-orm";
66
import {
77
sendDiscordNotification,
88
sendEmailNotification,
@@ -16,16 +16,21 @@ export const sendDatabaseBackupNotifications = async ({
1616
databaseType,
1717
type,
1818
errorMessage,
19+
adminId,
1920
}: {
2021
projectName: string;
2122
applicationName: string;
2223
databaseType: "postgres" | "mysql" | "mongodb" | "mariadb";
2324
type: "error" | "success";
25+
adminId: string;
2426
errorMessage?: string;
2527
}) => {
2628
const date = new Date();
2729
const notificationList = await db.query.notifications.findMany({
28-
where: eq(notifications.databaseBackup, true),
30+
where: and(
31+
eq(notifications.databaseBackup, true),
32+
eq(notifications.adminId, adminId),
33+
),
2934
with: {
3035
email: true,
3136
discord: true,

packages/server/src/utils/notifications/docker-cleanup.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { db } from "@dokploy/server/db";
22
import { notifications } from "@dokploy/server/db/schema";
33
import DockerCleanupEmail from "@dokploy/server/emails/emails/docker-cleanup";
44
import { renderAsync } from "@react-email/components";
5-
import { eq } from "drizzle-orm";
5+
import { and, eq } from "drizzle-orm";
66
import {
77
sendDiscordNotification,
88
sendEmailNotification,
@@ -11,11 +11,15 @@ import {
1111
} from "./utils";
1212

1313
export const sendDockerCleanupNotifications = async (
14+
adminId: string,
1415
message = "Docker cleanup for dokploy",
1516
) => {
1617
const date = new Date();
1718
const notificationList = await db.query.notifications.findMany({
18-
where: eq(notifications.dockerCleanup, true),
19+
where: and(
20+
eq(notifications.dockerCleanup, true),
21+
eq(notifications.adminId, adminId),
22+
),
1923
with: {
2024
email: true,
2125
discord: true,

0 commit comments

Comments
 (0)