BURs: don't allow implying tags from different categories.

Don't allow requests for implications between tags of different
categories. For example, don't allow character tags to imply copyright
tags.
This commit is contained in:
evazion
2020-12-02 15:02:29 -06:00
parent 6275e85148
commit 4a4c198287
3 changed files with 20 additions and 0 deletions

View File

@@ -192,6 +192,7 @@ class Artist < ApplicationRecord
# potential race condition but unlikely
unless TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").exists?
Tag.find_or_create_by_name("artist:banned_artist") # ensure the banned_artist exists and is an artist tag.
TagImplication.approve!(antecedent_name: name, consequent_name: "banned_artist", approver: banner)
end

View File

@@ -7,6 +7,7 @@ class TagImplication < TagRelationship
validate :absence_of_transitive_relation
validate :antecedent_is_not_aliased
validate :consequent_is_not_aliased
validate :tag_categories_are_compatible
validate :has_wiki_page, on: :request
concerning :HierarchyMethods do
@@ -93,6 +94,12 @@ class TagImplication < TagRelationship
end
end
def tag_categories_are_compatible
if antecedent_tag.category != consequent_tag.category
errors[:base] << "Can't imply a #{antecedent_tag.category_name.downcase} tag to a #{consequent_tag.category_name.downcase} tag"
end
end
def has_wiki_page
if !antecedent_tag.empty? && antecedent_wiki.blank?
errors[:base] << "'#{antecedent_name}' must have a wiki page"

View File

@@ -140,6 +140,18 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_equal(false, @bur.valid?)
assert_equal(["Can't create implication a -> c (a already implies c through another implication)"], @bur.errors.full_messages)
end
should "fail for an implication between tags of different categories" do
create(:tag, name: "hatsune_miku", category: Tag.categories.character)
create(:tag, name: "vocaloid", category: Tag.categories.copyright)
create(:wiki_page, title: "hatsune_miku")
create(:wiki_page, title: "vocaloid")
@bur = build(:bulk_update_request, script: "imply hatsune_miku -> vocaloid")
assert_equal(false, @bur.valid?)
assert_equal(["Can't create implication hatsune_miku -> vocaloid (Can't imply a character tag to a copyright tag)"], @bur.errors.full_messages)
end
end
context "the remove alias command" do