From ad8fcae0402d611fad4a305586345bd08609869f Mon Sep 17 00:00:00 2001 From: NAGGINDA MARTHA Date: Thu, 25 Aug 2022 18:30:48 +0300 Subject: [PATCH] [Fixes #9881] AttributeError on viewing recent activities (#9907) * -[Fixes #9881] AttributeError on viewing recent activities * - remove actions about comments --- .../0084_remove_comments_from_actions.py | 27 ++++++++++++++++ geonode/context_processors.py | 4 --- geonode/documents/__init__.py | 1 - geonode/geoapps/__init__.py | 1 - geonode/geoserver/__init__.py | 1 - geonode/geoserver/helpers.py | 2 +- geonode/groups/templates/groups/activity.html | 10 ------ geonode/groups/views.py | 6 ---- geonode/layers/__init__.py | 1 - geonode/maps/__init__.py | 1 - geonode/messaging/notifications.py | 2 +- geonode/notifications_helper.py | 10 ++---- geonode/settings.py | 1 - geonode/social/signals.py | 31 +++---------------- .../templates/social/activity_list.html | 10 ------ geonode/social/templatetags/social_tags.py | 6 ---- geonode/social/views.py | 2 -- geonode/templates/_actions.html | 3 -- geonode/templates/about.html | 2 +- .../notifications/document_comment/full.txt | 3 -- .../notifications/document_comment/short.txt | 3 -- .../notifications/layer_comment/full.txt | 3 -- .../notifications/layer_comment/short.txt | 3 -- .../pinax/notifications/map_comment/full.txt | 4 --- .../pinax/notifications/map_comment/short.txt | 3 -- 25 files changed, 36 insertions(+), 104 deletions(-) create mode 100644 geonode/base/migrations/0084_remove_comments_from_actions.py delete mode 100644 geonode/templates/pinax/notifications/document_comment/full.txt delete mode 100644 geonode/templates/pinax/notifications/document_comment/short.txt delete mode 100644 geonode/templates/pinax/notifications/layer_comment/full.txt delete mode 100644 geonode/templates/pinax/notifications/layer_comment/short.txt delete mode 100644 geonode/templates/pinax/notifications/map_comment/full.txt delete mode 100644 geonode/templates/pinax/notifications/map_comment/short.txt diff --git a/geonode/base/migrations/0084_remove_comments_from_actions.py b/geonode/base/migrations/0084_remove_comments_from_actions.py new file mode 100644 index 00000000000..cb1c0e76d64 --- /dev/null +++ b/geonode/base/migrations/0084_remove_comments_from_actions.py @@ -0,0 +1,27 @@ +import logging + +from django.db import migrations + +from actstream.models import Action + +logger = logging.getLogger(__name__) + + +def delete_comments_actions(apps, _): + "Removes Action items related to comments" + try: + Action.objects.filter( + action_object_content_type__model='comment').delete() + except Exception as e: + logger.exception(e) + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0083_clean_resources_with_missing_thumb'), + ] + + operations = [ + migrations.RunPython(delete_comments_actions, migrations.RunPython.noop), + ] diff --git a/geonode/context_processors.py b/geonode/context_processors.py index 2ac466e908e..ec0e997eeac 100644 --- a/geonode/context_processors.py +++ b/geonode/context_processors.py @@ -64,10 +64,6 @@ def resource_urls(request): settings, 'DISPLAY_SOCIAL', False), - DISPLAY_COMMENTS=getattr( - settings, - 'DISPLAY_COMMENTS', - False), DISPLAY_RATINGS=getattr( settings, 'DISPLAY_RATINGS', diff --git a/geonode/documents/__init__.py b/geonode/documents/__init__.py index ed2b956f7f5..e34e2a1acd5 100644 --- a/geonode/documents/__init__.py +++ b/geonode/documents/__init__.py @@ -28,7 +28,6 @@ class DocumentsAppConfig(NotificationsAppConfigBase): ("document_approved", _("Document Approved"), _("A Document was approved by a Manager"),), ("document_published", _("Document Published"), _("A Document was published"),), ("document_deleted", _("Document Deleted"), _("A Document was deleted"),), - ("document_comment", _("Comment on Document"), _("A Document was commented on"),), ("document_rated", _("Rating for Document"), _("A rating was given to a document"),), ) diff --git a/geonode/geoapps/__init__.py b/geonode/geoapps/__init__.py index a789f94d1b7..9990f003eea 100644 --- a/geonode/geoapps/__init__.py +++ b/geonode/geoapps/__init__.py @@ -29,7 +29,6 @@ class GeoNodeAppsConfig(NotificationsAppConfigBase): ("geoapp_approved", _("App Approved"), _("A App was approved by a Manager"),), ("geoapp_published", _("App Published"), _("A App was published"),), ("geoapp_deleted", _("App Deleted"), _("A App was deleted"),), - ("geoapp_comment", _("Comment on App"), _("An App was commented on"),), ("geoapp_rated", _("Rating for App"), _("A rating was given to an App"),), ) diff --git a/geonode/geoserver/__init__.py b/geonode/geoserver/__init__.py index 37f5e331c5e..071aad3a8ec 100644 --- a/geonode/geoserver/__init__.py +++ b/geonode/geoserver/__init__.py @@ -61,7 +61,6 @@ def set_resource_links(*args, **kwargs): class GeoserverAppConfig(NotificationsAppConfigBase): name = 'geonode.geoserver' NOTIFICATIONS = (("dataset_uploaded", _("Dataset Uploaded"), _("A layer was uploaded"),), - ("dataset_comment", _("Comment on Dataset"), _("A layer was commented on"),), ("dataset_rated", _("Rating for Dataset"), _("A rating was given to a layer"),), ) diff --git a/geonode/geoserver/helpers.py b/geonode/geoserver/helpers.py index e2880c7f6ea..6110b5c1f0b 100755 --- a/geonode/geoserver/helpers.py +++ b/geonode/geoserver/helpers.py @@ -883,7 +883,7 @@ def gs_slurp( layer.workspace, layer.store) try: - # delete ratings, comments, and taggit tags: + # delete ratings, and taggit tags: ct = ContentType.objects.get_for_model(layer) OverallRating.objects.filter( content_type=ct, diff --git a/geonode/groups/templates/groups/activity.html b/geonode/groups/templates/groups/activity.html index 5fd2e6c12bb..2edbb4372ce 100644 --- a/geonode/groups/templates/groups/activity.html +++ b/geonode/groups/templates/groups/activity.html @@ -26,7 +26,6 @@

{% trans "Activity Feed for" %} {% trans "Datasets" %}
  • {% trans "Maps" %}
  • {% trans "Documents" %}
  • -
  • {% trans "Comments" %}
  • diff --git a/geonode/groups/views.py b/geonode/groups/views.py index c9f9bce7065..e4978f69455 100644 --- a/geonode/groups/views.py +++ b/geonode/groups/views.py @@ -302,7 +302,6 @@ def getKey(action): context = super().get_context_data(**kwargs) context['group'] = self.group - members = ([(member.user.id) for member in self.group.member_queryset()]) # Additional Filtered Lists Below action_list = [] actions = Action.objects.filter( @@ -333,11 +332,6 @@ def getKey(action): action.action_object and action.action_object.group == self.group.group][ :15] action_list.extend(context['action_list_documents']) - context['action_list_comments'] = Action.objects.filter( - public=True, - actor_object_id__in=members, - action_object_content_type__model='comment')[:15] - action_list.extend(context['action_list_comments']) context['action_list'] = sorted(action_list, key=getKey, reverse=True) return context diff --git a/geonode/layers/__init__.py b/geonode/layers/__init__.py index 189e10fd2e7..264c7aa9b66 100644 --- a/geonode/layers/__init__.py +++ b/geonode/layers/__init__.py @@ -31,7 +31,6 @@ class DatasetAppConfig(NotificationsAppConfigBase): ("dataset_approved", _("Dataset Approved"), _("A Dataset was approved by a Manager"),), ("dataset_published", _("Dataset Published"), _("A Dataset was published"),), ("dataset_deleted", _("Dataset Deleted"), _("A Dataset was deleted"),), - ("dataset_comment", _("Comment on Dataset"), _("A layer was commented on"),), ("dataset_rated", _("Rating for Dataset"), _("A rating was given to a layer"),),) diff --git a/geonode/maps/__init__.py b/geonode/maps/__init__.py index 4c9fa8c6a3c..df182e8e617 100644 --- a/geonode/maps/__init__.py +++ b/geonode/maps/__init__.py @@ -29,7 +29,6 @@ class MapsAppConfig(NotificationsAppConfigBase): ("map_approved", _("Map Approved"), _("A Map was approved by a Manager"),), ("map_published", _("Map Published"), _("A Map was published"),), ("map_deleted", _("Map Deleted"), _("A Map was deleted"),), - ("map_comment", _("Comment on Map"), _("A map was commented on"),), ("map_rated", _("Rating for Map"), _("A rating was given to a map"),), ) diff --git a/geonode/messaging/notifications.py b/geonode/messaging/notifications.py index 79a7053a604..7da8290227d 100644 --- a/geonode/messaging/notifications.py +++ b/geonode/messaging/notifications.py @@ -28,7 +28,7 @@ def message_received_notification(**kwargs): - """ Send a notification when a comment to a layer, map or document has + """ Send a notification when a request to a layer, map or document has been submitted """ notice_type_label = 'message_received' diff --git a/geonode/notifications_helper.py b/geonode/notifications_helper.py index 547524fb2a8..899fad8aa13 100644 --- a/geonode/notifications_helper.py +++ b/geonode/notifications_helper.py @@ -21,7 +21,7 @@ from django.apps import AppConfig from django.conf import settings -from django.db.models import signals, Q +from django.db.models import signals from django.contrib.auth import get_user_model from geonode.tasks.tasks import send_queued_notifications @@ -128,16 +128,10 @@ def get_notification_recipients(notice_type_label, exclude_user=None, resource=N not user.has_perm('view_resourcebase', resource.get_self_resource()): exclude_users_ids.append(user.id) if user.pk == resource.owner.pk and \ - not notice_type_label.split("_")[-1] in ("updated", "rated", "comment", "approved", "published"): + not notice_type_label.split("_")[-1] in ("updated", "rated", "approved", "published"): exclude_users_ids.append(user.id) except Exception as e: # fallback which wont send mails logger.exception(f"Could not send notifications: {e}") return [] return profiles.exclude(id__in=exclude_users_ids) - - -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=resource.owner.pk) | Q(is_superuser=True)) - return profiles diff --git a/geonode/settings.py b/geonode/settings.py index 8d6f6fb30e9..a695558f362 100644 --- a/geonode/settings.py +++ b/geonode/settings.py @@ -1178,7 +1178,6 @@ DATETIME_INPUT_FORMATS = DATETIME_INPUT_FORMATS + _DATETIME_INPUT_FORMATS DISPLAY_SOCIAL = ast.literal_eval(os.getenv('DISPLAY_SOCIAL', 'True')) -DISPLAY_COMMENTS = ast.literal_eval(os.getenv('DISPLAY_COMMENTS', 'True')) DISPLAY_RATINGS = ast.literal_eval(os.getenv('DISPLAY_RATINGS', 'True')) DISPLAY_WMS_LINKS = ast.literal_eval(os.getenv('DISPLAY_WMS_LINKS', 'True')) diff --git a/geonode/social/signals.py b/geonode/social/signals.py index 22413a934bb..f2aad7af589 100644 --- a/geonode/social/signals.py +++ b/geonode/social/signals.py @@ -33,8 +33,7 @@ from geonode.maps.models import Map from geonode.documents.models import Document from geonode.notifications_helper import (send_notification, queue_notification, - has_notifications, get_notification_recipients, - get_comment_notification_recipients) + has_notifications, get_notification_recipients) logger = logging.getLogger(__name__) @@ -51,7 +50,7 @@ def activity_post_modify_object(sender, instance, created=None, **kwargs): """ - Creates new activities after a Map, Dataset, Document, or Comment is created/updated/deleted. + Creates new activities after a Map, Dataset, or Document is created/updated/deleted. action_settings: actor: the user who performed the activity @@ -59,7 +58,7 @@ def activity_post_modify_object(sender, instance, created=None, **kwargs): created_verb: a translatable verb that is used when an object is created deleted_verb: a translatable verb that is used when an object is deleted object_name: the title of the object that is used to keep information about the object after it is deleted - target: the target of an action (if a comment is added to a map, the comment is the object the map is the target) + target: the target of an action updated_verb: a translatable verb that is used when an object is updated raw_action: a constant that describes the type of action performed (values should be: created, uploaded, deleted) @@ -82,15 +81,6 @@ def activity_post_modify_object(sender, instance, created=None, **kwargs): except Exception as e: logger.exception(e) - try: - action_settings['comment'].update(actor=getattr(instance, 'author', None), - created_verb=_("added a comment"), - target=getattr(instance, 'content_object', None), - updated_verb=_("updated a comment"), - ) - except Exception as e: - logger.exception(e) - try: action_settings['dataset'].update(created_verb=_('uploaded')) except Exception as e: @@ -101,7 +91,7 @@ def activity_post_modify_object(sender, instance, created=None, **kwargs): except Exception as e: logger.exception(e) - if obj_type not in ['document', 'dataset', 'map', 'comment']: + if obj_type not in ['document', 'dataset', 'map']: try: action_settings[obj_type].update(object_name=getattr(instance, 'title', None),) except Exception as e: @@ -182,19 +172,6 @@ def rating_post_save(instance, sender, created, **kwargs): {'resource': instance.content_object, 'user': instance.user, 'rating': instance.rating}) -def comment_post_save(instance, sender, created, **kwargs): - """ Send a notification when a comment to a layer, map or document has - been submitted - """ - notice_type_label = f'{instance.content_type.model.lower()}_comment' - recipients = get_comment_notification_recipients(notice_type_label, - instance.author, - resource=instance.content_object) - send_notification(recipients, - notice_type_label, - {'resource': instance.content_object, 'author': instance.author}) - - # rating notifications if ratings and has_notifications: signals.post_save.connect(rating_post_save, sender=Rating) diff --git a/geonode/social/templates/social/activity_list.html b/geonode/social/templates/social/activity_list.html index c7a7b823105..4f38207ccc2 100644 --- a/geonode/social/templates/social/activity_list.html +++ b/geonode/social/templates/social/activity_list.html @@ -26,7 +26,6 @@

    {% trans "Recent activity" %}

    {% trans app|title %}
    {% endfor %} -
  • {% trans "Comments" %}
  • @@ -65,15 +64,6 @@

    {% trans "Recent activity" %}

    {% endfor %}
    -
    -
      - {% for action in action_list_comments %} - {% activity_item action %} - {% empty %} -

      {% trans "No actions yet" %}

      - {% endfor %} -
    -
    {% for app_name, app_action_list in action_list_geoapps.items %}
      diff --git a/geonode/social/templatetags/social_tags.py b/geonode/social/templatetags/social_tags.py index 9764d6765b9..4de59dc47ce 100644 --- a/geonode/social/templatetags/social_tags.py +++ b/geonode/social/templatetags/social_tags.py @@ -77,12 +77,6 @@ def activity_item(action, **kwargs): if object_type in geoapps: activity_class = object_type - if object_type == 'comment': - activity_class = 'comment' - preposition = _("on") - object = None - fragment = "comments" - if object_type == 'map': activity_class = 'map' diff --git a/geonode/social/views.py b/geonode/social/views.py index 95f67ea6c37..abe8acf2b52 100644 --- a/geonode/social/views.py +++ b/geonode/social/views.py @@ -77,8 +77,6 @@ def _filter_actions(action, request): id__in=_filter_actions('map', self.request))[:15] context['action_list_documents'] = Action.objects.filter( id__in=_filter_actions('document', self.request))[:15] - context['action_list_comments'] = Action.objects.filter( - id__in=_filter_actions('comment', self.request))[:15] context['action_list_geoapps'] = self.get_geoapp_actions( _filter_actions('geoapp', self.request)) return context diff --git a/geonode/templates/_actions.html b/geonode/templates/_actions.html index 7dbec2c18d6..4fbd01f970d 100644 --- a/geonode/templates/_actions.html +++ b/geonode/templates/_actions.html @@ -13,9 +13,6 @@ {% if DISPLAY_RATINGS %}
    • {% trans "Ratings" %}
    • {% endif %} - {% if DISPLAY_COMMENTS %} -
    • {% trans "Comments" %}
    • - {% endif %} {% if EXIF_ENABLED and resource.polymorphic_ctype.name == 'document' and exif_data %}
    • {% trans "Exif" %}
    • {% endif %} diff --git a/geonode/templates/about.html b/geonode/templates/about.html index 9df6d0c9c24..31dad874d0a 100644 --- a/geonode/templates/about.html +++ b/geonode/templates/about.html @@ -11,7 +11,7 @@

      {% trans "About GeoNode" %}

        {% trans "GeoNode is a geospatial content management system, a platform for the management and publication of geospatial data. It brings together mature and stable open-source software projects under a consistent and easy-to-use interface allowing non-specialized users to share data and create interactive maps." %}

      -  {% trans "Data management tools built into GeoNode allow for integrated creation of data, metadata, and map visualizations. Each dataset in the system can be shared publicly or restricted to allow access to only specific users. Social features like user profiles and commenting and rating systems allow for the development of communities around each platform to facilitate the use, management, and quality control of the data the GeoNode instance contains." %} +  {% trans "Data management tools built into GeoNode allow for integrated creation of data, metadata, and map visualizations. Each dataset in the system can be shared publicly or restricted to allow access to only specific users. Social features like user profiles and rating systems allow for the development of communities around each platform to facilitate the use, management, and quality control of the data the GeoNode instance contains." %}

        {% trans "It is also designed to be a flexible platform that software developers can extend, modify or integrate against to meet requirements in their own applications." %} diff --git a/geonode/templates/pinax/notifications/document_comment/full.txt b/geonode/templates/pinax/notifications/document_comment/full.txt deleted file mode 100644 index c377e8c328c..00000000000 --- a/geonode/templates/pinax/notifications/document_comment/full.txt +++ /dev/null @@ -1,3 +0,0 @@ -{% load i18n %} -{% trans "A comment has been posted for the document" %} {{ resource.title }} {% trans "by the user" %} {{ author.username }}
      -{% trans "You can visit the document's detail page here" %}: http://{{ current_site }}{{ resource.get_absolute_url }} diff --git a/geonode/templates/pinax/notifications/document_comment/short.txt b/geonode/templates/pinax/notifications/document_comment/short.txt deleted file mode 100644 index 88ca6bcd084..00000000000 --- a/geonode/templates/pinax/notifications/document_comment/short.txt +++ /dev/null @@ -1,3 +0,0 @@ -{% load i18n %} - -{% trans "A comment has been posted for a document" %} diff --git a/geonode/templates/pinax/notifications/layer_comment/full.txt b/geonode/templates/pinax/notifications/layer_comment/full.txt deleted file mode 100644 index 80f14786fdf..00000000000 --- a/geonode/templates/pinax/notifications/layer_comment/full.txt +++ /dev/null @@ -1,3 +0,0 @@ -{% load i18n %} -{% trans "A comment has been posted for the dataset" %} {{ resource.title }} {% trans "by the user" %} {{ author.username }}
      -{% trans "You can visit the dataset's detail page here" %}: http://{{ current_site }}{% url "layer_detail" resource.service_typename %} diff --git a/geonode/templates/pinax/notifications/layer_comment/short.txt b/geonode/templates/pinax/notifications/layer_comment/short.txt deleted file mode 100644 index 1e564c28351..00000000000 --- a/geonode/templates/pinax/notifications/layer_comment/short.txt +++ /dev/null @@ -1,3 +0,0 @@ -{% load i18n %} - -{% trans "A comment has been posted for a dataset" %} diff --git a/geonode/templates/pinax/notifications/map_comment/full.txt b/geonode/templates/pinax/notifications/map_comment/full.txt deleted file mode 100644 index 8cd3ebf89c0..00000000000 --- a/geonode/templates/pinax/notifications/map_comment/full.txt +++ /dev/null @@ -1,4 +0,0 @@ -{% load i18n %} -{% trans "A comment has been posted for the map" %} {{ resource.title }}
      -{% trans "by the user" %} {{ author.username }}
      -{% trans "You can visit the map's detail page here" %}: http://{{ current_site }}{{ resource.get_absolute_url }} diff --git a/geonode/templates/pinax/notifications/map_comment/short.txt b/geonode/templates/pinax/notifications/map_comment/short.txt deleted file mode 100644 index 4d15139b58b..00000000000 --- a/geonode/templates/pinax/notifications/map_comment/short.txt +++ /dev/null @@ -1,3 +0,0 @@ -{% load i18n %} - -{% trans "A comment has been posted for a map" %}