From 9453bc60178b032aa92a6da3f14bf22d603eb098 Mon Sep 17 00:00:00 2001 From: elliot14A Date: Tue, 30 Jan 2024 11:32:33 +0530 Subject: [PATCH] make sending email optional in organisation/user/create.go --- server/action/organisation/user/create.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server/action/organisation/user/create.go b/server/action/organisation/user/create.go index 4897775a..8ae1f7dd 100644 --- a/server/action/organisation/user/create.go +++ b/server/action/organisation/user/create.go @@ -23,7 +23,9 @@ import ( ) type invites struct { - Users []invite `json:"users"` + // flag to send email or not, default is true + SendEmail bool `json:"send_email"` + Users []invite `json:"users"` } type invite struct { @@ -80,13 +82,14 @@ func create(w http.ResponseWriter, r *http.Request) { } // FindOrCreate invitee - req := invites{} + req := invites{SendEmail: true} err = json.NewDecoder(r.Body).Decode(&req) if err != nil { loggerx.Error(err) errorx.Render(w, errorx.Parser(errorx.DecodeError())) return } + sendEmail := req.SendEmail for _, user := range req.Users { validationError := validationx.Check(user) if validationError != nil { @@ -193,12 +196,14 @@ func create(w http.ResponseWriter, r *http.Request) { OrganisationName: fmt.Sprintf("%v", organisationMap[0]["title"]), ActionURL: response.RecoveryURL, } - err = email.SendmailwithSendGrid(receiver) - if err != nil { - // tx.Rollback() - loggerx.Error(err) - // errorx.Render(w, errorx.Parser(errorx.InternalServerError())) - // return + if sendEmail { + err = email.SendmailwithSendGrid(receiver) + if err != nil { + // tx.Rollback() + loggerx.Error(err) + // errorx.Render(w, errorx.Parser(errorx.InternalServerError())) + // return + } } } else { //domainName := viper.GetString("domain_name")