Skip to content

Commit

Permalink
update email integration settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mik3y committed Feb 25, 2020
1 parent 2977ba4 commit d8f5351
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 48 deletions.
29 changes: 0 additions & 29 deletions deploy/travis/local_settings.py

This file was deleted.

4 changes: 4 additions & 0 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ These values can be set in the shell environment of the server program.

**Example:** ``mysql://kegbot@localhost/kegbot``

.. data:: KEGBOT_EMAIL_FROM_ADDRESS

The "From:" address to use in emails from the system. No default.

.. data:: KEGBOT_REDIS_URL

URL to the Kegbot Redis instance, in the format ``redis://:PASSWORD@HOST:PORT/DATABASE``. ``PASSWORD`` and ``PORT`` are optional.
Expand Down
1 change: 1 addition & 0 deletions pykeg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def is_setup():


Setting('KEGBOT_ENV', 'test' if IS_RUNNING_PYTEST else ENV_DEBUG)
Setting('KEGBOT_EMAIL_FROM_ADDRESS', '')
Setting('KEGBOT_DATA_DIR', '/kegbot-data')
Setting('KEGBOT_IN_DOCKER', False, typefn=boolstr)
Setting('KEGBOT_SECRET_KEY', 'not-configured')
Expand Down
2 changes: 1 addition & 1 deletion pykeg/notification/backends/email_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

@override_settings(KEGBOT_BACKEND='pykeg.core.testutils.TestBackend')
@override_settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend')
@override_settings(EMAIL_FROM_ADDRESS='test-from@example')
@override_settings(DEFAULT_FROM_EMAIL='test-from@example')
class EmailNotificationBackendTestCase(TestCase):
def setUp(self):
self.backend = get_kegbot_backend()
Expand Down
5 changes: 1 addition & 4 deletions pykeg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@

# E-mail
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
EMAIL_FROM_ADDRESS = ''
DEFAULT_FROM_EMAIL = KEGBOT['KEGBOT_EMAIL_FROM_ADDRESS']
EMAIL_SUBJECT_PREFIX = ''

# Imagekit
Expand Down Expand Up @@ -311,6 +311,3 @@
# Override any user-specified timezone: As of Kegbot 0.9.12, this is
# specified in site settings.
TIME_ZONE = 'UTC'

# Update email addresses.
DEFAULT_FROM_EMAIL = EMAIL_FROM_ADDRESS
4 changes: 2 additions & 2 deletions pykeg/util/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@


def build_message(to_address, template_name, context):
from_address = getattr(settings, 'EMAIL_FROM_ADDRESS', None)
from_address = getattr(settings, 'DEFAULT_FROM_EMAIL', None)
if not from_address:
logger.error('EMAIL_FROM_ADDRESS is not available; aborting!')
logger.error('DEFAULT_FROM_EMAIL is not available; aborting!')
return None

template = get_template(template_name)
Expand Down
2 changes: 1 addition & 1 deletion pykeg/web/api/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_record_drink_usernames(self):
self.assertEqual(data.meta.result, 'ok')

