diff --git a/src/pretix/plugins/sendmail/forms.py b/src/pretix/plugins/sendmail/forms.py index 8694a4fbc4..80748496aa 100644 --- a/src/pretix/plugins/sendmail/forms.py +++ b/src/pretix/plugins/sendmail/forms.py @@ -231,7 +231,7 @@ class RuleForm(FormPlaceholderMixin, I18nModelForm): fields = ['subject', 'template', 'send_date', 'send_offset_days', 'send_offset_time', 'include_pending', 'all_products', 'limit_products', - 'send_to'] + 'send_to', 'enabled'] field_classes = { 'subevent': SafeModelMultipleChoiceField, diff --git a/src/pretix/plugins/sendmail/migrations/0002_rule_enabled.py b/src/pretix/plugins/sendmail/migrations/0002_rule_enabled.py new file mode 100644 index 0000000000..a714468a3d --- /dev/null +++ b/src/pretix/plugins/sendmail/migrations/0002_rule_enabled.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.3 on 2021-06-07 09:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sendmail', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='rule', + name='enabled', + field=models.BooleanField(default=True), + ), + ] diff --git a/src/pretix/plugins/sendmail/models.py b/src/pretix/plugins/sendmail/models.py index 0b3e46e435..f92d5a36be 100644 --- a/src/pretix/plugins/sendmail/models.py +++ b/src/pretix/plugins/sendmail/models.py @@ -201,6 +201,12 @@ class Rule(models.Model): send_to = models.CharField(max_length=10, choices=SEND_TO_CHOICES, default=CUSTOMERS, verbose_name='Send email to') + enabled = models.BooleanField( + default=True, + verbose_name=_('Enabled'), + help_text=_('Only enabled rules are actually sent') + ) + objects = ScopedManager(organizer='event__organizer') def save(self, **kwargs): diff --git a/src/pretix/plugins/sendmail/signals.py b/src/pretix/plugins/sendmail/signals.py index 33c0aeaf5b..a2700d9d68 100644 --- a/src/pretix/plugins/sendmail/signals.py +++ b/src/pretix/plugins/sendmail/signals.py @@ -146,6 +146,7 @@ def sendmail_run_rules(sender, **kwargs): ) for m_id in mails.filter( state__in=(ScheduledMail.STATE_SCHEDULED, ScheduledMail.STATE_FAILED), + rule__enabled=True, computed_datetime__gte=timezone.now() - datetime.timedelta(days=2), computed_datetime__lte=timezone.now(), ).values_list('pk', flat=True): @@ -161,7 +162,7 @@ def sendmail_run_rules(sender, **kwargs): # emails might be sent a second time. This isn't nice, but any solution would either # require settings some arbitrary timeout for a process or risk not sending some # emails at all. Under the assumption that system-level failures are rare and (more - # importantly) usually don't happen multiple times in a row, this seems liek a + # importantly) usually don't happen multiple times in a row, this seems like a # good tradeoff. # - We never retry for more than two days. diff --git a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/rule_create.html b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/rule_create.html index ab562182c3..26b541f745 100644 --- a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/rule_create.html +++ b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/rule_create.html @@ -9,6 +9,8 @@ {% csrf_token %} {% bootstrap_form_errors form %} + {% bootstrap_field form.enabled layout='control' %} +