From: Jessica Tallon Date: Tue, 1 Mar 2016 11:58:38 +0000 (+0000) Subject: Fix #5376 - Ensure links have correct ID X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=161bc6b2c18f2d20eb759725b2df7fc7ac4a2728;p=mediagoblin.git Fix #5376 - Ensure links have correct ID This ensures that links to comments have the correct ID (the ID of the Comment object) as well as fixing deletion on reports and fixing a few other little things. I hope this fixes the #5376 issue, though cannot reproduce so unable to confirm. --- diff --git a/mediagoblin/db/base.py b/mediagoblin/db/base.py index 0f17a3a8..c59b0ebf 100644 --- a/mediagoblin/db/base.py +++ b/mediagoblin/db/base.py @@ -96,7 +96,7 @@ class GMGTableBase(object): # cause issues if it isn't. See #5382. # Import here to prevent cyclic imports. from mediagoblin.db.models import CollectionItem, GenericModelReference, \ - Report, Notification + Report, Notification, Comment # Some of the models don't have an "id" field which means they can't be # used with GMR, these models won't be in collections because they @@ -123,6 +123,12 @@ class GMGTableBase(object): ) notifications.delete() + # Delete this as a comment + comments = Comment.query.filter_by( + comment_id=gmr.id + ) + comments.delete() + # Set None on reports found reports = Report.query.filter_by( object_id=gmr.id diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 3f36f227..5393f679 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -609,7 +609,7 @@ class MediaEntry(Base, MediaEntryMixin, CommentingMixin): else: query = query.order_by(Comment.added.desc()) - return FakeCursor(query, lambda c:c.comment()) + return query def url_to_prev(self, urlgen): """get the next 'newer' entry by this user""" @@ -778,7 +778,7 @@ class MediaEntry(Base, MediaEntryMixin, CommentingMixin): if show_comments: comments = [ - comment.serialize(request) for comment in self.get_comments()] + l.comment().serialize(request) for l in self.get_comments()] total = len(comments) context["replies"] = { "totalItems": total, @@ -1008,17 +1008,6 @@ class TextComment(Base, TextCommentMixin, CommentingMixin): cascade="all, delete-orphan")) deletion_mode = Base.SOFT_DELETE - def soft_delete(self, *args, **kwargs): - # Find the GMR for this model. - gmr = GenericModelReference.query.filter_by( - obj_pk=self.id, - model_type=self.__tablename__ - ).first() - - # Delete the Comment object for this comment - Comment.query.filter_by(comment_id=gmr.id).delete() - return super(TextComment, self).soft_delete(*args, **kwargs) - def serialize(self, request): """ Unserialize to python dictionary for API """ target = self.get_reply_to() diff --git a/mediagoblin/moderation/tools.py b/mediagoblin/moderation/tools.py index 73afd051..36d89d71 100644 --- a/mediagoblin/moderation/tools.py +++ b/mediagoblin/moderation/tools.py @@ -69,7 +69,7 @@ def take_punitive_actions(request, form, report, user): if u'delete' in form.action_to_resolve.data and \ report.is_comment_report(): deleted_comment = report.obj() - Session.delete(deleted_comment) + deleted_comment.delete() form.resolution_content.data += \ _(u"\n{mod} deleted the comment.").format( mod=request.user.username) diff --git a/mediagoblin/notifications/__init__.py b/mediagoblin/notifications/__init__.py index 3ed9ba79..9d2f2b78 100644 --- a/mediagoblin/notifications/__init__.py +++ b/mediagoblin/notifications/__init__.py @@ -75,6 +75,11 @@ def mark_comment_notification_seen(comment_id, user): obj_pk=comment.id, model_type=comment.__tablename__ ).first() + + # If there is no GMR, there is no notification + if comment_gmr == None: + return + notification = Notification.query.filter_by( user_id=user.id, object_id=comment_gmr.id diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 1a35414f..48a91ab7 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -123,7 +123,8 @@ {% endif %}