aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/moderation/tools.py
diff options
context:
space:
mode:
authortilly-Q <nattilypigeonfowl@gmail.com>2013-09-23 13:20:18 -0400
committertilly-Q <nattilypigeonfowl@gmail.com>2013-09-23 13:20:18 -0400
commit6483b37060062ef7c7d40d9ae712c99a7e73775a (patch)
treed35aaad7910526f2e32768b5e2614435533637e3 /mediagoblin/moderation/tools.py
parent045fe0ee9d43aa825de6fbf14fe8fd48953d4eff (diff)
downloadmediagoblin-6483b37060062ef7c7d40d9ae712c99a7e73775a.tar.lz
mediagoblin-6483b37060062ef7c7d40d9ae712c99a7e73775a.tar.xz
mediagoblin-6483b37060062ef7c7d40d9ae712c99a7e73775a.zip
At this point, I am very close to done with this code! I made one big change at
paroneayea's request, which was to make to possible to turn off user's ability to file reports through a mediagoblin.ini setting. Aside from this, I had to make it possible for the Moderation User Panel to display more than 10 users. And aside from that, I just had to fix some errors which cropped up with my most recent additions. I also fixed some tests that were broken because I had changed the checks for whether or not a user is active. Nearing the end! =============================================================================== Made it possible to turn off reports through a mediagoblin.ini setting =============================================================================== --\ mediagoblin.ini --\ mediagoblin/config_spec.ini --\ mediagoblin/decorators.py --\ mediagoblin/moderation/views.py --\ mediagoblin/templates/mediagoblin/user_pages/media.html --\ mediagoblin/user_pages/views.py =============================================================================== Made User Panel capable of showing more than 1 page of users =============================================================================== --\ mediagoblin/moderation/forms.py --\ mediagoblin/moderation/views.py --\ mediagoblin/templates/mediagoblin/moderation/user_panel.html =============================================================================== Fixed Broken Tests =============================================================================== --\ mediagoblin/tests/test_notifications.py --\ mediagoblin/tests/test_openid.py --\ mediagoblin/tests/test_persona.py --\ mediagoblin/tests/test_reporting.py =============================================================================== Fixed errors in code =============================================================================== --\ mediagoblin/db/migrations.py --| Set nullable to True for MediaReports' and CommentReports' content foreign |keys --\ mediagoblin/db/models.py --| Got rid of cascading rules for MediaReports' and CommentReports' content |foreign keys. This makes it possible for the Reports to continue to exist |after the content is deleted. --\ mediagoblin/moderation/tools.py --| Fixed formatting of Report Resolution Methods --| Took out pieces of code used in debugging --\ mediagoblin/templates/mediagoblin/base.html --\ mediagoblin/templates/mediagoblin/moderation/report.html --| Made reports details page able to tell what is a deleted archived report. --\ mediagoblin/templates/mediagoblin/moderation/report_panel.html --\ mediagoblin/templates/mediagoblin/utils/report.html
Diffstat (limited to 'mediagoblin/moderation/tools.py')
-rw-r--r--mediagoblin/moderation/tools.py149
1 files changed, 69 insertions, 80 deletions
diff --git a/mediagoblin/moderation/tools.py b/mediagoblin/moderation/tools.py
index 109f3d8f..224a0c73 100644
--- a/mediagoblin/moderation/tools.py
+++ b/mediagoblin/moderation/tools.py
@@ -25,90 +25,79 @@ import sys, traceback
def take_punitive_actions(request, form, report, user):
message_body =''
- try:
-
- # The bulk of this action is running through all of the different
- # punitive actions that a moderator could take.
- if u'takeaway' in form.action_to_resolve.data:
- for privilege_name in form.take_away_privileges.data:
- take_away_privileges(user.username, privilege_name)
- form.resolution_content.data += \
- u"\n{mod} took away {user}\'{privilege} privileges.".format(
- mod=request.user.username,
- user=user.username,
- privilege=privilege_name)
-
- # If the moderator elects to ban the user, a new instance of user_ban
- # will be created.
- if u'userban' in form.action_to_resolve.data:
- user_ban = ban_user(form.targeted_user.data,
- expiration_date=form.user_banned_until.data,
- reason=form.why_user_was_banned.data)
- Session.add(user_ban)
+
+ # The bulk of this action is running through all of the different
+ # punitive actions that a moderator could take.
+ if u'takeaway' in form.action_to_resolve.data:
+ for privilege_name in form.take_away_privileges.data:
+ take_away_privileges(user.username, privilege_name)
form.resolution_content.data += \
- u"\n{mod} banned user {user} until {expiration_date}.".format(
+ u"\n{mod} took away {user}\'{privilege} privileges.".format(
mod=request.user.username,
user=user.username,
- expiration_date = (
- "until {date}".format(date=form.user_banned_until.data)
- if form.user_banned_until.data
- else "indefinitely"
- )
- )
-
- # If the moderator elects to send a warning message. An email will be
- # sent to the email address given at sign up
- if u'sendmessage' in form.action_to_resolve.data:
- message_body = form.message_to_user.data
+ privilege=privilege_name)
+
+ # If the moderator elects to ban the user, a new instance of user_ban
+ # will be created.
+ if u'userban' in form.action_to_resolve.data:
+ user_ban = ban_user(form.targeted_user.data,
+ expiration_date=form.user_banned_until.data,
+ reason=form.why_user_was_banned.data)
+ Session.add(user_ban)
+ form.resolution_content.data += \
+ u"\n{mod} banned user {user} {expiration_date}.".format(
+ mod=request.user.username,
+ user=user.username,
+ expiration_date = (
+ "until {date}".format(date=form.user_banned_until.data)
+ if form.user_banned_until.data
+ else "indefinitely"
+ )
+ )
+
+ # If the moderator elects to send a warning message. An email will be
+ # sent to the email address given at sign up
+ if u'sendmessage' in form.action_to_resolve.data:
+ message_body = form.message_to_user.data
+ form.resolution_content.data += \
+ u"\n{mod} sent a warning email to the {user}.".format(
+ mod=request.user.username,
+ user=user.username)
+
+ if u'delete' in form.action_to_resolve.data and \
+ report.is_comment_report():
+ deleted_comment = report.comment
+ Session.delete(deleted_comment)
form.resolution_content.data += \
- u"\n{mod} sent a warning email to the {user}.".format(
- mod=request.user.username,
- user=user.username)
-
- if u'delete' in form.action_to_resolve.data and \
- report.is_comment_report():
- deleted_comment = report.comment
- Session.delete(deleted_comment)
- form.resolution_content.data += \
- u"\n{mod} deleted the comment.".format(
- mod=request.user.username)
- elif u'delete' in form.action_to_resolve.data and \
- report.is_media_entry_report():
- deleted_media = report.media_entry
- Session.delete(deleted_media)
- form.resolution_content.data += \
- u"\n{mod} deleted the media entry.".format(
- mod=request.user.username)
- 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(
- mg_globals.app_config['email_sender_address'],
- [user.email],
- _('Warning from')+ '- {moderator} '.format(
- moderator=request.user.username),
- message_body)
-
- return redirect(
- request,
- 'mediagoblin.moderation.users_detail',
- user=user.username)
- except:
-#TODO make a more effective and specific try except statement. To account for
-# incorrect value addition my moderators
- print sys.exc_info()[0]
- print sys.exc_info()[1]
- traceback.print_tb(sys.exc_info()[2])
- Session.rollback()
- return redirect(
- request,
- 'mediagoblin.moderation.reports_detail',
- report_id=report.id)
+ u"\n{mod} deleted the comment.".format(
+ mod=request.user.username)
+ elif u'delete' in form.action_to_resolve.data and \
+ report.is_media_entry_report():
+ deleted_media = report.media_entry
+ Session.delete(deleted_media)
+ form.resolution_content.data += \
+ u"\n{mod} deleted the media entry.".format(
+ mod=request.user.username)
+ 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(
+ mg_globals.app_config['email_sender_address'],
+ [user.email],
+ _('Warning from')+ '- {moderator} '.format(
+ moderator=request.user.username),
+ message_body)
+
+ return redirect(
+ request,
+ 'mediagoblin.moderation.users_detail',
+ user=user.username)
+
def take_away_privileges(user,*privileges):
"""