Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Merge pull request #558 from xrpd/require-min-karma-to-vote
Browse files Browse the repository at this point in the history
require a minimum user karma to upvote and downvote
  • Loading branch information
cdaloisio committed Feb 18, 2016
2 parents b1384c0 + cffef07 commit b470c5f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ about_post_id = 1
issues_post_id = 5

karma_to_post = 40
karma_to_vote = 10
discussion_karma_to_post = 5
post_karma_multiplier = 10
karma_to_vote = 0
karma_to_vote_on_polls = 0
karma_to_vote_in_overview = 1000
karma_percentage_to_be_voted = 80
downvoted_reply_score_threshold = -3
Expand Down
3 changes: 2 additions & 1 deletion r2/example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ about_post_id = 1
issues_post_id = 2

karma_to_post = 40
karma_to_vote = 10
post_karma_multiplier = 10
karma_to_vote = 20
karma_to_vote_on_polls = 20
# Karma required for a user vote on another user's overview page
karma_to_vote_in_overview = 1000
# User's with karma above can vote on another user's overview page if that user
Expand Down
4 changes: 2 additions & 2 deletions r2/r2/controllers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,9 @@ def POST_submitballot(self, res, comment, anonymous):
if not comment:
return

if c.user.safe_karma < g.karma_to_vote:
if c.user.safe_karma < g.karma_to_vote_on_polls:
res._set_error(errors.BAD_POLL_BALLOT, comment._fullname,
'You do not have the required {0} karma to vote'.format(g.karma_to_vote))
'You do not have the required {0} karma to vote'.format(g.karma_to_vote_on_polls))
return

any_submitted = False
Expand Down
3 changes: 2 additions & 1 deletion r2/r2/lib/app_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ class Globals(object):
'max_sr_images',
'karma_to_post',
'discussion_karma_to_post',
'karma_to_vote',
'karma_to_vote_on_polls',
'karma_to_vote_in_overview',
'karma_percentage_to_be_voted',
'meetup_grace_period',
'poll_max_choices',
'downvoted_reply_score_threshold',
'downvoted_reply_karma_cost',
'karma_to_vote',
'hide_comment_threshold',
'side_meetups_max_age',
'side_comments_max_age',
Expand Down
14 changes: 11 additions & 3 deletions r2/r2/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,11 @@ def clicked():
# Don't allow users to vote on their own posts and don't
# allow users to vote on collapsed posts shown when
# viewing comment permalinks.
item.votable = bool(c.user != item.author and
not getattr(item, 'for_comment_permalink', False))
# Also require user karma to be >= global threshold as anti-sockpuppet measure
item.votable = bool(c.user_is_loggedin
and c.user != item.author
and not getattr(item, 'for_comment_permalink', False)
and c.user.safe_karma >= g.karma_to_vote)

if c.user_is_loggedin and item.author._id == c.user._id:
item.nofollow = False
Expand Down Expand Up @@ -1185,7 +1188,12 @@ def add_props(cls, user, wrapped):
item.can_reply = (item.sr_id in can_reply_srs)

# Don't allow users to vote on their own comments
item.votable = bool(c.user != item.author and not item.retracted)
# Also require user karma to be >= global threshold as anti-sockpuppet measure
item.votable = bool(c.user_is_loggedin
and c.user != item.author
and not item.retracted
and c.user.safe_karma >= g.karma_to_vote)

if item.votable and c.profilepage:
# Can only vote on profile page under certain conditions
item.votable = bool((c.user.safe_karma > g.karma_to_vote_in_overview) and (g.karma_percentage_to_be_voted > item.author.percent_up()))
Expand Down
3 changes: 2 additions & 1 deletion r2/test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ about_post_id = 1
issues_post_id = 2

karma_to_post = 40
karma_to_vote = 10
post_karma_multiplier = 10
discussion_karma_to_post = 0
karma_to_vote = 20
karma_to_vote_on_polls = 20
poll_max_choices = 20

downvoted_reply_score_threshold = -4
Expand Down

0 comments on commit b470c5f

Please sign in to comment.