Deleting maillogs when a campaign is completed to prevent accidental future emails from being sent. Fixes #719

pull/1323/head
Jordan Wright 2018-12-15 22:09:15 -06:00
parent c14be36e05
commit 53b3a98521
2 changed files with 20 additions and 0 deletions

View File

@ -591,6 +591,12 @@ func CompleteCampaign(id int64, uid int64) error {
if err != nil {
return err
}
// Delete any maillogs still set to be sent out, preventing future emails
err = db.Where("campaign_id=?", id).Delete(&MailLog{}).Error
if err != nil {
log.Error(err)
return err
}
// Don't overwrite original completed time
if c.Status == CampaignComplete {
return nil

View File

@ -119,3 +119,17 @@ func (s *ModelsSuite) TestDeleteCampaignAlsoDeletesMailLogs(c *check.C) {
c.Assert(err, check.Equals, nil)
c.Assert(len(ms), check.Equals, 0)
}
func (s *ModelsSuite) TestCompleteCampaignAlsoDeletesMailLogs(c *check.C) {
campaign := s.createCampaign(c)
ms, err := GetMailLogsByCampaign(campaign.Id)
c.Assert(err, check.Equals, nil)
c.Assert(len(ms), check.Equals, len(campaign.Results))
err = CompleteCampaign(campaign.Id, campaign.UserId)
c.Assert(err, check.Equals, nil)
ms, err = GetMailLogsByCampaign(campaign.Id)
c.Assert(err, check.Equals, nil)
c.Assert(len(ms), check.Equals, 0)
}