Fix #3363: Prevent setting tags to invalid categories.

This commit is contained in:
evazion
2017-11-13 16:54:18 -06:00
parent 40bd313ac4
commit 6fbd7c23e1
3 changed files with 10 additions and 1 deletions

View File

@@ -45,6 +45,10 @@ class TagCategory
@@categories ||= Danbooru.config.full_tag_config_info.keys
end
def category_ids
@@categories ||= canonical_mapping.values
end
def short_name_list
@@short_name_list ||= short_name_mapping.keys
end
@@ -75,4 +79,4 @@ class TagCategory
extend Mappings
extend Lists
extend Regexes
end
end

View File

@@ -12,6 +12,7 @@ class Tag < ApplicationRecord
has_many :consequent_implications, lambda {active}, :class_name => "TagImplication", :foreign_key => "consequent_name", :primary_key => "name"
validates :name, uniqueness: true, tag_name: true, on: :create
validates_inclusion_of :category, in: TagCategory.category_ids
module ApiMethods
def to_legacy_json

View File

@@ -119,6 +119,10 @@ class TagTest < ActiveSupport::TestCase
tag.update_category_cache_for_all
assert_equal(Tag.categories.copyright, Cache.get("tc:#{Cache.hash(tag.name)}"))
end
context "not be settable to an invalid category" do
should validate_inclusion_of(:category).in_array(TagCategory.category_ids)
end
end
context "A tag parser" do