[FIX] forum: closing spam/offensive questions should give author karma penalty
This is a partial patch for issue #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.
This commit is contained in:
parent
d6cfd8ed4b
commit
6c55dab261
|
@ -286,7 +286,7 @@ class WebsiteForum(http.Controller):
|
|||
|
||||
@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 @@ from datetime import datetime
|
|||
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.osv import osv, fields
|
|||
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 @@ class Post(osv.Model):
|
|||
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),
|
||||
|
|
Loading…
Reference in New Issue