Add a Restricted user level. Restricted users are level 10, below Members. New users start out as Restricted if they sign up from a proxy or an IP recently used by another user. Restricted users can't update or edit any public content on the site until they verify their email address, at which point they're promoted to Member. Restricted users are only allowed to do personal actions like keep favorites, keep favgroups and saved searches, mark dmails as read or deleted, or mark forum posts as read. The restricted state already existed before, the only change here is that now it's an actual user level instead of a hidden state. Before it was based on two hidden flags on the user, the `requires_verification` flag (set when a user signs up from a proxy, etc), and the `is_verified` flag (set after the user verifies their email). Making it a user level means that now the Restricted status will be shown publicly. Introducing a new level below Member means that we have to change every `is_member?` check to `!is_anonymous` for every place where we used `is_member?` to check that the current user is logged in.
44 lines
1011 B
Ruby
44 lines
1011 B
Ruby
class CommentVote < ApplicationRecord
|
|
class Error < StandardError; end
|
|
|
|
belongs_to :comment
|
|
belongs_to :user
|
|
validates_presence_of :score
|
|
validates_uniqueness_of :user_id, :scope => :comment_id, :message => "have already voted for this comment"
|
|
validate :validate_comment_can_be_down_voted
|
|
validates_inclusion_of :score, :in => [-1, 1], :message => "must be 1 or -1"
|
|
|
|
def self.visible(user)
|
|
if user.is_moderator?
|
|
all
|
|
elsif user.is_anonymous?
|
|
none
|
|
else
|
|
where(user: user)
|
|
end
|
|
end
|
|
|
|
def self.search(params)
|
|
q = search_attributes(params, :id, :created_at, :updated_at, :score, :comment, :user)
|
|
q.apply_default_order(params)
|
|
end
|
|
|
|
def validate_comment_can_be_down_voted
|
|
if is_positive? && comment.creator == CurrentUser.user
|
|
errors.add(:base, "You cannot upvote your own comments")
|
|
end
|
|
end
|
|
|
|
def is_positive?
|
|
score == 1
|
|
end
|
|
|
|
def is_negative?
|
|
score == -1
|
|
end
|
|
|
|
def self.available_includes
|
|
[:comment, :user]
|
|
end
|
|
end
|