From eaaa6fd554b187916a5f93ac10283825051dbe4b Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:13:01 +0300 Subject: [PATCH 1/5] Use GMAIL as email provider --- qgis-app/settings.py | 2 +- qgis-app/settings_docker.py | 6 +++--- qgis-app/settings_local.py.templ | 2 +- qgis-app/settings_local_vagrant.py | 2 +- vagrant_assets/settings_local_vagrant.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qgis-app/settings.py b/qgis-app/settings.py index 8e6e8ef3..ae2219fc 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 = "automation@qgis.org" # 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 bb151b7f..2862340c 100644 --- a/qgis-app/settings_docker.py +++ b/qgis-app/settings_docker.py @@ -109,12 +109,12 @@ "EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend" ) # Host for sending e-mail. -EMAIL_HOST = os.environ.get("EMAIL_HOST", "smtp") +EMAIL_HOST = os.environ.get("EMAIL_HOST", "smtp.gmail.com") # Port for sending e-mail. -EMAIL_PORT = int(os.environ.get("EMAIL_PORT", "25")) +EMAIL_PORT = int(os.environ.get("EMAIL_PORT", "587")) # 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@qgis.org") 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..7605a161 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 = 'automation@qgis.org' INSTALLED_APPS = [ 'django.contrib.auth', diff --git a/qgis-app/settings_local_vagrant.py b/qgis-app/settings_local_vagrant.py index c7bbaead..e819b2e3 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 = "automation@qgis.org" INSTALLED_APPS = [ "django.contrib.auth", diff --git a/vagrant_assets/settings_local_vagrant.py b/vagrant_assets/settings_local_vagrant.py index b612fcfc..d19a6b21 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 = "automation@qgis.org" INSTALLED_APPS = [ "django.contrib.auth", From cc9f2c3dc27a0249f01508839f133bdc0e46f77c Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Tue, 13 Feb 2024 08:38:27 +0300 Subject: [PATCH 2/5] Use a local setting for email auth --- .gitignore | 1 + INSTALL.md | 15 +++++++++++++++ qgis-app/settings_docker.py | 7 ++++++- qgis-app/settings_email.py.templ | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 qgis-app/settings_email.py.templ diff --git a/.gitignore b/.gitignore index 4267cc6f..f3cd2aac 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ venv *.session # ABP: ignore local settings qgis-app/settings_local.py +qgis-app/settings_email.py # ABP: ignore pyc *.pyc # ABP: ignore zips diff --git a/INSTALL.md b/INSTALL.md index 5a5459eb..51843e13 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -193,6 +193,21 @@ $ make dbrestore ``` --- + +## Email-sending setup + +Create the file `settings_email.py` from the template: + +```sh +cp settings_email.py.templ settings_email.py +``` + +Update the new file with your email settings variables: + +```python title="settings_email.py" +EMAIL_HOST_PASSWORD = "your_email_app_password" +``` + ## Deploy Update with Rancher - Go to [https://rancher.qgis.org](https://rancher.qgis.org) diff --git a/qgis-app/settings_docker.py b/qgis-app/settings_docker.py index 2862340c..be6c3e2c 100644 --- a/qgis-app/settings_docker.py +++ b/qgis-app/settings_docker.py @@ -116,7 +116,7 @@ # See fig.yml for where these are defined EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", "automation@qgis.org") EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", "docker") -EMAIL_USE_TLS = ast.literal_eval(os.environ.get("EMAIL_USE_TLS", "False")) +EMAIL_USE_TLS = ast.literal_eval(os.environ.get("EMAIL_USE_TLS", "True")) EMAIL_SUBJECT_PREFIX = os.environ.get("EMAIL_SUBJECT_PREFIX", "[QGIS Plugins]") # django uploaded file permission @@ -134,3 +134,8 @@ MATOMO_SITE_ID="1" MATOMO_URL="//matomo.qgis.org/" + +try: + from settings_email import * +except ImportError: + pass \ No newline at end of file diff --git a/qgis-app/settings_email.py.templ b/qgis-app/settings_email.py.templ new file mode 100644 index 00000000..b8cdf371 --- /dev/null +++ b/qgis-app/settings_email.py.templ @@ -0,0 +1 @@ +EMAIL_HOST_PASSWORD = "" \ No newline at end of file From 8266bef7ddf78a9273edd69b8e4843310ecac429 Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:00:47 +0300 Subject: [PATCH 3/5] Update tests for new email --- qgis-app/fixtures/auth.json | 2 +- qgis-app/plugins/tests/test_plugin_update.py | 23 +++++++++++++++++++ qgis-app/plugins/tests/test_plugin_upload.py | 11 +++++++++ .../tests/test_plugin_version_feedback.py | 12 ++++++++++ qgis-app/styles/tests/test_views.py | 6 +++++ 5 files changed, 53 insertions(+), 1 deletion(-) 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/tests/test_plugin_update.py b/qgis-app/plugins/tests/test_plugin_update.py index 5ee6312e..064bda93 100644 --- a/qgis-app/plugins/tests/test_plugin_update.py +++ b/qgis-app/plugins/tests/test_plugin_update.py @@ -7,6 +7,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile from plugins.models import Plugin, PluginVersion from plugins.forms import PluginVersionForm +from django.core import mail def do_nothing(*args, **kwargs): pass @@ -90,6 +91,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, + 'automation@qgis.org' + ) + @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 +143,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, + 'automation@qgis.org' + ) + 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..d5efaa4d 100644 --- a/qgis-app/plugins/tests/test_plugin_upload.py +++ b/qgis-app/plugins/tests/test_plugin_upload.py @@ -7,6 +7,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile from plugins.models import Plugin, PluginVersion from plugins.forms import PackageUploadForm +from django.core import mail def do_nothing(*args, **kwargs): pass @@ -67,5 +68,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, + 'automation@qgis.org' + ) 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..498c72fc 100644 --- a/qgis-app/plugins/tests/test_plugin_version_feedback.py +++ b/qgis-app/plugins/tests/test_plugin_version_feedback.py @@ -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, + 'automation@qgis.org' + ) + 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, + 'automation@qgis.org' + ) + class TestPluginFeedbackReceivedList(SetupMixin, TestCase): fixtures = ["fixtures/simplemenu.json", "fixtures/auth.json"] diff --git a/qgis-app/styles/tests/test_views.py b/qgis-app/styles/tests/test_views.py index 48d1b7fc..83d408fd 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, + 'automation@qgis.org' + ) + # style should be in Waiting Review url = reverse("style_unapproved") self.response = self.client.get(url) From c488edeb2edd8ca1419960c92641b2fe9ba8c91f Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:13:38 +0300 Subject: [PATCH 4/5] Merge migrations --- .../plugins/migrations/0008_merge_20240206_0448.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 qgis-app/plugins/migrations/0008_merge_20240206_0448.py 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 = [ + ] From 5bfb1cac275fe934a845690e85fced98abf3f4c2 Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Wed, 6 Mar 2024 10:50:22 +0300 Subject: [PATCH 5/5] Use environment variables for email sending --- .gitignore | 1 - INSTALL.md | 14 -------------- qgis-app/plugins/tests/test_plugin_update.py | 5 +++-- qgis-app/plugins/tests/test_plugin_upload.py | 3 ++- .../plugins/tests/test_plugin_version_feedback.py | 6 +++--- qgis-app/settings.py | 2 +- qgis-app/settings_docker.py | 13 ++++--------- qgis-app/settings_email.py.templ | 1 - qgis-app/settings_local.py.templ | 2 +- qgis-app/settings_local_vagrant.py | 2 +- qgis-app/styles/tests/test_views.py | 2 +- vagrant_assets/settings_local_vagrant.py | 2 +- 12 files changed, 17 insertions(+), 36 deletions(-) delete mode 100644 qgis-app/settings_email.py.templ diff --git a/.gitignore b/.gitignore index f3cd2aac..4267cc6f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ venv *.session # ABP: ignore local settings qgis-app/settings_local.py -qgis-app/settings_email.py # ABP: ignore pyc *.pyc # ABP: ignore zips diff --git a/INSTALL.md b/INSTALL.md index 51843e13..1a66d939 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -194,20 +194,6 @@ $ make dbrestore --- -## Email-sending setup - -Create the file `settings_email.py` from the template: - -```sh -cp settings_email.py.templ settings_email.py -``` - -Update the new file with your email settings variables: - -```python title="settings_email.py" -EMAIL_HOST_PASSWORD = "your_email_app_password" -``` - ## Deploy Update with Rancher - Go to [https://rancher.qgis.org](https://rancher.qgis.org) diff --git a/qgis-app/plugins/tests/test_plugin_update.py b/qgis-app/plugins/tests/test_plugin_update.py index 064bda93..2bc5979a 100644 --- a/qgis-app/plugins/tests/test_plugin_update.py +++ b/qgis-app/plugins/tests/test_plugin_update.py @@ -8,6 +8,7 @@ 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 @@ -99,7 +100,7 @@ def test_plugin_new_version(self): # Should use the new email self.assertEqual( mail.outbox[0].from_email, - 'automation@qgis.org' + settings.EMAIL_HOST_USER ) @patch("plugins.tasks.generate_plugins_xml.delay", new=do_nothing) @@ -151,7 +152,7 @@ def test_plugin_version_update(self): # Should use the new email self.assertEqual( mail.outbox[0].from_email, - 'automation@qgis.org' + settings.EMAIL_HOST_USER ) diff --git a/qgis-app/plugins/tests/test_plugin_upload.py b/qgis-app/plugins/tests/test_plugin_upload.py index d5efaa4d..3539701a 100644 --- a/qgis-app/plugins/tests/test_plugin_upload.py +++ b/qgis-app/plugins/tests/test_plugin_upload.py @@ -8,6 +8,7 @@ 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 @@ -76,7 +77,7 @@ def test_plugin_upload_form(self): # Should use the new email self.assertEqual( mail.outbox[0].from_email, - 'automation@qgis.org' + 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 498c72fc..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"] @@ -92,7 +92,7 @@ def test_version_feedback_notify_sent(self): # Should use the new email self.assertEqual( mail.outbox[0].from_email, - 'automation@qgis.org' + settings.EMAIL_HOST_USER ) def test_add_recipient_in_email_notification(self): @@ -117,7 +117,7 @@ def test_add_recipient_in_email_notification(self): # Should use the new email self.assertEqual( mail.outbox[0].from_email, - 'automation@qgis.org' + settings.EMAIL_HOST_USER ) diff --git a/qgis-app/settings.py b/qgis-app/settings.py index ae2219fc..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 = "automation@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 07246cbb..f51dc50b 100644 --- a/qgis-app/settings_docker.py +++ b/qgis-app/settings_docker.py @@ -114,14 +114,14 @@ "EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend" ) # Host for sending e-mail. -EMAIL_HOST = os.environ.get("EMAIL_HOST", "smtp.gmail.com") +EMAIL_HOST = os.environ.get("EMAIL_HOST", "smtp") # Port for sending e-mail. -EMAIL_PORT = int(os.environ.get("EMAIL_PORT", "587")) +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", "automation@qgis.org") +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", "True")) +EMAIL_USE_TLS = ast.literal_eval(os.environ.get("EMAIL_USE_TLS", "False")) EMAIL_SUBJECT_PREFIX = os.environ.get("EMAIL_SUBJECT_PREFIX", "[QGIS Plugins]") # django uploaded file permission @@ -139,8 +139,3 @@ MATOMO_SITE_ID="1" MATOMO_URL="//matomo.qgis.org/" - -try: - from settings_email import * -except ImportError: - pass \ No newline at end of file diff --git a/qgis-app/settings_email.py.templ b/qgis-app/settings_email.py.templ deleted file mode 100644 index b8cdf371..00000000 --- a/qgis-app/settings_email.py.templ +++ /dev/null @@ -1 +0,0 @@ -EMAIL_HOST_PASSWORD = "" \ No newline at end of file diff --git a/qgis-app/settings_local.py.templ b/qgis-app/settings_local.py.templ index 7605a161..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 = 'automation@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 e819b2e3..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 = "automation@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 83d408fd..8aee501c 100644 --- a/qgis-app/styles/tests/test_views.py +++ b/qgis-app/styles/tests/test_views.py @@ -82,7 +82,7 @@ def test_upload_xml_file(self): # Should use the new email self.assertEqual( mail.outbox[0].from_email, - 'automation@qgis.org' + settings.EMAIL_HOST_USER ) # style should be in Waiting Review diff --git a/vagrant_assets/settings_local_vagrant.py b/vagrant_assets/settings_local_vagrant.py index d19a6b21..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 = "automation@qgis.org" +DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_HOST_USER", "automation") INSTALLED_APPS = [ "django.contrib.auth",