Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added webhook notifications toggle #1107

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions frontend/types/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;
Expand Down
Loading