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):
|
| 1386 | 1386 | def is_comment_report(self): |
| 1387 | 1387 | if self.object_id is None: |
| 1388 | 1388 | return False |
| 1389 | | return isinstance(self.obj(), TextComment) |
| | 1389 | return isinstance(self.obj(), Comment) |
| 1390 | 1390 | |
| 1391 | 1391 | def is_media_entry_report(self): |
| 1392 | 1392 | if self.object_id is None: |
diff --git a/mediagoblin/tests/test_moderation.py b/mediagoblin/tests/test_moderation.py
index 55bb4c4b..298f3c5a 100644
|
a
|
b
|
import pytest
|
| 18 | 18 | |
| 19 | 19 | from mediagoblin.tests.tools import (fixture_add_user, |
| 20 | 20 | fixture_add_comment_report, fixture_add_comment) |
| 21 | | from mediagoblin.db.models import User, LocalUser, Report, TextComment, \ |
| | 21 | from mediagoblin.db.models import User, LocalUser, Report, Comment, \ |
| 22 | 22 | UserBan, GenericModelReference |
| 23 | 23 | from mediagoblin.tools import template, mail |
| 24 | 24 | from webtest import AppError |
| … |
… |
VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
|
| 156 | 156 | # actions to resolve a report |
| 157 | 157 | #---------------------------------------------------------------------- |
| 158 | 158 | self.query_for_users() |
| 159 | | fixture_add_comment(author=self.user.id, |
| | 159 | test_comment = fixture_add_comment(author=self.user.id, |
| 160 | 160 | 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 |
| 163 | 164 | fixture_add_comment_report(comment=test_comment, |
| 164 | 165 | reported_user=self.user) |
| 165 | 166 | comment_gmr = GenericModelReference.query.filter_by( |
| … |
… |
VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
|
| 181 | 182 | test_user_ban = UserBan.query.filter( |
| 182 | 183 | UserBan.user_id == self.user.id).first() |
| 183 | 184 | 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) |
| 186 | 186 | assert test_comment is None |
| 187 | 187 | |
| 188 | 188 | # Then, test what happens when a moderator attempts to punish an admin |
diff --git a/mediagoblin/tests/test_reporting.py b/mediagoblin/tests/test_reporting.py
index 803fc849..294518e0 100644
|
a
|
b
|
class TestReportFiling:
|
| 129 | 129 | allie_user, natalie_user = self.query_for_users() |
| 130 | 130 | allie_id, natalie_id = allie_user.id, natalie_user.id |
| 131 | 131 | |
| 132 | | fixture_add_comment(author=allie_user.id, |
| | 132 | test_comment = fixture_add_comment(author=allie_user.id, |
| 133 | 133 | comment=u'Comment will be removed') |
| 134 | | test_comment = TextComment.query.filter( |
| 135 | | TextComment.actor==allie_user.id).first() |
| 136 | 134 | fixture_add_comment_report(comment=test_comment, |
| 137 | 135 | reported_user=allie_user, |
| 138 | 136 | report_content=u'Testing Archived Reports #1', |
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):
|
| 309 | 309 | comment_link.comment = text_comment |
| 310 | 310 | comment_link.save() |
| 311 | 311 | |
| 312 | | Session.expunge(comment_link) |
| | 312 | #Session.expunge(comment_link) |
| 313 | 313 | |
| 314 | | return text_comment |
| | 314 | return comment_link |
| 315 | 315 | |
| 316 | 316 | def fixture_add_comment_report(comment=None, reported_user=None, |
| 317 | 317 | reporter=None, created=None, report_content=None): |
diff --git a/mediagoblin/user_pages/lib.py b/mediagoblin/user_pages/lib.py
index b6741001..f5528b3e 100644
|
a
|
b
|
|
| 16 | 16 | |
| 17 | 17 | from mediagoblin import mg_globals |
| 18 | 18 | from mediagoblin.db.base import Session |
| 19 | | from mediagoblin.db.models import CollectionItem, Report, TextComment, \ |
| | 19 | from mediagoblin.db.models import CollectionItem, Report, Comment, \ |
| 20 | 20 | MediaEntry |
| 21 | 21 | from mediagoblin.tools.mail import send_email |
| 22 | 22 | from mediagoblin.tools.pluginapi import hook_runall |
| … |
… |
def build_report_object(report_form, media_entry=None, comment=None):
|
| 98 | 98 | """ |
| 99 | 99 | report_object = Report() |
| 100 | 100 | 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( |
| 103 | 103 | comment.id).get_actor.id |
| 104 | 104 | elif report_form.validate() and media_entry is not None: |
| 105 | 105 | report_object.obj = media_entry |