diff --git a/app/models/post.rb b/app/models/post.rb index 8faaa91a7..c5c7099f0 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -47,6 +47,7 @@ class Post < ActiveRecord::Base 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] @@ -769,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 @@ -1762,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