Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gannebamm/1bc1a263ef29df7d14cf5fd8f8a35781 to your computer and use it in GitHub Desktop.
Save gannebamm/1bc1a263ef29df7d14cf5fd8f8a35781 to your computer and use it in GitHub Desktop.
Index: geonode/social/signals.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- geonode/social/signals.py (revision 3720021380ba0d2a07c39d9fa58e4fe176a4272a)
+++ geonode/social/signals.py (date 1605787715394)
@@ -177,7 +177,7 @@
""" Send a notification when rating a layer, map or document
"""
notice_type_label = '%s_rated' % instance.content_object.class_name.lower()
- recipients = get_notification_recipients(notice_type_label, instance.user)
+ recipients = get_notification_recipients(notice_type_label, instance.user, resource=instance.content_object)
send_notification(recipients, notice_type_label, {"instance": instance})
@@ -186,7 +186,8 @@
been submitted
"""
notice_type_label = '%s_comment' % instance.content_type.model.lower()
- recipients = get_comment_notification_recipients(notice_type_label, instance.content_object.owner)
+ recipients = get_comment_notification_recipients(notice_type_label, instance.content_object.owner,
+ resource=instance.content_object)
send_notification(recipients,
notice_type_label,
extra_context={
Index: geonode/base/models.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- geonode/base/models.py (revision 3720021380ba0d2a07c39d9fa58e4fe176a4272a)
+++ geonode/base/models.py (date 1605784656081)
@@ -889,7 +889,7 @@
if self.pk is None:
# Resource Created
notice_type_label = '%s_created' % self.class_name.lower()
- recipients = get_notification_recipients(notice_type_label)
+ recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
else:
@@ -905,7 +905,7 @@
# Send "approved" notification
notice_type_label = '%s_approved' % self.class_name.lower()
- recipients = get_notification_recipients(notice_type_label)
+ recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True
@@ -918,14 +918,14 @@
# Send "published" notification
notice_type_label = '%s_published' % self.class_name.lower()
- recipients = get_notification_recipients(notice_type_label)
+ recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True
# Updated Notifications Here
if not _notification_sent:
notice_type_label = '%s_updated' % self.class_name.lower()
- recipients = get_notification_recipients(notice_type_label)
+ recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
super(ResourceBase, self).save(*args, **kwargs)
@@ -938,7 +938,7 @@
"""
if hasattr(self, 'class_name') and notify:
notice_type_label = '%s_deleted' % self.class_name.lower()
- recipients = get_notification_recipients(notice_type_label)
+ recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
super(ResourceBase, self).delete(*args, **kwargs)
Index: geonode/notifications_helper.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- geonode/notifications_helper.py (revision 3720021380ba0d2a07c39d9fa58e4fe176a4272a)
+++ geonode/notifications_helper.py (date 1605790389480)
@@ -103,7 +103,7 @@
return notifications.models.queue(*args, **kwargs)
-def get_notification_recipients(notice_type_label, exclude_user=None):
+def get_notification_recipients(notice_type_label, exclude_user=None, resource=None):
""" Get notification recipients
"""
if not has_notifications:
@@ -115,11 +115,21 @@
profiles = get_user_model().objects.filter(id__in=recipients_ids)
if exclude_user:
profiles.exclude(username=exclude_user.username)
-
+ if resource and resource.title:
+ for user in profiles:
+ logtext = "check permissions for " + resource.title
+ logtext = logtext + " and " + user.username
+ logtext = logtext + ">> view permission: " + str(user.has_perm('base.view_resourcebase',
+ resource.get_self_resource()))
+ print(logtext)
+ if not user.has_perm('base.view_resourcebase', resource.get_self_resource()) or \
+ user.has_perm('view_resourcebase', resource):
+ profiles = profiles.exclude(username=user.username)
+ print(user.username + " will get excluded from notifaction list")
return profiles
-def get_comment_notification_recipients(notice_type_label, instance_owner, exclude_user=None):
- profiles = get_notification_recipients(notice_type_label, exclude_user)
+def get_comment_notification_recipients(notice_type_label, instance_owner, exclude_user=None, resource=None):
+ profiles = get_notification_recipients(notice_type_label, exclude_user, resource=resource)
profiles = profiles.filter(Q(pk=instance_owner.pk) | Q(is_superuser=True))
return profiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment