Files
Charon/backend/internal/models/notification_provider.go
GitHub Actions 34347b1ff5 Refactor uptime service and tests; add WAF configuration UI and e2e tests
- Refactored `SyncMonitors` method in `uptime_service.go` for better readability.
- Updated unit tests for `UptimeService` to ensure proper functionality.
- Introduced Playwright configuration for end-to-end testing.
- Added e2e tests for WAF blocking and monitoring functionality.
- Enhanced the Security page to include WAF mode and rule set selection.
- Implemented tests for WAF configuration changes and validation.
- Created a `.last-run.json` file to store test results.
2025-12-02 02:51:50 +00:00

49 lines
1.7 KiB
Go

package models
import (
"strings"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type NotificationProvider struct {
ID string `gorm:"primaryKey" json:"id"`
Name string `json:"name"`
Type string `json:"type"` // discord, slack, gotify, telegram, generic, webhook
URL string `json:"url"` // The shoutrrr URL or webhook URL
Config string `json:"config"` // JSON payload template for custom webhooks
Template string `json:"template" gorm:"default:minimal"` // minimal|detailed|custom
Enabled bool `json:"enabled"`
// Notification Preferences
NotifyProxyHosts bool `json:"notify_proxy_hosts" gorm:"default:true"`
NotifyRemoteServers bool `json:"notify_remote_servers" gorm:"default:true"`
NotifyDomains bool `json:"notify_domains" gorm:"default:true"`
NotifyCerts bool `json:"notify_certs" gorm:"default:true"`
NotifyUptime bool `json:"notify_uptime" gorm:"default:true"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (n *NotificationProvider) BeforeCreate(tx *gorm.DB) (err error) {
if n.ID == "" {
n.ID = uuid.New().String()
}
// Set defaults if not explicitly set (though gorm default tag handles DB side)
// We can't easily distinguish between false and unset for bools here without pointers,
// but for new creations via API, we can assume the frontend sends what it wants.
// If we wanted to force defaults in Go:
// n.NotifyProxyHosts = true ...
if strings.TrimSpace(n.Template) == "" {
if strings.TrimSpace(n.Config) != "" {
n.Template = "custom"
} else {
n.Template = "minimal"
}
}
return
}