Repository navigation
Conversation
| const owner = await db.query.member.findFirst({ | ||
| where: eq(member.role, "owner"), | ||
| }); | ||
|
|
||
| organizationId = owner?.organizationId ?? ""; |
There was a problem hiding this comment.
Alerts reach the wrong organization
Creating another organization adds another member with role: "owner", so this lookup can match several rows. The unordered findFirst can select another organization's channels—or drop the alert if that organization has none enabled. Resolve the main host's intended organization explicitly instead of selecting an arbitrary owner.
| expect(mocks.findMany).toHaveBeenCalledOnce(); | ||
| const callArgs = mocks.findMany.mock.calls[0]?.[0]; | ||
| expect(callArgs).toBeDefined(); | ||
| expect(callArgs.where).toBeDefined(); |
There was a problem hiding this comment.
Tests miss incorrect organization filters
The scoped test only checks that where exists. The fallback tests return fixed rows regardless of the query, then check that a notification was sent. Both the old always-scoped query and an always-unscoped query would pass. Assert the generated SQL and parameters for populated and missing organizationId values so these tests catch wrong recipients or dropped alerts.
Summary
Resolves #5830 (Linear:
DOK-931).When
ServerType === "Dokploy"inreceiveNotification(apps/dokploy/server/api/routers/notification.ts),organizationIdwas hardcoded to"".In
packages/server/src/utils/notifications/server-threshold.ts, notifications were queried with:Because notifications saved in the UI always belong to a valid non-empty
organizationId, querying withorganizationId: ""matched zero rows. As a result, CPU and memory threshold alerts for the Dokploy main server were silently dropped, even though the metrics client received an HTTP 200/success response.Changes
Resolve Owner Organization for Dokploy Host:
receiveNotificationmutation (apps/dokploy/server/api/routers/notification.ts), look up the owner member record (db.query.member.findFirst({ where: eq(member.role, "owner") })), mirroring the host instance pattern used inpackages/server/src/utils/backups/index.ts.organizationId = owner?.organizationId ?? "".Resilient Notification Delivery Query:
sendServerThresholdNotifications(packages/server/src/utils/notifications/server-threshold.ts):organizationIdparameter type tostring | null | undefined.organizationIdfilter: if provided, filter byorganizationId; if empty/falsy, fall back to matching all enabledserverThreshold: truenotifications (mirroringdokploy-restart.ts), ensuring alerts are never silently dropped even if an owner record is missing.Hermetic Automated Tests:
apps/dokploy/__test__/notifications/server-threshold.test.tscovering:organizationIdis present.organizationIdis empty or undefined.apps/dokploy/__test__/notifications/receive-notification.test.tscovering:Resolve the main host's organization consistently before merging.
Summary
Routes main-server threshold alerts through an owner organization and adds a fallback when no organization is supplied.
Reviews (1) · Last reviewed commit: "fix(notifications): deliver main server ..." · Reviewed by Greptile