diff --git a/qgis-app/plugins/tests/test_plugin_version_feedback.py b/qgis-app/plugins/tests/test_plugin_version_feedback.py index 1a90a48e..2db9dd6c 100644 --- a/qgis-app/plugins/tests/test_plugin_version_feedback.py +++ b/qgis-app/plugins/tests/test_plugin_version_feedback.py @@ -8,7 +8,7 @@ from freezegun import freeze_time from plugins.models import Plugin, PluginVersion, PluginVersionFeedback -from plugins.views import version_feedback_notify +from plugins.views import version_feedback_notify, version_feedback_resolved_notify from django.conf import settings from django.utils.dateformat import format import json @@ -139,6 +139,30 @@ def test_non_staff_should_not_see_plugin_feedback_completed_list(self): response = self.client.get(self.url) self.assertEqual(response.status_code, 404) + def test_version_feedback_resolved_notify(self): + self.creator.email = 'email@example.com' + + # add feedback for plugin 2 + PluginVersionFeedback.objects.create( + version=self.version_1, + reviewer=self.staff, + task="test comment in a feedback for plugin 2." + ) + all_tasks = PluginVersionFeedback.objects.filter(version=self.version_1) + + with self.assertLogs(level='DEBUG'): + version_feedback_resolved_notify(self.version_1, self.creator, all_tasks) + self.assertEqual( + mail.outbox[0].recipients(), + ['staff@staff.it'] + ) + + # Should use the new email + self.assertEqual( + mail.outbox[0].from_email, + settings.EMAIL_HOST_USER + ) + def test_staff_should_see_plugin_feedback_completed(self): self.client.force_login(user=self.staff) response = self.client.get(self.url) diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index e41f5125..e7d02b8b 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -213,6 +213,41 @@ def version_feedback_notify(version, user): % (plugin, ) ) +def version_feedback_resolved_notify(version, user, all_tasks): + """ + Sends a message when a version feedback is resolved. + """ + plugin = version.plugin + + reviewers_emails = all_tasks.values_list('reviewer__email', flat=True) + reviewers_emails = list(set(reviewers_emails)) + + if reviewers_emails: + domain = Site.objects.get_current().domain + mail_from = settings.DEFAULT_FROM_EMAIL + + logging.debug( + "Sending email feedback resolved notification for %s plugin version %s, recipients: %s" + % (plugin, version.version, reviewers_emails) + ) + send_mail_wrapper( + _("Plugin %s feedback resolved notification.") % (plugin, ), + _("\r\nPlugin %s feedback resolved by %s.\r\nLink: http://%s%sfeedback/\r\n. The plugin is now ready for review again.") + % ( + plugin.name, + user, + domain, + version.get_absolute_url(), + ), + mail_from, + reviewers_emails, + fail_silently=True, + ) + else: + logging.warning( + "No recipients found for %s plugin feedback resolved notification" + % (plugin, ) + ) def user_trust_notify(user): """ @@ -1473,7 +1508,12 @@ def version_feedback_update(request, package_name, version): feedback = PluginVersionFeedback.objects.filter( version=version, pk=task_id).first() feedback.is_completed = True - feedback.save() + feedback.save() + all_tasks = PluginVersionFeedback.objects.filter( + version=version) + if all_tasks.count() == len(completed_tasks): + version_feedback_resolved_notify(version, request.user, all_tasks) + return JsonResponse({"success": True}, status=201)