set maximum time during which comments and stories can be downvoted
always allow a user to "unvote" if they're previously downvoted, but after a certain number of days, don't accept new downvotes there isn't really any benefit in downvoting old stuff that is already off the front pages or on a dead comment thread, other than to maliciously strip karma for particular users
This commit is contained in:
parent
20c870b78b
commit
67fc2cc75c
|
@ -150,7 +150,7 @@ class CommentsController < ApplicationController
|
||||||
return render :text => "invalid reason", :status => 400
|
return render :text => "invalid reason", :status => 400
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@user.can_downvote?
|
if !@user.can_downvote?(comment)
|
||||||
return render :text => "not permitted to downvote", :status => 400
|
return render :text => "not permitted to downvote", :status => 400
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -260,6 +260,12 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_comment
|
def find_comment
|
||||||
Comment.where(:short_id => params[:id]).first
|
comment = Comment.where(:short_id => params[:id]).first
|
||||||
|
if @user && comment
|
||||||
|
comment.current_vote = Vote.where(:user_id => @user.id,
|
||||||
|
:story_id => comment.story_id, :comment_id => comment.id).first
|
||||||
|
end
|
||||||
|
|
||||||
|
comment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -213,7 +213,7 @@ class StoriesController < ApplicationController
|
||||||
return render :text => "invalid reason", :status => 400
|
return render :text => "invalid reason", :status => 400
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@user.can_downvote?
|
if !@user.can_downvote?(story)
|
||||||
return render :text => "not permitted to downvote", :status => 400
|
return render :text => "not permitted to downvote", :status => 400
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -239,7 +239,13 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_story
|
def find_story
|
||||||
Story.where(:short_id => params[:story_id]).first
|
story = Story.where(:short_id => params[:story_id]).first
|
||||||
|
if @user && story
|
||||||
|
story.vote = Vote.where(:user_id => @user.id,
|
||||||
|
:story_id => story.id, :comment_id => nil).first.try(:vote)
|
||||||
|
end
|
||||||
|
|
||||||
|
story
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_user_story
|
def find_user_story
|
||||||
|
|
|
@ -20,6 +20,9 @@ class Comment < ActiveRecord::Base
|
||||||
:deliver_mention_notifications, :log_to_countinual
|
:deliver_mention_notifications, :log_to_countinual
|
||||||
after_destroy :unassign_votes
|
after_destroy :unassign_votes
|
||||||
|
|
||||||
|
DOWNVOTABLE_DAYS = 7
|
||||||
|
|
||||||
|
# after this many minutes old, a comment cannot be edited
|
||||||
MAX_EDIT_MINS = 90
|
MAX_EDIT_MINS = 90
|
||||||
|
|
||||||
validate do
|
validate do
|
||||||
|
@ -278,6 +281,14 @@ class Comment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_downvotable?
|
||||||
|
if self.created_at
|
||||||
|
Time.now - self.created_at <= DOWNVOTABLE_DAYS.days
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def is_editable_by_user?(user)
|
def is_editable_by_user?(user)
|
||||||
if user && user.id == self.user_id
|
if user && user.id == self.user_id
|
||||||
if self.is_moderated?
|
if self.is_moderated?
|
||||||
|
|
|
@ -10,10 +10,12 @@ class Story < ActiveRecord::Base
|
||||||
validates_length_of :description, :maximum => (64 * 1024)
|
validates_length_of :description, :maximum => (64 * 1024)
|
||||||
validates_presence_of :user_id
|
validates_presence_of :user_id
|
||||||
|
|
||||||
|
DOWNVOTABLE_DAYS = 14
|
||||||
|
|
||||||
# after this many minutes old, a story cannot be edited
|
# after this many minutes old, a story cannot be edited
|
||||||
MAX_EDIT_MINS = 30
|
MAX_EDIT_MINS = 30
|
||||||
|
|
||||||
# days a story is considered recent
|
# days a story is considered recent, for resubmitting
|
||||||
RECENT_DAYS = 30
|
RECENT_DAYS = 30
|
||||||
|
|
||||||
attr_accessor :vote, :already_posted_story, :fetched_content, :previewing,
|
attr_accessor :vote, :already_posted_story, :fetched_content, :previewing,
|
||||||
|
@ -220,6 +222,14 @@ class Story < ActiveRecord::Base
|
||||||
"hotness = '#{self.calculated_hotness}' WHERE id = #{self.id.to_i}")
|
"hotness = '#{self.calculated_hotness}' WHERE id = #{self.id.to_i}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_downvotable?
|
||||||
|
if self.created_at
|
||||||
|
Time.now - self.created_at <= DOWNVOTABLE_DAYS.days
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def is_editable_by_user?(user)
|
def is_editable_by_user?(user)
|
||||||
if user && user.is_moderator?
|
if user && user.is_moderator?
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -98,9 +98,26 @@ class User < ActiveRecord::Base
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_downvote?
|
def can_downvote?(obj)
|
||||||
# TODO: maybe change this to require a certain level of karma
|
if is_new?
|
||||||
!is_new?
|
return false
|
||||||
|
elsif obj.is_a?(Story)
|
||||||
|
if obj.is_downvotable?
|
||||||
|
return true
|
||||||
|
elsif obj.vote == -1
|
||||||
|
# user can unvote
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elsif obj.is_a?(Comment)
|
||||||
|
if obj.is_downvotable?
|
||||||
|
return true
|
||||||
|
elsif obj.current_vote.try(:vote).to_i == -1
|
||||||
|
# user can unvote
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_session_token
|
def check_session_token
|
||||||
|
|
|
@ -14,7 +14,7 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
|
||||||
<%= link_to "", login_url, :class => "upvoter" %>
|
<%= link_to "", login_url, :class => "upvoter" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="score"><%= comment.score %></div>
|
<div class="score"><%= comment.score %></div>
|
||||||
<% if @user && @user.can_downvote? %>
|
<% if @user && @user.can_downvote?(comment) %>
|
||||||
<a class="downvoter"></a>
|
<a class="downvoter"></a>
|
||||||
<% else %>
|
<% else %>
|
||||||
<span class="downvoter downvoter_stub"></span>
|
<span class="downvoter downvoter_stub"></span>
|
||||||
|
|
|
@ -9,7 +9,7 @@ class="story <%= story.vote == 1 ? "upvoted" : (story.vote == -1 ?
|
||||||
<%= link_to "", login_url, :class => "upvoter" %>
|
<%= link_to "", login_url, :class => "upvoter" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="score"><%= story.upvotes - story.downvotes %></div>
|
<div class="score"><%= story.upvotes - story.downvotes %></div>
|
||||||
<% if @user && @user.can_downvote? %>
|
<% if @user && @user.can_downvote?(story) %>
|
||||||
<a class="downvoter"></a>
|
<a class="downvoter"></a>
|
||||||
<% else %>
|
<% else %>
|
||||||
<span class="downvoter downvoter_stub"></span>
|
<span class="downvoter downvoter_stub"></span>
|
||||||
|
|
Loading…
Reference in a new issue