Browse Source

Add the EMAIL_USE_VERIFICATION configuration setting. Fixes #232

pull/241/head
Pēteris Caune 6 years ago
parent
commit
7c13adbf18
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 48 additions and 2 deletions
  1. +6
    -0
      CHANGELOG.md
  2. +6
    -0
      README.md
  3. +26
    -1
      hc/front/tests/test_add_email.py
  4. +9
    -1
      hc/front/views.py
  5. +1
    -0
      hc/settings.py

+ 6
- 0
CHANGELOG.md View File

@ -1,6 +1,12 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## Unreleased
### Improvements
- Add the EMAIL_USE_VERIFICATION configuration setting (#232)
## 1.6.0 - 2019-04-01 ## 1.6.0 - 2019-04-01
### Improvements ### Improvements


+ 6
- 0
README.md View File

@ -106,6 +106,7 @@ Configurations settings loaded from environment variables:
| EMAIL_HOST_USER | `""` *(empty string)* | EMAIL_HOST_USER | `""` *(empty string)*
| EMAIL_HOST_PASSWORD | `""` *(empty string)* | EMAIL_HOST_PASSWORD | `""` *(empty string)*
| EMAIL_USE_TLS | `"True"` | EMAIL_USE_TLS | `"True"`
| EMAIL_USE_VERIFICATION | `"True"`
| SITE_ROOT | `"http://localhost:8000"` | SITE_ROOT | `"http://localhost:8000"`
| SITE_NAME | `"Mychecks"` | SITE_NAME | `"Mychecks"`
| MASTER_BADGE_LABEL | `"Mychecks"` | MASTER_BADGE_LABEL | `"Mychecks"`
@ -158,6 +159,11 @@ can send pings).
If you close new user registration, you can still selectively invite users If you close new user registration, you can still selectively invite users
to your team account. to your team account.
`EMAIL_USE_VERIFICATION` enables/disables the sending of a verification
link when an email address is added to the list of notification methods.
Set it to `False` if you are setting up a private healthchecks instance where
you trust your users and want to avoid the extra verification step.
## Database Configuration ## Database Configuration


+ 26
- 1
hc/front/tests/test_add_email.py View File

@ -1,8 +1,11 @@
from django.core import mail
from django.test.utils import override_settings
from hc.api.models import Channel from hc.api.models import Channel
from hc.test import BaseTestCase from hc.test import BaseTestCase
class AddPdTestCase(BaseTestCase):
class AddEmailTestCase(BaseTestCase):
url = "/integrations/add_email/" url = "/integrations/add_email/"
def test_instructions_work(self): def test_instructions_work(self):
@ -23,6 +26,12 @@ class AddPdTestCase(BaseTestCase):
self.assertFalse(c.email_verified) self.assertFalse(c.email_verified)
self.assertEqual(c.project, self.project) self.assertEqual(c.project, self.project)
# Email should have been sent
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
self.assertTrue(email.subject.startswith("Verify email address on"))
def test_team_access_works(self): def test_team_access_works(self):
form = {"value": "[email protected]"} form = {"value": "[email protected]"}
@ -48,3 +57,19 @@ class AddPdTestCase(BaseTestCase):
c = Channel.objects.get() c = Channel.objects.get()
self.assertEqual(c.value, "[email protected]") self.assertEqual(c.value, "[email protected]")
@override_settings(EMAIL_USE_VERIFICATION=False)
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()
self.assertEqual(c.kind, "email")
self.assertEqual(c.value, "[email protected]")
self.assertTrue(c.email_verified)
# Email should *not* have been sent
self.assertEqual(len(mail.outbox), 0)

+ 9
- 1
hc/front/views.py View File

@ -646,7 +646,15 @@ def add_email(request):
channel.save() channel.save()
channel.assign_all_checks() channel.assign_all_checks()
channel.send_verify_link()
if settings.EMAIL_USE_VERIFICATION:
channel.send_verify_link()
else:
# In self-hosted setting, administator has the option to
# disable the email verification step.
channel.email_verified = True
channel.save()
return redirect("hc-channels") return redirect("hc-channels")
else: else:
form = AddEmailForm() form = AddEmailForm()


+ 1
- 0
hc/settings.py View File

@ -166,6 +166,7 @@ EMAIL_PORT = envint("EMAIL_PORT", "587")
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "") EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "") EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True") EMAIL_USE_TLS = envbool("EMAIL_USE_TLS", "True")
EMAIL_USE_VERIFICATION = envbool("EMAIL_USE_VERIFICATION", "True")
# Slack integration # Slack integration
SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID") SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")


Loading…
Cancel
Save