Skip to content
Snippets Groups Projects
Commit ccb73abd authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

Merge branch '558_search_cleanup_url_prefix' into 'django3_migration'

Cleanup url prefix use in search

See merge request !382
parents 17e476e0 c16287a1
No related branches found
No related tags found
2 merge requests!382Cleanup url prefix use in search,!342Django 3 migration
Pipeline #43040 failed
......@@ -38,4 +38,6 @@ class SearchConfig(CommonAppConfig):
super(SearchConfig, self).ready()
from actstream import registry
import beat.web.search.signals # noqa: F401
registry.register(self.get_model("Search"))
......@@ -73,6 +73,9 @@ class Command(BaseCommand):
logger.info("Notifying interested parties for %s" % obj.search)
objects_changed += 1
current_site = Site.objects.get_current()
leaderboard_search_link = (
f"https://{current_site.domain}" + obj.search.get_absolute_url()
)
template_path = "search/leaderboard_changed.txt"
subject = (
'Experiment ranking for leaderboard "%s" changed'
......@@ -86,7 +89,7 @@ class Command(BaseCommand):
"leaderboard": obj,
"prev_date": prev_date,
"beat_version": __version__,
"site": current_site,
"leaderboard_search_link": leaderboard_search_link,
},
),
settings.DEFAULT_FROM_EMAIL,
......
......@@ -39,9 +39,16 @@ from .models import Leaderboard
@receiver(models.signals.pre_delete, sender=Leaderboard)
def notify_users(sender, instance, **kwargs):
"""Notify users the leaderboard was deleted"""
emails = instance.notify.exclude(instance.author).values_list("email", flat=True)
emails = instance.notify.exclude(
username=instance.search.author.username
).values_list("email", flat=True)
if emails:
current_site = Site.objects.get_current()
leaderboard_search_link = (
f"https://{current_site.domain}" + instance.search.get_absolute_url()
)
template_path = "search/leaderboard_deleted.txt"
subject = 'Leaderboard "%s" was deleted' % instance.search.fullname()
mesg = EmailMessage(
......@@ -51,7 +58,7 @@ def notify_users(sender, instance, **kwargs):
{
"leaderboard": instance,
"beat_version": version.__version__,
"site": current_site,
"leaderboard_search_link": leaderboard_search_link,
},
),
settings.DEFAULT_FROM_EMAIL,
......
......@@ -3,7 +3,7 @@
The experiment ranking for search "{{ leaderboard.search.fullname }}"
changed since our last reading {{ prev_date|naturaltime }}.
More details: http://{{ site.domain }}{{ leaderboard.search.get_absolute_url }}
More details: {{ leaderboard_search_link }}
You're receiving this notification because you have enabled notifications
for this leaderboard. You may disable notifications or automatic updates
......
......@@ -4,7 +4,7 @@ The the leaderboard associated to search "{{ leaderboard.search.fullname }}"
was just deleted and, with it, the associated e-mail notification for your
account.
More details: https://{{ site.domain }}{{ leaderboard.search.get_absolute_url }}
More details: {{ leaderboard_search_link }}
You're receiving this notification because you have enabled notifications
for this leaderboard. You may check the link above to see if the search
......
# vim: set fileencoding=utf-8 :
# encoding: utf-8
###############################################################################
# #
# Copyright (c) 2020 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.web module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import io
from unittest.mock import patch
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core import mail
from django.core.management import call_command
from django.test import override_settings
from ..algorithms.tests.core import setup_users
from ..common.testutils import BaseTestCase
from ..common.testutils import tearDownModule # noqa test runner will call it
from ..utils.tests.helpers import reload_urlconf
from .models import Leaderboard
from .models import Search
class UpdateLeaderBoardManagementTestCase(BaseTestCase):
def setUp(self):
setup_users()
self.johndoe = User.objects.get(username="johndoe")
self.jackdoe = User.objects.get(username="jackdoe")
self.janedoe = User.objects.get(username="janedoe")
def run_command(self):
new_io = io.StringIO()
call_command("update_leaderboards", stdout=new_io)
return new_io.getvalue().strip()
def test_leaderboard_update(self):
current_site = Site.objects.get_current()
search = Search.objects.create(author=self.johndoe, name="test")
search.filters = "{}"
search.settings = "{}"
search.save()
leaderboard = Leaderboard.objects.create(search=search)
leaderboard.notify.add(self.johndoe, self.jackdoe, self.janedoe)
leaderboard.save()
# Simulating update
with patch.object(Leaderboard, "update_experiments", return_value=True):
for prefix in ["", "/platform"]:
with self.subTest(url_prefix=prefix):
with override_settings(URL_PREFIX=prefix):
reload_urlconf()
mail.outbox = []
self.run_command()
self.assertEqual(len(mail.outbox), 1)
self.assertTrue(
f"https://{current_site.domain}{prefix}"
in mail.outbox[0].body
)
class EmailOnLeaderboarDeletionTestCase(BaseTestCase):
def setUp(self):
setup_users()
self.johndoe = User.objects.get(username="johndoe")
self.jackdoe = User.objects.get(username="jackdoe")
self.janedoe = User.objects.get(username="janedoe")
def test_leaderboard_deletion(self):
current_site = Site.objects.get_current()
for prefix in ["", "/platform"]:
with self.subTest(url_prefix=prefix):
search = Search.objects.create(author=self.johndoe, name="test")
search.filters = "{}"
search.settings = "{}"
search.save()
leaderboard = Leaderboard.objects.create(search=search)
leaderboard.notify.add(self.johndoe, self.jackdoe, self.janedoe)
leaderboard.save()
with override_settings(URL_PREFIX=prefix):
reload_urlconf()
mail.outbox = []
leaderboard.delete()
self.assertEqual(len(mail.outbox), 1)
self.assertTrue(
f"https://{current_site.domain}{prefix}" in mail.outbox[0].body
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment