Fix #3363: Prevent setting tags to invalid categories.
This commit is contained in:
@@ -45,6 +45,10 @@ class TagCategory
|
|||||||
@@categories ||= Danbooru.config.full_tag_config_info.keys
|
@@categories ||= Danbooru.config.full_tag_config_info.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def category_ids
|
||||||
|
@@categories ||= canonical_mapping.values
|
||||||
|
end
|
||||||
|
|
||||||
def short_name_list
|
def short_name_list
|
||||||
@@short_name_list ||= short_name_mapping.keys
|
@@short_name_list ||= short_name_mapping.keys
|
||||||
end
|
end
|
||||||
@@ -75,4 +79,4 @@ class TagCategory
|
|||||||
extend Mappings
|
extend Mappings
|
||||||
extend Lists
|
extend Lists
|
||||||
extend Regexes
|
extend Regexes
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Tag < ApplicationRecord
|
|||||||
has_many :consequent_implications, lambda {active}, :class_name => "TagImplication", :foreign_key => "consequent_name", :primary_key => "name"
|
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 :name, uniqueness: true, tag_name: true, on: :create
|
||||||
|
validates_inclusion_of :category, in: TagCategory.category_ids
|
||||||
|
|
||||||
module ApiMethods
|
module ApiMethods
|
||||||
def to_legacy_json
|
def to_legacy_json
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ class TagTest < ActiveSupport::TestCase
|
|||||||
tag.update_category_cache_for_all
|
tag.update_category_cache_for_all
|
||||||
assert_equal(Tag.categories.copyright, Cache.get("tc:#{Cache.hash(tag.name)}"))
|
assert_equal(Tag.categories.copyright, Cache.get("tc:#{Cache.hash(tag.name)}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "not be settable to an invalid category" do
|
||||||
|
should validate_inclusion_of(:category).in_array(TagCategory.category_ids)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A tag parser" do
|
context "A tag parser" do
|
||||||
|
|||||||
Reference in New Issue
Block a user