Skip to content

Commit

Permalink
Use smtp.gmail.com as EMAIL_HOST (qgis#356)
Browse files Browse the repository at this point in the history
* Use GMAIL as email provider

* Use a local setting for email auth

* Update tests for new email

* Merge migrations

* Use environment variables for email sending
  • Loading branch information
Xpirix authored Mar 6, 2024
1 parent 32e0504 commit 173850f
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 7 deletions.
1 change: 1 addition & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ $ make dbrestore
```

---

## Deploy Update with Rancher

- Go to [https://rancher.qgis.org](https://rancher.qgis.org)
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/fixtures/auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"groups": [],
"user_permissions": [],
"password": "pbkdf2_sha256$150000$GJga5YEinaWz$zJAjCXccvWHNPGmoZEjvBNgm1DGkjZGA3BmTVaNAxP4=",
"email": "",
"email": "[email protected]",
"date_joined": "2010-11-25 07:35:20"
}
}
Expand Down
14 changes: 14 additions & 0 deletions qgis-app/plugins/migrations/0008_merge_20240206_0448.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.2.25 on 2024-02-04 23:16

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('plugins', '0007_auto_20240109_0428'),
('plugins', '0006_plugin_display_created_by'),
]

operations = [
]
24 changes: 24 additions & 0 deletions qgis-app/plugins/tests/test_plugin_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.core.files.uploadedfile import SimpleUploadedFile
from plugins.models import Plugin, PluginVersion
from plugins.forms import PluginVersionForm
from django.core import mail
from django.conf import settings

def do_nothing(*args, **kwargs):
pass
Expand Down Expand Up @@ -90,6 +92,17 @@ def test_plugin_new_version(self):
self.assertEqual(self.plugin.tracker, "https://github.com/")
self.assertEqual(self.plugin.repository, "https://github.com/")

self.assertEqual(
mail.outbox[0].recipients(),
['[email protected]', '[email protected]']
)

# Should use the new email
self.assertEqual(
mail.outbox[0].from_email,
settings.EMAIL_HOST_USER
)

@patch("plugins.tasks.generate_plugins_xml.delay", new=do_nothing)
@patch("plugins.validator._check_url_link", new=do_nothing)
def test_plugin_version_update(self):
Expand Down Expand Up @@ -131,6 +144,17 @@ def test_plugin_version_update(self):
self.assertEqual(self.plugin.tracker, "https://github.com/")
self.assertEqual(self.plugin.repository, "https://github.com/")

self.assertEqual(
mail.outbox[0].recipients(),
['[email protected]', '[email protected]']
)

# Should use the new email
self.assertEqual(
mail.outbox[0].from_email,
settings.EMAIL_HOST_USER
)


def tearDown(self):
self.client.logout()
12 changes: 12 additions & 0 deletions qgis-app/plugins/tests/test_plugin_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.core.files.uploadedfile import SimpleUploadedFile
from plugins.models import Plugin, PluginVersion
from plugins.forms import PackageUploadForm
from django.core import mail
from django.conf import settings

def do_nothing(*args, **kwargs):
pass
Expand Down Expand Up @@ -67,5 +69,15 @@ def test_plugin_upload_form(self):
3)
self.assertTrue(PluginVersion.objects.filter(plugin__name='Test Plugin', version='0.0.1').exists())

self.assertEqual(
mail.outbox[0].recipients(),
['[email protected]', '[email protected]']
)

# Should use the new email
self.assertEqual(
mail.outbox[0].from_email,
settings.EMAIL_HOST_USER
)
def tearDown(self):
self.client.logout()
14 changes: 13 additions & 1 deletion qgis-app/plugins/tests/test_plugin_version_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from plugins.models import Plugin, PluginVersion, PluginVersionFeedback
from plugins.views import version_feedback_notify

from django.conf import settings

class SetupMixin:
fixtures = ["fixtures/auth.json", "fixtures/simplemenu.json"]
Expand Down Expand Up @@ -89,6 +89,12 @@ def test_version_feedback_notify_sent(self):
['[email protected]']
)

# Should use the new email
self.assertEqual(
mail.outbox[0].from_email,
settings.EMAIL_HOST_USER
)

def test_add_recipient_in_email_notification(self):
self.creator.email = '[email protected]'
self.creator.save()
Expand All @@ -108,6 +114,12 @@ def test_add_recipient_in_email_notification(self):
['[email protected]', '[email protected]']
)

# Should use the new email
self.assertEqual(
mail.outbox[0].from_email,
settings.EMAIL_HOST_USER
)


class TestPluginFeedbackReceivedList(SetupMixin, TestCase):
fixtures = ["fixtures/simplemenu.json", "fixtures/auth.json"]
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@

INTERNAL_IPS = ("127.0.0.1",)

DEFAULT_FROM_EMAIL = "[email protected]"
DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation")


# TINYMCE_JS_URL = 'http://debug.example.org/tiny_mce/tiny_mce_src.js'
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/settings_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
EMAIL_PORT = int(os.environ.get("EMAIL_PORT", "25"))
# SMTP authentication information for EMAIL_HOST.
# See fig.yml for where these are defined
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", "noreply")
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", "automation")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", "docker")
EMAIL_USE_TLS = ast.literal_eval(os.environ.get("EMAIL_USE_TLS", "False"))
EMAIL_SUBJECT_PREFIX = os.environ.get("EMAIL_SUBJECT_PREFIX", "[QGIS Plugins]")
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/settings_local.py.templ
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ HAYSTACK_WHOOSH_PATH = '/home/web/qgis-django/search-index'
# Tim Email settings
EMAIL_HOST = 'localhost'
#EMAIL_PORT =
DEFAULT_FROM_EMAIL = '[email protected]'
DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation")

INSTALLED_APPS = [
'django.contrib.auth',
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/settings_local_vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
# Tim Email settings
EMAIL_HOST = "localhost"
# EMAIL_PORT =
DEFAULT_FROM_EMAIL = "[email protected]"
DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation")

INSTALLED_APPS = [
"django.contrib.auth",
Expand Down
6 changes: 6 additions & 0 deletions qgis-app/styles/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def test_upload_xml_file(self):
['[email protected]']
)

# Should use the new email
self.assertEqual(
mail.outbox[0].from_email,
settings.EMAIL_HOST_USER
)

# style should be in Waiting Review
url = reverse("style_unapproved")
self.response = self.client.get(url)
Expand Down
2 changes: 1 addition & 1 deletion vagrant_assets/settings_local_vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
# Tim Email settings
EMAIL_HOST = "localhost"
# EMAIL_PORT =
DEFAULT_FROM_EMAIL = "[email protected]"
DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation")

INSTALLED_APPS = [
"django.contrib.auth",
Expand Down

0 comments on commit 173850f

Please sign in to comment.