post.rb: validate newly added tags.
Existing tags with invalid names are still permitted. This is to allow for a gradual transition to good tag names.
This commit is contained in:
@@ -16,6 +16,7 @@ class Post < ActiveRecord::Base
|
||||
before_validation :remove_parent_loops
|
||||
validates_uniqueness_of :md5, :on => :create
|
||||
validates_inclusion_of :rating, in: %w(s q e), message: "rating must be s, q, or e"
|
||||
validate :tag_names_are_valid
|
||||
validate :post_is_not_its_own_parent
|
||||
validate :updater_can_change_rating
|
||||
before_save :update_tag_post_counts
|
||||
@@ -1699,6 +1700,21 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tag_names_are_valid
|
||||
# only validate new tags; allow invalid names for tags that already exist.
|
||||
added_tags = tag_array - tag_array_was
|
||||
new_tags = added_tags - Tag.where(name: added_tags).pluck(:name)
|
||||
|
||||
new_tags.each do |name|
|
||||
tag = Tag.new(name: name)
|
||||
tag.valid?
|
||||
|
||||
tag.errors.messages.each do |attribute, messages|
|
||||
errors[:tag_string] << "tag #{attribute} #{messages.join(';')}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include FileMethods
|
||||
|
||||
@@ -2,7 +2,7 @@ class Tag < ActiveRecord::Base
|
||||
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 1000
|
||||
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype"
|
||||
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm"
|
||||
attr_accessible :category, :as => [:moderator, :janitor, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
|
||||
attr_accessible :name, :category
|
||||
attr_accessible :is_locked, :as => [:moderator, :admin]
|
||||
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user