Skip to content

Commit

Permalink
Merge pull request #787 from euphorie/scrum-3024-notifications-contex…
Browse files Browse the repository at this point in the history
…t-filter

Notifications: Use `webhelpers.get_sessions_query()`
  • Loading branch information
reinhardt authored Jan 24, 2025
2 parents 096d55d + 0f914bf commit f2a3ddc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Changelog
Ref: scrum-2726.
[thet]

- Don't try to send notifications for sessions of depublished tools.
(`#3024 <https://github.com/syslabcom/scrum/issues/3024>`_)
[reinhardt]


16.2.7 (2025-01-15)
-------------------
Expand Down
21 changes: 14 additions & 7 deletions src/euphorie/client/notifications/notification__ra_not_modified.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 _(
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/euphorie/client/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f2a3ddc

Please sign in to comment.