Fix #4470: Check URLs for duplicates when creating artists
Show a warning when creating a duplicate artist; that is, when adding a URL that already belongs to another artist. This is a soft warning rather than a hard error because there are some cases where multiple artists legitimately share the same site or account.
This commit is contained in:
@@ -5,6 +5,7 @@ class ArtistURL < ApplicationRecord
|
||||
|
||||
validates :url, presence: true, uniqueness: { scope: :artist_id }
|
||||
validate :validate_url_format
|
||||
validate :validate_url_is_not_duplicate
|
||||
belongs_to :artist, :touch => true
|
||||
|
||||
scope :url_matches, ->(url) { url_attribute_matches(:url, url) }
|
||||
@@ -140,6 +141,14 @@ class ArtistURL < ApplicationRecord
|
||||
errors.add(:url, "'#{uri}' is malformed: #{e}")
|
||||
end
|
||||
|
||||
def validate_url_is_not_duplicate
|
||||
artists = ArtistFinder.find_artists(url).without(artist)
|
||||
|
||||
artists.each do |a|
|
||||
warnings.add(:base, "Duplicate of [[#{a.name}]]")
|
||||
end
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
[:artist]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user