diff --git a/backups.go b/backups.go index 33b16b2..eadad73 100644 --- a/backups.go +++ b/backups.go @@ -214,7 +214,6 @@ func (app *appContext) makeBackup() (fileDetails CreateBackupDTO) { count += 1 backupsByCommit[b.Commit] = count } - fmt.Printf("remaining:%+v\n", backupsByCommit) } // fmt.Printf("toDelete: %d, backCount: %d, keep: %d, length: %d\n", toDelete, backups.count, toKeep, len(backups.files)) if toDelete > 0 && toDelete <= backups.count { diff --git a/email.go b/email.go index 78e94a1..1660dc6 100644 --- a/email.go +++ b/email.go @@ -492,6 +492,7 @@ func (emailer *Emailer) constructDeleted(username, reason string, placeholders b reason = "{reason}" } contentInfo, template := emailer.baseValues("UserDeleted", username, placeholders, map[string]any{ + "helloUser": emailer.lang.Strings.template("helloUser", tmpl{"username": username}), "yourAccountWas": emailer.lang.UserDeleted.get("yourAccountWasDeleted"), "reasonString": emailer.lang.Strings.get("reason"), "reason": reason, @@ -506,6 +507,7 @@ func (emailer *Emailer) constructDisabled(username, reason string, placeholders reason = "{reason}" } contentInfo, template := emailer.baseValues("UserDisabled", username, placeholders, map[string]any{ + "helloUser": emailer.lang.Strings.template("helloUser", tmpl{"username": username}), "yourAccountWas": emailer.lang.UserDisabled.get("yourAccountWasDisabled"), "reasonString": emailer.lang.Strings.get("reason"), "reason": reason, @@ -520,6 +522,7 @@ func (emailer *Emailer) constructEnabled(username, reason string, placeholders b reason = "{reason}" } contentInfo, template := emailer.baseValues("UserEnabled", username, placeholders, map[string]any{ + "helloUser": emailer.lang.Strings.template("helloUser", tmpl{"username": username}), "yourAccountWas": emailer.lang.UserEnabled.get("yourAccountWasEnabled"), "reasonString": emailer.lang.Strings.get("reason"), "reason": reason, diff --git a/email_test.go b/email_test.go index 0e33225..25e15fb 100644 --- a/email_test.go +++ b/email_test.go @@ -1,8 +1,6 @@ package main import ( - "embed" - "errors" "fmt" "io/fs" "log" @@ -18,8 +16,6 @@ import ( "github.com/timshannon/badgerhold/v4" ) -//go:embed build/data/config-default.ini -var configFS embed.FS var db *badgerhold.Store func dbClose(e *Emailer) { @@ -34,9 +30,6 @@ func Fatal(err any) { // NewTestEmailer initialises most of what the emailer depends on, which happens to be most of the app. func NewTestEmailer() (*Emailer, error) { - if binaryType != "external" { - return nil, errors.New("test only supported with -tags \"external\"") - } emailer := &Emailer{ fromAddr: "from@addr", fromName: "fromName", @@ -47,20 +40,16 @@ func NewTestEmailer() (*Emailer, error) { }, sender: &DummyClient{}, } - dConfig, err := fs.ReadFile(configFS, "build/data/config-default.ini") - if err != nil { - return emailer, err - } - wd, err := os.Getwd() + // Assume our working directory is the root of the repo + wd, _ := os.Getwd() + loadFilesystems(filepath.Join(wd, "build"), logger.NewEmptyLogger()) + dConfig, err := fs.ReadFile(localFS, "config-default.ini") if err != nil { return emailer, err } // Force emailer to construct markdown discordEnabled = true - // Use working directory - localFS = dirFS(filepath.Join(wd, "build", "data")) - langFS = dirFS(filepath.Join(wd, "build", "data", "lang")) noInfoLS := emailer.LoggerSet noInfoLS.info = logger.NewEmptyLogger() emailer.config, err = NewConfig(dConfig, "/tmp/jfa-go-test", noInfoLS) @@ -327,13 +316,17 @@ func TestDeleted(t *testing.T) { } testContent(e, customContent["UserDeleted"], t, func(t *testing.T) { reason := shortuuid.New() - msg, err := e.constructDeleted(reason, false) + username := shortuuid.New() + msg, err := e.constructDeleted(username, reason, false) if err != nil { t.Fatalf("failed construct: %+v", err) } for _, content := range []string{msg.Text, msg.HTML} { if !strings.Contains(content, reason) { - t.Fatalf("reason n)ot found in output: %s", content) + t.Fatalf("reason not found in output: %s", content) + } + if !strings.Contains(content, username) { + t.Fatalf("username not found in output: %s", content) } } }) @@ -348,7 +341,8 @@ func TestDisabled(t *testing.T) { } testContent(e, customContent["UserDeleted"], t, func(t *testing.T) { reason := shortuuid.New() - msg, err := e.constructDisabled(reason, false) + username := shortuuid.New() + msg, err := e.constructDisabled(username, reason, false) if err != nil { t.Fatalf("failed construct: %+v", err) } @@ -356,6 +350,9 @@ func TestDisabled(t *testing.T) { if !strings.Contains(content, reason) { t.Fatalf("reason not found in output: %s", content) } + if !strings.Contains(content, username) { + t.Fatalf("username not found in output: %s", content) + } } }) } @@ -369,7 +366,8 @@ func TestEnabled(t *testing.T) { } testContent(e, customContent["UserDeleted"], t, func(t *testing.T) { reason := shortuuid.New() - msg, err := e.constructEnabled(reason, false) + username := shortuuid.New() + msg, err := e.constructEnabled(username, reason, false) if err != nil { t.Fatalf("failed construct: %+v", err) } @@ -377,6 +375,9 @@ func TestEnabled(t *testing.T) { if !strings.Contains(content, reason) { t.Fatalf("reason not found in output: %s", content) } + if !strings.Contains(content, username) { + t.Fatalf("username not found in output: %s", content) + } } }) } diff --git a/external.go b/external.go index df69e94..3036a89 100644 --- a/external.go +++ b/external.go @@ -4,10 +4,11 @@ package main import ( - "log" "os" "path/filepath" "strings" + + "github.com/hrfee/jfa-go/logger" ) const binaryType = "external" @@ -28,9 +29,12 @@ func FSJoin(elem ...string) string { return strings.TrimSuffix(path, sep) } -func loadFilesystems() { - log.Println("Using external storage") - executable, _ := os.Executable() - localFS = dirFS(filepath.Join(filepath.Dir(executable), "data")) - langFS = dirFS(filepath.Join(filepath.Dir(executable), "data", "lang")) +func loadFilesystems(rootDir string, logger *logger.Logger) { + logger.Println("Using external storage") + if rootDir == "" { + executable, _ := os.Executable() + rootDir = filepath.Dir(executable) + } + localFS = dirFS(filepath.Join(rootDir, "data")) + langFS = dirFS(filepath.Join(rootDir, "data", "lang")) } diff --git a/internal.go b/internal.go index 2f6046e..0e521c5 100644 --- a/internal.go +++ b/internal.go @@ -6,7 +6,8 @@ package main import ( "embed" "io/fs" - "log" + + "github.com/hrfee/jfa-go/logger" ) const binaryType = "internal" @@ -35,8 +36,8 @@ func FSJoin(elem ...string) string { return out[:len(out)-1] } -func loadFilesystems() { +func loadFilesystems(rootDir string, logger *logger.Logger) { langFS = rewriteFS{laFS, "lang/"} localFS = rewriteFS{loFS, "data/"} - log.Println("Using internal storage") + logger.Println("Using internal storage") } diff --git a/mail/deleted.mjml b/mail/deleted.mjml index 28f3e72..066f59b 100644 --- a/mail/deleted.mjml +++ b/mail/deleted.mjml @@ -60,6 +60,8 @@ +

{{ .helloUser }}

+

{{ .yourAccountWas }}

{{ .reasonString }}: {{ .reason }}

diff --git a/mail/deleted.txt b/mail/deleted.txt index a6e90c4..e003e52 100644 --- a/mail/deleted.txt +++ b/mail/deleted.txt @@ -1,3 +1,5 @@ +{{ .helloUser }} + {{ .yourAccountWas }} {{ .reasonString }}: {{ .reason }} diff --git a/main.go b/main.go index 24d392f..e94f8a6 100644 --- a/main.go +++ b/main.go @@ -784,7 +784,8 @@ func main() { if flagPassed("test") { TEST = true } - loadFilesystems() + executable, _ := os.Executable() + loadFilesystems(filepath.Dir(executable), logger.NewLogger(os.Stdout, "[INFO] ", log.Ltime, color.FgHiWhite)) quit := make(chan os.Signal, 0) signal.Notify(quit, os.Interrupt, syscall.SIGTERM)