@override_settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend')
@override_settings(EMAIL_FROM_ADDRESS='test-from@example')
@override_settings(DEFAULT_FROM_EMAIL='test-from@example')
def test_registration(self):
response, data = self.post(
'new-user/', data={'username': 'newuser', 'email': '[email protected]'})
Expand Down
2 changes: 1 addition & 1 deletion pykeg/web/kbregistration/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def save(self, domain_override=None,
# a password marked as unusable
if not user.has_usable_password():
continue
from_email = getattr(settings, 'EMAIL_FROM_ADDRESS', from_email)
from_email = settings.DEFAULT_FROM_EMAIL or from_email

be = get_kegbot_backend()
base_url = be.get_base_url()
Expand Down
5 changes: 3 additions & 2 deletions pykeg/web/kbregistration/registration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setUp(self):
self.user.save()

@override_settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend')
@override_settings(EMAIL_FROM_ADDRESS='test-from@example')
@override_settings(DEFAULT_FROM_EMAIL='test-from@example')
def test_notifications(self):
response = self.client.get('/accounts/password/reset/')
self.assertContains(response, "Reset Password", status_code=200)
Expand All @@ -52,6 +52,7 @@ def test_notifications(self):

msg = mail.outbox[0]

self.assertEqual('Password reset on My Kegbot', msg.subject)
# TODO(mikey): Customize subject with `kbsite.title`
self.assertEqual('Password reset', msg.subject)
self.assertEqual(['[email protected]'], msg.to)
self.assertEqual('test-from@example', msg.from_email)
3 changes: 1 addition & 2 deletions pykeg/web/kegadmin/templates/kegadmin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ <h4>Warning: Debug Mode</h4>
<h4>Warning: E-Mail Configuration Problem</h4>
E-mail is not properly configured; no mails will be sent. Please
<a href="https://kegbot.org/docs/server/extras/">read the docs</a>
for more information (hint: set <code>EMAIL_BACKEND</code> and
<code>EMAIL_FROM_ADDRESS</code> in <code>local_settings.py</code>).
for more information.
</div>
{% endif %}

Expand Down
3 changes: 1 addition & 2 deletions pykeg/web/kegadmin/templates/kegadmin/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<h4>Warning!</h4>
E-mail is not properly configured; no mails will be sent. Please
<a href="https://kegbot.org/docs/server/extras/">read the docs</a>
for more information (hint: set <code>EMAIL_BACKEND</code> and
<code>EMAIL_FROM_ADDRESS</code> in <code>local_settings.py</code>).
for more information.
</div>
{% else %}
<h2>Test E-mail Configuration</h2>
Expand Down
4 changes: 2 additions & 2 deletions pykeg/web/kegadmin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def dashboard(request):

email_backend = getattr(settings, 'EMAIL_BACKEND', None)
email_configured = email_backend and email_backend != 'django.core.mail.backends.dummy.EmailBackend'
email_configured = email_configured and bool(getattr(settings, 'EMAIL_FROM_ADDRESS', None))
email_configured = email_configured and settings.DEFAULT_FROM_EMAIL

context['email_configured'] = email_configured

Expand Down Expand Up @@ -168,7 +168,7 @@ def email(request):

email_backend = getattr(settings, 'EMAIL_BACKEND', None)
email_configured = email_backend and email_backend != 'django.core.mail.backends.dummy.EmailBackend'
email_configured = email_configured and bool(getattr(settings, 'EMAIL_FROM_ADDRESS', None))
email_configured = email_configured and settings.DEFAULT_FROM_EMAIL

if request.method == 'POST':
if 'send_test_email' in request.POST:
Expand Down
4 changes: 2 additions & 2 deletions pykeg/web/kegweb/kegweb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_activation(self):
self.assertIsNone(user.activation_key)

@override_settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend')
@override_settings(EMAIL_FROM_ADDRESS='test-from@example')
@override_settings(DEFAULT_FROM_EMAIL='test-from@example')
def test_registration(self):
kbsite = models.KegbotSite.get()
self.assertEqual('public', kbsite.privacy)
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_registration(self):
status_code=200)

@override_settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend')
@override_settings(EMAIL_FROM_ADDRESS='test-from@example')
@override_settings(DEFAULT_FROM_EMAIL='test-from@example')
def test_registration_with_invite(self):
kbsite = models.KegbotSite.get()
kbsite.registration_mode = 'staff-invite-online'
Expand Down
3 changes: 3 additions & 0 deletions pykeg/web/templates/registration/password_reset_subject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% load i18n %}{% autoescape off %}
{% blocktrans %}Password reset{% endblocktrans %}
{% endautoescape %}

0 comments on commit d8f5351

Please sign in to comment.