From ed0a19663d0f89f96cd04348edf2ee217cc84a49 Mon Sep 17 00:00:00 2001 From: sabinem Date: Thu, 15 Dec 2022 13:22:36 +0100 Subject: [PATCH 1/2] fix: prevent sending notifications when subscription is not verified --- ckanext/subscribe/notification.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ckanext/subscribe/notification.py b/ckanext/subscribe/notification.py index f967787..adfdf4a 100644 --- a/ckanext/subscribe/notification.py +++ b/ckanext/subscribe/notification.py @@ -301,7 +301,8 @@ def get_notifications_by_email(activities, objects_subscribed_to, # ignore activity that occurs before this subscription was created if subscription.created > activity.timestamp: continue - + if not subscription.verified: + continue notifications[subscription.email][subscription].append(activity) # dictize From 895d37ebd1695e9d23c35a7b151c16e9f296526f Mon Sep 17 00:00:00 2001 From: sabinem Date: Thu, 15 Dec 2022 15:58:38 +0100 Subject: [PATCH 2/2] fix: filter subscriptions by verified send only notifications to subscriptions that have been verified --- ckanext/subscribe/notification.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ckanext/subscribe/notification.py b/ckanext/subscribe/notification.py index adfdf4a..d58a8db 100644 --- a/ckanext/subscribe/notification.py +++ b/ckanext/subscribe/notification.py @@ -143,10 +143,12 @@ def get_objects_subscribed_to(subscription_frequency): objects_subscribed_to = defaultdict(list) # {object_id: [subscriptions]} # direct subscriptions - i.e. datasets, orgs & groups for subscription in model.Session.query(Subscription) \ + .filter(Subscription.verified.is_(True)) \ .filter(Subscription.frequency == subscription_frequency).all(): objects_subscribed_to[subscription.object_id].append(subscription) # also include the datasets attached to the subscribed orgs for subscription, package_id in model.Session.query(Subscription, Package.id) \ + .filter(Subscription.verified.is_(True)) \ .filter(Subscription.frequency == subscription_frequency) \ .join(Group, Group.id == Subscription.object_id) \ .filter(Group.state == 'active') \ @@ -156,6 +158,7 @@ def get_objects_subscribed_to(subscription_frequency): objects_subscribed_to[package_id].append(subscription) # also include the datasets attached to the subscribed orgs for subscription, package_id in model.Session.query(Subscription, Package.id) \ + .filter(Subscription.verified.is_(True)) \ .filter(Subscription.frequency == subscription_frequency) \ .join(Group, Group.id == Subscription.object_id) \ .filter(Group.state == 'active') \ @@ -301,8 +304,7 @@ def get_notifications_by_email(activities, objects_subscribed_to, # ignore activity that occurs before this subscription was created if subscription.created > activity.timestamp: continue - if not subscription.verified: - continue + notifications[subscription.email][subscription].append(activity) # dictize