[IMP] don't allow user to post on hos own post.

bzr revid: tpa@tinyerp.com-20140321063855-ok26jsyyhza7x3ff
This commit is contained in:
Turkesh Patel (Open ERP) 2014-03-21 12:08:55 +05:30
parent 141eecfa4c
commit e0ec4271f3
3 changed files with 27 additions and 13 deletions

View File

@ -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'

View File

@ -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 = $('<div class="alert alert-danger alert-dismissable" id="vote_alert" style="position: fixed; margin-top: -75px;">'+
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">&times;</button>'+
'Sorry, you cannot vote for your own posts'+
'</div>');
$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) {

View File

@ -310,7 +310,7 @@
<t t-call="website_forum.header">
<div class="question">
<div class="text-center pull-left">
<div class="text-center pull-left" id="post_vote">
<div t-attf-class="box oe_grey">
<a t-attf-class="fa fa-thumbs-up #{question.user_vote == 1 and 'text-success' or ''}"
t-attf-id="#{question.id}" t-attf-value="1"/>
@ -364,7 +364,7 @@
<div t-foreach="question.child_ids" t-as="answer" class="mt16 mb32" id="answer">
<a t-attf-id="answer-#{str(answer.id)}"/>
<div class="text-center pull-left">
<div class="text-center pull-left" id="post_vote">
<div t-attf-class="box oe_grey">
<a t-attf-class="fa fa-thumbs-up #{answer.user_vote == 1 and 'text-success' or ''}"
t-attf-id="#{answer.id}" t-attf-value="1"/>