-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from LalitDeore/dev_lalit
added the default alert threshold as 50% and 100% for new register user
- Loading branch information
Showing
3 changed files
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,12 +303,17 @@ func HandleIncrement(dataType string, orgStatistics *ExecutionInfo, increment ui | |
if int64(AlertThreshold.Count) < orgStatistics.MonthlyAppExecutions && AlertThreshold.Email_send == false { | ||
for _, user := range org.Users { | ||
if user.Role == "admin" { | ||
var BccAddress []string | ||
if int64(AlertThreshold.Count) >= 5000 || int64(AlertThreshold.Count) >= 10000 && AlertThreshold.Email_send == false { | ||
BccAddress = []string{"[email protected]", "[email protected]"} | ||
} | ||
|
||
mailbody := Mailcheck{ | ||
Targets: []string{user.Username}, | ||
Subject: "You have reached the threshold limit of app executions", | ||
Body: fmt.Sprintf("You have reached the threshold limit of %v percent Or %v app executions run. Please login to shuffle and check it.", AlertThreshold.Percentage, AlertThreshold.Count), | ||
} | ||
err = sendMailSendgrid(mailbody.Targets, mailbody.Subject, mailbody.Body, false) | ||
err = sendMailSendgrid(mailbody.Targets, mailbody.Subject, mailbody.Body, false, BccAddress) | ||
if err != nil { | ||
log.Printf("[ERROR] Failed sending alert mail in increment: %s", err) | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11826,7 +11826,7 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) { | |
|
||
} | ||
|
||
func sendMailSendgrid(toEmail []string, subject, body string, emailApp bool) error { | ||
func sendMailSendgrid(toEmail []string, subject, body string, emailApp bool, BccAddresses []string) error { | ||
log.Printf("[DEBUG] In mail sending with subject %s and body length %s. TO: %s", subject, body, toEmail) | ||
srequest := sendgrid.GetRequest(os.Getenv("SENDGRID_API_KEY"), "/v3/mail/send", "https://api.sendgrid.com") | ||
srequest.Method = "POST" | ||
|
@@ -11842,6 +11842,7 @@ func sendMailSendgrid(toEmail []string, subject, body string, emailApp bool) err | |
|
||
type SendgridPersonalization struct { | ||
To []SendgridEmail `json:"to"` | ||
Bcc []SendgridEmail `json:"bcc"` | ||
Subject string `json:"subject"` | ||
} | ||
|
||
|
@@ -11855,7 +11856,7 @@ func sendMailSendgrid(toEmail []string, subject, body string, emailApp bool) err | |
|
||
newBody := sendgridMailBody{ | ||
Personalizations: []SendgridPersonalization{ | ||
SendgridPersonalization{ | ||
{ | ||
To: []SendgridEmail{}, | ||
Subject: subject, | ||
}, | ||
|
@@ -11864,7 +11865,7 @@ func sendMailSendgrid(toEmail []string, subject, body string, emailApp bool) err | |
Email: "Shuffle Support <[email protected]>", | ||
}, | ||
Content: []SendgridContent{ | ||
SendgridContent{ | ||
{ | ||
Type: "text/html", | ||
Value: body, | ||
}, | ||
|
@@ -11882,6 +11883,17 @@ func sendMailSendgrid(toEmail []string, subject, body string, emailApp bool) err | |
}) | ||
} | ||
|
||
// Conditionally add BCC addresses if they exist | ||
if len(BccAddresses) > 0 { | ||
for _, bccEmail := range BccAddresses { | ||
newBody.Personalizations[0].Bcc = append(newBody.Personalizations[0].Bcc, | ||
SendgridEmail{ | ||
Email: strings.TrimSpace(bccEmail), | ||
}) | ||
} | ||
} | ||
|
||
|
||
parsedBody, err := json.Marshal(newBody) | ||
if err != nil { | ||
log.Printf("[ERROR] Failed to parse JSON in sendmail: %s", err) | ||
|
@@ -29005,7 +29017,7 @@ func HandleUserPrivateTraining(resp http.ResponseWriter, request *http.Request) | |
Subject := "Thank you for your private training request" | ||
Message := fmt.Sprintf("Hi there, Thank you for submitting request for shuffle private training. This is confirmation that we have received your private training request. You have requested a private training for %v members. We will get back to you shortly. <br> <br> Best Regards <br>Shuffle Team", tmpData.Training) | ||
|
||
err = sendMailSendgrid(email, Subject, Message, false) | ||
err = sendMailSendgrid(email, Subject, Message, false, []string{}) | ||
if err != nil { | ||
log.Printf("[ERROR] Failed sending mail: %s", err) | ||
resp.WriteHeader(http.StatusBadRequest) | ||
|
@@ -29018,7 +29030,7 @@ func HandleUserPrivateTraining(resp http.ResponseWriter, request *http.Request) | |
Subject = fmt.Sprintf("Private training request") | ||
Message = fmt.Sprintf("Private training request : <br>Org id: %v <br> Org Name: %v <br>Username: %v <br> Training Members: %v <br>Customer: %v <br> Message: %v", org.Id, org.Name, User.Username, tmpData.Training, org.LeadInfo.Customer, tmpData.Message) | ||
|
||
err = sendMailSendgrid(email, Subject, Message, false) | ||
err = sendMailSendgrid(email, Subject, Message, false, []string{}) | ||
if err != nil { | ||
log.Printf("[ERROR] Failed sending mail: %s", err) | ||
resp.WriteHeader(http.StatusBadRequest) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters