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

Commit

Permalink
Merge pull request #2084 from OpenBazaar/brian.addStoreToSMTP
Browse files Browse the repository at this point in the history
Add Store Name to Email Notifications
  • Loading branch information
cpacia committed Jun 4, 2020
2 parents 9024d81 + 57b2771 commit 52981bc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/jsonapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,12 @@ func (i *jsonAPIHandler) POSTTestEmailNotifications(w http.ResponseWriter, r *ht
ErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
profile, err := i.node.GetProfile()
if err != nil {
ErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
settings.OpenBazaarName = profile.Name
notifier := smtpNotifier{&settings}
err = notifier.notify(repo.TestNotification{})
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions api/jsonapi_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const settingsJSON = `{
"mispaymentBuffer": 1,
"smtpSettings": {
"notifications": true,
"openBazaarName": "",
"serverAddress": "smtp.urbanart.com:465",
"username": "urbanart",
"password": "letmein",
Expand Down Expand Up @@ -94,6 +95,7 @@ const settingsUpdateJSON = `{
"mispaymentBuffer": 1,
"smtpSettings": {
"notifications": true,
"openBazaarName": "",
"serverAddress": "smtp.urbanart.com:465",
"username": "urbanart",
"password": "letmein",
Expand Down Expand Up @@ -142,6 +144,7 @@ const settingsPatchedJSON = `{
"mispaymentBuffer": 1,
"smtpSettings": {
"notifications": true,
"openBazaarName": "",
"serverAddress": "smtp.urbanart.com:465",
"username": "urbanart",
"password": "letmein",
Expand Down
1 change: 1 addition & 0 deletions api/jsonapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestSettingsSetModerator(t *testing.T) {
"showNsfw": true,
"smtpSettings": {
"notifications": false,
"openBazaarName": "",
"password": "",
"recipientEmail": "",
"senderEmail": "",
Expand Down
11 changes: 9 additions & 2 deletions api/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ func (m *notificationManager) getNotifiers() []notifier {

// SMTP notifier
conf := settings.SMTPSettings

profile, err := m.node.GetProfile()
if err != nil {
return nil
}
conf.OpenBazaarName = profile.Name

if conf != nil && conf.Notifications {
notifiers = append(notifiers, &smtpNotifier{settings: conf})
}
Expand All @@ -85,15 +92,15 @@ func (notifier *smtpNotifier) notify(n repo.Notifier) error {
"To: %s",
"MIME-Version: 1.0",
"Content-Type: text/html; charset=UTF-8",
"Subject: [OpenBazaar] %s\r\n",
"Subject: [OpenBazaar - %s] %s\r\n",
"%s\r\n",
}, "\r\n")
head, body, ok := n.GetSMTPTitleAndBody()
if !ok {
return nil
}
conf := notifier.settings
data := fmt.Sprintf(template, conf.SenderEmail, conf.RecipientEmail, head, body)
data := fmt.Sprintf(template, conf.SenderEmail, conf.RecipientEmail, conf.OpenBazaarName, head, body)
return sendEmail(notifier.settings, []byte(data))
}

Expand Down
1 change: 1 addition & 0 deletions repo/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type SMTPSettings struct {
Password string `json:"password"`
SenderEmail string `json:"senderEmail"`
RecipientEmail string `json:"recipientEmail"`
OpenBazaarName string `json:"openBazaarName"`
}

type Follower struct {
Expand Down
1 change: 1 addition & 0 deletions test/factory/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func MustNewValidSettings() repo.SettingsData {
"mispaymentBuffer": 1,
"smtpSettings" : {
"notifications": false,
"openBazaarName": "",
"password": "",
"recipientEmail": "",
"senderEmail": "",
Expand Down

0 comments on commit 52981bc

Please sign in to comment.