package service import ( "bytes" "html/template" "strings" "go.uber.org/zap" "github.com/prabhupadasays/spsays-bff/internal/model" ) // defaultAdminURL is where the welcome email sends new staff when ADMIN_URL // isn't configured (local development leaves it empty). const defaultAdminURL = "https://admin.prabhupadasays.org" // sendStaffWelcome tells someone they've been given admin access, and as // what. Fire-and-forget, like the other notification emails: the grant is // already committed, so a mail failure is logged, never surfaced. func (s *StaffService) sendStaffWelcome(m *model.StaffMember) { if s.mail == nil { return } if m.Email == nil || strings.TrimSpace(*m.Email) == "" { s.logger.Info("staff granted; no email on file, skipping welcome", zap.String("user_id", m.UserID)) return } var buf bytes.Buffer if err := staffWelcomeEmailTpl.Execute(&buf, map[string]any{ "RecipientName": strings.TrimSpace(m.Name), "RoleName": m.RoleName, "AdminURL": s.adminURL, }); err != nil { s.logger.Warn("render staff welcome email failed", zap.Error(err)) return } to := strings.TrimSpace(*m.Email) go func() { if err := s.mail.Send(to, "You've been promoted to "+m.RoleName+" — Prabhupāda Says", buf.String()); err != nil { s.logger.Warn("staff welcome email send failed", zap.String("user_id", m.UserID), zap.Error(err)) } }() } // staffWelcomeEmailTpl — same styling as the other account emails. The role // name is admin-entered (custom roles) and auto-escaped by html/template. var staffWelcomeEmailTpl = template.Must(template.New("staffWelcome").Parse(`
Hare Kṛṣṇa{{if .RecipientName}}, {{.RecipientName}}{{end}} 🙏
You have been promoted to {{.RoleName}} on Prabhupāda Says.
Log in with your email and password at {{.AdminURL}}.
For any queries, contact your co-ordinator.
Your servants,
The Prabhupāda Says team