mirror of https://github.com/gophish/gophish
Deleting maillogs when a campaign is completed to prevent accidental future emails from being sent. Fixes #719
parent
c14be36e05
commit
53b3a98521
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue