From 173850fd92994447c1686ff6f59a26f2668dc8cb Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Wed, 6 Mar 2024 14:08:33 +0300 Subject: [PATCH] Use smtp.gmail.com as EMAIL_HOST (#356) * 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 --- INSTALL.md | 1 + qgis-app/fixtures/auth.json | 2 +- .../migrations/0008_merge_20240206_0448.py | 14 +++++++++++ qgis-app/plugins/tests/test_plugin_update.py | 24 +++++++++++++++++++ qgis-app/plugins/tests/test_plugin_upload.py | 12 ++++++++++ .../tests/test_plugin_version_feedback.py | 14 ++++++++++- qgis-app/settings.py | 2 +- qgis-app/settings_docker.py | 2 +- qgis-app/settings_local.py.templ | 2 +- qgis-app/settings_local_vagrant.py | 2 +- qgis-app/styles/tests/test_views.py | 6 +++++ vagrant_assets/settings_local_vagrant.py | 2 +- 12 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 qgis-app/plugins/migrations/0008_merge_20240206_0448.py diff --git a/INSTALL.md b/INSTALL.md index 5a5459eb..1a66d939 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -193,6 +193,7 @@ $ make dbrestore ``` --- + ## Deploy Update with Rancher - Go to [https://rancher.qgis.org](https://rancher.qgis.org) diff --git a/qgis-app/fixtures/auth.json b/qgis-app/fixtures/auth.json index 24af50b9..a4b9939c 100644 --- a/qgis-app/fixtures/auth.json +++ b/qgis-app/fixtures/auth.json @@ -49,7 +49,7 @@ "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$150000$GJga5YEinaWz$zJAjCXccvWHNPGmoZEjvBNgm1DGkjZGA3BmTVaNAxP4=", - "email": "", + "email": "staff@staff.it", "date_joined": "2010-11-25 07:35:20" } } diff --git a/qgis-app/plugins/migrations/0008_merge_20240206_0448.py b/qgis-app/plugins/migrations/0008_merge_20240206_0448.py new file mode 100644 index 00000000..ad09b265 --- /dev/null +++ b/qgis-app/plugins/migrations/0008_merge_20240206_0448.py @@ -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 = [ + ] diff --git a/qgis-app/plugins/tests/test_plugin_update.py b/qgis-app/plugins/tests/test_plugin_update.py index 5ee6312e..2bc5979a 100644 --- a/qgis-app/plugins/tests/test_plugin_update.py +++ b/qgis-app/plugins/tests/test_plugin_update.py @@ -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 @@ -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(), + ['admin@admin.it', 'staff@staff.it'] + ) + + # 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): @@ -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(), + ['admin@admin.it', 'staff@staff.it'] + ) + + # Should use the new email + self.assertEqual( + mail.outbox[0].from_email, + settings.EMAIL_HOST_USER + ) + def tearDown(self): self.client.logout() diff --git a/qgis-app/plugins/tests/test_plugin_upload.py b/qgis-app/plugins/tests/test_plugin_upload.py index 7a3a54dc..3539701a 100644 --- a/qgis-app/plugins/tests/test_plugin_upload.py +++ b/qgis-app/plugins/tests/test_plugin_upload.py @@ -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 @@ -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(), + ['admin@admin.it', 'staff@staff.it'] + ) + + # Should use the new email + self.assertEqual( + mail.outbox[0].from_email, + settings.EMAIL_HOST_USER + ) def tearDown(self): self.client.logout() diff --git a/qgis-app/plugins/tests/test_plugin_version_feedback.py b/qgis-app/plugins/tests/test_plugin_version_feedback.py index 36f6fc0f..8f7c7702 100644 --- a/qgis-app/plugins/tests/test_plugin_version_feedback.py +++ b/qgis-app/plugins/tests/test_plugin_version_feedback.py @@ -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"] @@ -89,6 +89,12 @@ def test_version_feedback_notify_sent(self): ['email@example.com'] ) + # 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@example.com' self.creator.save() @@ -108,6 +114,12 @@ def test_add_recipient_in_email_notification(self): ['new@example.com', 'email@example.com'] ) + # 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"] diff --git a/qgis-app/settings.py b/qgis-app/settings.py index 8e6e8ef3..c3e7a79b 100644 --- a/qgis-app/settings.py +++ b/qgis-app/settings.py @@ -219,7 +219,7 @@ INTERNAL_IPS = ("127.0.0.1",) -DEFAULT_FROM_EMAIL = "noreply@qgis.org" +DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation") # TINYMCE_JS_URL = 'http://debug.example.org/tiny_mce/tiny_mce_src.js' diff --git a/qgis-app/settings_docker.py b/qgis-app/settings_docker.py index eac5b075..f51dc50b 100644 --- a/qgis-app/settings_docker.py +++ b/qgis-app/settings_docker.py @@ -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]") diff --git a/qgis-app/settings_local.py.templ b/qgis-app/settings_local.py.templ index 2b7f2ad6..8b604a68 100644 --- a/qgis-app/settings_local.py.templ +++ b/qgis-app/settings_local.py.templ @@ -58,7 +58,7 @@ HAYSTACK_WHOOSH_PATH = '/home/web/qgis-django/search-index' # Tim Email settings EMAIL_HOST = 'localhost' #EMAIL_PORT = -DEFAULT_FROM_EMAIL = 'noreply@qgis.org' +DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation") INSTALLED_APPS = [ 'django.contrib.auth', diff --git a/qgis-app/settings_local_vagrant.py b/qgis-app/settings_local_vagrant.py index c7bbaead..2d570d59 100644 --- a/qgis-app/settings_local_vagrant.py +++ b/qgis-app/settings_local_vagrant.py @@ -156,7 +156,7 @@ # Tim Email settings EMAIL_HOST = "localhost" # EMAIL_PORT = -DEFAULT_FROM_EMAIL = "noreply@qgis.org" +DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation") INSTALLED_APPS = [ "django.contrib.auth", diff --git a/qgis-app/styles/tests/test_views.py b/qgis-app/styles/tests/test_views.py index 48d1b7fc..8aee501c 100644 --- a/qgis-app/styles/tests/test_views.py +++ b/qgis-app/styles/tests/test_views.py @@ -79,6 +79,12 @@ def test_upload_xml_file(self): ['staff@email.com'] ) + # 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) diff --git a/vagrant_assets/settings_local_vagrant.py b/vagrant_assets/settings_local_vagrant.py index b612fcfc..f8b7e546 100644 --- a/vagrant_assets/settings_local_vagrant.py +++ b/vagrant_assets/settings_local_vagrant.py @@ -156,7 +156,7 @@ # Tim Email settings EMAIL_HOST = "localhost" # EMAIL_PORT = -DEFAULT_FROM_EMAIL = "noreply@qgis.org" +DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation") INSTALLED_APPS = [ "django.contrib.auth",