* Missing files
* Work on post exploration code by traversing dates
This commit is contained in:
@@ -4,6 +4,7 @@ class Comment < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :creator, :class_name => "User"
|
||||
has_many :votes, :class_name => "CommentVote", :dependent => :destroy
|
||||
before_validation :initialize_creator, :on => :create
|
||||
after_save :update_last_commented_at
|
||||
attr_accessible :body
|
||||
attr_accessor :do_not_bump_post
|
||||
@@ -12,6 +13,11 @@ class Comment < ActiveRecord::Base
|
||||
scope :search_body, lambda {|query| where("body_index @@ plainto_tsquery(?)", query).order("comments.id DESC")}
|
||||
scope :hidden, lambda {|user| where("score < ?", user.comment_threshold)}
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.user.id
|
||||
self.ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def creator_name
|
||||
User.id_to_name(creator_id)
|
||||
end
|
||||
@@ -26,20 +32,21 @@ class Comment < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def vote!(is_positive)
|
||||
def vote!(score)
|
||||
if !CurrentUser.user.can_comment_vote?
|
||||
raise CommentVote::Error.new("You can only vote ten times an hour on comments")
|
||||
|
||||
elsif !is_positive && creator.is_janitor_or_higher?
|
||||
elsif score == "down" && creator.is_janitor?
|
||||
raise CommentVote::Error.new("You cannot downvote janitor/moderator/admin comments")
|
||||
|
||||
elsif votes.find_by_user_id(CurrentUser.user.id).nil?
|
||||
if is_positive
|
||||
update_attribute(:score, score + 1)
|
||||
else
|
||||
update_attribute(:score, score - 1)
|
||||
if score == "up"
|
||||
increment!(:score)
|
||||
elsif score == "down"
|
||||
decrement!(:score)
|
||||
end
|
||||
votes.create(:user_id => CurrentUser.user.id)
|
||||
|
||||
votes.create
|
||||
|
||||
else
|
||||
raise CommentVote::Error.new("You have already voted for this comment")
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
class CommentVote < ActiveRecord::Base
|
||||
class Error < Exception ; end
|
||||
|
||||
attr_accessor :is_positive
|
||||
belongs_to :comment
|
||||
belongs_to :user
|
||||
before_validation :initialize_user, :on => :create
|
||||
validates_presence_of :user_id, :comment_id
|
||||
|
||||
def self.prune!
|
||||
destroy_all(["created_at < ?", 14.days.ago])
|
||||
end
|
||||
|
||||
def initialize_user
|
||||
self.user_id = CurrentUser.user.id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -644,15 +644,15 @@ class Post < ActiveRecord::Base
|
||||
!votes.exists?(["user_id = ?", user.id])
|
||||
end
|
||||
|
||||
def vote!(user, is_positive)
|
||||
if can_be_voted_by?(user)
|
||||
if is_positive
|
||||
def vote!(score)
|
||||
if can_be_voted_by?(CurrentUser.user)
|
||||
if score == "up"
|
||||
increment!(:score)
|
||||
else
|
||||
elsif score == "down"
|
||||
decrement!(:score)
|
||||
end
|
||||
|
||||
votes.create(:user_id => user.id)
|
||||
votes.create(:score => score)
|
||||
else
|
||||
raise PostVote::Error.new("You have already voted for this comment")
|
||||
end
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
class PostVote < ActiveRecord::Base
|
||||
class Error < Exception ; end
|
||||
|
||||
attr_accessor :is_positive
|
||||
belongs_to :post
|
||||
before_validation :initialize_user, :on => :create
|
||||
validates_presence_of :post_id, :user_id, :score
|
||||
validates_inclusion_of :score, :in => [1, -1]
|
||||
|
||||
def score=(x)
|
||||
if x == "up"
|
||||
write_attribute(:score, 1)
|
||||
elsif x == "down"
|
||||
write_attribute(:score, -1)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_user
|
||||
self.user_id = CurrentUser.user.id
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user