From 3b55cf37ade201b29be6106b6f8121c2f9b80548 Mon Sep 17 00:00:00 2001 From: Stefan Pletka <124689083+Eisei24@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:25:10 +0100 Subject: [PATCH 1/2] Added webhook notifications toggle --- backend/pkg/api/data_access/notifications.go | 16 ++++++++++++---- backend/pkg/api/types/notifications.go | 7 ++++--- frontend/types/api/notifications.ts | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/backend/pkg/api/data_access/notifications.go b/backend/pkg/api/data_access/notifications.go index 0a07f5b7c..40115691d 100644 --- a/backend/pkg/api/data_access/notifications.go +++ b/backend/pkg/api/data_access/notifications.go @@ -1181,10 +1181,15 @@ func (d *DataAccessService) GetNotificationSettings(ctx context.Context, userId } for _, channel := range notificationChannels { - if channel.Channel == types.EmailNotificationChannel { + switch channel.Channel { + case types.EmailNotificationChannel: result.GeneralSettings.IsEmailNotificationsEnabled = channel.Active - } else if channel.Channel == types.PushNotificationChannel { + case types.PushNotificationChannel: result.GeneralSettings.IsPushNotificationsEnabled = channel.Active + case types.WebhookNotificationChannel: + result.GeneralSettings.IsWebhookNotificationsEnabled = channel.Active + default: + log.Warnf("notification channel is not defined: %s (user_id: %d)", channel.Channel, userId) } } @@ -1315,10 +1320,13 @@ func (d *DataAccessService) UpdateNotificationSettingsGeneral(ctx context.Contex // Set the notification channels _, err = tx.ExecContext(ctx, ` INSERT INTO users_notification_channels (user_id, channel, active) - VALUES ($1, $2, $3), ($1, $4, $5) + VALUES ($1, $2, $3), ($1, $4, $5), ($1, $6, $7) ON CONFLICT (user_id, channel) DO UPDATE SET active = EXCLUDED.active`, - userId, types.EmailNotificationChannel, settings.IsEmailNotificationsEnabled, types.PushNotificationChannel, settings.IsPushNotificationsEnabled) + userId, + types.EmailNotificationChannel, settings.IsEmailNotificationsEnabled, + types.PushNotificationChannel, settings.IsPushNotificationsEnabled, + types.WebhookNotificationChannel, settings.IsWebhookNotificationsEnabled) if err != nil { return err } diff --git a/backend/pkg/api/types/notifications.go b/backend/pkg/api/types/notifications.go index d3616a7bc..23a3ea0e9 100644 --- a/backend/pkg/api/types/notifications.go +++ b/backend/pkg/api/types/notifications.go @@ -165,9 +165,10 @@ type NotificationSettingsClient struct { type InternalPutUserNotificationSettingsClientResponse ApiDataResponse[NotificationSettingsClient] type NotificationSettingsGeneral struct { - DoNotDisturbTimestamp int64 `json:"do_not_disturb_timestamp"` // notifications are disabled until this timestamp - IsEmailNotificationsEnabled bool `json:"is_email_notifications_enabled"` - IsPushNotificationsEnabled bool `json:"is_push_notifications_enabled"` + DoNotDisturbTimestamp int64 `json:"do_not_disturb_timestamp"` // notifications are disabled until this timestamp + IsEmailNotificationsEnabled bool `json:"is_email_notifications_enabled"` + IsPushNotificationsEnabled bool `json:"is_push_notifications_enabled"` + IsWebhookNotificationsEnabled bool `json:"is_webhook_notifications_enabled"` IsMachineOfflineSubscribed bool `json:"is_machine_offline_subscribed"` IsMachineStorageUsageSubscribed bool `json:"is_machine_storage_usage_subscribed"` diff --git a/frontend/types/api/notifications.ts b/frontend/types/api/notifications.ts index c49b9db1e..3cc00afa8 100644 --- a/frontend/types/api/notifications.ts +++ b/frontend/types/api/notifications.ts @@ -157,6 +157,7 @@ export interface NotificationSettingsGeneral { do_not_disturb_timestamp: number /* int64 */; // notifications are disabled until this timestamp is_email_notifications_enabled: boolean; is_push_notifications_enabled: boolean; + is_webhook_notifications_enabled: boolean; is_machine_offline_subscribed: boolean; is_machine_storage_usage_subscribed: boolean; machine_storage_usage_threshold: number /* float64 */; From 364304bd77d37643b6e4f5b650a5385e7ad66079 Mon Sep 17 00:00:00 2001 From: Stefan Pletka <124689083+Eisei24@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:36:57 +0100 Subject: [PATCH 2/2] Fixed frontend issue --- frontend/stores/notifications/useNotificationsManagementStore.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/stores/notifications/useNotificationsManagementStore.ts b/frontend/stores/notifications/useNotificationsManagementStore.ts index 17570732d..ae6a1f716 100644 --- a/frontend/stores/notifications/useNotificationsManagementStore.ts +++ b/frontend/stores/notifications/useNotificationsManagementStore.ts @@ -22,6 +22,7 @@ export const useNotificationsManagementStore = defineStore('notifications-manage is_machine_offline_subscribed: false, is_machine_storage_usage_subscribed: false, is_push_notifications_enabled: false, + is_webhook_notifications_enabled: false, machine_cpu_usage_threshold: 0.0, machine_memory_usage_threshold: 0.0, machine_storage_usage_threshold: 0.0,