tags: don't allow aliases inside *_(cosplay) tags.
Don't treat *_(cosplay) tags as being invisibly aliased when a character tag is aliased. For example, if toosaka_rin is aliased to tohsaka_rin, and toosaka_rin_(cosplay) is later added to a post, don't magically translate the tag to tohsaka_rin_(cosplay). Instead, treat it as an error to create a *_(cosplay) tag for an aliased character tag. This removes some of the complexity and magic behavior surrounding *_(cosplay) tags.
This commit is contained in:
@@ -42,7 +42,6 @@ class PostEdit
|
||||
def tag_names
|
||||
tag_names = current_tag_names + effective_added_tag_names - user_removed_tag_names
|
||||
tag_names = post.add_automatic_tags(tag_names)
|
||||
tag_names = ::Tag.convert_cosplay_tags(tag_names)
|
||||
tag_names += ::Tag.automatic_tags_for(tag_names)
|
||||
tag_names += TagImplication.tags_implied_by(tag_names).map(&:name)
|
||||
tag_names.uniq.sort
|
||||
|
||||
@@ -46,12 +46,13 @@ class TagNameValidator < ActiveModel::EachValidator
|
||||
when "new", "search", "and", "or", "not"
|
||||
record.errors.add(attribute, "'#{value}' is a reserved name and cannot be used")
|
||||
when /\A(.+)_\(cosplay\)\z/i
|
||||
# XXX don't allow aliases here?
|
||||
tag_name = TagAlias.to_aliased([$1]).first
|
||||
tag = Tag.find_by_name(tag_name)
|
||||
tag_name = $1;
|
||||
char_tag = Tag.find_by_name(tag_name)
|
||||
|
||||
if tag.present? && !tag.empty? && !tag.character?
|
||||
record.errors.add(attribute, "#{tag_name} must be a character tag")
|
||||
if char_tag.present? && char_tag.antecedent_alias.present?
|
||||
record.errors.add(attribute, "'#{value}' is not allowed because '#{tag_name}' is aliased to '#{char_tag.antecedent_alias.consequent_name}'")
|
||||
elsif char_tag.present? && !char_tag.empty? && !char_tag.character?
|
||||
record.errors.add(attribute, "'#{value}' is not allowed because '#{tag_name}' is not a character tag")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -362,7 +362,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
def self.automatic_tags_for(names)
|
||||
tags = []
|
||||
tags += names.grep(/\A(.+)_\(cosplay\)\z/i) { TagAlias.to_aliased([$1]).first }
|
||||
tags += names.grep(/\A(.+)_\(cosplay\)\z/i) { $1 }
|
||||
tags << "cosplay" if names.any?(/_\(cosplay\)\z/i)
|
||||
tags << "school_uniform" if names.any?(/_school_uniform\z/i)
|
||||
tags << "meme" if names.any?(/_\(meme\)\z/i)
|
||||
@@ -370,13 +370,6 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
concerning :CosplayTagMethods do
|
||||
class_methods do
|
||||
def convert_cosplay_tags(tags)
|
||||
cosplay_tags, other_tags = tags.partition {|tag| tag.match(/\A(.+)_\(cosplay\)\Z/) }
|
||||
cosplay_tags.grep(/\A(.+)_\(cosplay\)\Z/) { "#{TagAlias.to_aliased([$1]).first}_(cosplay)" } + other_tags
|
||||
end
|
||||
end
|
||||
|
||||
def create_character_tag_for_cosplay_tag
|
||||
character_name = name.delete_suffix("_(cosplay)")
|
||||
Tag.find_or_create_by_name("char:#{character_name}")
|
||||
|
||||
Reference in New Issue
Block a user