From 79b4512546f91e8b9742d744f4ea75659959e6cb Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 2 Feb 2023 19:35:27 +0000 Subject: [PATCH] Make notification rule ID field UUID and fix default sources --- core/db/elastic.py | 2 +- core/lib/rules.py | 2 +- .../0024_alter_notificationrule_id.py | 19 +++++++++++++++++++ .../0025_alter_notificationrule_id.py | 19 +++++++++++++++++++ core/models.py | 4 ++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 core/migrations/0024_alter_notificationrule_id.py create mode 100644 core/migrations/0025_alter_notificationrule_id.py diff --git a/core/db/elastic.py b/core/db/elastic.py index 54be0cd..7f24079 100644 --- a/core/db/elastic.py +++ b/core/db/elastic.py @@ -300,7 +300,7 @@ class ElasticsearchBackend(StorageBackend): search_query, index=index, ) - # self.log.debug(f"Running scheduled query on {index}: {search_query}") + self.log.debug(f"Running scheduled query on {index}: {search_query}") # self.log.debug(f"Response from scheduled query: {response}") if isinstance(response, Exception): error = response.info["error"]["root_cause"][0]["reason"] diff --git a/core/lib/rules.py b/core/lib/rules.py index 2789033..4f36d61 100644 --- a/core/lib/rules.py +++ b/core/lib/rules.py @@ -564,7 +564,7 @@ class NotificationRuleData(object): else: # Get the default value for the user if not present source = parse_source(self.user, {}, raise_error=True) - self.parsed["source"] = [source] + self.parsed["source"] = source def parse_data(self): """ diff --git a/core/migrations/0024_alter_notificationrule_id.py b/core/migrations/0024_alter_notificationrule_id.py new file mode 100644 index 0000000..c7faa82 --- /dev/null +++ b/core/migrations/0024_alter_notificationrule_id.py @@ -0,0 +1,19 @@ +# Generated by Django 4.1.5 on 2023-02-02 19:08 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0023_alter_perms_options'), + ] + + operations = [ + migrations.AlterField( + model_name='notificationrule', + name='id', + field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False), + ), + ] diff --git a/core/migrations/0025_alter_notificationrule_id.py b/core/migrations/0025_alter_notificationrule_id.py new file mode 100644 index 0000000..d9fa6dc --- /dev/null +++ b/core/migrations/0025_alter_notificationrule_id.py @@ -0,0 +1,19 @@ +# Generated by Django 4.1.5 on 2023-02-02 19:35 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0024_alter_notificationrule_id'), + ] + + operations = [ + migrations.AlterField( + model_name='notificationrule', + name='id', + field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True), + ), + ] diff --git a/core/models.py b/core/models.py index 85a4b54..092cfb3 100644 --- a/core/models.py +++ b/core/models.py @@ -1,4 +1,5 @@ import logging +import uuid import stripe from django.conf import settings @@ -175,6 +176,9 @@ class Perms(models.Model): class NotificationRule(models.Model): + id = models.UUIDField( + default=uuid.uuid4, primary_key=True, editable=False, unique=True + ) user = models.ForeignKey(User, on_delete=models.CASCADE) name = models.CharField(max_length=255) priority = models.IntegerField(choices=PRIORITY_CHOICES, default=1)