From 128c37ea79dedc3d3c271779387c4b8849e0046b Mon Sep 17 00:00:00 2001
From: NameLesS
Date: Sun, 9 May 2021 22:15:03 +0200
Subject: [PATCH 1/9] add SendNotificationsMixin
---
backend-project/small_eod/cases/views.py | 6 +-
.../small_eod/notifications/__init__.py | 0
.../small_eod/notifications/utils.py | 164 ++++++++++++++++++
.../small_eod/notifications/views.py | 64 +++++++
backend-project/small_eod/users/models.py | 6 +-
5 files changed, 237 insertions(+), 3 deletions(-)
create mode 100644 backend-project/small_eod/notifications/__init__.py
create mode 100644 backend-project/small_eod/notifications/utils.py
create mode 100644 backend-project/small_eod/notifications/views.py
diff --git a/backend-project/small_eod/cases/views.py b/backend-project/small_eod/cases/views.py
index 264718ab6..313faf5bb 100644
--- a/backend-project/small_eod/cases/views.py
+++ b/backend-project/small_eod/cases/views.py
@@ -6,9 +6,10 @@
from .filterset import CaseFilterSet
from .models import Case
from .serializers import CaseCountSerializer
+from ..notifications.views import SendNotificationsMixin
-class CaseViewSet(viewsets.ModelViewSet):
+class CaseViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
queryset = Case.objects.with_counter().with_nested_resources().all()
serializer_class = CaseCountSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
@@ -27,6 +28,7 @@ class CaseViewSet(viewsets.ModelViewSet):
"created_on",
"modified_on",
]
+ notified_users = "notified_users"
class ResponsibleUserViewSet(viewsets.ReadOnlyModelViewSet):
@@ -56,4 +58,4 @@ class NotifiedUserViewSet(viewsets.ReadOnlyModelViewSet):
)
def get_queryset(self):
- return Case.objects.get(pk=self.kwargs["case_pk"]).notified_users.all()
+ return Case.objects.get(pk=self.kwargs["case_pk"]).notified_users.all()
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/__init__.py b/backend-project/small_eod/notifications/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/backend-project/small_eod/notifications/utils.py b/backend-project/small_eod/notifications/utils.py
new file mode 100644
index 000000000..0e38c4e6a
--- /dev/null
+++ b/backend-project/small_eod/notifications/utils.py
@@ -0,0 +1,164 @@
+import sys
+from enum import Enum
+
+import logging
+from django.conf import settings
+from django.core.mail import get_connection
+from django.core.mail.message import EmailMultiAlternatives
+from django.template import loader
+
+logger = logging.getLogger(__name__)
+
+
+def make_auto():
+ """eum.auto replacement"""
+
+ def loop():
+ i = 1
+ while True:
+ yield i
+ i += 1
+
+ loop = loop()
+ return lambda: next(loop)
+
+
+auto = make_auto()
+
+
+class TemplateKey(Enum):
+ CASE_CLOSED = auto()
+ CASE_GRANT_GROUP = auto()
+ CASE_GRANTED = auto()
+ CASE_NEW = auto()
+ CASE_REGISTERED = auto()
+ CASE_UPDATED = auto()
+
+ EVENT_CREATED = auto()
+ EVENT_UPDATED = auto()
+ EVENT_REMINDER = auto()
+
+ LETTER_ACCEPTED = auto()
+ LETTER_CREATED = auto()
+ LETTER_DROP_A_NOTE = auto()
+ LETTER_SEND_TO_CLIENT = auto()
+ LETTER_UPDATED = auto()
+
+ USER_NEW = auto()
+
+ @classmethod
+ def get_by_target_verb(cls, target, verb):
+ model_name = target._meta.model_name
+ name = "{model}_{verb}".format(model=model_name, verb=verb).upper()
+ return TemplateKey[name]
+
+
+class MailTemplate:
+ def __init__(self, txt_path, html_path=None):
+ self.txt_path = txt_path
+ self.html_path = html_path
+
+ def __str__(self):
+ return "{}-{}".format(self.txt_path, self.html_path)
+
+ @classmethod
+ def from_prefix(cls, prefix):
+ txt_path = prefix + ".txt"
+ html_path = prefix + ".html"
+ return cls(txt_path, html_path)
+
+ def render(self, context):
+ txt = loader.get_template(self.txt_path).render(context)
+ html = loader.get_template(self.html_path).render(context)
+ return (txt, html)
+
+
+class TemplateMailManager:
+
+ TEMPLATE_MAP = {
+ TemplateKey.CASE_CLOSED: MailTemplate.from_prefix("cases/email/case_closed"),
+ TemplateKey.CASE_GRANT_GROUP: MailTemplate.from_prefix(
+ "cases/email/case_grant_group"
+ ),
+ TemplateKey.CASE_GRANTED: MailTemplate.from_prefix("cases/email/case_granted"),
+ TemplateKey.CASE_NEW: MailTemplate.from_prefix("cases/email/case_new"),
+ TemplateKey.CASE_REGISTERED: MailTemplate.from_prefix(
+ "cases/email/case_registered"
+ ),
+ TemplateKey.CASE_UPDATED: MailTemplate.from_prefix("cases/email/case_updated"),
+ TemplateKey.EVENT_CREATED: MailTemplate.from_prefix(
+ "events/email/event_created"
+ ),
+ TemplateKey.EVENT_UPDATED: MailTemplate.from_prefix(
+ "events/email/event_updated"
+ ),
+ TemplateKey.EVENT_REMINDER: MailTemplate.from_prefix(
+ "events/email/event_reminder"
+ ),
+ TemplateKey.LETTER_ACCEPTED: MailTemplate.from_prefix(
+ "letters/email/letter_accepted"
+ ),
+ TemplateKey.LETTER_CREATED: MailTemplate.from_prefix(
+ "letters/email/letter_created"
+ ),
+ TemplateKey.LETTER_DROP_A_NOTE: MailTemplate.from_prefix(
+ "letters/email/letter_drop_a_note"
+ ),
+ TemplateKey.LETTER_SEND_TO_CLIENT: MailTemplate.from_prefix(
+ "letters/email/letter_send_to_client"
+ ),
+ TemplateKey.LETTER_UPDATED: MailTemplate.from_prefix(
+ "letters/email/letter_updated"
+ ),
+ TemplateKey.USER_NEW: MailTemplate.from_prefix("users/email/new_user"),
+ }
+
+ @classmethod
+ def send(cls, template_key, recipient_list, context=None, from_email=None, **kwds):
+ template = cls.TEMPLATE_MAP[template_key]
+ txt, html = template.render(context or {})
+ subject, txt = txt.strip().split("\n", 1)
+ from_email = from_email if from_email else settings.DEFAULT_FROM_EMAIL
+ headers = {}
+ if len(sys.argv) > 1 and sys.argv[1] == "test":
+ headers["Template"] = str(template)
+ return cls._send_mail_with_header(
+ subject=subject.strip(),
+ message=txt,
+ html_message=html,
+ from_email=from_email,
+ recipient_list=recipient_list,
+ headers=headers,
+ **kwds,
+ )
+
+ @staticmethod
+ def _send_mail_with_header(
+ subject,
+ message,
+ from_email,
+ recipient_list,
+ fail_silently=False,
+ auth_user=None,
+ auth_password=None,
+ connection=None,
+ html_message=None,
+ headers=None,
+ ):
+ """
+ Fork of django.core.mail.send_mail to add haders attribute
+ """
+ connection = connection or get_connection(
+ username=auth_user, password=auth_password, fail_silently=fail_silently
+ )
+ mail = EmailMultiAlternatives(
+ subject,
+ message,
+ from_email,
+ recipient_list,
+ connection=connection,
+ headers=headers or {},
+ )
+ if html_message:
+ mail.attach_alternative(html_message, "text/html")
+ return mail.send()
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/views.py b/backend-project/small_eod/notifications/views.py
new file mode 100644
index 000000000..d43205620
--- /dev/null
+++ b/backend-project/small_eod/notifications/views.py
@@ -0,0 +1,64 @@
+from rest_framework.views import APIView
+from django.forms.models import model_to_dict
+
+
+class SendNotificationsMixin(APIView):
+ notified_users = ""
+ initial_instance = None
+
+ def send_notifications(self, http_action, **kwargs):
+ instance = None
+
+ if http_action in ["post", "put"]:
+ self.kwargs["pk"] = kwargs["data"]["id"]
+ instance = self.get_object()
+ else:
+ instance = self.initial_instance
+
+ notified_users = self.get_user_list(instance)
+ sender = self.basename
+
+ for user in notified_users:
+ user.notify(sender, self.action, **kwargs)
+
+ def get_user_list(self, instance):
+ for attr in self.notified_users.split("."):
+ instance = getattr(instance, attr)
+ return instance.all()
+
+ def initial(self, request, *args, **kwargs):
+ if (self.lookup_url_kwarg or self.lookup_field) in self.kwargs:
+ self.initial_instance = self.get_object()
+ return super(SendNotificationsMixin, self).initial(request, *args, **kwargs)
+
+ def dispatch(self, request, *args, **kwargs):
+ response = super(SendNotificationsMixin, self).dispatch(request, *args, **kwargs)
+ http_action = list(self.action_map.keys())[list(self.action_map.values()).index(self.action)]
+ if http_action in ["delete", "post", "put"]:
+ self.send_notifications(http_action, data=response.data)
+ return response
+
+ """
+ def get_changes(self, init_instance, instance):
+ d1 = model_to_dict(init_instance)
+ d2 = model_to_dict(instance)
+ diff = dict([(k, (v, d2[k])) for k, v in d1.items() if v != d2[k]])
+
+ changes = {}
+ for field, field_changes in diff.items():
+ before, after = field_changes[0], field_changes[1]
+ if type(before) == list:
+ removed, added = self._remove_common(before, after)
+ changes.update({field: {"added": added, "removed": removed, "changed": None}})
+ else:
+ changes.update({field: {"added": None, "removed": None, "changed": {"from": before, "to": after}}})
+
+ return changes
+
+ def _remove_common(self, l1, l2):
+ for element in l1.copy() if len(l1) > len(l2) else l2.copy():
+ if element in l1 and element in l2:
+ l1.remove(element)
+ l2.remove(element)
+ return l1, l2
+ """
\ No newline at end of file
diff --git a/backend-project/small_eod/users/models.py b/backend-project/small_eod/users/models.py
index 3d305253b..c709cde68 100644
--- a/backend-project/small_eod/users/models.py
+++ b/backend-project/small_eod/users/models.py
@@ -2,4 +2,8 @@
class User(AbstractUser):
- pass
+ def notify(self, sender, action, **kwargs):
+ pass
+
+ def get_enabled_notifications(self):
+ pass
From e259fc1d0d1ed15009987fe935196d4cc9128d37 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Sun, 9 May 2021 20:27:46 +0000
Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
backend-project/small_eod/cases/views.py | 4 ++--
backend-project/small_eod/notifications/utils.py | 8 ++++----
backend-project/small_eod/notifications/views.py | 14 +++++++++-----
3 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/backend-project/small_eod/cases/views.py b/backend-project/small_eod/cases/views.py
index 313faf5bb..8090d2d15 100644
--- a/backend-project/small_eod/cases/views.py
+++ b/backend-project/small_eod/cases/views.py
@@ -2,11 +2,11 @@
from rest_framework import viewsets
from rest_framework.filters import OrderingFilter
+from ..notifications.views import SendNotificationsMixin
from ..users.serializers import UserSerializer
from .filterset import CaseFilterSet
from .models import Case
from .serializers import CaseCountSerializer
-from ..notifications.views import SendNotificationsMixin
class CaseViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
@@ -58,4 +58,4 @@ class NotifiedUserViewSet(viewsets.ReadOnlyModelViewSet):
)
def get_queryset(self):
- return Case.objects.get(pk=self.kwargs["case_pk"]).notified_users.all()
\ No newline at end of file
+ return Case.objects.get(pk=self.kwargs["case_pk"]).notified_users.all()
diff --git a/backend-project/small_eod/notifications/utils.py b/backend-project/small_eod/notifications/utils.py
index 0e38c4e6a..001727e03 100644
--- a/backend-project/small_eod/notifications/utils.py
+++ b/backend-project/small_eod/notifications/utils.py
@@ -1,7 +1,7 @@
+import logging
import sys
from enum import Enum
-import logging
from django.conf import settings
from django.core.mail import get_connection
from django.core.mail.message import EmailMultiAlternatives
@@ -49,7 +49,7 @@ class TemplateKey(Enum):
@classmethod
def get_by_target_verb(cls, target, verb):
model_name = target._meta.model_name
- name = "{model}_{verb}".format(model=model_name, verb=verb).upper()
+ name = f"{model_name}_{verb}".upper()
return TemplateKey[name]
@@ -59,7 +59,7 @@ def __init__(self, txt_path, html_path=None):
self.html_path = html_path
def __str__(self):
- return "{}-{}".format(self.txt_path, self.html_path)
+ return f"{self.txt_path}-{self.html_path}"
@classmethod
def from_prefix(cls, prefix):
@@ -161,4 +161,4 @@ def _send_mail_with_header(
)
if html_message:
mail.attach_alternative(html_message, "text/html")
- return mail.send()
\ No newline at end of file
+ return mail.send()
diff --git a/backend-project/small_eod/notifications/views.py b/backend-project/small_eod/notifications/views.py
index d43205620..7d27e015b 100644
--- a/backend-project/small_eod/notifications/views.py
+++ b/backend-project/small_eod/notifications/views.py
@@ -1,5 +1,5 @@
-from rest_framework.views import APIView
from django.forms.models import model_to_dict
+from rest_framework.views import APIView
class SendNotificationsMixin(APIView):
@@ -29,11 +29,15 @@ def get_user_list(self, instance):
def initial(self, request, *args, **kwargs):
if (self.lookup_url_kwarg or self.lookup_field) in self.kwargs:
self.initial_instance = self.get_object()
- return super(SendNotificationsMixin, self).initial(request, *args, **kwargs)
+ return super().initial(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs):
- response = super(SendNotificationsMixin, self).dispatch(request, *args, **kwargs)
- http_action = list(self.action_map.keys())[list(self.action_map.values()).index(self.action)]
+ response = super().dispatch(
+ request, *args, **kwargs
+ )
+ http_action = list(self.action_map.keys())[
+ list(self.action_map.values()).index(self.action)
+ ]
if http_action in ["delete", "post", "put"]:
self.send_notifications(http_action, data=response.data)
return response
@@ -61,4 +65,4 @@ def _remove_common(self, l1, l2):
l1.remove(element)
l2.remove(element)
return l1, l2
- """
\ No newline at end of file
+ """
From 83325b993ef40ade8c24261b9a6e47935365b1c0 Mon Sep 17 00:00:00 2001
From: NameLesS
Date: Fri, 14 May 2021 02:39:28 +0200
Subject: [PATCH 3/9] add notify method in User model
---
backend-project/config/settings/base.py | 15 +++-
.../templates/cases/email/case_created.html | 2 +
.../templates/cases/email/case_created.txt | 2 +
.../cases/templates/cases/email/case_removed | 2 +
.../templates/cases/email/case_removed.html | 2 +
.../templates/cases/email/case_updated.html | 2 +
.../templates/cases/email/case_updated.txt | 2 +
backend-project/small_eod/cases/views.py | 5 +-
backend-project/small_eod/events/views.py | 5 +-
backend-project/small_eod/letters/views.py | 5 +-
backend-project/small_eod/notes/views.py | 5 +-
.../small_eod/notifications/utils.py | 80 ++++---------------
.../small_eod/notifications/views.py | 71 ++++++++--------
backend-project/small_eod/users/models.py | 12 ++-
14 files changed, 98 insertions(+), 112 deletions(-)
create mode 100644 backend-project/small_eod/cases/templates/cases/email/case_created.html
create mode 100644 backend-project/small_eod/cases/templates/cases/email/case_created.txt
create mode 100644 backend-project/small_eod/cases/templates/cases/email/case_removed
create mode 100644 backend-project/small_eod/cases/templates/cases/email/case_removed.html
create mode 100644 backend-project/small_eod/cases/templates/cases/email/case_updated.html
create mode 100644 backend-project/small_eod/cases/templates/cases/email/case_updated.txt
diff --git a/backend-project/config/settings/base.py b/backend-project/config/settings/base.py
index 81ca9c494..c4fad8688 100644
--- a/backend-project/config/settings/base.py
+++ b/backend-project/config/settings/base.py
@@ -19,6 +19,7 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
DEBUG = False
# Quick-start development settings - unsuitable for production
@@ -59,6 +60,7 @@
"small_eod.events",
"small_eod.administrative_units",
"small_eod.authkey",
+ "small_eod.notifications"
]
MIDDLEWARE = [
@@ -85,7 +87,7 @@
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
- ],
+ ]
},
},
]
@@ -173,3 +175,14 @@
MINIO_SECRET_KEY = env("MINIO_SECRET_KEY")
MINIO_URL = env("MINIO_URL")
MINIO_BUCKET = env("MINIO_BUCKET", default="files")
+
+
+EMAIL_BACKEND = env("DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend")
+EMAIL_HOST = env("DJANGO_EMAIL_HOST", default="")
+EMAIL_HOST_PASSWORD = env("DJANGO_EMAIL_HOST_PASSWORD", default="")
+EMAIL_HOST_USER = env("DJANGO_EMAIL_HOST_USER", default="")
+EMAIL_PORT = env("DJANGO_EMAIL_PORT", default="")
+DEFAULT_FROM_EMAIL = env("DJANGO_DEFAULT_FROM_EMAIL", default="")
+EMAIL_SUBJECT_PREFIX = env("DJANGO_EMAIL_SUBJECT_PREFIX", default="")
+EMAIL_USE_TLS = env("DJANGO_EMAIL_USE_TLS", default=True)
+SERVER_EMAIL = EMAIL_HOST_USER
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.html b/backend-project/small_eod/cases/templates/cases/email/case_created.html
new file mode 100644
index 000000000..ac9cc0f14
--- /dev/null
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.html
@@ -0,0 +1,2 @@
+Case create
>
+Case create
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.txt b/backend-project/small_eod/cases/templates/cases/email/case_created.txt
new file mode 100644
index 000000000..2371cafb6
--- /dev/null
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.txt
@@ -0,0 +1,2 @@
+Case create
+Case create
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed b/backend-project/small_eod/cases/templates/cases/email/case_removed
new file mode 100644
index 000000000..8e072c387
--- /dev/null
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed
@@ -0,0 +1,2 @@
+Case removed
+Case removed
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed.html b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
new file mode 100644
index 000000000..fafa63e0f
--- /dev/null
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
@@ -0,0 +1,2 @@
+Case removed
+Case removed
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.html b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
new file mode 100644
index 000000000..e231fe6ab
--- /dev/null
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
@@ -0,0 +1,2 @@
+Case updated
+Case updated
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
new file mode 100644
index 000000000..c9f0c6743
--- /dev/null
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
@@ -0,0 +1,2 @@
+Case update
+Case update
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/views.py b/backend-project/small_eod/cases/views.py
index 313faf5bb..51bbe5eac 100644
--- a/backend-project/small_eod/cases/views.py
+++ b/backend-project/small_eod/cases/views.py
@@ -10,6 +10,8 @@
class CaseViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
+ notified_users = "notified_users"
+ ignored_fields = ["modified_by", "modified_on"]
queryset = Case.objects.with_counter().with_nested_resources().all()
serializer_class = CaseCountSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
@@ -28,7 +30,6 @@ class CaseViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
"created_on",
"modified_on",
]
- notified_users = "notified_users"
class ResponsibleUserViewSet(viewsets.ReadOnlyModelViewSet):
@@ -58,4 +59,4 @@ class NotifiedUserViewSet(viewsets.ReadOnlyModelViewSet):
)
def get_queryset(self):
- return Case.objects.get(pk=self.kwargs["case_pk"]).notified_users.all()
\ No newline at end of file
+ return Case.objects.get(pk=self.kwargs["case_pk"]).notified_users.all()
diff --git a/backend-project/small_eod/events/views.py b/backend-project/small_eod/events/views.py
index 9ac0ffd6e..6185c3442 100644
--- a/backend-project/small_eod/events/views.py
+++ b/backend-project/small_eod/events/views.py
@@ -15,9 +15,12 @@
from .filterset import EventFilterSet
from .models import Event
from .serializers import EventSerializer
+from ..notifications.views import SendNotificationsMixin
-class EventViewSet(viewsets.ModelViewSet):
+class EventViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
+ notified_users = "case.notified_users"
+ ignored_fields = ["modified_by"]
queryset = Event.objects.prefetch_related("case").all()
serializer_class = EventSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
diff --git a/backend-project/small_eod/letters/views.py b/backend-project/small_eod/letters/views.py
index b283e6088..2b7288d03 100644
--- a/backend-project/small_eod/letters/views.py
+++ b/backend-project/small_eod/letters/views.py
@@ -11,9 +11,12 @@
from .filterset import DocumentTypeFilterSet, LetterFilterSet
from .models import DocumentType, Letter
from .serializers import DocumentTypeSerializer, LetterSerializer, SignRequestSerializer
+from ..notifications.views import SendNotificationsMixin
-class LetterViewSet(viewsets.ModelViewSet):
+class LetterViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
+ notified_users = "case.notified_users"
+ ignored_fields = ["modified_on", "modified_by"]
queryset = Letter.objects.prefetch_related("attachments").all()
serializer_class = LetterSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
diff --git a/backend-project/small_eod/notes/views.py b/backend-project/small_eod/notes/views.py
index bbad901e7..f5c6a7c74 100644
--- a/backend-project/small_eod/notes/views.py
+++ b/backend-project/small_eod/notes/views.py
@@ -5,9 +5,12 @@
from .filterset import NoteFilterSet
from .models import Note
from .serializers import NoteSerializer
+from ..notifications.views import SendNotificationsMixin
-class NoteViewSet(viewsets.ModelViewSet):
+class NoteViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
+ notified_users = "case.notified_users"
+ ignored_fields = ["modified_by"]
queryset = Note.objects.all()
serializer_class = NoteSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
diff --git a/backend-project/small_eod/notifications/utils.py b/backend-project/small_eod/notifications/utils.py
index 0e38c4e6a..9f8775491 100644
--- a/backend-project/small_eod/notifications/utils.py
+++ b/backend-project/small_eod/notifications/utils.py
@@ -1,7 +1,8 @@
import sys
-from enum import Enum
-
+import random
import logging
+
+from enum import Enum
from django.conf import settings
from django.core.mail import get_connection
from django.core.mail.message import EmailMultiAlternatives
@@ -27,30 +28,9 @@ def loop():
class TemplateKey(Enum):
- CASE_CLOSED = auto()
- CASE_GRANT_GROUP = auto()
- CASE_GRANTED = auto()
- CASE_NEW = auto()
- CASE_REGISTERED = auto()
- CASE_UPDATED = auto()
-
- EVENT_CREATED = auto()
- EVENT_UPDATED = auto()
- EVENT_REMINDER = auto()
-
- LETTER_ACCEPTED = auto()
- LETTER_CREATED = auto()
- LETTER_DROP_A_NOTE = auto()
- LETTER_SEND_TO_CLIENT = auto()
- LETTER_UPDATED = auto()
-
- USER_NEW = auto()
-
- @classmethod
- def get_by_target_verb(cls, target, verb):
- model_name = target._meta.model_name
- name = "{model}_{verb}".format(model=model_name, verb=verb).upper()
- return TemplateKey[name]
+ CASE_CREATE = auto()
+ CASE_UPDATE = auto()
+ CASE_DESTROY = auto()
class MailTemplate:
@@ -59,7 +39,7 @@ def __init__(self, txt_path, html_path=None):
self.html_path = html_path
def __str__(self):
- return "{}-{}".format(self.txt_path, self.html_path)
+ return f"{self.txt_path}-{self.html_path}"
@classmethod
def from_prefix(cls, prefix):
@@ -70,58 +50,26 @@ def from_prefix(cls, prefix):
def render(self, context):
txt = loader.get_template(self.txt_path).render(context)
html = loader.get_template(self.html_path).render(context)
- return (txt, html)
+ return txt, html
class TemplateMailManager:
-
TEMPLATE_MAP = {
- TemplateKey.CASE_CLOSED: MailTemplate.from_prefix("cases/email/case_closed"),
- TemplateKey.CASE_GRANT_GROUP: MailTemplate.from_prefix(
- "cases/email/case_grant_group"
- ),
- TemplateKey.CASE_GRANTED: MailTemplate.from_prefix("cases/email/case_granted"),
- TemplateKey.CASE_NEW: MailTemplate.from_prefix("cases/email/case_new"),
- TemplateKey.CASE_REGISTERED: MailTemplate.from_prefix(
- "cases/email/case_registered"
- ),
- TemplateKey.CASE_UPDATED: MailTemplate.from_prefix("cases/email/case_updated"),
- TemplateKey.EVENT_CREATED: MailTemplate.from_prefix(
- "events/email/event_created"
- ),
- TemplateKey.EVENT_UPDATED: MailTemplate.from_prefix(
- "events/email/event_updated"
- ),
- TemplateKey.EVENT_REMINDER: MailTemplate.from_prefix(
- "events/email/event_reminder"
- ),
- TemplateKey.LETTER_ACCEPTED: MailTemplate.from_prefix(
- "letters/email/letter_accepted"
- ),
- TemplateKey.LETTER_CREATED: MailTemplate.from_prefix(
- "letters/email/letter_created"
- ),
- TemplateKey.LETTER_DROP_A_NOTE: MailTemplate.from_prefix(
- "letters/email/letter_drop_a_note"
- ),
- TemplateKey.LETTER_SEND_TO_CLIENT: MailTemplate.from_prefix(
- "letters/email/letter_send_to_client"
- ),
- TemplateKey.LETTER_UPDATED: MailTemplate.from_prefix(
- "letters/email/letter_updated"
- ),
- TemplateKey.USER_NEW: MailTemplate.from_prefix("users/email/new_user"),
+ TemplateKey.CASE_CREATE: [MailTemplate.from_prefix("cases/email/case_created")],
+ TemplateKey.CASE_DESTROY: [MailTemplate.from_prefix("cases/email/case_closed")],
+ TemplateKey.CASE_UPDATE: [MailTemplate.from_prefix("cases/email/case_updated")],
}
@classmethod
def send(cls, template_key, recipient_list, context=None, from_email=None, **kwds):
- template = cls.TEMPLATE_MAP[template_key]
+ template = random.choice(cls.TEMPLATE_MAP[template_key])
txt, html = template.render(context or {})
subject, txt = txt.strip().split("\n", 1)
from_email = from_email if from_email else settings.DEFAULT_FROM_EMAIL
headers = {}
if len(sys.argv) > 1 and sys.argv[1] == "test":
headers["Template"] = str(template)
+
return cls._send_mail_with_header(
subject=subject.strip(),
message=txt,
@@ -161,4 +109,4 @@ def _send_mail_with_header(
)
if html_message:
mail.attach_alternative(html_message, "text/html")
- return mail.send()
\ No newline at end of file
+ return mail.send()
diff --git a/backend-project/small_eod/notifications/views.py b/backend-project/small_eod/notifications/views.py
index d43205620..8675a4ed3 100644
--- a/backend-project/small_eod/notifications/views.py
+++ b/backend-project/small_eod/notifications/views.py
@@ -3,62 +3,59 @@
class SendNotificationsMixin(APIView):
- notified_users = ""
- initial_instance = None
+ notified_users = None
+ ignored_fields = []
+ init_instance = None
def send_notifications(self, http_action, **kwargs):
+ self.kwargs["pk"] = self.kwargs.get("pk", None) or kwargs["data"].get("id", None)
instance = None
if http_action in ["post", "put"]:
- self.kwargs["pk"] = kwargs["data"]["id"]
instance = self.get_object()
else:
- instance = self.initial_instance
+ instance = self.init_instance
- notified_users = self.get_user_list(instance)
- sender = self.basename
+ if http_action == "put" and not self.has_instance_changed(self.init_instance, instance):
+ return
+
+ notified_users = self.get_notified_uers(instance)
+ kwargs["actor"] = self.basename
+ kwargs["action"] = self.action
+ kwargs["instance"] = model_to_dict(instance)
for user in notified_users:
- user.notify(sender, self.action, **kwargs)
+ user.notify(**kwargs)
+
+ def has_instance_changed(self, init_instance, instance):
+ d1 = model_to_dict(init_instance)
+ d2 = model_to_dict(instance)
+
+ for field in self.ignored_fields:
+ d1.pop(field, None)
+ d2.pop(field, None)
+
+ return d1 != d2
- def get_user_list(self, instance):
+ def get_notified_uers(self, instance):
+ if not self.notified_users:
+ raise TypeError("{0} is missing a `notified_users` attribute.".format(self.__class__.__name__))
for attr in self.notified_users.split("."):
instance = getattr(instance, attr)
return instance.all()
def initial(self, request, *args, **kwargs):
if (self.lookup_url_kwarg or self.lookup_field) in self.kwargs:
- self.initial_instance = self.get_object()
- return super(SendNotificationsMixin, self).initial(request, *args, **kwargs)
+ self.init_instance = self.get_object()
+ return super().initial(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs):
- response = super(SendNotificationsMixin, self).dispatch(request, *args, **kwargs)
- http_action = list(self.action_map.keys())[list(self.action_map.values()).index(self.action)]
+ response = super().dispatch(
+ request, *args, **kwargs
+ )
+ http_action = list(self.action_map.keys())[
+ list(self.action_map.values()).index(self.action)
+ ]
if http_action in ["delete", "post", "put"]:
self.send_notifications(http_action, data=response.data)
return response
-
- """
- def get_changes(self, init_instance, instance):
- d1 = model_to_dict(init_instance)
- d2 = model_to_dict(instance)
- diff = dict([(k, (v, d2[k])) for k, v in d1.items() if v != d2[k]])
-
- changes = {}
- for field, field_changes in diff.items():
- before, after = field_changes[0], field_changes[1]
- if type(before) == list:
- removed, added = self._remove_common(before, after)
- changes.update({field: {"added": added, "removed": removed, "changed": None}})
- else:
- changes.update({field: {"added": None, "removed": None, "changed": {"from": before, "to": after}}})
-
- return changes
-
- def _remove_common(self, l1, l2):
- for element in l1.copy() if len(l1) > len(l2) else l2.copy():
- if element in l1 and element in l2:
- l1.remove(element)
- l2.remove(element)
- return l1, l2
- """
\ No newline at end of file
diff --git a/backend-project/small_eod/users/models.py b/backend-project/small_eod/users/models.py
index c709cde68..4b5f112db 100644
--- a/backend-project/small_eod/users/models.py
+++ b/backend-project/small_eod/users/models.py
@@ -1,9 +1,15 @@
from django.contrib.auth.models import AbstractUser
+from ..notifications.utils import TemplateMailManager, TemplateKey
class User(AbstractUser):
- def notify(self, sender, action, **kwargs):
- pass
+ def notify(self, actor, action, **kwargs):
+ enabled = self.get_enabled_notifications()
+ key = getattr(TemplateKey, f"{actor}_{action}".upper(), None)
+ if key not in enabled:
+ return False
+
+ return TemplateMailManager.send(template_key=key, recipient_list=[self.email], context=kwargs)
def get_enabled_notifications(self):
- pass
+ return TemplateMailManager.TEMPLATE_MAP.keys()
From 63826d363c602a6ae5e520af1cf20e3b97bb9550 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Fri, 14 May 2021 01:10:50 +0000
Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
backend-project/config/settings/base.py | 6 ++++--
.../templates/cases/email/case_created.html | 2 +-
.../cases/templates/cases/email/case_removed | 2 +-
.../templates/cases/email/case_removed.html | 2 +-
.../templates/cases/email/case_updated.html | 2 +-
.../templates/cases/email/case_updated.txt | 2 +-
backend-project/small_eod/cases/views.py | 2 +-
backend-project/small_eod/events/views.py | 2 +-
backend-project/small_eod/letters/views.py | 2 +-
backend-project/small_eod/notes/views.py | 2 +-
.../small_eod/notifications/utils.py | 6 +++---
.../small_eod/notifications/views.py | 20 ++++++++++++-------
backend-project/small_eod/users/models.py | 7 +++++--
13 files changed, 34 insertions(+), 23 deletions(-)
diff --git a/backend-project/config/settings/base.py b/backend-project/config/settings/base.py
index c4fad8688..e58b022e1 100644
--- a/backend-project/config/settings/base.py
+++ b/backend-project/config/settings/base.py
@@ -60,7 +60,7 @@
"small_eod.events",
"small_eod.administrative_units",
"small_eod.authkey",
- "small_eod.notifications"
+ "small_eod.notifications",
]
MIDDLEWARE = [
@@ -177,7 +177,9 @@
MINIO_BUCKET = env("MINIO_BUCKET", default="files")
-EMAIL_BACKEND = env("DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend")
+EMAIL_BACKEND = env(
+ "DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend"
+)
EMAIL_HOST = env("DJANGO_EMAIL_HOST", default="")
EMAIL_HOST_PASSWORD = env("DJANGO_EMAIL_HOST_PASSWORD", default="")
EMAIL_HOST_USER = env("DJANGO_EMAIL_HOST_USER", default="")
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.html b/backend-project/small_eod/cases/templates/cases/email/case_created.html
index ac9cc0f14..dd0da5b51 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_created.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.html
@@ -1,2 +1,2 @@
Case create
>
-Case create
\ No newline at end of file
+Case create
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed b/backend-project/small_eod/cases/templates/cases/email/case_removed
index 8e072c387..960c836a7 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_removed
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed
@@ -1,2 +1,2 @@
Case removed
-Case removed
\ No newline at end of file
+Case removed
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed.html b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
index fafa63e0f..1dfb0aa52 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_removed.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
@@ -1,2 +1,2 @@
Case removed
-Case removed
\ No newline at end of file
+Case removed
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.html b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
index e231fe6ab..e2c6c1c07 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
@@ -1,2 +1,2 @@
Case updated
-Case updated
\ No newline at end of file
+Case updated
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
index c9f0c6743..0a1914aac 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
@@ -1,2 +1,2 @@
Case update
-Case update
\ No newline at end of file
+Case update
diff --git a/backend-project/small_eod/cases/views.py b/backend-project/small_eod/cases/views.py
index 51bbe5eac..9dddb3582 100644
--- a/backend-project/small_eod/cases/views.py
+++ b/backend-project/small_eod/cases/views.py
@@ -2,11 +2,11 @@
from rest_framework import viewsets
from rest_framework.filters import OrderingFilter
+from ..notifications.views import SendNotificationsMixin
from ..users.serializers import UserSerializer
from .filterset import CaseFilterSet
from .models import Case
from .serializers import CaseCountSerializer
-from ..notifications.views import SendNotificationsMixin
class CaseViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
diff --git a/backend-project/small_eod/events/views.py b/backend-project/small_eod/events/views.py
index 6185c3442..3d2902245 100644
--- a/backend-project/small_eod/events/views.py
+++ b/backend-project/small_eod/events/views.py
@@ -12,10 +12,10 @@
from ..authkey.authentication import AuthKeyAuthentication
from ..authkey.permissions import AuthKeyPermission
+from ..notifications.views import SendNotificationsMixin
from .filterset import EventFilterSet
from .models import Event
from .serializers import EventSerializer
-from ..notifications.views import SendNotificationsMixin
class EventViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
diff --git a/backend-project/small_eod/letters/views.py b/backend-project/small_eod/letters/views.py
index 2b7288d03..d30256030 100644
--- a/backend-project/small_eod/letters/views.py
+++ b/backend-project/small_eod/letters/views.py
@@ -8,10 +8,10 @@
from ..files.models import File
from ..files.serializers import FileSerializer
+from ..notifications.views import SendNotificationsMixin
from .filterset import DocumentTypeFilterSet, LetterFilterSet
from .models import DocumentType, Letter
from .serializers import DocumentTypeSerializer, LetterSerializer, SignRequestSerializer
-from ..notifications.views import SendNotificationsMixin
class LetterViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
diff --git a/backend-project/small_eod/notes/views.py b/backend-project/small_eod/notes/views.py
index f5c6a7c74..fd4710302 100644
--- a/backend-project/small_eod/notes/views.py
+++ b/backend-project/small_eod/notes/views.py
@@ -2,10 +2,10 @@
from rest_framework import viewsets
from rest_framework.filters import OrderingFilter
+from ..notifications.views import SendNotificationsMixin
from .filterset import NoteFilterSet
from .models import Note
from .serializers import NoteSerializer
-from ..notifications.views import SendNotificationsMixin
class NoteViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
diff --git a/backend-project/small_eod/notifications/utils.py b/backend-project/small_eod/notifications/utils.py
index 9f8775491..6651db617 100644
--- a/backend-project/small_eod/notifications/utils.py
+++ b/backend-project/small_eod/notifications/utils.py
@@ -1,8 +1,8 @@
-import sys
-import random
import logging
-
+import random
+import sys
from enum import Enum
+
from django.conf import settings
from django.core.mail import get_connection
from django.core.mail.message import EmailMultiAlternatives
diff --git a/backend-project/small_eod/notifications/views.py b/backend-project/small_eod/notifications/views.py
index 8675a4ed3..a5af9c649 100644
--- a/backend-project/small_eod/notifications/views.py
+++ b/backend-project/small_eod/notifications/views.py
@@ -1,5 +1,5 @@
-from rest_framework.views import APIView
from django.forms.models import model_to_dict
+from rest_framework.views import APIView
class SendNotificationsMixin(APIView):
@@ -8,7 +8,9 @@ class SendNotificationsMixin(APIView):
init_instance = None
def send_notifications(self, http_action, **kwargs):
- self.kwargs["pk"] = self.kwargs.get("pk", None) or kwargs["data"].get("id", None)
+ self.kwargs["pk"] = self.kwargs.get("pk", None) or kwargs["data"].get(
+ "id", None
+ )
instance = None
if http_action in ["post", "put"]:
@@ -16,7 +18,9 @@ def send_notifications(self, http_action, **kwargs):
else:
instance = self.init_instance
- if http_action == "put" and not self.has_instance_changed(self.init_instance, instance):
+ if http_action == "put" and not self.has_instance_changed(
+ self.init_instance, instance
+ ):
return
notified_users = self.get_notified_uers(instance)
@@ -39,7 +43,11 @@ def has_instance_changed(self, init_instance, instance):
def get_notified_uers(self, instance):
if not self.notified_users:
- raise TypeError("{0} is missing a `notified_users` attribute.".format(self.__class__.__name__))
+ raise TypeError(
+ "{} is missing a `notified_users` attribute.".format(
+ self.__class__.__name__
+ )
+ )
for attr in self.notified_users.split("."):
instance = getattr(instance, attr)
return instance.all()
@@ -50,9 +58,7 @@ def initial(self, request, *args, **kwargs):
return super().initial(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs):
- response = super().dispatch(
- request, *args, **kwargs
- )
+ response = super().dispatch(request, *args, **kwargs)
http_action = list(self.action_map.keys())[
list(self.action_map.values()).index(self.action)
]
diff --git a/backend-project/small_eod/users/models.py b/backend-project/small_eod/users/models.py
index 4b5f112db..fc9016a40 100644
--- a/backend-project/small_eod/users/models.py
+++ b/backend-project/small_eod/users/models.py
@@ -1,5 +1,6 @@
from django.contrib.auth.models import AbstractUser
-from ..notifications.utils import TemplateMailManager, TemplateKey
+
+from ..notifications.utils import TemplateKey, TemplateMailManager
class User(AbstractUser):
@@ -9,7 +10,9 @@ def notify(self, actor, action, **kwargs):
if key not in enabled:
return False
- return TemplateMailManager.send(template_key=key, recipient_list=[self.email], context=kwargs)
+ return TemplateMailManager.send(
+ template_key=key, recipient_list=[self.email], context=kwargs
+ )
def get_enabled_notifications(self):
return TemplateMailManager.TEMPLATE_MAP.keys()
From b8251814168384e80becd853e6138dbaeb7ffc66 Mon Sep 17 00:00:00 2001
From: NameLesS
Date: Mon, 7 Jun 2021 00:29:18 +0200
Subject: [PATCH 5/9] add tests, notifications content
---
backend-project/small_eod/cases/factories.py | 2 +-
.../templates/cases/email/case_created.html | 16 ++-
.../templates/cases/email/case_created.txt | 14 ++-
.../cases/templates/cases/email/case_removed | 2 -
.../templates/cases/email/case_removed.html | 10 +-
.../templates/cases/email/case_removed.txt | 8 ++
.../templates/cases/email/case_updated.html | 16 ++-
.../templates/cases/email/case_updated.txt | 13 ++-
.../templates/events/email/event_created.html | 16 +++
.../templates/events/email/event_created.txt | 15 +++
.../templates/events/email/event_removed.html | 13 +++
.../templates/events/email/event_removed.txt | 11 ++
.../templates/events/email/event_updated.html | 16 +++
.../templates/events/email/event_updated.txt | 14 +++
.../small_eod/events/tests/test_views.py | 20 ++++
.../letters/email/letter_created.html | 18 +++
.../letters/email/letter_created.txt | 17 +++
.../letters/email/letter_removed.html | 8 ++
.../letters/email/letter_removed.txt | 8 ++
.../letters/email/letter_updated.html | 14 +++
.../letters/email/letter_updated.txt | 12 ++
.../templates/notes/email/note_created.html | 15 +++
.../templates/notes/email/note_created.txt | 13 +++
.../templates/notes/email/note_removed.html | 8 ++
.../templates/notes/email/note_removed.txt | 8 ++
.../templates/notes/email/note_updated.html | 16 +++
.../templates/notes/email/note_updated.txt | 14 +++
.../notifications/email/mail_base.html | 10 ++
.../notifications/email/mail_base.txt | 9 ++
.../email/test_notifications.html | 2 +
.../email/test_notifications.txt | 2 +
.../small_eod/notifications/utils.py | 108 ++++++++++--------
.../small_eod/notifications/views.py | 36 ++++--
backend-project/small_eod/users/models.py | 1 +
.../small_eod/users/tests/test_models.py | 29 +++++
35 files changed, 462 insertions(+), 72 deletions(-)
delete mode 100644 backend-project/small_eod/cases/templates/cases/email/case_removed
create mode 100644 backend-project/small_eod/cases/templates/cases/email/case_removed.txt
create mode 100644 backend-project/small_eod/events/templates/events/email/event_created.html
create mode 100644 backend-project/small_eod/events/templates/events/email/event_created.txt
create mode 100644 backend-project/small_eod/events/templates/events/email/event_removed.html
create mode 100644 backend-project/small_eod/events/templates/events/email/event_removed.txt
create mode 100644 backend-project/small_eod/events/templates/events/email/event_updated.html
create mode 100644 backend-project/small_eod/events/templates/events/email/event_updated.txt
create mode 100644 backend-project/small_eod/letters/templates/letters/email/letter_created.html
create mode 100644 backend-project/small_eod/letters/templates/letters/email/letter_created.txt
create mode 100644 backend-project/small_eod/letters/templates/letters/email/letter_removed.html
create mode 100644 backend-project/small_eod/letters/templates/letters/email/letter_removed.txt
create mode 100644 backend-project/small_eod/letters/templates/letters/email/letter_updated.html
create mode 100644 backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
create mode 100644 backend-project/small_eod/notes/templates/notes/email/note_created.html
create mode 100644 backend-project/small_eod/notes/templates/notes/email/note_created.txt
create mode 100644 backend-project/small_eod/notes/templates/notes/email/note_removed.html
create mode 100644 backend-project/small_eod/notes/templates/notes/email/note_removed.txt
create mode 100644 backend-project/small_eod/notes/templates/notes/email/note_updated.html
create mode 100644 backend-project/small_eod/notes/templates/notes/email/note_updated.txt
create mode 100644 backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
create mode 100644 backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
create mode 100644 backend-project/small_eod/notifications/templates/notifications/email/test_notifications.html
create mode 100644 backend-project/small_eod/notifications/templates/notifications/email/test_notifications.txt
create mode 100644 backend-project/small_eod/users/tests/test_models.py
diff --git a/backend-project/small_eod/cases/factories.py b/backend-project/small_eod/cases/factories.py
index 2ffdb947b..7ad438f94 100644
--- a/backend-project/small_eod/cases/factories.py
+++ b/backend-project/small_eod/cases/factories.py
@@ -18,7 +18,7 @@ class CaseFactory(AbstractTimestampUserFactory, factory.django.DjangoModelFactor
m2m_field_name="responsible_users", factory_cls=UserFactory
)
notified_users = ManyToManyPostGeneration(
- m2m_field_name="notified_users", factory_cls=UserFactory
+ m2m_field_name="notified_users", factory_cls=UserFactory, size=3
)
tags = ManyToManyPostGeneration(
m2m_field_name="tags", factory_cls=TagFactory, size=3
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.html b/backend-project/small_eod/cases/templates/cases/email/case_created.html
index dd0da5b51..1c08795d5 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_created.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.html
@@ -1,2 +1,14 @@
-Case create
>
-Case create
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Utworzono nową sprawę - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+W systemie small_eod pojawiła się nowa sprawa.
+
+
+Sprawa: {{instance.name}}
+Utworzył: {{instance.created_by}}
+Data utworzenia: {{instance.created_on}}
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.txt b/backend-project/small_eod/cases/templates/cases/email/case_created.txt
index 2371cafb6..9483b9d61 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_created.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.txt
@@ -1,2 +1,12 @@
-Case create
-Case create
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Utworzono nową sprawę - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+W systemie small_eod pojawiła się nowa sprawa.
+
+Sprawa: {{instance.name}}
+Utworzył: {{instance.created_by}}
+Data utworzenia: {{instance.created_on}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed b/backend-project/small_eod/cases/templates/cases/email/case_removed
deleted file mode 100644
index 960c836a7..000000000
--- a/backend-project/small_eod/cases/templates/cases/email/case_removed
+++ /dev/null
@@ -1,2 +0,0 @@
-Case removed
-Case removed
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed.html b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
index 1dfb0aa52..8bf589deb 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_removed.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
@@ -1,2 +1,8 @@
-Case removed
-Case removed
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Zamknięto sprawę - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+{{instance.modified_by}} zamknął obserwowaną przez ciebie sprawę - {{instance.name}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed.txt b/backend-project/small_eod/cases/templates/cases/email/case_removed.txt
new file mode 100644
index 000000000..36c48c5e6
--- /dev/null
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed.txt
@@ -0,0 +1,8 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Zamknięto sprawę - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+{{instance.modified_by}} zamknął obserwowaną przez ciebie sprawę - {{instance.name}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.html b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
index e2c6c1c07..d5f1549a7 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
@@ -1,2 +1,14 @@
-Case updated
-Case updated
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Zaktualizowano sprawę - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+{{modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
+
+
+Sprawa: {{instance.name}}
+Zmodyfikował: {{instance.modified_by}}
+Data modyfikacji: {{instance.modified_on}}
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
index 0a1914aac..2d6f1cf14 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
@@ -1,2 +1,11 @@
-Case update
-Case update
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Zaktualizowano sprawę - {{instance.name}}
+{% endblock %}
+{% block content %}
+{{instance.modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
+
+Sprawa: {{instance.name}}
+Zmodyfikował: {{instance.modified_by}}
+Data modyfikacji: {{instance.modified_on}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.html b/backend-project/small_eod/events/templates/events/email/event_created.html
new file mode 100644
index 000000000..35bdfae13
--- /dev/null
+++ b/backend-project/small_eod/events/templates/events/email/event_created.html
@@ -0,0 +1,16 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Nowe wydarzenie w sprawie - {{instance.case.name}}
+{% endblock %}
+
+{% block content %}
+{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
+
+
+Wydarzenie: {{instance.name}}
+Dotyczy: {{instance.case.name}}
+Zaplanowano na: {{instance.date}}
+Utworzył: {{instance.created_by}}
+Data utworzenia: {{instance.created_on}}
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.txt b/backend-project/small_eod/events/templates/events/email/event_created.txt
new file mode 100644
index 000000000..aafcc42d3
--- /dev/null
+++ b/backend-project/small_eod/events/templates/events/email/event_created.txt
@@ -0,0 +1,15 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Utworzono nowe wydarzenie w sprawie - {{instance.case.name}}
+{% endblock %}
+
+{% block content %}
+{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
+
+
+Wydarzenie: {{instance.name}}
+Dotyczy: {{instance.case.name}}
+Zaplanowano na: {{instance.date}}
+Utworzył: {{instance.created_by}}
+Data utworzenia: {{instance.created_on}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_removed.html b/backend-project/small_eod/events/templates/events/email/event_removed.html
new file mode 100644
index 000000000..f0bb79f39
--- /dev/null
+++ b/backend-project/small_eod/events/templates/events/email/event_removed.html
@@ -0,0 +1,13 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Usunięto wydarzenie - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+Usunięto zaplanowane wydarzenie - {{instance.name}}
+
+
+Wydarzenie: {{instance.name}}
+Dotyczy: {{instance.case.name}}
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_removed.txt b/backend-project/small_eod/events/templates/events/email/event_removed.txt
new file mode 100644
index 000000000..c920da867
--- /dev/null
+++ b/backend-project/small_eod/events/templates/events/email/event_removed.txt
@@ -0,0 +1,11 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Usunięto wydarzenie - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+Usunięto zaplanowane wydarzenie - {{instance.name}}
+
+Wydarzenie: {{instance.name}}
+Dotyczy: {{instance.case.name}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.html b/backend-project/small_eod/events/templates/events/email/event_updated.html
new file mode 100644
index 000000000..8f1719619
--- /dev/null
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.html
@@ -0,0 +1,16 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Zaktualizowano wydarzenie - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
+
+
+Wydarzenie: {{instance.name}}
+Dotyczy: {{instance.case.name}}
+Zmodyfikował: {{instance.modified_by}}
+Data modyfikacji: {{instance.modified_on}}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.txt b/backend-project/small_eod/events/templates/events/email/event_updated.txt
new file mode 100644
index 000000000..f27f6f8d0
--- /dev/null
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.txt
@@ -0,0 +1,14 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Zaktualizowano wydarzenie - {{instance.name}}
+{% endblock %}
+
+{% block content %}
+{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
+
+
+Wydarzenie: {{instance.name}}
+Dotyczy: {{instance.case.name}}
+Zmodyfikował: {{instance.modified_by}}
+Data modyfikacji: {{instance.modified_on}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/tests/test_views.py b/backend-project/small_eod/events/tests/test_views.py
index 81a8a1fd4..ea57aaa9f 100644
--- a/backend-project/small_eod/events/tests/test_views.py
+++ b/backend-project/small_eod/events/tests/test_views.py
@@ -1,4 +1,5 @@
from test_plus.test import TestCase
+from django.core import mail
from ...authkey.factories import KeyFactory
from ...generic.tests.test_views import GenericViewSetMixin, OrderingViewSetMixin
@@ -53,3 +54,22 @@ def test_ical_validate_response_format(self):
self.assertIn(self.obj.name, body)
self.assertIn(self.obj.comment, body)
self.assertIn(self.obj.case.name, body)
+
+ def test_send_post_notifications(self):
+ super().test_create_plain()
+ self.assertGreater(len(mail.outbox), 0)
+
+ def test_send_delete_notifications(self):
+ response = self.client.delete(
+ self.get_url(name="detail", pk=self.obj.pk, **self.get_extra_kwargs()),
+ )
+ self.assertTrue(response.status_code, 200)
+ self.assertGreater(len(mail.outbox), 0)
+
+ def test_send_patch_notifications(self):
+ super().test_update_partial_plain()
+ self.assertGreater(len(mail.outbox), 0)
+
+ def test_notify_user_only_once(self):
+ super().test_update_partial_plain()
+ self.assertEqual(len(mail.outbox), len(self.obj.case.notified_users.all()))
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_created.html b/backend-project/small_eod/letters/templates/letters/email/letter_created.html
new file mode 100644
index 000000000..db98cc8ef
--- /dev/null
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_created.html
@@ -0,0 +1,18 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Nowa wiadomość w sprawie - {{instance.case.name}}
+{% endblock %}
+
+{% block content %}
+{% if instance.direction == "received" %}
+Otrzymano nową wiadomość - {{instance.reference_number}} - dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}
+{% else %}
+Wysłano wiadomość - {{instance.reference_number}} - w sprawie - {{instance.case.name}}
+{% endif %}
+
+
+Dotyczy: {{instance.case.name}}
+Utworzył: {{instance.created_by}}
+Data utworzenia: {{instance.created_on}}
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_created.txt b/backend-project/small_eod/letters/templates/letters/email/letter_created.txt
new file mode 100644
index 000000000..76bea51e3
--- /dev/null
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_created.txt
@@ -0,0 +1,17 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Nowa wiadomość w sprawie - {{instance.case.name}}
+{% endblock %}
+
+{% block content %}
+{% if instance.direction == "received" %}
+Otrzymano nową wiadomość - {{instance.reference_number}} - dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}
+{% else %}
+Wysłano wiadomość - {{instance.reference_number}} - w sprawie - {{instance.case.name}}
+{% endif %}
+
+
+Dotyczy: {{instance.case.name}}
+Utworzył: {{instance.created_by}}
+Data utworzenia: {{instance.created_on}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_removed.html b/backend-project/small_eod/letters/templates/letters/email/letter_removed.html
new file mode 100644
index 000000000..b03d84df2
--- /dev/null
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_removed.html
@@ -0,0 +1,8 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Usunięto wiadomość - {{instance.reference_number}}
+{% endblock %}
+
+{% block content %}
+Usunięto wiadomość - {{instance.reference_number}} - dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}.
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_removed.txt b/backend-project/small_eod/letters/templates/letters/email/letter_removed.txt
new file mode 100644
index 000000000..5b1afce02
--- /dev/null
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_removed.txt
@@ -0,0 +1,8 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Usunięto wiadomość - {{instance.reference_number}}
+{% endblock %}
+
+{% block content %}
+Usunięto wiadomość - {{instance.reference_number}} - dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}.
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
new file mode 100644
index 000000000..fb5ef0259
--- /dev/null
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
@@ -0,0 +1,14 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Zmodyfikowano wiadomość - {{instance.reference_number}}
+{% endblock %}
+
+{% block content %}
+{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
+
+
+Dotyczy: {{instance.case.name}}
+Zmodyfikował: {{instance.modified_by}}
+Data modyfikacji: {{instance.modified_on}}
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
new file mode 100644
index 000000000..9350e74a8
--- /dev/null
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
@@ -0,0 +1,12 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Zmodyfikowano wiadomość - {{instance.reference_number}}
+{% endblock %}
+
+{% block content %}
+{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
+
+Dotyczy: {{instance.case.name}}
+Zmodyfikował: {{instance.modified_by}}
+Data modyfikacji: {{instance.modified_on}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.html b/backend-project/small_eod/notes/templates/notes/email/note_created.html
new file mode 100644
index 000000000..6f0ce2c0f
--- /dev/null
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.html
@@ -0,0 +1,15 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Dodano notatkę do sprawy - {{case}}
+{% endblock %}
+
+{% block content %}
+{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
+
+
+Dotyczy: {{instance.case.name}}
+Utworzył: {{instance.created_by}}
+Data utworzenia: {{instance.created_on}}
+Treść: {{instance.comment}}
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.txt b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
new file mode 100644
index 000000000..ab6689672
--- /dev/null
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
@@ -0,0 +1,13 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Dodano notatkę do sprawy - {{case}}
+{% endblock %}
+
+{% block content %}
+{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
+
+Dotyczy: {{instance.case.name}}
+Utworzył: {{instance.created_by}}
+Data utworzenia: {{instance.created_on}}
+Treść: {{instance.comment}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_removed.html b/backend-project/small_eod/notes/templates/notes/email/note_removed.html
new file mode 100644
index 000000000..969d5cf88
--- /dev/null
+++ b/backend-project/small_eod/notes/templates/notes/email/note_removed.html
@@ -0,0 +1,8 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Usunięto notatkę dotyczącą sprawy - {{instance.case.name}}
+{% endblock %}
+
+{% block content %}
+Usunięto notatkę dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_removed.txt b/backend-project/small_eod/notes/templates/notes/email/note_removed.txt
new file mode 100644
index 000000000..d6e9ee640
--- /dev/null
+++ b/backend-project/small_eod/notes/templates/notes/email/note_removed.txt
@@ -0,0 +1,8 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Usunięto notatkę dotyczącą sprawy - {{instance.case.name}}
+{% endblock %}
+
+{% block content %}
+Usunięto notatkę dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.html b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
new file mode 100644
index 000000000..37a3498ae
--- /dev/null
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
@@ -0,0 +1,16 @@
+{% extends "notifications/email/mail_base.html" %}
+{% block subject %}
+Zaktualizowano notatkę dotyczącą sprawy - {{instance.case.name}}
+{% endblock %}
+
+{% block content %}
+
+{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
+
+
+Sprawa: {{instance.case.name}}
+Zmieniona przez: {{instance.modified_by}}
+Data modyfikacji: {{instance.midofied_on}}
+Treść: {{instance.comment}}
+
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
new file mode 100644
index 000000000..0e7ae1bf8
--- /dev/null
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
@@ -0,0 +1,14 @@
+{% extends "notifications/email/mail_base.txt" %}
+{% block subject %}
+Zaktualizowano notatkę dotyczącą sprawy - {{instance.case.name}}
+{% endblock %}
+
+{% block content %}
+
+{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
+
+Sprawa: {{instance.case.name}}
+Zmieniona przez: {{instance.modified_by}}
+Data modyfikacji: {{instance.midofied_on}}
+Treść: {{instance.comment}}
+{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
new file mode 100644
index 000000000..585a4c4e2
--- /dev/null
+++ b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
@@ -0,0 +1,10 @@
+{% block subject %}
+{% endblock %}
+Witaj {{user.username}},
+
+{% block content %}
+{% endblock %}
+
+
+Więcej szczegółów znajdziesz pod adresem: {{url}}
+
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
new file mode 100644
index 000000000..25d0670c9
--- /dev/null
+++ b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
@@ -0,0 +1,9 @@
+{% block subject %}
+{% endblock %}
+Witaj {{user.username}},
+
+{% block content %}
+{% endblock %}
+
+
+Więcej szczegółów znajdziesz pod adresem: {{url}}
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.html b/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.html
new file mode 100644
index 000000000..626a48323
--- /dev/null
+++ b/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.html
@@ -0,0 +1,2 @@
+{{username}} wysłał testowe powiadomienie
+testowe powiadomienie
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.txt b/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.txt
new file mode 100644
index 000000000..a344c3cf5
--- /dev/null
+++ b/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.txt
@@ -0,0 +1,2 @@
+{{username}} wysłał testowe powiadomienie
+testowe powiadomienie
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/utils.py b/backend-project/small_eod/notifications/utils.py
index 6651db617..e1745276e 100644
--- a/backend-project/small_eod/notifications/utils.py
+++ b/backend-project/small_eod/notifications/utils.py
@@ -1,10 +1,8 @@
import logging
import random
-import sys
from enum import Enum
from django.conf import settings
-from django.core.mail import get_connection
from django.core.mail.message import EmailMultiAlternatives
from django.template import loader
@@ -12,7 +10,7 @@
def make_auto():
- """eum.auto replacement"""
+ """enum.auto replacement"""
def loop():
i = 1
@@ -30,7 +28,21 @@ def loop():
class TemplateKey(Enum):
CASE_CREATE = auto()
CASE_UPDATE = auto()
+ CASE_PARTIAL_UPDATE = CASE_UPDATE
CASE_DESTROY = auto()
+ EVENT_CREATE = auto()
+ EVENT_UPDATE = auto()
+ EVENT_PARTIAL_UPDATE = EVENT_UPDATE
+ EVENT_DESTROY = auto()
+ NOTE_CREATE = auto()
+ NOTE_UPDATE = auto()
+ NOTE_PARTIAL_UPDATE = NOTE_UPDATE
+ NOTE_DESTROY = auto()
+ LETTER_CREATE = auto()
+ LETTER_UPDATE = auto()
+ LETTER_PARTIAL_UPDATE = LETTER_UPDATE
+ LETTER_DESTROY = auto()
+ NOTIFICATION_TEST = auto()
class MailTemplate:
@@ -56,57 +68,57 @@ def render(self, context):
class TemplateMailManager:
TEMPLATE_MAP = {
TemplateKey.CASE_CREATE: [MailTemplate.from_prefix("cases/email/case_created")],
- TemplateKey.CASE_DESTROY: [MailTemplate.from_prefix("cases/email/case_closed")],
+ TemplateKey.CASE_DESTROY: [
+ MailTemplate.from_prefix("cases/email/case_removed")
+ ],
TemplateKey.CASE_UPDATE: [MailTemplate.from_prefix("cases/email/case_updated")],
+ TemplateKey.CASE_PARTIAL_UPDATE: [
+ MailTemplate.from_prefix("cases/email/case_updated")
+ ],
+ TemplateKey.EVENT_CREATE: [
+ MailTemplate.from_prefix("events/email/event_created")
+ ],
+ TemplateKey.EVENT_PARTIAL_UPDATE: [
+ MailTemplate.from_prefix("events/email/event_updated")
+ ],
+ TemplateKey.EVENT_UPDATE: [
+ MailTemplate.from_prefix("events/email/event_updated")
+ ],
+ TemplateKey.EVENT_DESTROY: [
+ MailTemplate.from_prefix("events/email/event_removed")
+ ],
+ TemplateKey.NOTE_CREATE: [MailTemplate.from_prefix("notes/email/note_created")],
+ TemplateKey.NOTE_UPDATE: [MailTemplate.from_prefix("notes/email/note_updated")],
+ TemplateKey.NOTE_PARTIAL_UPDATE: [
+ MailTemplate.from_prefix("notes/email/note_updated")
+ ],
+ TemplateKey.NOTE_DESTROY: [
+ MailTemplate.from_prefix("notes/email/note_removed")
+ ],
+ TemplateKey.LETTER_CREATE: [
+ MailTemplate.from_prefix("letters/email/letter_created")
+ ],
+ TemplateKey.LETTER_UPDATE: [
+ MailTemplate.from_prefix("letters/email/letter_updated")
+ ],
+ TemplateKey.LETTER_PARTIAL_UPDATE: [
+ MailTemplate.from_prefix("letters/email/letter_updated")
+ ],
+ TemplateKey.LETTER_DESTROY: [
+ MailTemplate.from_prefix("letters/email/letter_removed")
+ ],
+ TemplateKey.NOTIFICATION_TEST: [
+ MailTemplate.from_prefix("notifications/email/test_notifications")
+ ],
}
@classmethod
- def send(cls, template_key, recipient_list, context=None, from_email=None, **kwds):
+ def send(cls, template_key, recipient_list, context=None, from_email=None):
template = random.choice(cls.TEMPLATE_MAP[template_key])
txt, html = template.render(context or {})
subject, txt = txt.strip().split("\n", 1)
from_email = from_email if from_email else settings.DEFAULT_FROM_EMAIL
- headers = {}
- if len(sys.argv) > 1 and sys.argv[1] == "test":
- headers["Template"] = str(template)
-
- return cls._send_mail_with_header(
- subject=subject.strip(),
- message=txt,
- html_message=html,
- from_email=from_email,
- recipient_list=recipient_list,
- headers=headers,
- **kwds,
- )
-
- @staticmethod
- def _send_mail_with_header(
- subject,
- message,
- from_email,
- recipient_list,
- fail_silently=False,
- auth_user=None,
- auth_password=None,
- connection=None,
- html_message=None,
- headers=None,
- ):
- """
- Fork of django.core.mail.send_mail to add haders attribute
- """
- connection = connection or get_connection(
- username=auth_user, password=auth_password, fail_silently=fail_silently
- )
- mail = EmailMultiAlternatives(
- subject,
- message,
- from_email,
- recipient_list,
- connection=connection,
- headers=headers or {},
- )
- if html_message:
- mail.attach_alternative(html_message, "text/html")
+ mail = EmailMultiAlternatives(subject, txt, from_email, recipient_list)
+ mail.attach_alternative(html, "text/html")
+
return mail.send()
diff --git a/backend-project/small_eod/notifications/views.py b/backend-project/small_eod/notifications/views.py
index a5af9c649..28cb58b60 100644
--- a/backend-project/small_eod/notifications/views.py
+++ b/backend-project/small_eod/notifications/views.py
@@ -1,24 +1,26 @@
from django.forms.models import model_to_dict
from rest_framework.views import APIView
+from django.urls import reverse
class SendNotificationsMixin(APIView):
notified_users = None
ignored_fields = []
init_instance = None
+ http_action = None
- def send_notifications(self, http_action, **kwargs):
+ def send_notifications(self, request, **kwargs):
self.kwargs["pk"] = self.kwargs.get("pk", None) or kwargs["data"].get(
"id", None
)
instance = None
- if http_action in ["post", "put"]:
+ if self.http_action in ["post", "put", "patch"]:
instance = self.get_object()
else:
instance = self.init_instance
- if http_action == "put" and not self.has_instance_changed(
+ if self.http_action == "put" and not self.has_instance_changed(
self.init_instance, instance
):
return
@@ -26,7 +28,8 @@ def send_notifications(self, http_action, **kwargs):
notified_users = self.get_notified_uers(instance)
kwargs["actor"] = self.basename
kwargs["action"] = self.action
- kwargs["instance"] = model_to_dict(instance)
+ kwargs["instance"] = instance
+ kwargs["url"] = self.get_abs_path(request)
for user in notified_users:
user.notify(**kwargs)
@@ -41,6 +44,12 @@ def has_instance_changed(self, init_instance, instance):
return d1 != d2
+ def get_abs_path(self, request):
+ path = reverse(f"{self.basename}-list")
+ path = path.replace("/api", "", 1)
+ path = request.build_absolute_uri(path)
+ return path
+
def get_notified_uers(self, instance):
if not self.notified_users:
raise TypeError(
@@ -48,20 +57,25 @@ def get_notified_uers(self, instance):
self.__class__.__name__
)
)
+
for attr in self.notified_users.split("."):
- instance = getattr(instance, attr)
+ instance = getattr(instance, attr, None)
+
+ if not instance:
+ return []
+
return instance.all()
def initial(self, request, *args, **kwargs):
- if (self.lookup_url_kwarg or self.lookup_field) in self.kwargs:
+ self.http_action = list(self.action_map.keys())[
+ list(self.action_map.values()).index(self.action)
+ ]
+ if self.http_action in ["put", "delete", "patch"]:
self.init_instance = self.get_object()
return super().initial(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs):
response = super().dispatch(request, *args, **kwargs)
- http_action = list(self.action_map.keys())[
- list(self.action_map.values()).index(self.action)
- ]
- if http_action in ["delete", "post", "put"]:
- self.send_notifications(http_action, data=response.data)
+ if self.http_action in ["delete", "post", "put", "patch"]:
+ self.send_notifications(request=request, data=response.data)
return response
diff --git a/backend-project/small_eod/users/models.py b/backend-project/small_eod/users/models.py
index fc9016a40..8c5a06d7f 100644
--- a/backend-project/small_eod/users/models.py
+++ b/backend-project/small_eod/users/models.py
@@ -5,6 +5,7 @@
class User(AbstractUser):
def notify(self, actor, action, **kwargs):
+ kwargs["user"] = self
enabled = self.get_enabled_notifications()
key = getattr(TemplateKey, f"{actor}_{action}".upper(), None)
if key not in enabled:
diff --git a/backend-project/small_eod/users/tests/test_models.py b/backend-project/small_eod/users/tests/test_models.py
new file mode 100644
index 000000000..dda9491c4
--- /dev/null
+++ b/backend-project/small_eod/users/tests/test_models.py
@@ -0,0 +1,29 @@
+from ..factories import UserFactory
+from django.core import mail
+from django.test import TestCase
+
+
+class UserModelTestCase(TestCase):
+ def test_send_enabled_mail_notification(self):
+ actor = "NOTIFICATION"
+ action = "TEST"
+ user = UserFactory()
+ user.notify(actor, action)
+ self.assertEqual(len(mail.outbox), 1)
+
+ def test_do_not_send_disabled_notification(self):
+ actor = ""
+ action = ""
+ user = UserFactory()
+ user.notify(actor, action)
+ self.assertEqual(len(mail.outbox), 0)
+
+ def test_mail_notification_content_is_correct(self):
+ actor = "NOTIFICATION"
+ action = "TEST"
+ context = {"username": "user"}
+ user = UserFactory()
+ user.notify(actor, action, **context)
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertEqual(mail.outbox[0].subject, "user wysłał testowe powiadomienie")
+ self.assertEqual(mail.outbox[0].body, "testowe powiadomienie")
From c405e21659ee60b18d00cdcaa23eee1f5a4b5ede Mon Sep 17 00:00:00 2001
From: NameeLesS
Date: Mon, 12 Jul 2021 01:16:28 +0200
Subject: [PATCH 6/9] add more notification tests and mails content change
---
.../templates/cases/email/case_created.html | 6 -----
.../templates/cases/email/case_created.txt | 4 ---
.../templates/cases/email/case_removed.html | 2 +-
.../templates/cases/email/case_removed.txt | 2 +-
.../templates/cases/email/case_updated.html | 6 -----
.../templates/cases/email/case_updated.txt | 4 ---
.../templates/events/email/event_created.html | 8 ------
.../templates/events/email/event_created.txt | 7 -----
.../templates/events/email/event_removed.html | 5 ----
.../templates/events/email/event_removed.txt | 3 ---
.../templates/events/email/event_updated.html | 8 ------
.../templates/events/email/event_updated.txt | 6 -----
.../small_eod/events/tests/test_views.py | 7 +++++
.../letters/email/letter_created.html | 6 -----
.../letters/email/letter_created.txt | 5 ----
.../letters/email/letter_updated.html | 6 -----
.../letters/email/letter_updated.txt | 4 ---
.../templates/notes/email/note_created.html | 7 -----
.../templates/notes/email/note_created.txt | 5 ----
.../templates/notes/email/note_updated.html | 8 ------
.../templates/notes/email/note_updated.txt | 6 -----
.../notifications/email/mail_base.html | 7 +++--
.../notifications/email/mail_base.txt | 6 +++--
.../small_eod/notifications/utils.py | 5 +++-
.../small_eod/notifications/views.py | 11 ++------
backend-project/small_eod/users/models.py | 6 +++--
.../small_eod/users/tests/test_models.py | 26 ++++++++++++-------
27 files changed, 44 insertions(+), 132 deletions(-)
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.html b/backend-project/small_eod/cases/templates/cases/email/case_created.html
index 1c08795d5..bf36919e1 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_created.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.html
@@ -5,10 +5,4 @@
{% block content %}
W systemie small_eod pojawiła się nowa sprawa.
-
-
-Sprawa: {{instance.name}}
-Utworzył: {{instance.created_by}}
-Data utworzenia: {{instance.created_on}}
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.txt b/backend-project/small_eod/cases/templates/cases/email/case_created.txt
index 9483b9d61..ccfe4e152 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_created.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.txt
@@ -5,8 +5,4 @@ Utworzono nową sprawę - {{instance.name}}
{% block content %}
W systemie small_eod pojawiła się nowa sprawa.
-
-Sprawa: {{instance.name}}
-Utworzył: {{instance.created_by}}
-Data utworzenia: {{instance.created_on}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed.html b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
index 8bf589deb..52af9f5c6 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_removed.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
@@ -4,5 +4,5 @@
{% endblock %}
{% block content %}
-{{instance.modified_by}} zamknął obserwowaną przez ciebie sprawę - {{instance.name}}
+Zamknięto obserwowaną przez ciebie sprawę - {{instance.name}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed.txt b/backend-project/small_eod/cases/templates/cases/email/case_removed.txt
index 36c48c5e6..4a4592609 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_removed.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed.txt
@@ -4,5 +4,5 @@ Zamknięto sprawę - {{instance.name}}
{% endblock %}
{% block content %}
-{{instance.modified_by}} zamknął obserwowaną przez ciebie sprawę - {{instance.name}}
+Zamknięto obserwowaną przez ciebie sprawę - {{instance.name}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.html b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
index d5f1549a7..950407788 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
@@ -5,10 +5,4 @@
{% block content %}
{{modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
-
-
-Sprawa: {{instance.name}}
-Zmodyfikował: {{instance.modified_by}}
-Data modyfikacji: {{instance.modified_on}}
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
index 2d6f1cf14..358ebfb25 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
@@ -4,8 +4,4 @@ Zaktualizowano sprawę - {{instance.name}}
{% endblock %}
{% block content %}
{{instance.modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
-
-Sprawa: {{instance.name}}
-Zmodyfikował: {{instance.modified_by}}
-Data modyfikacji: {{instance.modified_on}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.html b/backend-project/small_eod/events/templates/events/email/event_created.html
index 35bdfae13..516fa475e 100644
--- a/backend-project/small_eod/events/templates/events/email/event_created.html
+++ b/backend-project/small_eod/events/templates/events/email/event_created.html
@@ -5,12 +5,4 @@
{% block content %}
{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
-
-
-Wydarzenie: {{instance.name}}
-Dotyczy: {{instance.case.name}}
-Zaplanowano na: {{instance.date}}
-Utworzył: {{instance.created_by}}
-Data utworzenia: {{instance.created_on}}
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.txt b/backend-project/small_eod/events/templates/events/email/event_created.txt
index aafcc42d3..bfafbee6d 100644
--- a/backend-project/small_eod/events/templates/events/email/event_created.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_created.txt
@@ -5,11 +5,4 @@ Utworzono nowe wydarzenie w sprawie - {{instance.case.name}}
{% block content %}
{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
-
-
-Wydarzenie: {{instance.name}}
-Dotyczy: {{instance.case.name}}
-Zaplanowano na: {{instance.date}}
-Utworzył: {{instance.created_by}}
-Data utworzenia: {{instance.created_on}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_removed.html b/backend-project/small_eod/events/templates/events/email/event_removed.html
index f0bb79f39..7bea27a56 100644
--- a/backend-project/small_eod/events/templates/events/email/event_removed.html
+++ b/backend-project/small_eod/events/templates/events/email/event_removed.html
@@ -5,9 +5,4 @@
{% block content %}
Usunięto zaplanowane wydarzenie - {{instance.name}}
-
-
-Wydarzenie: {{instance.name}}
-Dotyczy: {{instance.case.name}}
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_removed.txt b/backend-project/small_eod/events/templates/events/email/event_removed.txt
index c920da867..aad483203 100644
--- a/backend-project/small_eod/events/templates/events/email/event_removed.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_removed.txt
@@ -5,7 +5,4 @@ Usunięto wydarzenie - {{instance.name}}
{% block content %}
Usunięto zaplanowane wydarzenie - {{instance.name}}
-
-Wydarzenie: {{instance.name}}
-Dotyczy: {{instance.case.name}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.html b/backend-project/small_eod/events/templates/events/email/event_updated.html
index 8f1719619..4493e6088 100644
--- a/backend-project/small_eod/events/templates/events/email/event_updated.html
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.html
@@ -5,12 +5,4 @@
{% block content %}
{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
-
-
-Wydarzenie: {{instance.name}}
-Dotyczy: {{instance.case.name}}
-Zmodyfikował: {{instance.modified_by}}
-Data modyfikacji: {{instance.modified_on}}
-
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.txt b/backend-project/small_eod/events/templates/events/email/event_updated.txt
index f27f6f8d0..f8d950c44 100644
--- a/backend-project/small_eod/events/templates/events/email/event_updated.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.txt
@@ -5,10 +5,4 @@ Zaktualizowano wydarzenie - {{instance.name}}
{% block content %}
{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
-
-
-Wydarzenie: {{instance.name}}
-Dotyczy: {{instance.case.name}}
-Zmodyfikował: {{instance.modified_by}}
-Data modyfikacji: {{instance.modified_on}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/events/tests/test_views.py b/backend-project/small_eod/events/tests/test_views.py
index ea57aaa9f..eddaac39a 100644
--- a/backend-project/small_eod/events/tests/test_views.py
+++ b/backend-project/small_eod/events/tests/test_views.py
@@ -23,6 +23,10 @@ class EventViewSetTestCase(
def validate_item(self, item):
self.assertEqual(item["name"], self.obj.name)
+ def validate_notifications(self, action):
+ mail_types = [_mail.extra_headers["Action"] for _mail in mail.outbox]
+ self.assertEqual(mail_types, [action for _ in self.obj.case.notified_users.all()])
+
def test_ical_failed_authenticate_to_via_session(self):
self.login_required()
response = self.client.get(
@@ -58,6 +62,7 @@ def test_ical_validate_response_format(self):
def test_send_post_notifications(self):
super().test_create_plain()
self.assertGreater(len(mail.outbox), 0)
+ self.validate_notifications("create")
def test_send_delete_notifications(self):
response = self.client.delete(
@@ -65,10 +70,12 @@ def test_send_delete_notifications(self):
)
self.assertTrue(response.status_code, 200)
self.assertGreater(len(mail.outbox), 0)
+ self.validate_notifications("destroy")
def test_send_patch_notifications(self):
super().test_update_partial_plain()
self.assertGreater(len(mail.outbox), 0)
+ self.validate_notifications("partial_update")
def test_notify_user_only_once(self):
super().test_update_partial_plain()
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_created.html b/backend-project/small_eod/letters/templates/letters/email/letter_created.html
index db98cc8ef..cb16f3808 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_created.html
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_created.html
@@ -9,10 +9,4 @@
{% else %}
Wysłano wiadomość - {{instance.reference_number}} - w sprawie - {{instance.case.name}}
{% endif %}
-
-
-Dotyczy: {{instance.case.name}}
-Utworzył: {{instance.created_by}}
-Data utworzenia: {{instance.created_on}}
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_created.txt b/backend-project/small_eod/letters/templates/letters/email/letter_created.txt
index 76bea51e3..300c44f10 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_created.txt
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_created.txt
@@ -9,9 +9,4 @@ Otrzymano nową wiadomość - {{instance.reference_number}} - dotyczącą obserw
{% else %}
Wysłano wiadomość - {{instance.reference_number}} - w sprawie - {{instance.case.name}}
{% endif %}
-
-
-Dotyczy: {{instance.case.name}}
-Utworzył: {{instance.created_by}}
-Data utworzenia: {{instance.created_on}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
index fb5ef0259..7435a27bc 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
@@ -5,10 +5,4 @@
{% block content %}
{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
-
-
-Dotyczy: {{instance.case.name}}
-Zmodyfikował: {{instance.modified_by}}
-Data modyfikacji: {{instance.modified_on}}
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
index 9350e74a8..49f38630a 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
@@ -5,8 +5,4 @@ Zmodyfikowano wiadomość - {{instance.reference_number}}
{% block content %}
{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
-
-Dotyczy: {{instance.case.name}}
-Zmodyfikował: {{instance.modified_by}}
-Data modyfikacji: {{instance.modified_on}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.html b/backend-project/small_eod/notes/templates/notes/email/note_created.html
index 6f0ce2c0f..2d1e0441b 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_created.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.html
@@ -5,11 +5,4 @@
{% block content %}
{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
-
-
-Dotyczy: {{instance.case.name}}
-Utworzył: {{instance.created_by}}
-Data utworzenia: {{instance.created_on}}
-Treść: {{instance.comment}}
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.txt b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
index ab6689672..65af1af1f 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_created.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
@@ -5,9 +5,4 @@ Dodano notatkę do sprawy - {{case}}
{% block content %}
{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
-
-Dotyczy: {{instance.case.name}}
-Utworzył: {{instance.created_by}}
-Data utworzenia: {{instance.created_on}}
-Treść: {{instance.comment}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.html b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
index 37a3498ae..1693710da 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_updated.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
@@ -4,13 +4,5 @@
{% endblock %}
{% block content %}
-
{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
-
-
-Sprawa: {{instance.case.name}}
-Zmieniona przez: {{instance.modified_by}}
-Data modyfikacji: {{instance.midofied_on}}
-Treść: {{instance.comment}}
-
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
index 0e7ae1bf8..74fcb2eb5 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
@@ -4,11 +4,5 @@ Zaktualizowano notatkę dotyczącą sprawy - {{instance.case.name}}
{% endblock %}
{% block content %}
-
{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
-
-Sprawa: {{instance.case.name}}
-Zmieniona przez: {{instance.modified_by}}
-Data modyfikacji: {{instance.midofied_on}}
-Treść: {{instance.comment}}
{% endblock %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
index 585a4c4e2..59253be28 100644
--- a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
+++ b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
@@ -1,3 +1,4 @@
+{% url source|add:"-list" as path %}
{% block subject %}
{% endblock %}
Witaj {{user.username}},
@@ -5,6 +6,8 @@
{% block content %}
{% endblock %}
+{% with full_path=request.scheme|add:"://"|add:request.get_host|add:path|cut:"api/"%}
-Więcej szczegółów znajdziesz pod adresem: {{url}}
-
\ No newline at end of file
+Więcej szczegółów znajdziesz pod adresem: {{full_path}}
+
+{% endwith %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
index 25d0670c9..44eb69ee2 100644
--- a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
+++ b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
@@ -1,3 +1,4 @@
+{% url source|add:"-list" as path %}
{% block subject %}
{% endblock %}
Witaj {{user.username}},
@@ -5,5 +6,6 @@ Witaj {{user.username}},
{% block content %}
{% endblock %}
-
-Więcej szczegółów znajdziesz pod adresem: {{url}}
\ No newline at end of file
+{% with full_path=request.scheme|add:"://"|add:request.get_host|add:path|cut:"api/"%}
+Więcej szczegółów znajdziesz pod adresem: {{full_path}}
+{% endwith %}
\ No newline at end of file
diff --git a/backend-project/small_eod/notifications/utils.py b/backend-project/small_eod/notifications/utils.py
index e1745276e..c2dca1b89 100644
--- a/backend-project/small_eod/notifications/utils.py
+++ b/backend-project/small_eod/notifications/utils.py
@@ -118,7 +118,10 @@ def send(cls, template_key, recipient_list, context=None, from_email=None):
txt, html = template.render(context or {})
subject, txt = txt.strip().split("\n", 1)
from_email = from_email if from_email else settings.DEFAULT_FROM_EMAIL
- mail = EmailMultiAlternatives(subject, txt, from_email, recipient_list)
+ headers = {"Action": context["action"]}
+ mail = EmailMultiAlternatives(
+ subject, txt, from_email, recipient_list, headers=headers
+ )
mail.attach_alternative(html, "text/html")
return mail.send()
diff --git a/backend-project/small_eod/notifications/views.py b/backend-project/small_eod/notifications/views.py
index 28cb58b60..58a6e9e64 100644
--- a/backend-project/small_eod/notifications/views.py
+++ b/backend-project/small_eod/notifications/views.py
@@ -1,6 +1,5 @@
from django.forms.models import model_to_dict
from rest_framework.views import APIView
-from django.urls import reverse
class SendNotificationsMixin(APIView):
@@ -26,10 +25,10 @@ def send_notifications(self, request, **kwargs):
return
notified_users = self.get_notified_uers(instance)
- kwargs["actor"] = self.basename
+ kwargs["source"] = self.basename
kwargs["action"] = self.action
kwargs["instance"] = instance
- kwargs["url"] = self.get_abs_path(request)
+ kwargs["request"] = request
for user in notified_users:
user.notify(**kwargs)
@@ -44,12 +43,6 @@ def has_instance_changed(self, init_instance, instance):
return d1 != d2
- def get_abs_path(self, request):
- path = reverse(f"{self.basename}-list")
- path = path.replace("/api", "", 1)
- path = request.build_absolute_uri(path)
- return path
-
def get_notified_uers(self, instance):
if not self.notified_users:
raise TypeError(
diff --git a/backend-project/small_eod/users/models.py b/backend-project/small_eod/users/models.py
index 8c5a06d7f..3e7d231b8 100644
--- a/backend-project/small_eod/users/models.py
+++ b/backend-project/small_eod/users/models.py
@@ -4,10 +4,12 @@
class User(AbstractUser):
- def notify(self, actor, action, **kwargs):
+ def notify(self, **kwargs):
kwargs["user"] = self
enabled = self.get_enabled_notifications()
- key = getattr(TemplateKey, f"{actor}_{action}".upper(), None)
+ key = getattr(
+ TemplateKey, f"{kwargs['source']}_{kwargs['action']}".upper(), None
+ )
if key not in enabled:
return False
diff --git a/backend-project/small_eod/users/tests/test_models.py b/backend-project/small_eod/users/tests/test_models.py
index dda9491c4..1728db287 100644
--- a/backend-project/small_eod/users/tests/test_models.py
+++ b/backend-project/small_eod/users/tests/test_models.py
@@ -5,25 +5,31 @@
class UserModelTestCase(TestCase):
def test_send_enabled_mail_notification(self):
- actor = "NOTIFICATION"
- action = "TEST"
+ kwargs = {
+ "source": "NOTIFICATION",
+ "action": "TEST"
+ }
user = UserFactory()
- user.notify(actor, action)
+ user.notify(**kwargs)
self.assertEqual(len(mail.outbox), 1)
def test_do_not_send_disabled_notification(self):
- actor = ""
- action = ""
+ kwargs = {
+ "source": "NOTIFICATION",
+ "action": "DISABLED"
+ }
user = UserFactory()
- user.notify(actor, action)
+ user.notify(**kwargs)
self.assertEqual(len(mail.outbox), 0)
def test_mail_notification_content_is_correct(self):
- actor = "NOTIFICATION"
- action = "TEST"
- context = {"username": "user"}
+ kwargs = {
+ "source": "NOTIFICATION",
+ "action": "TEST",
+ "username": "user"
+ }
user = UserFactory()
- user.notify(actor, action, **context)
+ user.notify(**kwargs)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, "user wysłał testowe powiadomienie")
self.assertEqual(mail.outbox[0].body, "testowe powiadomienie")
From bd6b1eadaf7ffe357eb49e2102fbf822d034f56c Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Wed, 28 Jul 2021 20:45:38 +0000
Subject: [PATCH 7/9] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
.../small_eod/cases/templates/cases/email/case_created.html | 2 +-
.../small_eod/cases/templates/cases/email/case_created.txt | 2 +-
.../small_eod/cases/templates/cases/email/case_removed.html | 2 +-
.../small_eod/cases/templates/cases/email/case_removed.txt | 2 +-
.../small_eod/cases/templates/cases/email/case_updated.html | 2 +-
.../small_eod/cases/templates/cases/email/case_updated.txt | 2 +-
.../small_eod/events/templates/events/email/event_created.html | 2 +-
.../small_eod/events/templates/events/email/event_created.txt | 2 +-
.../small_eod/events/templates/events/email/event_removed.html | 2 +-
.../small_eod/events/templates/events/email/event_removed.txt | 2 +-
.../small_eod/events/templates/events/email/event_updated.html | 2 +-
.../small_eod/events/templates/events/email/event_updated.txt | 2 +-
backend-project/small_eod/events/tests/test_views.py | 2 +-
.../letters/templates/letters/email/letter_created.html | 2 +-
.../letters/templates/letters/email/letter_created.txt | 2 +-
.../letters/templates/letters/email/letter_removed.html | 2 +-
.../letters/templates/letters/email/letter_removed.txt | 2 +-
.../letters/templates/letters/email/letter_updated.html | 2 +-
.../letters/templates/letters/email/letter_updated.txt | 2 +-
.../small_eod/notes/templates/notes/email/note_created.html | 2 +-
.../small_eod/notes/templates/notes/email/note_created.txt | 2 +-
.../small_eod/notes/templates/notes/email/note_removed.html | 2 +-
.../small_eod/notes/templates/notes/email/note_removed.txt | 2 +-
.../small_eod/notes/templates/notes/email/note_updated.html | 2 +-
.../small_eod/notes/templates/notes/email/note_updated.txt | 2 +-
.../notifications/templates/notifications/email/mail_base.html | 2 +-
.../notifications/templates/notifications/email/mail_base.txt | 2 +-
.../templates/notifications/email/test_notifications.html | 2 +-
.../templates/notifications/email/test_notifications.txt | 2 +-
backend-project/small_eod/users/tests/test_models.py | 3 ++-
30 files changed, 31 insertions(+), 30 deletions(-)
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.html b/backend-project/small_eod/cases/templates/cases/email/case_created.html
index bf36919e1..f1e7e5927 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_created.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.html
@@ -5,4 +5,4 @@
{% block content %}
W systemie small_eod pojawiła się nowa sprawa.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_created.txt b/backend-project/small_eod/cases/templates/cases/email/case_created.txt
index ccfe4e152..0c1c1ff36 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_created.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_created.txt
@@ -5,4 +5,4 @@ Utworzono nową sprawę - {{instance.name}}
{% block content %}
W systemie small_eod pojawiła się nowa sprawa.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed.html b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
index 52af9f5c6..3af5b5888 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_removed.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed.html
@@ -5,4 +5,4 @@
{% block content %}
Zamknięto obserwowaną przez ciebie sprawę - {{instance.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_removed.txt b/backend-project/small_eod/cases/templates/cases/email/case_removed.txt
index 4a4592609..84857ff01 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_removed.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_removed.txt
@@ -5,4 +5,4 @@ Zamknięto sprawę - {{instance.name}}
{% block content %}
Zamknięto obserwowaną przez ciebie sprawę - {{instance.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.html b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
index 950407788..2d5ff8973 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
@@ -5,4 +5,4 @@
{% block content %}
{{modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
index 358ebfb25..6704f6bfb 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
@@ -4,4 +4,4 @@ Zaktualizowano sprawę - {{instance.name}}
{% endblock %}
{% block content %}
{{instance.modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.html b/backend-project/small_eod/events/templates/events/email/event_created.html
index 516fa475e..87185dfe1 100644
--- a/backend-project/small_eod/events/templates/events/email/event_created.html
+++ b/backend-project/small_eod/events/templates/events/email/event_created.html
@@ -5,4 +5,4 @@
{% block content %}
{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.txt b/backend-project/small_eod/events/templates/events/email/event_created.txt
index bfafbee6d..c53d7e055 100644
--- a/backend-project/small_eod/events/templates/events/email/event_created.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_created.txt
@@ -5,4 +5,4 @@ Utworzono nowe wydarzenie w sprawie - {{instance.case.name}}
{% block content %}
{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/events/templates/events/email/event_removed.html b/backend-project/small_eod/events/templates/events/email/event_removed.html
index 7bea27a56..8bc6626df 100644
--- a/backend-project/small_eod/events/templates/events/email/event_removed.html
+++ b/backend-project/small_eod/events/templates/events/email/event_removed.html
@@ -5,4 +5,4 @@
{% block content %}
Usunięto zaplanowane wydarzenie - {{instance.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/events/templates/events/email/event_removed.txt b/backend-project/small_eod/events/templates/events/email/event_removed.txt
index aad483203..36f5b774f 100644
--- a/backend-project/small_eod/events/templates/events/email/event_removed.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_removed.txt
@@ -5,4 +5,4 @@ Usunięto wydarzenie - {{instance.name}}
{% block content %}
Usunięto zaplanowane wydarzenie - {{instance.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.html b/backend-project/small_eod/events/templates/events/email/event_updated.html
index 4493e6088..c6c877dbf 100644
--- a/backend-project/small_eod/events/templates/events/email/event_updated.html
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.html
@@ -5,4 +5,4 @@
{% block content %}
{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.txt b/backend-project/small_eod/events/templates/events/email/event_updated.txt
index f8d950c44..0c9a3d544 100644
--- a/backend-project/small_eod/events/templates/events/email/event_updated.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.txt
@@ -5,4 +5,4 @@ Zaktualizowano wydarzenie - {{instance.name}}
{% block content %}
{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/events/tests/test_views.py b/backend-project/small_eod/events/tests/test_views.py
index 40ac66834..69fa9d55c 100644
--- a/backend-project/small_eod/events/tests/test_views.py
+++ b/backend-project/small_eod/events/tests/test_views.py
@@ -1,5 +1,5 @@
-from test_plus.test import TestCase
from django.core import mail
+from test_plus.test import TestCase
from ...authkey.factories import KeyFactory
from ...generic.tests.test_views import GenericViewSetMixin, OrderingViewSetMixin
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_created.html b/backend-project/small_eod/letters/templates/letters/email/letter_created.html
index cb16f3808..367c57808 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_created.html
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_created.html
@@ -9,4 +9,4 @@
{% else %}
Wysłano wiadomość - {{instance.reference_number}} - w sprawie - {{instance.case.name}}
{% endif %}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_created.txt b/backend-project/small_eod/letters/templates/letters/email/letter_created.txt
index 300c44f10..0d6de2989 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_created.txt
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_created.txt
@@ -9,4 +9,4 @@ Otrzymano nową wiadomość - {{instance.reference_number}} - dotyczącą obserw
{% else %}
Wysłano wiadomość - {{instance.reference_number}} - w sprawie - {{instance.case.name}}
{% endif %}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_removed.html b/backend-project/small_eod/letters/templates/letters/email/letter_removed.html
index b03d84df2..e48b5e984 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_removed.html
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_removed.html
@@ -5,4 +5,4 @@
{% block content %}
Usunięto wiadomość - {{instance.reference_number}} - dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_removed.txt b/backend-project/small_eod/letters/templates/letters/email/letter_removed.txt
index 5b1afce02..7d33a93d8 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_removed.txt
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_removed.txt
@@ -5,4 +5,4 @@ Usunięto wiadomość - {{instance.reference_number}}
{% block content %}
Usunięto wiadomość - {{instance.reference_number}} - dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
index 7435a27bc..e6651e51e 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
@@ -5,4 +5,4 @@
{% block content %}
{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
index 49f38630a..fee182890 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
@@ -5,4 +5,4 @@ Zmodyfikowano wiadomość - {{instance.reference_number}}
{% block content %}
{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.html b/backend-project/small_eod/notes/templates/notes/email/note_created.html
index 2d1e0441b..aecdbf476 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_created.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.html
@@ -5,4 +5,4 @@
{% block content %}
{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.txt b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
index 65af1af1f..4e4f2fae4 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_created.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
@@ -5,4 +5,4 @@ Dodano notatkę do sprawy - {{case}}
{% block content %}
{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_removed.html b/backend-project/small_eod/notes/templates/notes/email/note_removed.html
index 969d5cf88..506d4a3f4 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_removed.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_removed.html
@@ -5,4 +5,4 @@
{% block content %}
Usunięto notatkę dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_removed.txt b/backend-project/small_eod/notes/templates/notes/email/note_removed.txt
index d6e9ee640..c2eb0e263 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_removed.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_removed.txt
@@ -5,4 +5,4 @@ Usunięto notatkę dotyczącą sprawy - {{instance.case.name}}
{% block content %}
Usunięto notatkę dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.html b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
index 1693710da..3e43d7fa0 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_updated.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
@@ -5,4 +5,4 @@
{% block content %}
{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
index 74fcb2eb5..42dfe0be2 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
@@ -5,4 +5,4 @@ Zaktualizowano notatkę dotyczącą sprawy - {{instance.case.name}}
{% block content %}
{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
index 59253be28..eede29b4d 100644
--- a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
+++ b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.html
@@ -10,4 +10,4 @@
Więcej szczegółów znajdziesz pod adresem: {{full_path}}
-{% endwith %}
\ No newline at end of file
+{% endwith %}
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
index 44eb69ee2..0072d0091 100644
--- a/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
+++ b/backend-project/small_eod/notifications/templates/notifications/email/mail_base.txt
@@ -8,4 +8,4 @@ Witaj {{user.username}},
{% with full_path=request.scheme|add:"://"|add:request.get_host|add:path|cut:"api/"%}
Więcej szczegółów znajdziesz pod adresem: {{full_path}}
-{% endwith %}
\ No newline at end of file
+{% endwith %}
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.html b/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.html
index 626a48323..30e1d82a1 100644
--- a/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.html
+++ b/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.html
@@ -1,2 +1,2 @@
{{username}} wysłał testowe powiadomienie
-testowe powiadomienie
\ No newline at end of file
+testowe powiadomienie
diff --git a/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.txt b/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.txt
index a344c3cf5..2052de71c 100644
--- a/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.txt
+++ b/backend-project/small_eod/notifications/templates/notifications/email/test_notifications.txt
@@ -1,2 +1,2 @@
{{username}} wysłał testowe powiadomienie
-testowe powiadomienie
\ No newline at end of file
+testowe powiadomienie
diff --git a/backend-project/small_eod/users/tests/test_models.py b/backend-project/small_eod/users/tests/test_models.py
index 277443df9..293f950ff 100644
--- a/backend-project/small_eod/users/tests/test_models.py
+++ b/backend-project/small_eod/users/tests/test_models.py
@@ -1,7 +1,8 @@
-from ..factories import UserFactory
from django.core import mail
from django.test import TestCase
+from ..factories import UserFactory
+
class UserModelTestCase(TestCase):
def test_send_enabled_mail_notification(self):
From ab614e7a8256044b5f1ef98db18ff6388d5d8de5 Mon Sep 17 00:00:00 2001
From: NameeLesS
Date: Wed, 4 Aug 2021 16:43:19 +0200
Subject: [PATCH 8/9] Adjust changes according to code review
---
.../templates/cases/email/case_updated.html | 5 ++
.../templates/cases/email/case_updated.txt | 5 ++
backend-project/small_eod/cases/views.py | 8 ++--
.../templates/events/email/event_created.html | 5 ++
.../templates/events/email/event_created.txt | 5 ++
.../templates/events/email/event_updated.html | 5 ++
.../templates/events/email/event_updated.txt | 5 ++
.../small_eod/events/tests/test_views.py | 6 +--
backend-project/small_eod/events/views.py | 8 ++--
.../letters/email/letter_updated.html | 5 ++
.../letters/email/letter_updated.txt | 5 ++
backend-project/small_eod/letters/views.py | 8 ++--
.../templates/notes/email/note_created.html | 5 ++
.../templates/notes/email/note_created.txt | 5 ++
.../templates/notes/email/note_updated.html | 5 ++
.../templates/notes/email/note_updated.txt | 5 ++
backend-project/small_eod/notes/views.py | 8 ++--
.../small_eod/notifications/utils.py | 20 +-------
.../small_eod/notifications/views.py | 47 ++++++++++---------
19 files changed, 105 insertions(+), 60 deletions(-)
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.html b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
index 2d5ff8973..61f2c1811 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
@@ -4,5 +4,10 @@
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
{% endblock %}
+=======
+{{modified_by}} dokonał(a) zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
index 6704f6bfb..df3106957 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
@@ -3,5 +3,10 @@
Zaktualizowano sprawę - {{instance.name}}
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
{% endblock %}
+=======
+{{instance.modified_by}} dokonał(a) zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/cases/views.py b/backend-project/small_eod/cases/views.py
index 9dddb3582..3ef4f3d0a 100644
--- a/backend-project/small_eod/cases/views.py
+++ b/backend-project/small_eod/cases/views.py
@@ -2,16 +2,16 @@
from rest_framework import viewsets
from rest_framework.filters import OrderingFilter
-from ..notifications.views import SendNotificationsMixin
+from ..notifications.views import NotificationsView
from ..users.serializers import UserSerializer
from .filterset import CaseFilterSet
from .models import Case
from .serializers import CaseCountSerializer
-class CaseViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
- notified_users = "notified_users"
- ignored_fields = ["modified_by", "modified_on"]
+class CaseViewSet(viewsets.ModelViewSet, NotificationsView):
+ notified_users_field = "notified_users"
+ notification_diff_ignored_fields = ["modified_by", "modified_on"]
queryset = Case.objects.with_counter().with_nested_resources().all()
serializer_class = CaseCountSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.html b/backend-project/small_eod/events/templates/events/email/event_created.html
index 87185dfe1..9488acd23 100644
--- a/backend-project/small_eod/events/templates/events/email/event_created.html
+++ b/backend-project/small_eod/events/templates/events/email/event_created.html
@@ -4,5 +4,10 @@
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
{% endblock %}
+=======
+{{instance.created_by}} utworzył(a) nowe wydarzenie - {{instance.name}}.
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.txt b/backend-project/small_eod/events/templates/events/email/event_created.txt
index c53d7e055..61626dbce 100644
--- a/backend-project/small_eod/events/templates/events/email/event_created.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_created.txt
@@ -4,5 +4,10 @@ Utworzono nowe wydarzenie w sprawie - {{instance.case.name}}
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
{% endblock %}
+=======
+{{instance.created_by}} utworzył(a) nowe wydarzenie - {{instance.name}}.
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.html b/backend-project/small_eod/events/templates/events/email/event_updated.html
index c6c877dbf..a9d67bf8f 100644
--- a/backend-project/small_eod/events/templates/events/email/event_updated.html
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.html
@@ -4,5 +4,10 @@
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
{% endblock %}
+=======
+{{instance.modified_by}} dokonał(a) zmian w zaplanowanym wydarzeniu - {{instance.name}}
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.txt b/backend-project/small_eod/events/templates/events/email/event_updated.txt
index 0c9a3d544..1c8cb8ac2 100644
--- a/backend-project/small_eod/events/templates/events/email/event_updated.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.txt
@@ -4,5 +4,10 @@ Zaktualizowano wydarzenie - {{instance.name}}
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
{% endblock %}
+=======
+{{instance.modified_by}} dokonał(a) zmian w zaplanowanym wydarzeniu - {{instance.name}}
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/events/tests/test_views.py b/backend-project/small_eod/events/tests/test_views.py
index 69fa9d55c..d02d2ec1f 100644
--- a/backend-project/small_eod/events/tests/test_views.py
+++ b/backend-project/small_eod/events/tests/test_views.py
@@ -24,10 +24,8 @@ def validate_item(self, item):
self.assertEqual(item["name"], self.obj.name)
def validate_notifications(self, action):
- mail_types = [_mail.extra_headers["Action"] for _mail in mail.outbox]
- self.assertEqual(
- mail_types, [action for _ in self.obj.case.notified_users.all()]
- )
+ mail_types = [mail.extra_headers["Action"] for mail in mail.outbox]
+ self.assertEqual(set(mail_types), {action})
def test_ical_failed_authenticate_to_via_session(self):
self.login_required()
diff --git a/backend-project/small_eod/events/views.py b/backend-project/small_eod/events/views.py
index 3d2902245..888926f49 100644
--- a/backend-project/small_eod/events/views.py
+++ b/backend-project/small_eod/events/views.py
@@ -12,15 +12,15 @@
from ..authkey.authentication import AuthKeyAuthentication
from ..authkey.permissions import AuthKeyPermission
-from ..notifications.views import SendNotificationsMixin
+from ..notifications.views import NotificationsView
from .filterset import EventFilterSet
from .models import Event
from .serializers import EventSerializer
-class EventViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
- notified_users = "case.notified_users"
- ignored_fields = ["modified_by"]
+class EventViewSet(viewsets.ModelViewSet, NotificationsView):
+ notified_users_field = "case.notified_users"
+ notification_diff_ignored_fields = ["modified_by"]
queryset = Event.objects.prefetch_related("case").all()
serializer_class = EventSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
index e6651e51e..246130410 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
@@ -4,5 +4,10 @@
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
{% endblock %}
+=======
+{{instance.modified_by}} dokonał(a) zmian w wiadomości - {{instance.reference_number}}.
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
index fee182890..3b0654639 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
@@ -4,5 +4,10 @@ Zmodyfikowano wiadomość - {{instance.reference_number}}
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
{% endblock %}
+=======
+{{instance.modified_by}} dokonał(a) zmian w wiadomości - {{instance.reference_number}}.
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/letters/views.py b/backend-project/small_eod/letters/views.py
index dedc824ba..d4cf13fab 100644
--- a/backend-project/small_eod/letters/views.py
+++ b/backend-project/small_eod/letters/views.py
@@ -8,7 +8,7 @@
from ..files.models import File
from ..files.serializers import FileSerializer
-from ..notifications.views import SendNotificationsMixin
+from ..notifications.views import NotificationsView
from .filterset import DocumentTypeFilterSet, LetterFilterSet, ReferenceNumberFilterSet
from .models import DocumentType, Letter, ReferenceNumber
from .serializers import (
@@ -19,9 +19,9 @@
)
-class LetterViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
- notified_users = "case.notified_users"
- ignored_fields = ["modified_on", "modified_by"]
+class LetterViewSet(viewsets.ModelViewSet, NotificationsView):
+ notified_users_field = "case.notified_users"
+ notification_diff_ignored_fields = ["modified_on", "modified_by"]
queryset = Letter.objects.prefetch_related("attachments", "reference_number").all()
serializer_class = LetterSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.html b/backend-project/small_eod/notes/templates/notes/email/note_created.html
index aecdbf476..cd209557d 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_created.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.html
@@ -4,5 +4,10 @@
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
{% endblock %}
+=======
+{{instance.created_by}} dodał(a) nową notatkę do sprawy - {{instance.case.name}}
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.txt b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
index 4e4f2fae4..c26d65888 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_created.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
@@ -4,5 +4,10 @@ Dodano notatkę do sprawy - {{case}}
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
{% endblock %}
+=======
+{{instance.created_by}} dodał(a) nową notatkę do sprawy - {{instance.case.name}}
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.html b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
index 3e43d7fa0..4c01fd8bc 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_updated.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
@@ -4,5 +4,10 @@
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
{% endblock %}
+=======
+{{instance.modified_by}} dokonał(a) zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
index 42dfe0be2..dc0c4d69f 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
@@ -4,5 +4,10 @@ Zaktualizowano notatkę dotyczącą sprawy - {{instance.case.name}}
{% endblock %}
{% block content %}
+<<<<<<< Updated upstream
{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
{% endblock %}
+=======
+{{instance.modified_by}} dokonał(a) zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
+{% endblock %}
+>>>>>>> Stashed changes
diff --git a/backend-project/small_eod/notes/views.py b/backend-project/small_eod/notes/views.py
index fd4710302..49e2f4ef4 100644
--- a/backend-project/small_eod/notes/views.py
+++ b/backend-project/small_eod/notes/views.py
@@ -2,15 +2,15 @@
from rest_framework import viewsets
from rest_framework.filters import OrderingFilter
-from ..notifications.views import SendNotificationsMixin
+from ..notifications.views import NotificationsView
from .filterset import NoteFilterSet
from .models import Note
from .serializers import NoteSerializer
-class NoteViewSet(viewsets.ModelViewSet, SendNotificationsMixin):
- notified_users = "case.notified_users"
- ignored_fields = ["modified_by"]
+class NoteViewSet(viewsets.ModelViewSet, NotificationsView):
+ notified_users_field = "case.notified_users"
+ notification_diff_ignored_fields = ["modified_by"]
queryset = Note.objects.all()
serializer_class = NoteSerializer
filter_backends = (DjangoFilterBackend, OrderingFilter)
diff --git a/backend-project/small_eod/notifications/utils.py b/backend-project/small_eod/notifications/utils.py
index c2dca1b89..d823bf844 100644
--- a/backend-project/small_eod/notifications/utils.py
+++ b/backend-project/small_eod/notifications/utils.py
@@ -1,6 +1,6 @@
import logging
import random
-from enum import Enum
+from enum import Enum, auto
from django.conf import settings
from django.core.mail.message import EmailMultiAlternatives
@@ -9,22 +9,6 @@
logger = logging.getLogger(__name__)
-def make_auto():
- """enum.auto replacement"""
-
- def loop():
- i = 1
- while True:
- yield i
- i += 1
-
- loop = loop()
- return lambda: next(loop)
-
-
-auto = make_auto()
-
-
class TemplateKey(Enum):
CASE_CREATE = auto()
CASE_UPDATE = auto()
@@ -46,7 +30,7 @@ class TemplateKey(Enum):
class MailTemplate:
- def __init__(self, txt_path, html_path=None):
+ def __init__(self, txt_path, html_path):
self.txt_path = txt_path
self.html_path = html_path
diff --git a/backend-project/small_eod/notifications/views.py b/backend-project/small_eod/notifications/views.py
index 58a6e9e64..52cde76ff 100644
--- a/backend-project/small_eod/notifications/views.py
+++ b/backend-project/small_eod/notifications/views.py
@@ -2,25 +2,28 @@
from rest_framework.views import APIView
-class SendNotificationsMixin(APIView):
- notified_users = None
- ignored_fields = []
- init_instance = None
- http_action = None
+class NotificationsView(APIView):
+ notified_users_field = None
+ notification_diff_ignored_fields = []
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self._http_action = None
+ self._init_instance = None
def send_notifications(self, request, **kwargs):
self.kwargs["pk"] = self.kwargs.get("pk", None) or kwargs["data"].get(
"id", None
)
- instance = None
- if self.http_action in ["post", "put", "patch"]:
- instance = self.get_object()
- else:
- instance = self.init_instance
+ instance = (
+ self.get_object()
+ if self._http_action in ["post", "put", "patch"]
+ else self._init_instance
+ )
- if self.http_action == "put" and not self.has_instance_changed(
- self.init_instance, instance
+ if self._http_action == "put" and not self.has_instance_changed(
+ self._init_instance, instance
):
return
@@ -37,21 +40,21 @@ def has_instance_changed(self, init_instance, instance):
d1 = model_to_dict(init_instance)
d2 = model_to_dict(instance)
- for field in self.ignored_fields:
+ for field in self.notification_diff_ignored_fields:
d1.pop(field, None)
d2.pop(field, None)
return d1 != d2
def get_notified_uers(self, instance):
- if not self.notified_users:
+ if not self.notified_users_field:
raise TypeError(
- "{} is missing a `notified_users` attribute.".format(
+ "{} is missing a `notified_users_field` attribute.".format(
self.__class__.__name__
)
)
- for attr in self.notified_users.split("."):
+ for attr in self.notified_users_field.split("."):
instance = getattr(instance, attr, None)
if not instance:
@@ -60,15 +63,15 @@ def get_notified_uers(self, instance):
return instance.all()
def initial(self, request, *args, **kwargs):
- self.http_action = list(self.action_map.keys())[
- list(self.action_map.values()).index(self.action)
- ]
- if self.http_action in ["put", "delete", "patch"]:
- self.init_instance = self.get_object()
+ self._http_action = next(
+ k for k, v in self.action_map.items() if v == self.action
+ )
+ if self._http_action in ["put", "delete", "patch"]:
+ self._init_instance = self.get_object()
return super().initial(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs):
response = super().dispatch(request, *args, **kwargs)
- if self.http_action in ["delete", "post", "put", "patch"]:
+ if self._http_action in ["delete", "post", "put", "patch"]:
self.send_notifications(request=request, data=response.data)
return response
From b4a7abe5fd68ad836e72824a9f50cb82e7d36601 Mon Sep 17 00:00:00 2001
From: NameeLesS
Date: Thu, 5 Aug 2021 17:29:20 +0200
Subject: [PATCH 9/9] Resolved merge conflicts
---
.../small_eod/cases/templates/cases/email/case_updated.html | 5 -----
.../small_eod/cases/templates/cases/email/case_updated.txt | 5 -----
.../events/templates/events/email/event_created.html | 5 -----
.../events/templates/events/email/event_created.txt | 5 -----
.../events/templates/events/email/event_updated.html | 5 -----
.../events/templates/events/email/event_updated.txt | 5 -----
.../letters/templates/letters/email/letter_updated.html | 5 -----
.../letters/templates/letters/email/letter_updated.txt | 5 -----
.../small_eod/notes/templates/notes/email/note_created.html | 5 -----
.../small_eod/notes/templates/notes/email/note_created.txt | 5 -----
.../small_eod/notes/templates/notes/email/note_updated.html | 5 -----
.../small_eod/notes/templates/notes/email/note_updated.txt | 5 -----
12 files changed, 60 deletions(-)
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.html b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
index 61f2c1811..0d781a03f 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.html
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.html
@@ -4,10 +4,5 @@
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
-{% endblock %}
-=======
{{modified_by}} dokonał(a) zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
index df3106957..5b8fff98f 100644
--- a/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
+++ b/backend-project/small_eod/cases/templates/cases/email/case_updated.txt
@@ -3,10 +3,5 @@
Zaktualizowano sprawę - {{instance.name}}
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
-{% endblock %}
-=======
{{instance.modified_by}} dokonał(a) zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.html b/backend-project/small_eod/events/templates/events/email/event_created.html
index 9488acd23..84409e801 100644
--- a/backend-project/small_eod/events/templates/events/email/event_created.html
+++ b/backend-project/small_eod/events/templates/events/email/event_created.html
@@ -4,10 +4,5 @@
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
-{% endblock %}
-=======
{{instance.created_by}} utworzył(a) nowe wydarzenie - {{instance.name}}.
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/events/templates/events/email/event_created.txt b/backend-project/small_eod/events/templates/events/email/event_created.txt
index 61626dbce..be49d227a 100644
--- a/backend-project/small_eod/events/templates/events/email/event_created.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_created.txt
@@ -4,10 +4,5 @@ Utworzono nowe wydarzenie w sprawie - {{instance.case.name}}
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.
-{% endblock %}
-=======
{{instance.created_by}} utworzył(a) nowe wydarzenie - {{instance.name}}.
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.html b/backend-project/small_eod/events/templates/events/email/event_updated.html
index a9d67bf8f..810160bc3 100644
--- a/backend-project/small_eod/events/templates/events/email/event_updated.html
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.html
@@ -4,10 +4,5 @@
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
-{% endblock %}
-=======
{{instance.modified_by}} dokonał(a) zmian w zaplanowanym wydarzeniu - {{instance.name}}
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/events/templates/events/email/event_updated.txt b/backend-project/small_eod/events/templates/events/email/event_updated.txt
index 1c8cb8ac2..621676b86 100644
--- a/backend-project/small_eod/events/templates/events/email/event_updated.txt
+++ b/backend-project/small_eod/events/templates/events/email/event_updated.txt
@@ -4,10 +4,5 @@ Zaktualizowano wydarzenie - {{instance.name}}
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}
-{% endblock %}
-=======
{{instance.modified_by}} dokonał(a) zmian w zaplanowanym wydarzeniu - {{instance.name}}
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
index 246130410..0439c8433 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.html
@@ -4,10 +4,5 @@
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
-{% endblock %}
-=======
{{instance.modified_by}} dokonał(a) zmian w wiadomości - {{instance.reference_number}}.
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
index 3b0654639..57fa148df 100644
--- a/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
+++ b/backend-project/small_eod/letters/templates/letters/email/letter_updated.txt
@@ -4,10 +4,5 @@ Zmodyfikowano wiadomość - {{instance.reference_number}}
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.
-{% endblock %}
-=======
{{instance.modified_by}} dokonał(a) zmian w wiadomości - {{instance.reference_number}}.
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.html b/backend-project/small_eod/notes/templates/notes/email/note_created.html
index cd209557d..a7b3638a5 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_created.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.html
@@ -4,10 +4,5 @@
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
-{% endblock %}
-=======
{{instance.created_by}} dodał(a) nową notatkę do sprawy - {{instance.case.name}}
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_created.txt b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
index c26d65888..f4fc2b971 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_created.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_created.txt
@@ -4,10 +4,5 @@ Dodano notatkę do sprawy - {{case}}
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}
-{% endblock %}
-=======
{{instance.created_by}} dodał(a) nową notatkę do sprawy - {{instance.case.name}}
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.html b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
index 4c01fd8bc..e3a4c9f57 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_updated.html
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.html
@@ -4,10 +4,5 @@
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
-{% endblock %}
-=======
{{instance.modified_by}} dokonał(a) zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
{% endblock %}
->>>>>>> Stashed changes
diff --git a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
index dc0c4d69f..c5ff3f011 100644
--- a/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
+++ b/backend-project/small_eod/notes/templates/notes/email/note_updated.txt
@@ -4,10 +4,5 @@ Zaktualizowano notatkę dotyczącą sprawy - {{instance.case.name}}
{% endblock %}
{% block content %}
-<<<<<<< Updated upstream
-{{instance.modified_by}} dokonał zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
-{% endblock %}
-=======
{{instance.modified_by}} dokonał(a) zmian w notatce dotyczącej obserwowanej przez ciebie sprawy - {{instance.case.name}}.
{% endblock %}
->>>>>>> Stashed changes