diff --git a/docs/changes.rst b/docs/changes.rst index b8adbcdf2..f34d335e8 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -11,6 +11,10 @@ Changelog Ref: scrum-2726. [thet] +- Don't try to send notifications for sessions of depublished tools. + (`#3024 `_) + [reinhardt] + 16.2.7 (2025-01-15) ------------------- diff --git a/src/euphorie/client/notifications/notification__ra_not_modified.py b/src/euphorie/client/notifications/notification__ra_not_modified.py index fb943dacd..cc31b161d 100644 --- a/src/euphorie/client/notifications/notification__ra_not_modified.py +++ b/src/euphorie/client/notifications/notification__ra_not_modified.py @@ -8,6 +8,7 @@ from euphorie.client.notifications.base import BaseNotificationEmail from logging import getLogger from plone import api +from plone.memoize.view import memoize from sqlalchemy import sql from z3c.saconfig import Session from zope.interface import implementer @@ -66,6 +67,11 @@ class Notification(BaseNotification): interval = INTERVAL_DAILY available = False # This feature is not yet available + @property + @memoize + def webhelpers(self): + return api.content.get_view("webhelpers", self.context, self.request) + @property def description(self): return _( @@ -111,13 +117,14 @@ def notify(self): today = datetime.date.today() - query = ( - Session.query(SurveySession) - .filter(SurveySession.get_archived_filter()) - .filter( - SurveySession.modified - <= (today - datetime.timedelta(days=self.reminder_days)) - ) + base_query = self.webhelpers.get_sessions_query( + context=self.context, + include_archived=False, + filter_by_account=False, + ) + query = base_query.filter( + SurveySession.modified + <= (today - datetime.timedelta(days=self.reminder_days)) ) # TODO filter for already sent notifications diff --git a/src/euphorie/client/tests/test_notifications.py b/src/euphorie/client/tests/test_notifications.py index 97d1421e6..e82089842 100644 --- a/src/euphorie/client/tests/test_notifications.py +++ b/src/euphorie/client/tests/test_notifications.py @@ -113,6 +113,16 @@ def setUp(self): ) survey_session.modified = datetime.datetime.now() - datetime.timedelta(days=366) Session.add(survey_session) + survey_session2 = SurveySession( + id=2, + title="Depublished", + zodb_path="nl/ict/depublished", + account=self.account, + ) + survey_session2.modified = datetime.datetime.now() - datetime.timedelta( + days=366 + ) + Session.add(survey_session2) api.portal.set_registry_record("euphorie.notifications__enabled", True) def test_send_notification(self):