Merge pull request #2727 from evazion/fix-post-ratings
Validate post ratings and fix ratings locks
This commit is contained in:
@@ -45,7 +45,9 @@ class Post < ActiveRecord::Base
|
||||
has_many :disapprovals, :class_name => "PostDisapproval", :dependent => :destroy
|
||||
has_many :favorites, :dependent => :destroy
|
||||
validates_uniqueness_of :md5
|
||||
validates_inclusion_of :rating, in: %w(s q e), message: "rating must be s, q, or e"
|
||||
validate :post_is_not_its_own_parent
|
||||
validate :updater_can_change_rating
|
||||
attr_accessible :source, :rating, :tag_string, :old_tag_string, :old_parent_id, :old_source, :old_rating, :parent_id, :has_embedded_notes, :as => [:member, :builder, :gold, :platinum, :janitor, :moderator, :admin, :default]
|
||||
attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :janitor, :moderator, :admin]
|
||||
attr_accessible :is_status_locked, :as => [:admin]
|
||||
@@ -768,9 +770,7 @@ class Post < ActiveRecord::Base
|
||||
self.source = $1
|
||||
|
||||
when /^rating:([qse])/i
|
||||
unless is_rating_locked?
|
||||
self.rating = $1.downcase
|
||||
end
|
||||
self.rating = $1.downcase
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1761,6 +1761,15 @@ class Post < ActiveRecord::Base
|
||||
save
|
||||
end
|
||||
|
||||
def updater_can_change_rating
|
||||
if rating_changed? && is_rating_locked?
|
||||
# Don't forbid changes if the rating lock was just now set in the same update.
|
||||
if !is_rating_locked_changed?
|
||||
errors.add(:rating, "is locked and cannot be changed. Unlock the post first.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_column(name, value)
|
||||
ret = super(name, value)
|
||||
notify_pubsub
|
||||
|
||||
Reference in New Issue
Block a user