Always obey rating locks; make rerating locked posts an error.

Currently rating locks are only obeyed when using the rating: metatag.
They aren't obeyed when:

* Changing the rating via the API.
* Changing the rating via 'Rate Safe' in the mode menu (uses the API).
* Reverting to previous versions.

Also, the current behavior is to ignore the rating: metatag if the post
is locked. This patch instead makes the update fail completely (note that
this could affect trying to mass revert posts that may be rating locked).

Note: the check for `!is_rating_locked_changed?` is so that

  PUT /posts/1.json?post[rating]=s&post[is_rating_locked]=true

works (ie., locking and changing the rating at the same time is okay).
This commit is contained in:
evazion
2016-10-19 19:21:32 -05:00
parent 88248e7ec7
commit 0006b76c4d

View File

@@ -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