Merge pull request #3504 from BrokenEagle/fix-3494
Fix how cosplay tags are handled
This commit is contained in:
@@ -705,6 +705,8 @@ class Post < ApplicationRecord
|
||||
normalized_tags = TagAlias.to_aliased(normalized_tags)
|
||||
normalized_tags = %w(tagme) if normalized_tags.empty?
|
||||
normalized_tags = add_automatic_tags(normalized_tags)
|
||||
normalized_tags = remove_invalid_tags(normalized_tags)
|
||||
normalized_tags = Tag.convert_cosplay_tags(normalized_tags)
|
||||
normalized_tags = normalized_tags + Tag.create_for_list(TagImplication.automatic_tags_for(normalized_tags))
|
||||
normalized_tags = TagImplication.with_descendants(normalized_tags)
|
||||
normalized_tags = normalized_tags.compact.uniq.sort
|
||||
@@ -712,6 +714,14 @@ class Post < ApplicationRecord
|
||||
set_tag_string(normalized_tags.join(" "))
|
||||
end
|
||||
|
||||
def remove_invalid_tags(tags)
|
||||
invalid_tags = Tag.invalid_cosplay_tags(tags)
|
||||
if invalid_tags.present?
|
||||
self.warnings[:base] << "The root tag must be a character tag: #{invalid_tags.map {|tag| "[b]#{tag}[/b]" }.join(", ")}"
|
||||
end
|
||||
tags - invalid_tags
|
||||
end
|
||||
|
||||
def remove_negated_tags(tags)
|
||||
@negated_tags, tags = tags.partition {|x| x =~ /\A-/i}
|
||||
@negated_tags = @negated_tags.map {|x| x[1..-1]}
|
||||
|
||||
@@ -950,6 +950,19 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def self.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
|
||||
|
||||
def self.invalid_cosplay_tags(tags)
|
||||
tags.grep(/\A(.+)_\(cosplay\)\Z/) {|match| [match,TagAlias.to_aliased([$1]).first] }.
|
||||
select do |name|
|
||||
tag = Tag.find_by_name(name[1])
|
||||
!tag.nil? && tag.category != Tag.categories.character
|
||||
end.map {|tag| tag[0]}
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
return true if user.is_admin?
|
||||
return true if !is_locked? && user.is_builder? && post_count < 1_000
|
||||
|
||||
Reference in New Issue
Block a user