Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pi: Dont rate limit "Voting Started" emails. #1684

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 3 additions & 5 deletions politeiawww/legacy/pi/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -573,7 +571,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():
Expand All @@ -589,7 +587,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 {
Expand Down
12 changes: 8 additions & 4 deletions politeiawww/legacy/pi/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -354,7 +356,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 {
Expand All @@ -371,7 +373,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 {
Expand Down