Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 52981bc

Browse files
authored
Merge pull request #2084 from OpenBazaar/brian.addStoreToSMTP
Add Store Name to Email Notifications
2 parents 9024d81 + 57b2771 commit 52981bc

File tree

6 files changed

+21
-2
lines changed

6 files changed

+21
-2
lines changed

api/jsonapi.go

+6
Original file line numberDiff line numberDiff line change
@@ -4083,6 +4083,12 @@ func (i *jsonAPIHandler) POSTTestEmailNotifications(w http.ResponseWriter, r *ht
40834083
ErrorResponse(w, http.StatusBadRequest, err.Error())
40844084
return
40854085
}
4086+
profile, err := i.node.GetProfile()
4087+
if err != nil {
4088+
ErrorResponse(w, http.StatusBadRequest, err.Error())
4089+
return
4090+
}
4091+
settings.OpenBazaarName = profile.Name
40864092
notifier := smtpNotifier{&settings}
40874093
err = notifier.notify(repo.TestNotification{})
40884094
if err != nil {

api/jsonapi_data_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const settingsJSON = `{
5555
"mispaymentBuffer": 1,
5656
"smtpSettings": {
5757
"notifications": true,
58+
"openBazaarName": "",
5859
"serverAddress": "smtp.urbanart.com:465",
5960
"username": "urbanart",
6061
"password": "letmein",
@@ -94,6 +95,7 @@ const settingsUpdateJSON = `{
9495
"mispaymentBuffer": 1,
9596
"smtpSettings": {
9697
"notifications": true,
98+
"openBazaarName": "",
9799
"serverAddress": "smtp.urbanart.com:465",
98100
"username": "urbanart",
99101
"password": "letmein",
@@ -142,6 +144,7 @@ const settingsPatchedJSON = `{
142144
"mispaymentBuffer": 1,
143145
"smtpSettings": {
144146
"notifications": true,
147+
"openBazaarName": "",
145148
"serverAddress": "smtp.urbanart.com:465",
146149
"username": "urbanart",
147150
"password": "letmein",

api/jsonapi_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func TestSettingsSetModerator(t *testing.T) {
101101
"showNsfw": true,
102102
"smtpSettings": {
103103
"notifications": false,
104+
"openBazaarName": "",
104105
"password": "",
105106
"recipientEmail": "",
106107
"senderEmail": "",

api/notifier.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ func (m *notificationManager) getNotifiers() []notifier {
6868

6969
// SMTP notifier
7070
conf := settings.SMTPSettings
71+
72+
profile, err := m.node.GetProfile()
73+
if err != nil {
74+
return nil
75+
}
76+
conf.OpenBazaarName = profile.Name
77+
7178
if conf != nil && conf.Notifications {
7279
notifiers = append(notifiers, &smtpNotifier{settings: conf})
7380
}
@@ -85,15 +92,15 @@ func (notifier *smtpNotifier) notify(n repo.Notifier) error {
8592
"To: %s",
8693
"MIME-Version: 1.0",
8794
"Content-Type: text/html; charset=UTF-8",
88-
"Subject: [OpenBazaar] %s\r\n",
95+
"Subject: [OpenBazaar - %s] %s\r\n",
8996
"%s\r\n",
9097
}, "\r\n")
9198
head, body, ok := n.GetSMTPTitleAndBody()
9299
if !ok {
93100
return nil
94101
}
95102
conf := notifier.settings
96-
data := fmt.Sprintf(template, conf.SenderEmail, conf.RecipientEmail, head, body)
103+
data := fmt.Sprintf(template, conf.SenderEmail, conf.RecipientEmail, conf.OpenBazaarName, head, body)
97104
return sendEmail(notifier.settings, []byte(data))
98105
}
99106

repo/models.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type SMTPSettings struct {
4040
Password string `json:"password"`
4141
SenderEmail string `json:"senderEmail"`
4242
RecipientEmail string `json:"recipientEmail"`
43+
OpenBazaarName string `json:"openBazaarName"`
4344
}
4445

4546
type Follower struct {

test/factory/settings.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func MustNewValidSettings() repo.SettingsData {
2222
"mispaymentBuffer": 1,
2323
"smtpSettings" : {
2424
"notifications": false,
25+
"openBazaarName": "",
2526
"password": "",
2627
"recipientEmail": "",
2728
"senderEmail": "",

0 commit comments

Comments
 (0)