Browse Source

Skip the verification step if user is setting up email notifications to their own email address.

pull/248/head
Pēteris Caune 6 years ago
parent
commit
d02a539a21
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 29 additions and 8 deletions
  1. +19
    -3
      hc/front/tests/test_add_email.py
  2. +10
    -5
      hc/front/views.py

+ 19
- 3
hc/front/tests/test_add_email.py View File

@ -17,7 +17,7 @@ class AddEmailTestCase(BaseTestCase):
self.assertContains(r, "Requires confirmation") self.assertContains(r, "Requires confirmation")
def test_it_creates_channel(self): def test_it_creates_channel(self):
form = {"value": "alice@example.org"}
form = {"value": "dan@example.org"}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form) r = self.client.post(self.url, form)
@ -26,7 +26,7 @@ class AddEmailTestCase(BaseTestCase):
c = Channel.objects.get() c = Channel.objects.get()
doc = json.loads(c.value) doc = json.loads(c.value)
self.assertEqual(c.kind, "email") self.assertEqual(c.kind, "email")
self.assertEqual(doc["value"], "alice@example.org")
self.assertEqual(doc["value"], "dan@example.org")
self.assertFalse(c.email_verified) self.assertFalse(c.email_verified)
self.assertEqual(c.project, self.project) self.assertEqual(c.project, self.project)
@ -36,7 +36,7 @@ class AddEmailTestCase(BaseTestCase):
email = mail.outbox[0] email = mail.outbox[0]
self.assertTrue(email.subject.startswith("Verify email address on")) self.assertTrue(email.subject.startswith("Verify email address on"))
# Make sure we're sending to an email address, not a JSON string: # Make sure we're sending to an email address, not a JSON string:
self.assertEqual(email.to[0], "alice@example.org")
self.assertEqual(email.to[0], "dan@example.org")
def test_team_access_works(self): def test_team_access_works(self):
form = {"value": "[email protected]"} form = {"value": "[email protected]"}
@ -73,6 +73,22 @@ class AddEmailTestCase(BaseTestCase):
@override_settings(EMAIL_USE_VERIFICATION=False) @override_settings(EMAIL_USE_VERIFICATION=False)
def test_it_auto_verifies_email(self): def test_it_auto_verifies_email(self):
form = {"value": "[email protected]"}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
c = Channel.objects.get()
doc = json.loads(c.value)
self.assertEqual(c.kind, "email")
self.assertEqual(doc["value"], "[email protected]")
self.assertTrue(c.email_verified)
# Email should *not* have been sent
self.assertEqual(len(mail.outbox), 0)
def test_it_auto_verifies_own_email(self):
form = {"value": "[email protected]"} form = {"value": "[email protected]"}
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")


+ 10
- 5
hc/front/views.py View File

@ -711,13 +711,18 @@ def add_email(request):
channel.assign_all_checks() channel.assign_all_checks()
if settings.EMAIL_USE_VERIFICATION:
channel.send_verify_link()
else:
# In self-hosted setting, administator has the option to
# disable the email verification step.
is_own_email = form.cleaned_data["value"] == request.user.email
if is_own_email or not settings.EMAIL_USE_VERIFICATION:
# If user is subscribing *their own* address
# we can skip the verification step.
# Additionally, in self-hosted setting, administator has the
# option to disable the email verification step altogether.
channel.email_verified = True channel.email_verified = True
channel.save() channel.save()
else:
channel.send_verify_link()
return redirect("hc-channels") return redirect("hc-channels")
else: else:


Loading…
Cancel
Save