Skip to content
Permalink
Browse files

[FIX] forum: closing spam/offensive questions should give author karm…

…a penalty

This is a partial patch for issue odoo#3460, pending more
improvements and refinements in master.

Currently the karma penalty is hardcoded to 5*downvote penalty,
which may or may not be sufficient to prevent posting, depending
on the other karma levels.
  • Loading branch information...
odony committed Nov 4, 2014
1 parent fab2e29 commit 879f125e574ad14c868e4d0e8137749638caf88b
Showing with 35 additions and 2 deletions.
  1. +1 −1 addons/website_forum/controllers/main.py
  2. +34 −1 addons/website_forum/models/forum.py
@@ -286,7 +286,7 @@ def question_close(self, forum, question, **post):

@http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/reopen', type='http', auth="user", methods=['POST'], website=True)
def question_reopen(self, forum, question, **kwarg):
request.registry['forum.post'].write(request.cr, request.uid, [question.id], {'state': 'active'}, context=request.context)
request.registry['forum.post'].reopen(request.cr, request.uid, [question.id], context=request.context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))

@http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/delete', type='http', auth="user", methods=['POST'], website=True)
@@ -4,7 +4,9 @@
import uuid
from werkzeug.exceptions import Forbidden

import logging
import openerp

from openerp import api, tools
from openerp import SUPERUSER_ID
from openerp.addons.website.models.website import slug
@@ -13,6 +15,7 @@
from openerp.tools import html2plaintext
from openerp.tools.translate import _

_logger = logging.getLogger(__name__)

class KarmaError(Forbidden):
""" Karma-related error, used for forum and posts. """
@@ -379,10 +382,40 @@ def write(self, cr, uid, ids, vals, context=None):
self.message_post(cr, uid, obj_id, body=body, subtype=subtype, context=context)
return res


def reopen(self, cr, uid, ids, context=None):
if any(post.parent_id or post.state != 'close'
for post in self.browse(cr, uid, ids, context=context)):
return False

reason_offensive = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'website_forum.reason_7')
reason_spam = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'website_forum.reason_8')
for post in self.browse(cr, uid, ids, context=context):
if post.closed_reason_id.id in (reason_offensive, reason_spam):
_logger.info('Upvoting user <%s>, reopening spam/offensive question',
post.create_uid.login)
# TODO: in master, consider making this a tunable karma parameter
self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [post.create_uid.id],
post.forum_id.karma_gen_question_downvote * -5,
context=context)
self.pool['forum.post'].write(cr, SUPERUSER_ID, ids, {'state': 'active'}, context=context)

def close(self, cr, uid, ids, reason_id, context=None):
if any(post.parent_id for post in self.browse(cr, uid, ids, context=context)):
return False
return self.pool['forum.post'].write(cr, uid, ids, {

reason_offensive = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'website_forum.reason_7')
reason_spam = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'website_forum.reason_8')
if reason_id in (reason_offensive, reason_spam):
for post in self.browse(cr, uid, ids, context=context):
_logger.info('Downvoting user <%s> for posting spam/offensive contents',
post.create_uid.login)
# TODO: in master, consider making this a tunable karma parameter
self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [post.create_uid.id],
post.forum_id.karma_gen_question_downvote * 5,
context=context)

self.pool['forum.post'].write(cr, uid, ids, {
'state': 'close',
'closed_uid': uid,
'closed_date': datetime.today().strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT),

0 comments on commit 879f125

Please sign in to comment.
You can’t perform that action at this time.