[wip] Add rule disabling to migration, add uninstall hook

This commit is contained in:
Phin Wolkwitz
2026-09-23 12:48:54 +02:00
parent c79644e002
commit 473290b88d
3 changed files with 13 additions and 3 deletions
+3
View File
@@ -40,3 +40,6 @@ class SendMailApp(AppConfig):
def ready(self):
from . import signals # NOQA
from . import tasks # NOQA
def uninstalled(self, event):
event.sendmail_rules.update(enabled=False)
@@ -5,15 +5,24 @@ from django.db.models import Exists, OuterRef
def activate_plugin(apps, schema_editor):
Event = apps.get_model("pretixbase", "Event")
ScheduledMail = apps.get_model("sendmail", "ScheduledMail")
Rule = apps.get_model("sendmail", "Rule")
events = (
Event.objects
.exclude(plugins__icontains="pretix.plugins.sendmail")
.filter(
Exists(
ScheduledMail.objects.filter(event=OuterRef('pk')).exclude(state=ScheduledMail.STATE_COMPLETED)
ScheduledMail.objects.filter(event=OuterRef('pk'), rule__enabled=True).exclude(state='completed')
)
)
)
only_completed_rules = Rule.objects.exclude(event__plugins__icontains="pretix.plugins.sendmail",
enabled=False).filter(
~Exists(ScheduledMail.objects.filter(rule=OuterRef('pk')).exclude(state='completed'))
)
only_completed_rules.update(enabled=False)
for event in events:
event.enable_plugin('pretix.plugins.sendmail')
event.save(update_fields=['plugins'])
-2
View File
@@ -150,8 +150,6 @@ class SendmailPluginRuleLogEntryType(EventLogEntryType):
@receiver(periodic_task)
def sendmail_run_rules(sender, **kwargs):
if "pretix.plugins.sendmail" not in sender.get_plugins():
return # do not send scheduled mails if this plugin is disabled
with scopes_disabled():
mails = ScheduledMail.objects.all()