Parcourir la source

Sends a confirmation email to the contributor

Containing the secret contrib management link

fix #45
Jocelyn Delalande il y a 7 ans
Parent
commit
339883d926

+ 1 - 0
wifiwithme/apps/contribmap/templates/contribmap/mails/new_contrib_author_notice.subject

@@ -0,0 +1 @@
+[wifi-with-me] votre demande, {{ contrib.name }}

+ 13 - 0
wifiwithme/apps/contribmap/templates/contribmap/mails/new_contrib_author_notice.txt

@@ -0,0 +1,13 @@
+Chèr·e {{ contrib.name }},
+
+Ta demande a bien été enregistrée. Elle est en ligne publiquement à l'adresse : <{{ permalink }}>.
+
+Si tout ou partie des informations n'apparaissent pas, c'est que tu as choisi qu'elles ne soient pas publiques.
+
+Tu peux gérer ou supprimer ta demande grace à ce lien privé à conserver :
+
+<{{ management_link }}>
+
+Bien à toi,
+
+Wifi-with-me

+ 18 - 0
wifiwithme/apps/contribmap/tests.py

@@ -151,6 +151,24 @@ class TestViews(APITestCase):
         self.assertEqual(len(mail.outbox), 1)
         self.assertIn('JohnCleese', mail.outbox[0].subject)
         self.assertIn('JohnCleese', mail.outbox[0].body)
+        self.assertEqual(mail.outbox[0].recipients(), ['foo@example.com'])
+
+    def test_add_contrib_sends_no_author_email(self):
+        # Send no email if author did not mentioned an email
+        post_data = self.mk_contrib_post_data()
+        del post_data['email']
+
+        response = self.client.post('/map/contribute', post_data)
+        self.assertEqual(response.status_code, 302)
+        self.assertEqual(len(mail.outbox), 0)
+
+    def test_add_contrib_sends_author_email(self):
+        # Send no email if author did not mentioned an email
+        response = self.client.post(
+            '/map/contribute',
+            self.mk_contrib_post_data(email='author@example.com'))
+        self.assertEqual(response.status_code, 302)
+        self.assertEqual(len(mail.outbox), 1)
 
 
 class TestManageView(APITestCase):

+ 14 - 0
wifiwithme/apps/contribmap/views.py

@@ -53,6 +53,20 @@ def add_contrib(request):
                     settings.NOTIFICATION_EMAILS,
                 )
 
+            # Notification email to the author
+            if contrib.email:
+                author_subject = get_template(
+                    'contribmap/mails/new_contrib_author_notice.subject')
+                author_body = get_template(
+                    'contribmap/mails/new_contrib_author_notice.txt')
+
+                send_mail(
+                    author_subject.render(context),
+                    author_body.render(context),
+                    settings.DEFAULT_FROM_EMAIL,
+                    [contrib.email],
+                )
+
             return redirect(reverse('thanks', kwargs={
                 'token': mgmt_token,
             }))