diff --git a/README.md b/README.md index 4d1596a..3977d9e 100644 --- a/README.md +++ b/README.md @@ -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` | diff --git a/backend/events.go b/backend/events.go index 3eca068..9580023 100644 --- a/backend/events.go +++ b/backend/events.go @@ -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 @@ -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: @@ -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 } diff --git a/backend/plugin_test.go b/backend/plugin_test.go index 99bb067..03b1df1 100644 --- a/backend/plugin_test.go +++ b/backend/plugin_test.go @@ -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 { @@ -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 { @@ -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") }