Skip to content

Commit

Permalink
BURs: don't allow implying tags from different categories.
Browse files Browse the repository at this point in the history
Don't allow requests for implications between tags of different
categories. For example, don't allow character tags to imply copyright
tags.
  • Loading branch information
evazion committed Dec 2, 2020
1 parent 6275e85 commit 4a4c198
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/artist.rb
Expand Up @@ -192,6 +192,7 @@ def ban!(banner: CurrentUser.user)

# 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

Expand Down
7 changes: 7 additions & 0 deletions app/models/tag_implication.rb
Expand Up @@ -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
Expand Down Expand Up @@ -93,6 +94,12 @@ def consequent_is_not_aliased
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"
Expand Down
12 changes: 12 additions & 0 deletions test/unit/bulk_update_request_test.rb
Expand Up @@ -140,6 +140,18 @@ def create_bur!(script, approver)
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
Expand Down

0 comments on commit 4a4c198

Please sign in to comment.