Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powiadomienie do obserwujących sprawę #934

Merged
merged 11 commits into from
Aug 14, 2021
16 changes: 15 additions & 1 deletion backend-project/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,6 +61,7 @@
"small_eod.events",
"small_eod.administrative_units",
"small_eod.authkey",
"small_eod.notifications",
"small_eod.migration_v1",
]

Expand Down Expand Up @@ -87,7 +89,7 @@
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
]
},
},
]
Expand Down Expand Up @@ -180,6 +182,18 @@
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

# Very basic logging config
LOGGING = {
"version": 1,
Expand Down
2 changes: 1 addition & 1 deletion backend-project/small_eod/cases/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Utworzono nową sprawę - {{instance.name}}</p>
{% endblock %}

{% block content %}
<p>W systemie small_eod pojawiła się nowa sprawa.</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% 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.
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Zamknięto sprawę - {{instance.name}}</p>
{% endblock %}

{% block content %}
<p>Zamknięto obserwowaną przez ciebie sprawę - {{instance.name}}</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "notifications/email/mail_base.txt" %}
{% block subject %}
Zamknięto sprawę - {{instance.name}}
{% endblock %}

{% block content %}
Zamknięto obserwowaną przez ciebie sprawę - {{instance.name}}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Zaktualizowano sprawę - {{instance.name}}</p>
{% endblock %}

{% block content %}
<<<<<<< Updated upstream
<p>{{modified_by}} dokonał zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.</p>
{% endblock %}
=======
<p>{{modified_by}} dokonał(a) zmian w obserwowanej przez ciebie sprawie - {{instance.name}}.</p>
{% endblock %}
>>>>>>> Stashed changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "notifications/email/mail_base.txt" %}
{% block subject %}
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
5 changes: 4 additions & 1 deletion backend-project/small_eod/cases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from rest_framework import viewsets
from rest_framework.filters import OrderingFilter

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):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Nowe wydarzenie w sprawie - {{instance.case.name}}</p>
{% endblock %}

{% block content %}
<<<<<<< Updated upstream
<p>{{instance.created_by}} utworzył nowe wydarzenie - {{instance.name}}.</p>
{% endblock %}
=======
<p>{{instance.created_by}} utworzył(a) nowe wydarzenie - {{instance.name}}.</p>
{% endblock %}
>>>>>>> Stashed changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.txt" %}
{% block subject %}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Usunięto wydarzenie - {{instance.name}}</p>
{% endblock %}

{% block content %}
<p>Usunięto zaplanowane wydarzenie - {{instance.name}}</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "notifications/email/mail_base.txt" %}
{% block subject %}
Usunięto wydarzenie - {{instance.name}}
{% endblock %}

{% block content %}
Usunięto zaplanowane wydarzenie - {{instance.name}}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Zaktualizowano wydarzenie - {{instance.name}}</p>
{% endblock %}

{% block content %}
<<<<<<< Updated upstream
<p>{{instance.modified_by}} dokonał zmian w zaplanowanym wydarzeniu - {{instance.name}}</p>
{% endblock %}
=======
<p>{{instance.modified_by}} dokonał(a) zmian w zaplanowanym wydarzeniu - {{instance.name}}</p>
{% endblock %}
>>>>>>> Stashed changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.txt" %}
{% block subject %}
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
27 changes: 27 additions & 0 deletions backend-project/small_eod/events/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.core import mail
from test_plus.test import TestCase

from ...authkey.factories import KeyFactory
Expand All @@ -22,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(set(mail_types), {action})

def test_ical_failed_authenticate_to_via_session(self):
self.login_required()
response = self.client.get(
Expand Down Expand Up @@ -53,3 +58,25 @@ 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)
self.validate_notifications("create")

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)
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()
self.assertEqual(len(mail.outbox), len(self.obj.case.notified_users.all()))
5 changes: 4 additions & 1 deletion backend-project/small_eod/events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@

from ..authkey.authentication import AuthKeyAuthentication
from ..authkey.permissions import AuthKeyPermission
from ..notifications.views import NotificationsView
from .filterset import EventFilterSet
from .models import Event
from .serializers import EventSerializer


class EventViewSet(viewsets.ModelViewSet):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Nowa wiadomość w sprawie - {{instance.case.name}}</p>
{% endblock %}

{% block content %}
{% if instance.direction == "received" %}
<p>Otrzymano nową wiadomość - {{instance.reference_number}} - dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}</p>
{% else %}
<p>Wysłano wiadomość - {{instance.reference_number}} - w sprawie - {{instance.case.name}}</p>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% 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 %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Usunięto wiadomość - {{instance.reference_number}}</p>
{% endblock %}

{% block content %}
<p>Usunięto wiadomość - {{instance.reference_number}} - dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}.</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Zmodyfikowano wiadomość - {{instance.reference_number}}</p>
{% endblock %}

{% block content %}
<<<<<<< Updated upstream
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O cholera xD Pycharm pokazywał mi że nie mam żadnych konfliktów.

<p>{{instance.modified_by}} dokonał zmian w wiadomości - {{instance.reference_number}}.</p>
{% endblock %}
=======
<p>{{instance.modified_by}} dokonał(a) zmian w wiadomości - {{instance.reference_number}}.</p>
{% endblock %}
>>>>>>> Stashed changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.txt" %}
{% block subject %}
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
5 changes: 4 additions & 1 deletion backend-project/small_eod/letters/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ..files.models import File
from ..files.serializers import FileSerializer
from ..notifications.views import NotificationsView
from .filterset import DocumentTypeFilterSet, LetterFilterSet, ReferenceNumberFilterSet
from .models import DocumentType, Letter, ReferenceNumber
from .serializers import (
Expand All @@ -18,7 +19,9 @@
)


class LetterViewSet(viewsets.ModelViewSet):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Dodano notatkę do sprawy - {{case}}</p>
{% endblock %}

{% block content %}
<<<<<<< Updated upstream
<p>{{instance.created_by}} dodał nową notatkę do sprawy - {{instance.case.name}}</p>
ad-m marked this conversation as resolved.
Show resolved Hide resolved
{% endblock %}
=======
<p>{{instance.created_by}} dodał(a) nową notatkę do sprawy - {{instance.case.name}}</p>
{% endblock %}
>>>>>>> Stashed changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "notifications/email/mail_base.txt" %}
{% block subject %}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "notifications/email/mail_base.html" %}
{% block subject %}
<p>Usunięto notatkę dotyczącą sprawy - {{instance.case.name}}</p>
{% endblock %}

{% block content %}
<p>Usunięto notatkę dotyczącą obserwowanej przez ciebie sprawy - {{instance.case.name}}</p>
{% endblock %}
Loading