Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ smtp/
|---|---|---|
| `user.created` | yes | `user_id`, `username`, `full_name`, `email?` |
| `user.password_reset` | yes | `user_id`, `username`, `full_name`, `email?` |
| `notification.assigned` | no (default on) | `recipient_user_id`, `recipient_email?`, `recipient_name`, `actor_name`, `link_url` |
| `notification.assigned` | no (default on) | `recipient_account_id`, `recipient_email?`, `recipient_name`, `actor_name`, `link_url` |
| `notification.mentioned` | no (default on) | same shape as `notification.assigned` |
| `notification.doc_mentioned` | no (default on) | same shape as `notification.assigned` |
| `notification.task_description_mentioned` | no (default on) | same shape as `notification.assigned` |
Expand Down
20 changes: 10 additions & 10 deletions backend/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ type passwordSetEventPayload struct {
// plugin treats that as "nothing to do" and no-ops, per the event-handling
// switch below.
type notificationPayload struct {
RecipientUserID string `json:"recipient_user_id"`
RecipientEmail string `json:"recipient_email"`
RecipientName string `json:"recipient_name"`
ActorName string `json:"actor_name"`
LinkURL string `json:"link_url"`
RecipientAccountID string `json:"recipient_account_id"`
RecipientEmail string `json:"recipient_email"`
RecipientName string `json:"recipient_name"`
ActorName string `json:"actor_name"`
LinkURL string `json:"link_url"`
// EntityTitle is the title of the task (assigned/mentioned/
// task_description_mentioned) or document (doc_mentioned) the
// notification is about. May be empty — an older core that predates the
Expand Down Expand Up @@ -70,7 +70,7 @@ func (p *smtpPlugin) handleEvent(topic string) plugin.EventHandler {
// immediately for every email sent afterward.
branding, _ := plugin.GetBranding()

var recipientUserID, recipientEmail, recipientName, subject, htmlBody, textBody string
var recipientAccountID, recipientEmail, recipientName, subject, htmlBody, textBody string

switch topic {
case topicUserCreated, topicUserPasswordReset:
Expand All @@ -83,28 +83,28 @@ func (p *smtpPlugin) handleEvent(topic string) plugin.EventHandler {
// configured, mandatory topic) that it's actually going to
// deliver a set-password link.
token, err := p.issuePasswordSetToken(data.UserID) //nolint:staticcheck // SA4023: native (!wasip1) stub always errors; wasip1 build can return nil
if err != nil { //nolint:staticcheck // SA4023: native (!wasip1) stub always errors; wasip1 build can return nil
if err != nil { //nolint:staticcheck // SA4023: native (!wasip1) stub always errors; wasip1 build can return nil
p.log.Error("handleEvent(" + topic + "): issue password set token: " + err.Error())
return
}
publicURL, _ := p.cfg.Get("PUBLIC_URL")
inviteURL := strings.TrimRight(publicURL, "/") + "/set-password?token=" + token

recipientUserID, recipientEmail, recipientName = data.UserID, data.Email, data.FullName
recipientAccountID, recipientEmail, recipientName = data.UserID, data.Email, data.FullName
subject, htmlBody, textBody = renderPasswordSetEmail(branding, topic, data, inviteURL)
case topicNotificationAssigned, topicNotificationMentioned, topicNotificationDocMentioned, topicNotificationTaskDescMentioned:
data, err := plugin.JSONPayload[notificationPayload](evt)
if err != nil || data.RecipientEmail == "" {
return
}
recipientUserID, recipientEmail, recipientName = data.RecipientUserID, data.RecipientEmail, data.RecipientName
recipientAccountID, recipientEmail, recipientName = data.RecipientAccountID, data.RecipientEmail, data.RecipientName
subject, htmlBody, textBody = renderNotificationEmail(branding, topic, data)
default:
return
}

if !mandatory {
disabled, err := p.loadUserPreferences(recipientUserID)
disabled, err := p.loadUserPreferences(recipientAccountID)
if err == nil && containsString(disabled, topic) {
return
}
Expand Down
6 changes: 3 additions & 3 deletions backend/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func TestHandleEvent_Notification_SkipsWhenRecipientOptedOut(t *testing.T) {

before := len(tc.Log.Entries())
payload, _ := json.Marshal(notificationPayload{
RecipientUserID: "u2", RecipientEmail: "u2@example.com", RecipientName: "U2",
RecipientAccountID: "u2", RecipientEmail: "u2@example.com", RecipientName: "U2",
ActorName: "Alice", LinkURL: "https://paca.example.com/tasks/1",
})
if ok := plugin.DispatchEvent(tc.PluginContext(), topicNotificationAssigned, payload); !ok {
Expand All @@ -391,7 +391,7 @@ func TestHandleEvent_Notification_ReachesSendBoundary(t *testing.T) {
`["notification.assigned"]`)

payload, _ := json.Marshal(notificationPayload{
RecipientUserID: "u2", RecipientEmail: "u2@example.com", RecipientName: "U2",
RecipientAccountID: "u2", RecipientEmail: "u2@example.com", RecipientName: "U2",
ActorName: "Alice", LinkURL: "https://paca.example.com/tasks/1",
})
if ok := plugin.DispatchEvent(tc.PluginContext(), topicNotificationAssigned, payload); !ok {
Expand All @@ -408,7 +408,7 @@ func TestHandleEvent_Notification_NoOpWhenRecipientEmailMissing(t *testing.T) {
`["notification.mentioned"]`)

before := len(tc.Log.Entries())
payload, _ := json.Marshal(notificationPayload{RecipientUserID: "u3", ActorName: "Alice"})
payload, _ := json.Marshal(notificationPayload{RecipientAccountID: "u3", ActorName: "Alice"})
if ok := plugin.DispatchEvent(tc.PluginContext(), topicNotificationMentioned, payload); !ok {
t.Fatal("expected notification.mentioned handler to be registered")
}
Expand Down
Loading