Skip to content

Commit

Permalink
[Fixes #9881] AttributeError on viewing recent activities (#9907)
Browse files Browse the repository at this point in the history
* -[Fixes #9881] AttributeError on viewing recent activities

* - remove actions about comments
  • Loading branch information
marthamareal authored Aug 25, 2022
1 parent c3d3eb6 commit ad8fcae
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 104 deletions.
27 changes: 27 additions & 0 deletions geonode/base/migrations/0084_remove_comments_from_actions.py
Original file line number Diff line number Diff line change
@@ -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),
]
4 changes: 0 additions & 4 deletions geonode/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion geonode/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),),
)

Expand Down
1 change: 0 additions & 1 deletion geonode/geoapps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),),
)

Expand Down
1 change: 0 additions & 1 deletion geonode/geoserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),),
)

Expand Down
2 changes: 1 addition & 1 deletion geonode/geoserver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions geonode/groups/templates/groups/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ <h2 class="page-title">{% trans "Activity Feed for" %} <a href="{% url "group_
<li><a href="#datasets" data-toggle="tab"><i class="fa fa-square-o rotate-45"></i> {% trans "Datasets" %}</a></li>
<li><a href="#maps" data-toggle="tab"><i class="fa fa-map-marker"></i> {% trans "Maps" %}</a></li>
<li><a href="#documents" data-toggle="tab"><i class="fa fa-file-text-o"></i> {% trans "Documents" %}</a></li>
<li><a href="#comments" data-toggle="tab"><i class="fa fa-comment-o"></i> {% trans "Comments" %}</a></li>
</ul>
<div class="tab-content">
<article id="all" class="tab-pane active">
Expand Down Expand Up @@ -65,15 +64,6 @@ <h2 class="page-title">{% trans "Activity Feed for" %} <a href="{% url "group_
{% endfor %}
</ul>
</article>
<article id="comments" class="tab-pane">
<ul class="no-style-list">
{% for action in action_list_comments %}
{% activity_item action %}
{% empty %}
<p>{% trans "No actions yet" %}</p>
{% endfor %}
</ul>
</article>
</div>
</div>
</div>
Expand Down
6 changes: 0 additions & 6 deletions geonode/groups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion geonode/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),),)


Expand Down
1 change: 0 additions & 1 deletion geonode/maps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),),
)

Expand Down
2 changes: 1 addition & 1 deletion geonode/messaging/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 2 additions & 8 deletions geonode/notifications_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
31 changes: 4 additions & 27 deletions geonode/social/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -51,15 +50,15 @@

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
action_object: the object that received the action
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)
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
10 changes: 0 additions & 10 deletions geonode/social/templates/social/activity_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ <h2>{% trans "Recent activity" %}</h2>
{% trans app|title %}
</a></li>
{% endfor %}
<li><a href="#comments" data-toggle="tab"><i class="fa fa-comment-o"></i> {% trans "Comments" %}</a></li>
</ul>
<div class="tab-content">
<article id="all" class="tab-pane active">
Expand Down Expand Up @@ -65,15 +64,6 @@ <h2>{% trans "Recent activity" %}</h2>
{% endfor %}
</ul>
</article>
<article id="comments" class="tab-pane">
<ul class="no-style-list">
{% for action in action_list_comments %}
{% activity_item action %}
{% empty %}
<p>{% trans "No actions yet" %}</p>
{% endfor %}
</ul>
</article>
{% for app_name, app_action_list in action_list_geoapps.items %}
<article id="{{app_name}}" class="tab-pane">
<ul class="no-style-list">
Expand Down
6 changes: 0 additions & 6 deletions geonode/social/templatetags/social_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 0 additions & 2 deletions geonode/social/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions geonode/templates/_actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
{% if DISPLAY_RATINGS %}
<li><a href="#rate" data-toggle="tab"><i class="fa fa-star"></i>{% trans "Ratings" %}</a></li>
{% endif %}
{% if DISPLAY_COMMENTS %}
<li><a href="#comments" data-toggle="tab"><i class="fa fa-comment-o"></i> {% trans "Comments" %}</a></li>
{% endif %}
{% if EXIF_ENABLED and resource.polymorphic_ctype.name == 'document' and exif_data %}
<li><a href="#exif" data-toggle="tab"><i class="fa fa-photo"></i> {% trans "Exif" %}</a></li>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion geonode/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2>{% trans "About GeoNode" %}</h2>
  {% 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." %}
</p>
<p>
  {% 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." %}
</p>
<p>
  {% 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." %}
Expand Down

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions geonode/templates/pinax/notifications/layer_comment/full.txt

This file was deleted.

3 changes: 0 additions & 3 deletions geonode/templates/pinax/notifications/layer_comment/short.txt

This file was deleted.

4 changes: 0 additions & 4 deletions geonode/templates/pinax/notifications/map_comment/full.txt

This file was deleted.

3 changes: 0 additions & 3 deletions geonode/templates/pinax/notifications/map_comment/short.txt

This file was deleted.

0 comments on commit ad8fcae

Please sign in to comment.