1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from mediagoblin
import mg_globals
18 from mediagoblin
.db
.models
import User
, Privilege
, ArchivedReport
, UserBan
19 from mediagoblin
.db
.base
import Session
20 from mediagoblin
.tools
.mail
import send_email
21 from mediagoblin
.tools
.response
import redirect
22 from datetime
import datetime
23 from mediagoblin
.tools
.translate
import lazy_pass_to_ugettext
as _
26 def take_punitive_actions(request
, form
, report
, user
):
30 # The bulk of this action is running through all of the different
31 # punitive actions that a moderator could take.
32 if u
'takeaway' in form
.action_to_resolve
.data
:
33 for privilege_name
in form
.take_away_privileges
.data
:
34 privilege
= Privilege
.one({u
'privilege_name':privilege_name
})
35 form
.resolution_content
.data
+= \
36 u
"<br>%s took away %s\'s %s privileges" % (
37 request
.user
.username
,
39 privilege
.privilege_name
)
40 user
.all_privileges
.remove(privilege
)
42 # If the moderator elects to ban the user, a new instance of user_ban
44 if u
'userban' in form
.action_to_resolve
.data
:
45 reason
= form
.resolution_content
.data
+ \
46 "<br>"+request
.user
.username
48 user_id
=form
.targeted_user
.data
,
49 expiration_date
=form
.user_banned_until
.data
,
50 reason
= form
.why_user_was_banned
.data
54 if form
.user_banned_until
.data
is not None:
55 form
.resolution_content
.data
+= \
56 u
"<br>%s banned user %s until %s." % (
57 request
.user
.username
,
59 form
.user_banned_until
.data
)
61 form
.resolution_content
.data
+= \
62 u
"<br>%s banned user %s indefinitely." % (
63 request
.user
.username
,
66 # If the moderator elects to send a warning message. An email will be
67 # sent to the email address given at sign up
68 if u
'sendmessage' in form
.action_to_resolve
.data
:
69 message_body
= form
.message_to_user
.data
70 form
.resolution_content
.data
+= \
71 u
"<br>%s sent a warning email to the offender." % (
72 request
.user
.username
)
74 archive
= ArchivedReport(
75 reporter_id
=report
.reporter_id
,
76 report_content
=report
.report_content
,
77 reported_user_id
=report
.reported_user_id
,
78 created
=report
.created
,
79 resolved
=datetime
.now(),
80 resolver_id
=request
.user
.id
83 if u
'delete' in form
.action_to_resolve
.data
and \
84 report
.is_comment_report():
85 deleted_comment
= report
.comment
86 Session
.delete(deleted_comment
)
87 form
.resolution_content
.data
+= \
88 u
"<br>%s deleted the comment" % (
89 request
.user
.username
)
90 elif u
'delete' in form
.action_to_resolve
.data
and \
91 report
.is_media_entry_report():
92 deleted_media
= report
.media_entry
93 Session
.delete(deleted_media
)
94 form
.resolution_content
.data
+= \
95 u
"<br>%s deleted the media entry" % (
96 request
.user
.username
)
98 # If the moderator didn't delete the content we then attach the
99 # content to the archived report. We also have to actively delete the
100 # old report, since it won't be deleted by cascading.
101 elif report
.is_comment_report():
102 archive
.comment_id
= report
.comment_id
103 Session
.delete(report
)
104 elif report
.is_media_entry_report():
105 archive
.media_entry_id
= report
.media_entry
.id
106 Session
.delete(report
)
109 archive
.result
=form
.resolution_content
.data
114 mg_globals
.app_config
['email_sender_address'],
116 _('Warning from')+ '- {moderator} '.format(
117 moderator
=request
.user
.username
),
122 'mediagoblin.moderation.users_detail',
125 #TODO make a more effective and specific try except statement. To account for
126 # incorrect value addition my moderators
127 print sys
.exc_info()[0]
128 print sys
.exc_info()[1]
129 traceback
.print_tb(sys
.exc_info()[2])
133 'mediagoblin.moderation.reports_detail',