mirror of https://github.com/gophish/gophish
Delete maillogs if a campaign is deleted. Fixes #1318
parent
a73ac4ab7c
commit
c14be36e05
|
@ -568,6 +568,11 @@ func DeleteCampaign(id int64) error {
|
|||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
err = db.Where("campaign_id=?", id).Delete(&MailLog{}).Error
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
// Delete the campaign
|
||||
err = db.Delete(&Campaign{Id: id}).Error
|
||||
if err != nil {
|
||||
|
|
|
@ -105,3 +105,17 @@ func (s *ModelsSuite) TestLaunchCampaignMaillogStatus(c *check.C) {
|
|||
c.Assert(m.Processing, check.Equals, false)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ModelsSuite) TestDeleteCampaignAlsoDeletesMailLogs(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 = DeleteCampaign(campaign.Id)
|
||||
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