Skip to content

Commit 2b0b89d

Browse files
committed
add separate mail for admins
Signed-off-by: Chayan Das <[email protected]>
1 parent 3015683 commit 2b0b89d

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

pkg/api/licenses.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package api
1010

1111
import (
12-
"context"
1312
"encoding/json"
1413
"errors"
1514
"fmt"
@@ -22,7 +21,6 @@ import (
2221

2322
"github.com/fossology/LicenseDb/pkg/db"
2423
email "github.com/fossology/LicenseDb/pkg/email"
25-
template "github.com/fossology/LicenseDb/pkg/email/templetes"
2624
logger "github.com/fossology/LicenseDb/pkg/log"
2725
"github.com/fossology/LicenseDb/pkg/models"
2826
"github.com/fossology/LicenseDb/pkg/utils"
@@ -728,24 +726,7 @@ func ImportLicenses(c *gin.Context) {
728726
if email.Email != nil && email.Email.IsRunning() {
729727
userName := *user.UserName
730728
userEmail := *user.UserEmail
731-
subject, html := template.ImportSummaryEmailTemplate(
732-
userName,
733-
"Licenses",
734-
total,
735-
success,
736-
failed,
737-
time.Now(),
738-
)
739-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
740-
defer cancel()
741-
742-
if err := email.Email.Queue(ctx, email.EmailData{
743-
To: []string{userEmail},
744-
Subject: subject,
745-
HTML: html,
746-
}); err != nil {
747-
logger.LogError("Failed to enqueue email")
748-
}
729+
email.NotifyImportSummary(userEmail, userName, "Licenses", total, success, failed)
749730
} else {
750731
logger.LogInfo("SMTP disabled or not reachable. Skipping email.")
751732
}

pkg/email/wrapper.go

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,30 @@ func NotifyLicenseCreated(toEmail, userName, shortName string) {
2222
if Email == nil || !Email.IsRunning() {
2323
return
2424
}
25-
25+
// sent mail to creator
2626
subject, html := templates.SingleLicenseEmailTemplate(
2727
userName,
2828
"Created",
2929
time.Now(),
3030
shortName,
3131
)
32-
32+
// email sent to admins
3333
_ = Email.Queue(ctx, EmailData{
3434
To: []string{toEmail},
35-
Cc: admins,
3635
Subject: subject,
3736
HTML: html,
3837
})
38+
Adminsubject, Adminhtml := templates.SingleLicenseEmailTemplate(
39+
"Admins",
40+
"Created",
41+
time.Now(),
42+
shortName,
43+
)
44+
_ = Email.Queue(ctx, EmailData{
45+
To: admins,
46+
Subject: Adminsubject,
47+
HTML: Adminhtml,
48+
})
3949
}()
4050
}
4151

@@ -51,7 +61,7 @@ func NotifyLicenseUpdated(to, userName, licenseName string) {
5161
if Email == nil || !Email.IsRunning() {
5262
return
5363
}
54-
64+
// sent mail to creator
5565
subject, html := templates.SingleLicenseEmailTemplate(
5666
userName,
5767
"Updated",
@@ -62,11 +72,26 @@ func NotifyLicenseUpdated(to, userName, licenseName string) {
6272
data := EmailData{
6373
To: []string{to},
6474
Subject: subject,
65-
Cc: admins,
6675
HTML: html,
6776
}
6877

6978
_ = Email.Queue(ctx, data)
79+
80+
// email sent to admins
81+
Adminsubject, Adminhtml := templates.SingleLicenseEmailTemplate(
82+
"Admins",
83+
"Updated",
84+
time.Now(),
85+
licenseName,
86+
)
87+
88+
Admindata := EmailData{
89+
To: admins,
90+
Subject: Adminsubject,
91+
HTML: Adminhtml,
92+
}
93+
94+
_ = Email.Queue(ctx, Admindata)
7095
}()
7196
}
7297

@@ -83,6 +108,7 @@ func NotifyImportSummary(to, userName, importedType string, total, success, fail
83108
return
84109
}
85110

111+
// email sent to the creator
86112
subject, html := templates.ImportSummaryEmailTemplate(
87113
userName,
88114
importedType,
@@ -95,10 +121,28 @@ func NotifyImportSummary(to, userName, importedType string, total, success, fail
95121
data := EmailData{
96122
To: []string{to},
97123
Subject: subject,
98-
Cc: admins,
99124
HTML: html,
100125
}
101126

102127
_ = Email.Queue(ctx, data)
128+
129+
// email sent to admins
130+
Adminsubject, Adminhtml := templates.ImportSummaryEmailTemplate(
131+
"Admins",
132+
importedType,
133+
total,
134+
success,
135+
failed,
136+
time.Now(),
137+
)
138+
139+
Admindata := EmailData{
140+
To: admins,
141+
Subject: Adminsubject,
142+
HTML: Adminhtml,
143+
}
144+
145+
_ = Email.Queue(ctx, Admindata)
146+
103147
}()
104148
}

0 commit comments

Comments
 (0)