posts: warn when a tag cannot be removed due to implications / automatic tags.
This commit is contained in:
@@ -19,6 +19,7 @@ class Post < ApplicationRecord
|
|||||||
validates_inclusion_of :rating, in: %w(s q e), message: "rating must be s, q, or e"
|
validates_inclusion_of :rating, in: %w(s q e), message: "rating must be s, q, or e"
|
||||||
validate :tag_names_are_valid
|
validate :tag_names_are_valid
|
||||||
validate :added_tags_are_valid
|
validate :added_tags_are_valid
|
||||||
|
validate :removed_tags_are_valid
|
||||||
validate :has_artist_tag
|
validate :has_artist_tag
|
||||||
validate :has_copyright_tag
|
validate :has_copyright_tag
|
||||||
validate :post_is_not_its_own_parent
|
validate :post_is_not_its_own_parent
|
||||||
@@ -648,12 +649,18 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def merge_old_changes
|
def merge_old_changes
|
||||||
|
@removed_tags = []
|
||||||
|
|
||||||
if old_tag_string
|
if old_tag_string
|
||||||
# If someone else committed changes to this post before we did,
|
# If someone else committed changes to this post before we did,
|
||||||
# then try to merge the tag changes together.
|
# then try to merge the tag changes together.
|
||||||
current_tags = tag_array_was()
|
current_tags = tag_array_was()
|
||||||
new_tags = tag_array()
|
new_tags = tag_array()
|
||||||
old_tags = Tag.scan_tags(old_tag_string)
|
old_tags = Tag.scan_tags(old_tag_string)
|
||||||
|
|
||||||
|
kept_tags = current_tags & new_tags
|
||||||
|
@removed_tags = old_tags - kept_tags
|
||||||
|
|
||||||
set_tag_string(((current_tags + new_tags) - old_tags + (current_tags & new_tags)).uniq.sort.join(" "))
|
set_tag_string(((current_tags + new_tags) - old_tags + (current_tags & new_tags)).uniq.sort.join(" "))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -702,10 +709,10 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def remove_negated_tags(tags)
|
def remove_negated_tags(tags)
|
||||||
negated_tags, tags = tags.partition {|x| x =~ /\A-/i}
|
@negated_tags, tags = tags.partition {|x| x =~ /\A-/i}
|
||||||
negated_tags = negated_tags.map {|x| x[1..-1]}
|
@negated_tags = @negated_tags.map {|x| x[1..-1]}
|
||||||
negated_tags = TagAlias.to_aliased(negated_tags)
|
@negated_tags = TagAlias.to_aliased(@negated_tags)
|
||||||
return tags - negated_tags
|
return tags - @negated_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_automatic_tags(tags)
|
def add_automatic_tags(tags)
|
||||||
@@ -1741,6 +1748,16 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def removed_tags_are_valid
|
||||||
|
attempted_removed_tags = @removed_tags + @negated_tags
|
||||||
|
unremoved_tags = tag_array & attempted_removed_tags
|
||||||
|
|
||||||
|
if unremoved_tags.present?
|
||||||
|
unremoved_tags_list = unremoved_tags.map { |t| "[[#{t}]]" }.to_sentence
|
||||||
|
self.warnings[:base] << "#{unremoved_tags_list} could not be removed. Check for implications and try again"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def has_artist_tag
|
def has_artist_tag
|
||||||
return if !new_record?
|
return if !new_record?
|
||||||
return if source !~ %r!\Ahttps?://!
|
return if source !~ %r!\Ahttps?://!
|
||||||
|
|||||||
Reference in New Issue
Block a user