diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index ea68250b986..08e03d9d6bf 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -298,12 +298,10 @@ class WebsiteForum(http.Controller): cr, uid, context = request.cr, request.uid, request.context if kwargs.get('comment') and post.forum_id.id == forum.id: # TDE FIXME: check that post_id is the question or one of its answers - request.registry['forum.post'].message_post( - cr, uid, post.id, + request.registry['forum.post']._post_comment( + cr, uid, post, body=kwargs.get('comment'), - type='comment', - subtype='mt_comment', - context=dict(context, mail_create_nosubcribe=True)) + context=context) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) @http.route('/forum//post//toggle_correct', type='json', auth="public", website=True) diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index b39298a5921..1bc9b69b37a 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -10,8 +10,9 @@ from openerp.osv import osv, fields from openerp.tools import html2plaintext from openerp.tools.translate import _ +from werkzeug.exceptions import Forbidden -class KarmaError(ValueError): +class KarmaError(Forbidden): """ Karma-related error, used for forum and posts. """ pass @@ -314,11 +315,11 @@ class Post(osv.Model): context = {} create_context = dict(context, mail_create_nolog=True) post_id = super(Post, self).create(cr, uid, vals, context=create_context) - post = self.browse(cr, SUPERUSER_ID, post_id, context=context) # SUPERUSER_ID to avoid read access rights issues when creating + post = self.browse(cr, uid, post_id, context=context) # karma-based access - if post.parent_id and not post.can_ask: + if not post.parent_id and not post.can_ask: raise KarmaError('Not enough karma to create a new question') - elif not post.parent_id and not post.can_answer: + elif post.parent_id and not post.can_answer: raise KarmaError('Not enough karma to answer to a question') # messaging and chatter base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') @@ -508,6 +509,15 @@ class Post(osv.Model): res_id = post.parent_id and "%s#answer-%s" % (post.parent_id.id, post.id) or post.id return "/forum/%s/question/%s" % (post.forum_id.id, res_id) + def _post_comment(self, cr, uid, post, body, context=None): + context = dict(context or {}, mail_create_nosubcribe=True) + if not post.can_comment: + raise KarmaError('Not enough karma to comment') + return self.message_post(cr, uid, post.id, + body=body, + type='comment', + subtype='mt_comment', + context=context) class PostReason(osv.Model): _name = "forum.post.reason" diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 9f1ef5159c2..9fbd27ef793 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -99,7 +99,10 @@
- Ask a Question + Ask a Question

Keep Informed

@@ -325,7 +328,8 @@

- +