Ticket #5376: 0001-Move-from-TextComment-to-comment-link-everywhere.patch

File 0001-Move-from-TextComment-to-comment-link-everywhere.patch, 5.4 KB (added by Boris Bobrov, 4 years ago)

I would appreciate review of this patch. Does it fix the issue? Does it break anything?

  • mediagoblin/db/models.py

    From e66c6f3d18252a6c4fdbc6e5a801991695137310 Mon Sep 17 00:00:00 2001
    From: Boris Bobrov <breton@cynicmansion.ru>
    Date: Tue, 20 Jun 2017 23:44:06 +0300
    Subject: [PATCH] Move from TextComment to comment link everywhere
    
    Closes bug 5376
    ---
     mediagoblin/db/models.py             |  2 +-
     mediagoblin/tests/test_moderation.py | 12 ++++++------
     mediagoblin/tests/test_reporting.py  |  4 +---
     mediagoblin/tests/tools.py           |  4 ++--
     mediagoblin/user_pages/lib.py        |  6 +++---
     5 files changed, 13 insertions(+), 15 deletions(-)
    
    diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
    index f4644b9f..a855058d 100644
    a b class Report(Base): 
    13861386    def is_comment_report(self):
    13871387        if self.object_id is None:
    13881388            return False
    1389         return isinstance(self.obj(), TextComment)
     1389        return isinstance(self.obj(), Comment)
    13901390
    13911391    def is_media_entry_report(self):
    13921392        if self.object_id is None:
  • mediagoblin/tests/test_moderation.py

    diff --git a/mediagoblin/tests/test_moderation.py b/mediagoblin/tests/test_moderation.py
    index 55bb4c4b..298f3c5a 100644
    a b import pytest 
    1818
    1919from mediagoblin.tests.tools import (fixture_add_user,
    2020            fixture_add_comment_report, fixture_add_comment)
    21 from mediagoblin.db.models import User, LocalUser, Report, TextComment, \
     21from mediagoblin.db.models import User, LocalUser, Report, Comment, \
    2222                                  UserBan, GenericModelReference
    2323from mediagoblin.tools import template, mail
    2424from webtest import AppError
    VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n', 
    156156        # actions to resolve a report
    157157        #----------------------------------------------------------------------
    158158        self.query_for_users()
    159         fixture_add_comment(author=self.user.id,
     159        test_comment = fixture_add_comment(author=self.user.id,
    160160            comment=u'Comment will be removed')
    161         test_comment = TextComment.query.filter(
    162             TextComment.actor==self.user.id).first()
     161        test_comment_id = test_comment.id  # remember it to use later
     162        # verify that the comment is fetchable this way
     163        assert Comment.query.get(test_comment_id) is not None
    163164        fixture_add_comment_report(comment=test_comment,
    164165            reported_user=self.user)
    165166        comment_gmr = GenericModelReference.query.filter_by(
    VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n', 
    181182        test_user_ban = UserBan.query.filter(
    182183            UserBan.user_id == self.user.id).first()
    183184        assert test_user_ban is not None
    184         test_comment = TextComment.query.filter(
    185             TextComment.actor==self.user.id).first()
     185        test_comment = Comment.query.get(test_comment_id)
    186186        assert test_comment is None
    187187
    188188        # Then, test what happens when a moderator attempts to punish an admin
  • mediagoblin/tests/test_reporting.py

    diff --git a/mediagoblin/tests/test_reporting.py b/mediagoblin/tests/test_reporting.py
    index 803fc849..294518e0 100644
    a b class TestReportFiling: 
    129129        allie_user, natalie_user = self.query_for_users()
    130130        allie_id, natalie_id = allie_user.id, natalie_user.id
    131131
    132         fixture_add_comment(author=allie_user.id,
     132        test_comment = fixture_add_comment(author=allie_user.id,
    133133            comment=u'Comment will be removed')
    134         test_comment = TextComment.query.filter(
    135             TextComment.actor==allie_user.id).first()
    136134        fixture_add_comment_report(comment=test_comment,
    137135            reported_user=allie_user,
    138136            report_content=u'Testing Archived Reports #1',
  • mediagoblin/tests/tools.py

    diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
    index 82def02c..5b78751c 100644
    a b def fixture_add_comment(author=None, media_entry=None, comment=None): 
    309309    comment_link.comment = text_comment
    310310    comment_link.save()
    311311
    312     Session.expunge(comment_link)
     312    #Session.expunge(comment_link)
    313313
    314     return text_comment
     314    return comment_link
    315315
    316316def fixture_add_comment_report(comment=None, reported_user=None,
    317317        reporter=None, created=None, report_content=None):
  • mediagoblin/user_pages/lib.py

    diff --git a/mediagoblin/user_pages/lib.py b/mediagoblin/user_pages/lib.py
    index b6741001..f5528b3e 100644
    a b  
    1616
    1717from mediagoblin import mg_globals
    1818from mediagoblin.db.base import Session
    19 from mediagoblin.db.models import CollectionItem, Report, TextComment, \
     19from mediagoblin.db.models import CollectionItem, Report, Comment, \
    2020                                  MediaEntry
    2121from mediagoblin.tools.mail import send_email
    2222from mediagoblin.tools.pluginapi import hook_runall
    def build_report_object(report_form, media_entry=None, comment=None): 
    9898    """
    9999    report_object = Report()
    100100    if report_form.validate() and comment is not None:
    101         report_object.obj = comment.comment()
    102         report_object.reported_user_id = TextComment.query.get(
     101        report_object.obj = comment
     102        report_object.reported_user_id = Comment.query.get(
    103103            comment.id).get_actor.id
    104104    elif report_form.validate() and media_entry is not None:
    105105        report_object.obj = media_entry