From e0ec4271f301762cad2e0638e4318c06efd51fa1 Mon Sep 17 00:00:00 2001 From: "Turkesh Patel (Open ERP)" Date: Fri, 21 Mar 2014 12:08:55 +0530 Subject: [PATCH] [IMP] don't allow user to post on hos own post. bzr revid: tpa@tinyerp.com-20140321063855-ok26jsyyhza7x3ff --- addons/website_forum/models/website_forum.py | 8 ++++-- .../static/src/js/website_forum.editor.js | 28 +++++++++++++------ addons/website_forum/views/website_forum.xml | 4 +-- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/addons/website_forum/models/website_forum.py b/addons/website_forum/models/website_forum.py index 683eb0902d7..ed25cbb42b1 100644 --- a/addons/website_forum/models/website_forum.py +++ b/addons/website_forum/models/website_forum.py @@ -290,7 +290,10 @@ class Vote(osv.Model): def vote(self, cr, uid, post_id, vote, context=None): assert int(vote) in (1, -1, 0), "vote can be -1 or 1, nothing else" - Post = self.pool.get('website.forum.post') + #user can not vote on own post. + post = self.pool['website.forum.post'].browse(cr, uid, post_id, context=context) + if post.user_id.id == uid: + return False vote_ids = self.search(cr, uid, [('post_id', '=', post_id), ('user_id','=',uid)], context=context) if vote_ids: #when user will click again on vote it should set it 0. @@ -310,7 +313,8 @@ class Vote(osv.Model): 'post_id': post_id, 'vote': vote, }, context=context) - return Post.browse(cr, uid, post_id, context=context).vote_count + post.refresh() + return {'vote_count': post.vote_count} class Badge(osv.Model): _inherit = 'gamification.badge' diff --git a/addons/website_forum/static/src/js/website_forum.editor.js b/addons/website_forum/static/src/js/website_forum.editor.js index 6574f74255a..485cf6f41ef 100644 --- a/addons/website_forum/static/src/js/website_forum.editor.js +++ b/addons/website_forum/static/src/js/website_forum.editor.js @@ -30,7 +30,6 @@ }); })(); - $(document).ready(function () { $('.fa-thumbs-up ,.fa-thumbs-down').on('click', function (ev) { @@ -41,19 +40,30 @@ $(document).ready(function () { 'post_id': $link.attr("id"), 'vote': value}) .then(function (data) { - $link.parent().find("#vote_count").html(data); - if (data == 0) { - $link.parent().find(".text-success").removeClass("text-success"); - $link.parent().find(".text-warning").removeClass("text-warning"); + if (data == false){ + vote_alert = $link.parents().find("#vote_alert"); + if (vote_alert.length <= 1) { + var $warning = $('
'+ + ''+ + 'Sorry, you cannot vote for your own posts'+ + '
'); + $link.parents().find("#post_vote").append($warning); + } } else { - if (value == 1) { - $link.addClass("text-success"); + $link.parent().find("#vote_count").html(data['vote_count']); + if (data == 0) { + $link.parent().find(".text-success").removeClass("text-success"); + $link.parent().find(".text-warning").removeClass("text-warning"); } else { - $link.addClass("text-warning"); + if (value == 1) { + $link.addClass("text-success"); + } else { + $link.addClass("text-warning"); + } } } }); - return false; + return true; }); $('.delete').on('click', function (ev) { diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 6916a4c9d5b..d1507d7722f 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -310,7 +310,7 @@