Fix #5013: BUR model doesn't validate tags.
Don't allow users to request aliases, implications, or renames for invalid tag names. As a side effect, it's no longer possible to request shortcut aliases like `/hr -> hakurei_reimu` (slash abbreviations still exist, but they can't be overridden with aliases). Tests involving these types of aliases are removed.
This commit is contained in:
@@ -112,11 +112,15 @@ class BulkUpdateRequestProcessor
|
||||
end
|
||||
|
||||
when :rename
|
||||
tag = Tag.find_by_name(args[0])
|
||||
if tag.nil?
|
||||
old_tag = Tag.find_by_name(args[0])
|
||||
new_tag = Tag.find_by_name(args[1]) || Tag.new(name: args[1])
|
||||
|
||||
if old_tag.nil?
|
||||
errors.add(:base, "Can't rename #{args[0]} -> #{args[1]} (the '#{args[0]}' tag doesn't exist)")
|
||||
elsif tag.post_count > MAXIMUM_RENAME_COUNT
|
||||
elsif old_tag.post_count > MAXIMUM_RENAME_COUNT
|
||||
errors.add(:base, "Can't rename #{args[0]} -> #{args[1]} ('#{args[0]}' has more than #{MAXIMUM_RENAME_COUNT} posts, use an alias instead)")
|
||||
elsif new_tag.invalid?(:name)
|
||||
errors.add(:base, "Can't rename #{args[0]} -> #{args[1]} (#{new_tag.errors.full_messages.join("; ")})")
|
||||
end
|
||||
|
||||
when :mass_update
|
||||
|
||||
@@ -26,8 +26,8 @@ class TagRelationship < ApplicationRecord
|
||||
|
||||
before_validation :normalize_names
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
validates :antecedent_name, presence: true
|
||||
validates :consequent_name, presence: true
|
||||
validates :antecedent_name, presence: true, tag_name: true, if: :antecedent_name_changed?
|
||||
validates :consequent_name, presence: true, tag_name: true, if: :consequent_name_changed?
|
||||
validates :approver, presence: { message: "must exist" }, if: -> { approver_id.present? }
|
||||
validates :forum_topic, presence: { message: "must exist" }, if: -> { forum_topic_id.present? }
|
||||
validate :antecedent_and_consequent_are_different
|
||||
|
||||
Reference in New Issue
Block a user