Skip to content

Commit

Permalink
Merge pull request #418 from factly/add-send-email-flag
Browse files Browse the repository at this point in the history
make sending email optional in organisation/user/create.go
  • Loading branch information
vsumit89 authored Jan 30, 2024
2 parents c630ff8 + 9453bc6 commit c01ea1d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions server/action/organisation/user/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c01ea1d

Please sign in to comment.