MCPcopy
hub / github.com/pocketbase/pocketbase / sendSystemAlert

Function sendSystemAlert

core/system_alert.go:89–131  ·  view source on GitHub ↗

sendSystemAlert sends a system error alert to a single superuser. note: unexported for now until there is clarity around the planned log level alerts.

(app App, superuser *Record, subject string, details string)

Source from the content-addressed store, hash-verified

87//
88// note: unexported for now until there is clarity around the planned log level alerts.
89func sendSystemAlert(app App, superuser *Record, subject string, details string) error {
90 if !superuser.IsSuperuser() {
91 return errors.New("system alerts can be sent only to superusers")
92 }
93
94 if subject == "" || details == "" {
95 return errors.New("system alerts subject and details are required")
96 }
97
98 data := struct {
99 AppName string
100 AlertDetails string
101 }{
102 AppName: app.Settings().Meta.AppName,
103 AlertDetails: details,
104 }
105
106 tpl := template.New("system_alert")
107
108 var parseErr error
109 tpl, parseErr = tpl.Parse(systemAlertHTML)
110 if parseErr != nil {
111 return parseErr
112 }
113
114 var buff bytes.Buffer
115 executeErr := tpl.Execute(&buff, data)
116 if executeErr != nil {
117 return executeErr
118 }
119
120 message := &mailer.Message{
121 From: mail.Address{
122 Name: app.Settings().Meta.SenderName,
123 Address: app.Settings().Meta.SenderAddress,
124 },
125 To: []mail.Address{{Address: superuser.Email()}},
126 Subject: "[" + app.Settings().Meta.AppName + " system alert] " + html.EscapeString(subject),
127 HTML: buff.String(),
128 }
129
130 return app.NewMailClient().Send(message)
131}

Callers 2

TestSendSystemAlertFunction · 0.85

Calls 8

IsSuperuserMethod · 0.80
ParseMethod · 0.80
ExecuteMethod · 0.80
EmailMethod · 0.80
SettingsMethod · 0.65
SendMethod · 0.65
NewMailClientMethod · 0.65
StringMethod · 0.45

Tested by 1

TestSendSystemAlertFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…