diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 7295b6623bc..6f9a0c601d5 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -534,24 +534,27 @@ class website_forum(http.Controller): }, context=context) return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id'))) - @http.route('/forum/correct_answer/', type='json', auth="user", multilang=True, methods=['POST'], website=True) + @http.route('/forum/correct_answer/', type='json', auth="public", multilang=True, methods=['POST'], website=True) def correct_answer(self, **kwarg): cr, uid, context = request.cr, request.uid, request.context + if not request.session.uid: + return {'error': 'anonymous_user'} + Post = request.registry['website.forum.post'] post = Post.browse(cr, uid, int(kwarg.get('post_id')), context=context) user = request.registry['res.users'].browse(cr, uid, uid, context=None) - if post.user_id.id == uid or user.karma >= 500: - correct = False if post.correct else True - #Note: only one answer can be right. - for child in post.parent_id.child_ids: - if child.correct and child.id != post.id: - Post.write( cr, uid, [child.id], { - 'correct': False, - }, context=context) - Post.write( cr, uid, [post.id, post.parent_id.id], { - 'correct': correct, - }, context=context) - return correct + + #if user have not access to accept answer then reise warning + if not (post.parent_id.user_id.id == uid or user.karma >= 500): + return {'error': 'user'} + + #Note: only one answer can be right. + correct = False if post.correct else True + for child in post.parent_id.child_ids: + if child.correct and child.id != post.id: + Post.write( cr, uid, [child.id], { 'correct': False }, context=context) + Post.write( cr, uid, [post.id, post.parent_id.id], { 'correct': correct }, context=context) + return correct @http.route('/forum//close/question/', type='http', auth="user", multilang=True, website=True) def close_question(self, forum, post, **kwarg): diff --git a/addons/website_forum/data/forum_demo.xml b/addons/website_forum/data/forum_demo.xml index a0370cbcefa..7431b26c6fa 100644 --- a/addons/website_forum/data/forum_demo.xml +++ b/addons/website_forum/data/forum_demo.xml @@ -282,7 +282,7 @@ Thank you in advance True - + @@ -356,7 +356,7 @@ Thank you in advance True - + diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 2bec9b91acd..bbcf64ad6c7 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -239,10 +239,6 @@ class Post(osv.Model): user = self.pool['res.users'].browse(cr, uid ,uid, context=context) self.create_history(cr, uid, ids, context=context) for post in self.browse(cr, uid, ids, context=context): - #just for precaution - if user.karma < 300 and post.user_id != uid: - raise osv.except_osv(_('Error!'), _('You are not allowed to edit this post!')) - body, subtype = "Edited question", "website_forum.mt_question_edit" if post.parent_id: body, subtype = "Edited answer", "website_forum.mt_answer_edit" diff --git a/addons/website_forum/static/src/css/website_forum.css b/addons/website_forum/static/src/css/website_forum.css index 8647adaded1..b4c6e2315ac 100644 --- a/addons/website_forum/static/src/css/website_forum.css +++ b/addons/website_forum/static/src/css/website_forum.css @@ -59,4 +59,8 @@ .load_tags{ width: 845px !important; +} + +.fa-thumbs-up, .fa-thumbs-down, .oe_answer_true, .oe_answer_false { + cursor:pointer; } \ No newline at end of file diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 591d2d24b69..2f950b58c23 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -64,15 +64,30 @@ $(document).ready(function () { ev.preventDefault(); var $link = $(ev.currentTarget); openerp.jsonRpc("/forum/correct_answer/", 'call', { - 'post_id': $link.attr("id")}) - .then(function (data) { - par = $link.parents().find(".oe_answer_true") - $link.parents().find(".oe_answer_true").removeClass("oe_answer_true").addClass('oe_answer_false') - if (data) { + 'post_id': $link.attr("id")}) + .then(function (data) { + if (data['error']) { + if (data['error'] == 'anonymous_user'){ + var $warning = $('
'+ + ''+ + 'Sorry, anonymous users cannot choose correct answer.'+ + '
'); + } else if (data['error'] == 'user'){ + var $warning = $('
'+ + ''+ + 'Sorry, You cannot choose correct answer.'+ + '
'); + } + correct_answer_alert = $link.parent().find("#correct_answer_alert"); + if (correct_answer_alert.length == 0) { + $link.parent().append($warning); + } + } else { + $link.parents().find(".oe_answer_true").removeClass("oe_answer_true").addClass('oe_answer_false'); $link.removeClass("oe_answer_false").addClass('oe_answer_true'); - } - }); - return false; + } + }); + return true; }); $('.comment_delete').on('click', function (ev) { diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 78265c5d8a9..f9f9a5d5995 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -448,8 +448,8 @@
  • share
  • - + Asked on
    @@ -505,8 +505,8 @@
  • share
  • - + Answered on