From bf6e069bf796b72d92f0833e68c0d32921badd92 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Tue, 7 Feb 2023 09:30:27 +0000 Subject: [PATCH 1/2] pi: Dont rate limit "Voting Started" emails. Voting on proposals is often started in batches which can cause the email rate limit to be hit for *all* users at once, despite the users themselves not taking any action. This has happened the last two times proposal voting has started. --- politeiawww/legacy/pi/events.go | 4 ++-- politeiawww/legacy/pi/mail.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/politeiawww/legacy/pi/events.go b/politeiawww/legacy/pi/events.go index 956e9e3178..e18383c759 100644 --- a/politeiawww/legacy/pi/events.go +++ b/politeiawww/legacy/pi/events.go @@ -573,7 +573,7 @@ func (p *Pi) ntfnVoteStarted(sd tkv1.StartDetails, eventUser user.User, authorID ) // Compile user notification list - recipients := make(map[uuid.UUID]string, 1024) + var recipients []string err := p.userdb.AllUsers(func(u *user.User) { switch { case u.ID.String() == eventUser.ID.String(): @@ -589,7 +589,7 @@ func (p *Pi) ntfnVoteStarted(sd tkv1.StartDetails, eventUser user.User, authorID return default: // User has notification bit set - recipients[u.ID] = u.Email + recipients = append(recipients, u.Email) } }) if err != nil { diff --git a/politeiawww/legacy/pi/mail.go b/politeiawww/legacy/pi/mail.go index 625816b941..cf4e64a276 100644 --- a/politeiawww/legacy/pi/mail.go +++ b/politeiawww/legacy/pi/mail.go @@ -354,7 +354,7 @@ Voting has started on a Politeia proposal. var voteStartedTmpl = template.Must( template.New("voteStarted").Parse(voteStartedText)) -func (p *Pi) mailNtfnVoteStarted(token, name string, recipients map[uuid.UUID]string) error { +func (p *Pi) mailNtfnVoteStarted(token, name string, recipients []string) error { route := strings.Replace(guiRouteRecordDetails, "{token}", token, 1) u, err := url.Parse(p.cfg.WebServerAddress + route) if err != nil { @@ -371,7 +371,9 @@ func (p *Pi) mailNtfnVoteStarted(token, name string, recipients map[uuid.UUID]st return err } - return p.mail.SendToUsers(subject, body, recipients) + // Don't subject this email to rate limits because proposal voting can only + // be started by admins, not regular users. + return p.mail.SendTo(subject, body, recipients) } type voteStartedToAuthor struct { From b0f0f58adb124fe1d7cd00a871e3ea46e5c566d7 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Wed, 8 Feb 2023 08:54:46 +0000 Subject: [PATCH 2/2] pi: Dont rate limit "Comment on Your Prop" emails. --- politeiawww/legacy/pi/events.go | 4 +--- politeiawww/legacy/pi/mail.go | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/politeiawww/legacy/pi/events.go b/politeiawww/legacy/pi/events.go index e18383c759..552e1ae8a4 100644 --- a/politeiawww/legacy/pi/events.go +++ b/politeiawww/legacy/pi/events.go @@ -342,9 +342,7 @@ func (p *Pi) ntfnCommentNewProposalAuthor(c cmv1.Comment, proposalAuthorID, prop } // Send notification email - recipient := map[uuid.UUID]string{ - pauthor.ID: pauthor.Email, - } + recipient := []string{pauthor.Email} err = p.mailNtfnCommentNewToProposalAuthor(c.Token, c.CommentID, c.Username, proposalName, recipient) if err != nil { diff --git a/politeiawww/legacy/pi/mail.go b/politeiawww/legacy/pi/mail.go index cf4e64a276..3ccf8b6291 100644 --- a/politeiawww/legacy/pi/mail.go +++ b/politeiawww/legacy/pi/mail.go @@ -241,7 +241,7 @@ var commentNewToProposalAuthorTmpl = template.Must( template.New("commentNewToProposalAuthor"). Parse(commentNewToProposalAuthorText)) -func (p *Pi) mailNtfnCommentNewToProposalAuthor(token string, commentID uint32, commentUsername, proposalName string, recipient map[uuid.UUID]string) error { +func (p *Pi) mailNtfnCommentNewToProposalAuthor(token string, commentID uint32, commentUsername, proposalName string, recipient []string) error { cid := strconv.FormatUint(uint64(commentID), 10) route := strings.Replace(guiRouteRecordComment, "{token}", token, 1) route = strings.Replace(route, "{id}", cid, 1) @@ -262,7 +262,9 @@ func (p *Pi) mailNtfnCommentNewToProposalAuthor(token string, commentID uint32, return err } - return p.mail.SendToUsers(subject, body, recipient) + // Don't subject this email to rate limits. A proposal can receive multiple + // comments in a short amount of time at no fault of the proposal owner. + return p.mail.SendTo(subject, body, recipient) } type commentReply struct {