mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-02-12 16:12:44 +00:00
Merge branch 'develop' into feat-schedule-jitter
This commit is contained in:
@@ -269,8 +269,10 @@ func (r *CampaignRecipient) GetByCampaignRecipientID(
|
||||
// GetUnsendRecipients gets all campaign recipients that are not sent
|
||||
// and have been attempted or been cancelled
|
||||
// if limit is larger than 0 it will limit the number of results
|
||||
// if campaignID is not nil, it will filter by that campaign
|
||||
func (r *CampaignRecipient) GetUnsendRecipients(
|
||||
ctx context.Context,
|
||||
campaignID *uuid.UUID,
|
||||
limit int,
|
||||
options *CampaignRecipientOption,
|
||||
) ([]*model.CampaignRecipient, error) {
|
||||
@@ -289,6 +291,12 @@ func (r *CampaignRecipient) GetUnsendRecipients(
|
||||
TableColumn(database.CAMPAIGN_RECIPIENT_TABLE_NAME, "last_attempt_at"),
|
||||
),
|
||||
)
|
||||
if campaignID != nil {
|
||||
q = q.Where(
|
||||
fmt.Sprintf("%s = ?", TableColumn(database.CAMPAIGN_RECIPIENT_TABLE_NAME, "campaign_id")),
|
||||
campaignID,
|
||||
)
|
||||
}
|
||||
if limit > 0 {
|
||||
q = q.Limit(limit)
|
||||
}
|
||||
|
||||
@@ -2603,13 +2603,14 @@ func (c *Campaign) closeCampaign(
|
||||
if !isAuthorized {
|
||||
return errs.ErrAuthorizationFailed
|
||||
}
|
||||
// find all recipients that are not sent and cancel them
|
||||
// find all recipients that are not sent and cancel them for this campaign
|
||||
campaignRecipients, err := c.CampaignRecipientRepository.GetUnsendRecipients(
|
||||
ctx,
|
||||
id,
|
||||
repository.NO_LIMIT,
|
||||
&repository.CampaignRecipientOption{},
|
||||
)
|
||||
c.Logger.Debugw("found unsent recipients to cancel", "count", len(campaignRecipients))
|
||||
c.Logger.Debugw("found unsent recipients to cancel for campaign", "count", len(campaignRecipients), "campaignID", id.String())
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.Logger.Errorw("failed to get unsent recipients", "error", err)
|
||||
return errs.Wrap(err)
|
||||
|
||||
Reference in New Issue
Block a user