[PATCH v2 2/6] signals: Only enable events when REST API enabled
Stephen Finucane
stephen at that.guru
Tue Apr 10 07:02:52 AEST 2018
Signed-off-by: Stephen Finucane <stephen at that.guru>
---
patchwork/signals.py | 22 ++++++++++++++--------
.../events-require-rest-api-47eab4a3be745f75.yaml | 5 +++++
2 files changed, 19 insertions(+), 8 deletions(-)
create mode 100644 releasenotes/notes/events-require-rest-api-47eab4a3be745f75.yaml
diff --git a/patchwork/signals.py b/patchwork/signals.py
index f7b4f547..b083b51a 100644
--- a/patchwork/signals.py
+++ b/patchwork/signals.py
@@ -19,6 +19,7 @@
from datetime import datetime as dt
+from django.conf import settings
from django.db.models.signals import post_save
from django.db.models.signals import pre_save
from django.dispatch import receiver
@@ -69,7 +70,6 @@ def patch_change_callback(sender, instance, raw, **kwargs):
notification.save()
- at receiver(post_save, sender=CoverLetter)
def create_cover_created_event(sender, instance, created, raw, **kwargs):
def create_event(cover):
@@ -85,7 +85,6 @@ def create_cover_created_event(sender, instance, created, raw, **kwargs):
create_event(instance)
- at receiver(post_save, sender=Patch)
def create_patch_created_event(sender, instance, created, raw, **kwargs):
def create_event(patch):
@@ -101,7 +100,6 @@ def create_patch_created_event(sender, instance, created, raw, **kwargs):
create_event(instance)
- at receiver(pre_save, sender=Patch)
def create_patch_state_changed_event(sender, instance, raw, **kwargs):
def create_event(patch, before, after):
@@ -124,7 +122,6 @@ def create_patch_state_changed_event(sender, instance, raw, **kwargs):
create_event(instance, orig_patch.state, instance.state)
- at receiver(pre_save, sender=Patch)
def create_patch_delegated_event(sender, instance, raw, **kwargs):
def create_event(patch, before, after):
@@ -147,7 +144,6 @@ def create_patch_delegated_event(sender, instance, raw, **kwargs):
create_event(instance, orig_patch.delegate, instance.delegate)
- at receiver(post_save, sender=SeriesPatch)
def create_patch_completed_event(sender, instance, created, raw, **kwargs):
"""Create patch completed event for patches with series."""
@@ -183,7 +179,6 @@ def create_patch_completed_event(sender, instance, created, raw, **kwargs):
count += 1
- at receiver(post_save, sender=Check)
def create_check_created_event(sender, instance, created, raw, **kwargs):
def create_event(check):
@@ -202,7 +197,6 @@ def create_check_created_event(sender, instance, created, raw, **kwargs):
create_event(instance)
- at receiver(post_save, sender=Series)
def create_series_created_event(sender, instance, created, raw, **kwargs):
def create_event(series):
@@ -218,7 +212,6 @@ def create_series_created_event(sender, instance, created, raw, **kwargs):
create_event(instance)
- at receiver(post_save, sender=SeriesPatch)
def create_series_completed_event(sender, instance, created, raw, **kwargs):
# NOTE(stephenfin): We subscribe to the SeriesPatch.post_save signal
@@ -245,3 +238,16 @@ def create_series_completed_event(sender, instance, created, raw, **kwargs):
if instance.series.received_all:
create_event(instance.series)
+
+
+if settings.ENABLE_REST_API:
+ post_save.connect(create_cover_created_event, sender=CoverLetter)
+ post_save.connect(create_patch_created_event, sender=Patch)
+
+ pre_save.connect(create_patch_state_changed_event, sender=Patch)
+ pre_save.connect(create_patch_delegated_event, sender=Patch)
+
+ post_save.connect(create_patch_completed_event, sender=SeriesPatch)
+ post_save.connect(create_check_created_event, sender=Check)
+ post_save.connect(create_series_created_event, sender=Series)
+ post_save.connect(create_series_completed_event, sender=SeriesPatch)
diff --git a/releasenotes/notes/events-require-rest-api-47eab4a3be745f75.yaml b/releasenotes/notes/events-require-rest-api-47eab4a3be745f75.yaml
new file mode 100644
index 00000000..8a4a4474
--- /dev/null
+++ b/releasenotes/notes/events-require-rest-api-47eab4a3be745f75.yaml
@@ -0,0 +1,5 @@
+---
+upgrade:
+ - |
+ The events API now requires the REST API. Events are only exposed over the
+ REST API so this should have no impact for most users.
--
2.14.3
More information about the Patchwork
mailing list