[FIX] website_forum: hide questions coming from abusive users
When a user's karma is driven to a negative value due to repeated abuse or the posting of spam, automatically hide all their posts from public view. This will reduce the effectiveness of their abuse, and simplify moderation and cleanup.
This commit is contained in:
parent
13476c844d
commit
64da3c5e17
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import werkzeug.exceptions
|
||||
import werkzeug.urls
|
||||
import werkzeug.wrappers
|
||||
import simplejson
|
||||
|
@ -239,6 +240,11 @@ class WebsiteForum(http.Controller):
|
|||
@http.route(['''/forum/<model("forum.forum"):forum>/question/<model("forum.post", "[('forum_id','=',forum[0]),('parent_id','=',False)]"):question>'''], type='http', auth="public", website=True)
|
||||
def question(self, forum, question, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
||||
# Hide posts from abusers (negative karma), except for moderators
|
||||
if not question.can_view:
|
||||
raise werkzeug.exceptions.NotFound()
|
||||
|
||||
# increment view counter
|
||||
request.registry['forum.post'].set_viewed(cr, SUPERUSER_ID, [question.id], context=context)
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ class Post(osv.Model):
|
|||
def _get_post_karma_rights(self, cr, uid, ids, field_name, arg, context=None):
|
||||
user = self.pool['res.users'].browse(cr, uid, uid, context=context)
|
||||
res = dict.fromkeys(ids, False)
|
||||
for post in self.browse(cr, uid, ids, context=context):
|
||||
for post in self.browse(cr, SUPERUSER_ID, ids, context=context):
|
||||
res[post.id] = {
|
||||
'karma_ask': post.forum_id.karma_ask,
|
||||
'karma_answer': post.forum_id.karma_answer,
|
||||
|
@ -246,6 +246,9 @@ class Post(osv.Model):
|
|||
'can_downvote': uid == SUPERUSER_ID or user.karma >= res[post.id]['karma_downvote'],
|
||||
'can_comment': uid == SUPERUSER_ID or user.karma >= res[post.id]['karma_comment'],
|
||||
'can_comment_convert': uid == SUPERUSER_ID or user.karma >= res[post.id]['karma_comment_convert'],
|
||||
'can_view': (uid == SUPERUSER_ID or
|
||||
user.karma >= res[post.id]['karma_close'] or
|
||||
post.create_uid.karma > 0),
|
||||
})
|
||||
return res
|
||||
|
||||
|
@ -335,6 +338,7 @@ class Post(osv.Model):
|
|||
'can_downvote': fields.function(_get_post_karma_rights, string='Can Downvote', type='boolean', multi='_get_post_karma_rights'),
|
||||
'can_comment': fields.function(_get_post_karma_rights, string='Can Comment', type='boolean', multi='_get_post_karma_rights'),
|
||||
'can_comment_convert': fields.function(_get_post_karma_rights, string='Can Convert to Comment', type='boolean', multi='_get_post_karma_rights'),
|
||||
'can_view': fields.function(_get_post_karma_rights, string='Can View', type='boolean', multi='_get_post_karma_rights'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
|
Loading…
Reference in New Issue