diff --git a/api.go b/api.go index 001cc17..a5bd698 100644 --- a/api.go +++ b/api.go @@ -539,8 +539,9 @@ func (app *appContext) Announce(gc *gin.Context) { // @Router /users [delete] // @Security Bearer // @tags Users -func (app *appContext) DeleteUser(gc *gin.Context) { +func (app *appContext) DeleteUsers(gc *gin.Context) { var req deleteUserDTO + var addresses []string gc.BindJSON(&req) errors := map[string]string{} ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false) @@ -569,19 +570,22 @@ func (app *appContext) DeleteUser(gc *gin.Context) { if emailEnabled && req.Notify { addr, ok := app.storage.emails[userID] if addr != nil && ok { - go func(userID, reason, address string) { - msg, err := app.email.constructDeleted(reason, app) - if err != nil { - app.err.Printf("%s: Failed to construct account deletion email: %s", userID, err) - } else if err := app.email.send(msg, address); err != nil { - app.err.Printf("%s: Failed to send to %s: %s", userID, address, err) - } else { - app.info.Printf("%s: Sent deletion email to %s", userID, address) - } - }(userID, req.Reason, addr.(string)) + addresses = append(addresses, addr.(string)) } } } + if len(addresses) != 0 { + go func(reason string, addresses []string) { + msg, err := app.email.constructDeleted(reason, app) + if err != nil { + app.err.Printf("Failed to construct account deletion emails: %s", err) + } else if err := app.email.send(msg, addresses...); err != nil { + app.err.Printf("Failed to send account deletion emails: %s", err) + } else { + app.info.Println("Sent account deletion emails") + } + }(req.Reason, addresses) + } app.jf.CacheExpiry = time.Now() if len(errors) == len(req.Users) { respondBool(500, false, gc) diff --git a/router.go b/router.go index d0139af..44e1498 100644 --- a/router.go +++ b/router.go @@ -123,7 +123,7 @@ func (app *appContext) loadRoutes(router *gin.Engine) { api := router.Group("/", app.webAuth()) for _, p := range routePrefixes { router.POST(p+"/logout", app.Logout) - api.DELETE(p+"/users", app.DeleteUser) + api.DELETE(p+"/users", app.DeleteUsers) api.GET(p+"/users", app.GetUsers) api.POST(p+"/users", app.NewUserAdmin) api.POST(p+"/invites", app.GenerateInvite)