In this commit, I'm deleting the ArchivedReports object, at paroneyea's recom-

-mendation. Instead, all of its functionality will be in the ReportBase object.
This commit is contained in:
tilly-Q 2013-09-11 17:09:21 -04:00
parent 6acf4ee60e
commit c906887025
6 changed files with 63 additions and 100 deletions

View File

@ -470,6 +470,9 @@ class ReportBase_v0(declarative_base()):
reported_user_id = Column(Integer, ForeignKey(User.id), nullable=False)
created = Column(DateTime, nullable=False, default=datetime.datetime.now)
discriminator = Column('type', Unicode(50))
resolver_id = Column(Integer, ForeignKey(User.id))
resolved = Column(DateTime)
result = Column(UnicodeText)
__mapper_args__ = {'polymorphic_on': discriminator}
class CommentReport_v0(ReportBase_v0):
@ -487,17 +490,6 @@ class MediaReport_v0(ReportBase_v0):
id = Column('id',Integer, ForeignKey('core__reports.id'), primary_key=True)
media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False)
class ArchivedReport_v0(ReportBase_v0):
__tablename__ = 'core__reports_archived'
__mapper_args__ = {'polymorphic_identity': 'archived_report'}
id = Column('id',Integer, ForeignKey('core__reports.id'), primary_key=True)
media_entry_id = Column(Integer, ForeignKey(MediaEntry.id))
comment_id = Column(Integer, ForeignKey(MediaComment.id))
resolver_id = Column(Integer, ForeignKey(User.id), nullable=False)
resolved_time = Column(DateTime)
result = Column(UnicodeText)
class UserBan_v0(declarative_base()):
__tablename__ = 'core__user_bans'
user_id = Column('id',Integer, ForeignKey(User.id), nullable=False,
@ -528,7 +520,6 @@ def create_moderation_tables(db):
ReportBase_v0.__table__.create(db.bind)
CommentReport_v0.__table__.create(db.bind)
MediaReport_v0.__table__.create(db.bind)
ArchivedReport_v0.__table__.create(db.bind)
UserBan_v0.__table__.create(db.bind)
Privilege_v0.__table__.create(db.bind)
PrivilegeUserAssociation_v0.__table__.create(db.bind)

View File

@ -694,6 +694,14 @@ class ReportBase(Base):
-port was filed.
:keyword discriminator This column distinguishes between the
different types of reports.
:keyword resolver_id Holds the id of the moderator/admin who
resolved the report.
:keyword resolved Holds the DateTime object which descri-
-bes when this report was resolved
:keyword result Holds the UnicodeText column of the
resolver's reasons for resolving
the report this way. Some of this
is auto-generated
"""
__tablename__ = 'core__reports'
id = Column(Integer, primary_key=True)
@ -714,6 +722,16 @@ class ReportBase(Base):
primaryjoin="User.id==ReportBase.reported_user_id")
created = Column(DateTime, nullable=False, default=datetime.datetime.now())
discriminator = Column('type', Unicode(50))
resolver_id = Column(Integer, ForeignKey(User.id))
resolver = relationship(
User,
backref=backref("reports_resolved_by",
lazy="dynamic",
cascade="all, delete-orphan"),
primaryjoin="User.id==ReportBase.resolver_id")
resolved = Column(DateTime)
result = Column(UnicodeText)
__mapper_args__ = {'polymorphic_on': discriminator}
def is_comment_report(self):
@ -723,7 +741,12 @@ class ReportBase(Base):
return self.discriminator=='media_report'
def is_archived_report(self):
return self.discriminator=='archived_report'
return self.resolved is not None
def archive(self,resolver_id, resolved, result):
self.resolver_id = resolver_id
self.resolved = resolved
self.result = result
class CommentReport(ReportBase):
@ -737,12 +760,13 @@ class CommentReport(ReportBase):
id = Column('id',Integer, ForeignKey('core__reports.id'),
primary_key=True)
comment_id = Column(Integer, ForeignKey(MediaComment.id), nullable=False)
comment_id = Column(Integer, ForeignKey(MediaComment.id), nullable=True)
comment = relationship(
MediaComment, backref=backref("reports_filed_on",
lazy="dynamic",
cascade="all, delete-orphan"))
class MediaReport(ReportBase):
"""
Reports that have been filed on media entries
@ -754,59 +778,13 @@ class MediaReport(ReportBase):
id = Column('id',Integer, ForeignKey('core__reports.id'),
primary_key=True)
media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False)
media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=True)
media_entry = relationship(
MediaEntry,
backref=backref("reports_filed_onmod/reports/1/",
lazy="dynamic",
cascade="all, delete-orphan"))
class ArchivedReport(ReportBase):
"""
Reports that have been resolved. The media_entry and comment columns must
be optional so that if the media entry/comment is deleted, the archive can
still exist.
:keyword comment_id Holds the Integer value of the reported
comment's ID. This column is optio-
-nal.
:keyword media_entry_id Holds the Integer value of the reported
media entry's ID. This column is
optional.
:keyword resolver_id Holds the id of the moderator/admin who
resolved the report.
:keyword resolved Holds the DateTime object which descri-
-bes when this report was resolved
:keyword result Holds the UnicodeText column of the
resolver's reasons for resolving
the report this way. Some of this
is auto-generated
"""
__tablename__ = 'core__reports_archived'
__mapper_args__ = {'polymorphic_identity': 'archived_report'}
id = Column('id',Integer, ForeignKey('core__reports.id'),
primary_key=True)
media_entry_id = Column(Integer, ForeignKey(MediaEntry.id))
media_entry = relationship(
MediaEntry,
backref=backref("past_reports_filed_on",
lazy="dynamic"))
comment_id = Column(Integer, ForeignKey(MediaComment.id))
comment = relationship(
MediaComment, backref=backref("past_reports_filed_on",
lazy="dynamic"))
resolver_id = Column(Integer, ForeignKey(User.id), nullable=False)
resolver = relationship(
User,
backref=backref("reports_resolved_by",
lazy="dynamic",
cascade="all, delete-orphan"),
primaryjoin="User.id==ArchivedReport.resolver_id")
resolved = Column(DateTime)
result = Column(UnicodeText)
class UserBan(Base):
"""
Holds the information on a specific user's ban-state. As long as one of
@ -887,7 +865,7 @@ MODELS = [
MediaFile, FileKeynames, MediaAttachmentFile, ProcessingMetaData,
Notification, CommentNotification, ProcessingNotification, Client,
CommentSubscription, ReportBase, CommentReport, MediaReport, UserBan,
Privilege, PrivilegeUserAssociation, ArchivedReport,
Privilege, PrivilegeUserAssociation,
RequestToken, AccessToken, NonceTimestamp]
"""

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from mediagoblin import mg_globals
from mediagoblin.db.models import User, Privilege, ArchivedReport, UserBan
from mediagoblin.db.models import User, Privilege, UserBan
from mediagoblin.db.base import Session
from mediagoblin.tools.mail import send_email
from mediagoblin.tools.response import redirect
@ -68,15 +68,6 @@ def take_punitive_actions(request, form, report, user):
u"<br>%s sent a warning email to the offender." % (
request.user.username)
archive = ArchivedReport(
reporter_id=report.reporter_id,
report_content=report.report_content,
reported_user_id=report.reported_user_id,
created=report.created,
resolved=datetime.now(),
resolver_id=request.user.id
)
if u'delete' in form.action_to_resolve.data and \
report.is_comment_report():
deleted_comment = report.comment
@ -91,20 +82,12 @@ def take_punitive_actions(request, form, report, user):
form.resolution_content.data += \
u"<br>%s deleted the media entry." % (
request.user.username)
# If the moderator didn't delete the content we then attach the
# content to the archived report. We also have to actively delete the
# old report, since it won't be deleted by cascading.
elif report.is_comment_report():
archive.comment_id = report.comment_id
Session.delete(report)
elif report.is_media_entry_report():
archive.media_entry_id = report.media_entry.id
Session.delete(report)
archive.result=form.resolution_content.data
Session.add(archive)
report.archive(
resolver_id=request.user.id,
resolved=datetime.now(),
result=form.resolution_content.data)
Session.add(report)
Session.commit()
if message_body:
send_email(

View File

@ -18,7 +18,7 @@ from werkzeug.exceptions import Forbidden
from mediagoblin.db.models import (MediaEntry, User, MediaComment, \
CommentReport, ReportBase, Privilege, \
UserBan, ArchivedReport)
UserBan)
from mediagoblin.decorators import (require_admin_or_moderator_login, \
active_user_from_url, user_has_privilege)
from mediagoblin.tools.response import render_to_response, redirect
@ -72,9 +72,9 @@ def moderation_users_detail(request):
'''
user = User.query.filter_by(username=request.matchdict['user']).first()
active_reports = user.reports_filed_on.filter(
ReportBase.discriminator!='archived_report').limit(5)
ReportBase.resolved==None).limit(5)
closed_reports = user.reports_filed_on.filter(
ReportBase.discriminator=='archived_report').all()
ReportBase.resolved!=None).all()
privileges = Privilege.query
user_banned = UserBan.query.get(user.id)
ban_form = moderation_forms.BanForm()
@ -108,10 +108,10 @@ def moderation_reports_panel(request):
for key,val in filters.viewitems()]
all_active = ReportBase.query.filter(
ReportBase.discriminator!="archived_report").filter(
ReportBase.resolved==None).filter(
*filters)
all_closed = ReportBase.query.filter(
ReportBase.discriminator=="archived_report").filter(
ReportBase.resolved!=None).filter(
*filters)
# report_list and closed_report_list are the two lists of up to 10

View File

@ -120,13 +120,17 @@ class TestModerationViews:
'targeted_user':self.user.id},
url='/mod/reports/{0}/'.format(comment_report.id))
self.query_for_users()
comment_report = CommentReport.query.filter(
CommentReport.reported_user==self.user).first()
assert response.status == '302 FOUND'
assert not self.user.has_privilege(u'commenter')
assert comment_report.is_archived_report() is True
fixture_add_comment_report(reported_user=self.user)
comment_report = CommentReport.query.filter(
CommentReport.reported_user==self.user).first()
assert not self.user.has_privilege(u'commenter')
# Then, test a moderator sending an email to a user in response to a
# reported comment
#----------------------------------------------------------------------
@ -137,6 +141,9 @@ class TestModerationViews:
'targeted_user':self.user.id},
url='/mod/reports/{0}/'.format(comment_report.id))
self.query_for_users()
comment_report = CommentReport.query.filter(
CommentReport.reported_user==self.user).first()
assert response.status == '302 FOUND'
assert mail.EMAIL_TEST_MBOX_INBOX == [{'to': [u'regular@example.com'],
'message': 'Content-Type: text/plain; charset="utf-8"\n\
@ -144,6 +151,7 @@ MIME-Version: 1.0\nContent-Transfer-Encoding: base64\nSubject: Warning from- \
moderator \nFrom: notice@mediagoblin.example.org\nTo: regular@example.com\n\n\
VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
'from': 'notice@mediagoblin.example.org'}]
assert comment_report.is_archived_report() is True
# Then test a moderator banning a user AND a moderator deleting the
# offending comment. This also serves as a test for taking multiple
@ -157,7 +165,8 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
fixture_add_comment_report(comment=test_comment,
reported_user=self.user)
comment_report = CommentReport.query.filter(
CommentReport.reported_user==self.user).first()
CommentReport.comment==test_comment).filter(
CommentReport.resolved==None).first()
response, context = self.do_post(
{'action_to_resolve':[u'userban', u'delete'],
@ -179,7 +188,8 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
#----------------------------------------------------------------------
fixture_add_comment_report(reported_user=self.admin_user)
comment_report = CommentReport.query.filter(
CommentReport.reported_user==self.admin_user).first()
CommentReport.reported_user==self.admin_user).filter(
CommentReport.resolved==None).first()
response, context = self.do_post({'action_to_resolve':[u'takeaway'],
'take_away_privileges':[u'active'],

View File

@ -20,7 +20,7 @@ from mediagoblin.tools import template
from mediagoblin.tests.tools import (fixture_add_user, fixture_media_entry,
fixture_add_comment, fixture_add_comment_report)
from mediagoblin.db.models import (MediaReport, CommentReport, User,
MediaComment,ArchivedReport)
MediaComment)
class TestReportFiling:
@ -148,11 +148,12 @@ class TestReportFiling:
url='/mod/reports/{0}/'.format(comment_report.id))
assert response.status == "302 FOUND"
self.query_for_users()
allie_user, natalie_user = self.query_for_users()
archived_report = ArchivedReport.query.first()
archived_report = CommentReport.query.filter(
CommentReport.reported_user==allie_user).first()
assert CommentReport.query.count() == 0
assert CommentReport.query.count() != 0
assert archived_report is not None
assert archived_report.report_content == u'Testing Archived Reports #1'
assert archived_report.reporter_id == natalie_id
@ -161,5 +162,5 @@ class TestReportFiling:
assert archived_report.resolved is not None
assert archived_report.result == u'This is a test of archiving reports\
.<br>natalie banned user allie indefinitely.<br>natalie deleted the comment.'
assert archived_report.discriminator == 'archived_report'
assert archived_report.discriminator == 'comment_report'