aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/moderation
diff options
context:
space:
mode:
authortilly-Q <nattilypigeonfowl@gmail.com>2013-09-03 16:19:07 -0400
committertilly-Q <nattilypigeonfowl@gmail.com>2013-09-03 16:19:07 -0400
commit8e91df87349b91611a4dfcf3f2640cb540307144 (patch)
treecc0a46a95a6411cb3c2dfe84a0ca0733ace0938b /mediagoblin/moderation
parentdc31cd1b658067d25cda470795020d3c377feae0 (diff)
downloadmediagoblin-8e91df87349b91611a4dfcf3f2640cb540307144.tar.lz
mediagoblin-8e91df87349b91611a4dfcf3f2640cb540307144.tar.xz
mediagoblin-8e91df87349b91611a4dfcf3f2640cb540307144.zip
I did some more code-keeping in this commit. I added a lot of documentation, so
that most of my functions do indeed have effective docstrings. I also changed the decorators so that they imply eachother in a logical way. I also modified the one decorator get_media_comment_by_id to be more usable with the variable urls of mediagoblin.user_pages.views:file_a_report. I also noticed a few tests had broken, so I went through them and fixed them up, finding that mostly there were problems in my actual writing of the tests. I also did a few other small tasks such as creating a new User method to check whether or not a User is ban- -ned. =============================================================================== Added in documentation =============================================================================== --\ mediagoblin/db/models.py --\ mediagoblin/decorators.py --\ mediagoblin/moderation/forms.py --\ mediagoblin/moderation/tools.py --\ mediagoblin/moderation/views.py --\ mediagoblin/user_pages/lib.py =============================================================================== Rearranged decorators to be more efficient =============================================================================== --\ mediagoblin/decorators.py --| Made it so that user_not_banned is encapsulated in require_active_login --| Made it so that require_active_login is encapsulated in user_has_privilege --| Changed get_media_comment_by_id into get_optional_media_comment_by_id. It | now returns valid code if the MediaComment id is absent. This makes it pos- | -sible to use this decorator for the function: | mediagoblin.user_pages.views:file_a_report --\ mediagoblin/user_pages/views.py --| Replaced the mediagoblin.user_pages.views:file_a_comment_report with the | decorator mentioned above --\ mediagoblin/user_pages/routing.py ----------------------------------------------------------- | took out unnecessary @user_not_banned decorators | ----------------------------------------------------------- --\ mediagoblin/submit/views.py --\ mediagoblin/user_pages/views.py =============================================================================== Fixed broken tests =============================================================================== --\ mediagoblin/tests/test_auth.py --\ mediagoblin/tests/test_privileges.py --\ mediagoblin/tests/test_submission.py =============================================================================== Fixed broken code =============================================================================== --\ mediagoblin/tools/response.py =============================================================================== Other Tasks =============================================================================== --\ mediagoblin/db/models.py --| Added in User.is_banned() method --\ mediagoblin/decorators.py --| Utitilized User.is_banned() method in the user_not_banned decorator --\ mediagoblin/moderation/views.py --| Made it impossible for an admin to ban themself. --| Got rid of a vestigial print statement --\ mediagoblin/templates/mediagoblin/base.html --| Made it so the top panel does not show up for users that are banned. --\ mediagoblin/templates/mediagoblin/moderation/user.html --| Rearranged the javascript slightly ===============================================================================
Diffstat (limited to 'mediagoblin/moderation')
-rw-r--r--mediagoblin/moderation/forms.py67
-rw-r--r--mediagoblin/moderation/tools.py34
-rw-r--r--mediagoblin/moderation/views.py7
3 files changed, 105 insertions, 3 deletions
diff --git a/mediagoblin/moderation/forms.py b/mediagoblin/moderation/forms.py
index bcb2fc77..7e225fb6 100644
--- a/mediagoblin/moderation/forms.py
+++ b/mediagoblin/moderation/forms.py
@@ -35,10 +35,19 @@ class MultiCheckboxField(wtforms.SelectMultipleField):
option_widget = wtforms.widgets.CheckboxInput()
+# ============ Forms for mediagoblin.moderation.user page ================== #
+
class PrivilegeAddRemoveForm(wtforms.Form):
+ """
+ This form is used by an admin to give/take away a privilege directly from
+ their user page.
+ """
privilege_name = wtforms.HiddenField('',[wtforms.validators.required()])
class BanForm(wtforms.Form):
+ """
+ This form is used by an admin to ban a user directly from their user page.
+ """
user_banned_until = wtforms.DateField(
_(u'User will be banned until:'),
format='%Y-%m-%d',
@@ -47,7 +56,54 @@ class BanForm(wtforms.Form):
_(u'Why are you banning this User?'),
validators=[wtforms.validators.optional()])
+# =========== Forms for mediagoblin.moderation.report page ================= #
+
class ReportResolutionForm(wtforms.Form):
+ """
+ This form carries all the information necessary to take punitive actions
+ against a user who created content that has been reported.
+
+ :param action_to_resolve A list of Unicode objects representing
+ a choice from the ACTION_CHOICES const-
+ -ant. Every choice passed affects what
+ punitive actions will be taken against
+ the user.
+
+ :param targeted_user A HiddenField object that holds the id
+ of the user that was reported.
+
+ :param take_away_privileges A list of Unicode objects which repres-
+ -ent the privileges that are being tak-
+ -en away. This field is optional and
+ only relevant if u'takeaway' is in the
+ `action_to_resolve` list.
+
+ :param user_banned_until A DateField object that holds the date
+ that the user will be unbanned. This
+ field is optional and only relevant if
+ u'userban' is in the action_to_resolve
+ list. If the user is being banned and
+ this field is blank, the user is banned
+ indefinitely.
+
+ :param why_user_was_banned A TextArea object that holds the
+ reason that a user was banned, to disp-
+ -lay to them when they try to log in.
+ This field is optional and only relevant
+ if u'userban' is in the
+ `action_to_resolve` list.
+
+ :param message_to_user A TextArea object that holds a message
+ which will be emailed to the user. This
+ is only relevant if the u'sendmessage'
+ option is in the `action_to_resolve`
+ list.
+
+ :param resolution_content A TextArea object that is required for
+ every report filed. It represents the
+ reasons that the moderator/admin resol-
+ -ved the report in such a way.
+ """
action_to_resolve = MultiCheckboxField(
_(u'What action will you take to resolve the report?'),
validators=[wtforms.validators.optional()],
@@ -67,7 +123,18 @@ class ReportResolutionForm(wtforms.Form):
validators=[wtforms.validators.optional()])
resolution_content = wtforms.TextAreaField()
+# ======== Forms for mediagoblin.moderation.report_panel page ============== #
+
class ReportPanelSortingForm(wtforms.Form):
+ """
+ This form is used for sorting and filtering through different reports in
+ the mediagoblin.moderation.reports_panel view.
+
+ Parameters that start with 'active_' refer to a sort/filter for the active
+ reports.
+ Parameters that start with 'closed_' refer to a sort/filter for the closed
+ reports.
+ """
active_p = wtforms.IntegerField(
_(u'Page'),
validators=[wtforms.validators.optional()])
diff --git a/mediagoblin/moderation/tools.py b/mediagoblin/moderation/tools.py
index 79a6e3f5..355ffa99 100644
--- a/mediagoblin/moderation/tools.py
+++ b/mediagoblin/moderation/tools.py
@@ -131,6 +131,23 @@ def take_punitive_actions(request, form, report, user):
report_id=report.id)
def take_away_privileges(user,*privileges):
+ """
+ Take away all of the privileges passed as arguments.
+
+ :param user A Unicode object representing the target user's
+ User.username value.
+
+ :param privileges A variable number of Unicode objects describing
+ the privileges being taken away.
+
+
+ :returns True If ALL of the privileges were taken away
+ successfully.
+
+ :returns False If ANY of the privileges were not taken away
+ successfully. This means the user did not have
+ (one of) the privilege(s) to begin with.
+ """
if len(privileges) == 1:
privilege = Privilege.query.filter(
Privilege.privilege_name==privileges[0]).first()
@@ -146,6 +163,23 @@ def take_away_privileges(user,*privileges):
take_away_privileges(user, *privileges[1:]))
def give_privileges(user,*privileges):
+ """
+ Take away all of the privileges passed as arguments.
+
+ :param user A Unicode object representing the target user's
+ User.username value.
+
+ :param privileges A variable number of Unicode objects describing
+ the privileges being granted.
+
+
+ :returns True If ALL of the privileges were granted successf-
+ -ully.
+
+ :returns False If ANY of the privileges were not granted succ-
+ essfully. This means the user already had (one
+ of) the privilege(s) to begin with.
+ """
if len(privileges) == 1:
privilege = Privilege.query.filter(
Privilege.privilege_name==privileges[0]).first()
diff --git a/mediagoblin/moderation/views.py b/mediagoblin/moderation/views.py
index 35c586ea..f09f4c99 100644
--- a/mediagoblin/moderation/views.py
+++ b/mediagoblin/moderation/views.py
@@ -169,7 +169,8 @@ def moderation_reports_detail(request):
@active_user_from_url
def give_or_take_away_privilege(request, url_user):
'''
- A form action to give or take away a particular privilege from a user
+ A form action to give or take away a particular privilege from a user.
+ Can only be used by an admin.
'''
form = moderation_forms.PrivilegeAddRemoveForm(request.form)
if request.method == "POST" and form.validate():
@@ -193,10 +194,10 @@ def ban_or_unban(request, url_user):
A page to ban or unban a user. Only can be used by an admin.
"""
form = moderation_forms.BanForm(request.form)
- print "accessed page"
if request.method == "POST" and form.validate():
already_banned = unban_user(url_user.id)
- if not already_banned:
+ same_as_requesting_user = (request.user.id == url_user.id)
+ if not already_banned and not same_as_requesting_user:
user_ban = ban_user(url_user.id,
expiration_date = form.user_banned_until.data,
reason = form.why_user_was_banned.data)