Repository: liqd/a4-meinberlin

Issue:
notify creator and contact emails are also sent when only is_archived flag is ahcnged in modretae form
**URL:** 
**user:** 
**expected behaviour:** The email should only be sent when the moderator feedback or statement are changed.
**behaviour:** 
**important screensize:**
**device & browser:** 
**Comment/Question:** 

Screenshot?

#6704 Form of address E-Mail-Notification
**URL:** https://meinberlin-dev.liqd.net/budgeting/2022-00936/
**user:** registered user
**expected behaviour:** The user should be adressed as in other E-Mail-Notifications (the current form of address is "Hallo 'username',"
**behaviour:** The form of adress in the current E-Mail-Notification is "Hallo ,". The username is missing and there is a space before the comma.
**important screensize:** -
**device & browser:** any
**Comment/Question:** This only applies to participatory budgeting, as users in the other modules have not yet received any e-mail notification when their status changes (see [issue #4697)](https://github.com/liqd/a4-meinberlin/issues/4697))

Screenshot?
<img width="700" alt="Bildschirmfoto 2022-11-17 um 15 53 01" src="https://user-images.githubusercontent.com/113608720/202479234-e96a5c98-a655-481d-9af8-47ffc6129f1d.png">




Discussion:

@CarolingerSeilchenspringer This is for the messages for the contact, so for the proposals from budgeting, where we get the email address from the form and not the creator. So, we don't have the username. Should we 
- use the username of the creator (which might be weird if the username is a Quartiesmanagement and the email sth. diffrenet, 
- use the email address
- use no username ("Hallo," or "Guten Tag,")
- use the username when the email from the creator is used and no username when another email was added (this might get a bit more complicated, though.)?

I think, I would prefer option 3 ("Guten Tag,"). 

Resolving patch:
diff --git a/meinberlin/apps/ideas/views.py b/meinberlin/apps/ideas/views.py
--- a/meinberlin/apps/ideas/views.py
+++ b/meinberlin/apps/ideas/views.py
@@ -20,9 +20,7 @@
 from meinberlin.apps.moderatorfeedback.models import ModeratorStatement
 from meinberlin.apps.moderatorremark.models import ModeratorRemark
 from meinberlin.apps.notifications.emails import \
-    NotifyContactOnModeratorFeedback
-from meinberlin.apps.notifications.emails import \
-    NotifyCreatorOnModeratorFeedback
+    NotifyCreatorOrContactOnModeratorFeedback
 
 from . import forms
 from . import models
@@ -220,12 +218,9 @@ def forms_save(self, forms, commit=True):
                 remark.item = moderateable
                 remark.save()
 
-            # FIXME: nooooooo! no email when added remark or changed tasks.
-            # but there's also no emails when an item is archived???
-            if hasattr(self.object, 'contact_email'):
-                NotifyContactOnModeratorFeedback.send(self.object)
-            else:
-                NotifyCreatorOnModeratorFeedback.send(self.object)
+            if 'moderator_feedback' in forms['moderateable'].changed_data \
+                    or 'statement' in forms['statement'].changed_data:
+                NotifyCreatorOrContactOnModeratorFeedback.send(self.object)
         return objects
 
     def get_instance(self, name):
diff --git a/meinberlin/apps/notifications/emails.py b/meinberlin/apps/notifications/emails.py
--- a/meinberlin/apps/notifications/emails.py
+++ b/meinberlin/apps/notifications/emails.py
@@ -48,32 +48,26 @@ def get_receivers(self):
         return []
 
 
-class NotifyCreatorOnModeratorFeedback(Email):
+class NotifyCreatorOrContactOnModeratorFeedback(Email):
     template_name = \
         'meinberlin_notifications/emails/notify_creator_on_moderator_feedback'
 
     def get_receivers(self):
-        receivers = [self.object.creator]
-        receivers = _exclude_notifications_disabled(receivers)
-        return receivers
-
-    def get_context(self):
-        context = super().get_context()
-        context['object'] = self.object
-        return context
-
-
-class NotifyContactOnModeratorFeedback(Email):
-    template_name = \
-        'meinberlin_notifications/emails/notify_contact_on_moderator_feedback'
-
-    def get_receivers(self):
-        receivers = [self.object.contact_email]
+        if hasattr(self.object, 'contact_email'):
+            #  send to contact
+            receivers = [self.object.contact_email]
+        else:
+            #  send to creator
+            receivers = [self.object.creator]
+            receivers = _exclude_notifications_disabled(receivers)
         return receivers
 
     def get_context(self):
         context = super().get_context()
         context['object'] = self.object
+        if not hasattr(self.object, 'contact_email'):
+            #  send to creator
+            context['send_to_creator'] = True
         return context
 
 


Test patch:
diff --git a/tests/budgeting/test_views_integration.py b/tests/budgeting/test_views_integration.py
--- a/tests/budgeting/test_views_integration.py
+++ b/tests/budgeting/test_views_integration.py
@@ -205,7 +205,7 @@ def test_moderate_view(client, phase_factory, proposal_factory, user,
         response = client.post(url, data)
         assert redirect_target(response) == 'proposal-detail'
 
-        # was the NotifyContactOnModeratorFeedback sent?
+        # was the NotifyCreatorOrContactOnModeratorFeedback sent?
         assert len(mail.outbox) == 1
         assert mail.outbox[0].to == [item.contact_email]
         assert mail.outbox[0].subject.startswith('Rückmeldung')
@@ -239,7 +239,7 @@ def test_moderate_view_same_creator_contact(
         response = client.post(url, data)
         assert redirect_target(response) == 'proposal-detail'
 
-        # was the NotifyContactOnModeratorFeedback sent,
+        # was the NotifyCreatorOrContactOnModeratorFeedback sent,
         # even though the contact email is the same as the creator's?
         assert len(mail.outbox) == 1
         assert mail.outbox[0].to == [item.contact_email]