Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin resolved email #504

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion qgis-app/plugins/tests/test_plugin_version_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 protected]'

# 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(),
['[email protected]']
)

# 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)
Expand Down
42 changes: 41 additions & 1 deletion qgis-app/plugins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)


Expand Down
Loading