diff --git a/app/models/doi.rb b/app/models/doi.rb index 6a3b21eec..e48206770 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -106,7 +106,7 @@ class Doi < ActiveRecord::Base validates_inclusion_of :agency, :in => %w(datacite crossref kisti medra istic jalc airiti cnki op), allow_blank: true validates :last_landing_page_status, numericality: { only_integer: true }, if: :last_landing_page_status? validates :xml, presence: true, xml_schema: true, if: Proc.new { |doi| doi.validatable? } - validate :check_url, if: :url?, if: Proc.new { |doi| doi.is_registered_or_findable? } + validate :check_url, if: :url? validate :check_dates, if: :dates? validate :check_rights_list, if: :rights_list? validate :check_titles, if: :titles? @@ -1774,7 +1774,7 @@ def update_url if %w(europ).include?(provider_id) || type == "OtherDoi" UrlJob.perform_later(doi) - elsif url_changed? + elsif url_changed? || changes["aasm_state"] == ["draft", "findable"] || changes["aasm_state"] == ["draft", "registered"] register_url end end @@ -1838,6 +1838,8 @@ def event=(value) end def check_url + return nil if doi.is_registered_or_findable? + unless match_url_with_domains(url: url, domains: client.domains) errors.add(:url, "URL is not allowed by repository domain settings.") end diff --git a/spec/fixtures/vcr_cassettes/DataciteDoisController/GET_/dois_with_views_and_downloads/includes_events.yml b/spec/fixtures/vcr_cassettes/DataciteDoisController/GET_/dois_with_views_and_downloads/includes_events.yml new file mode 100644 index 000000000..4e820103c --- /dev/null +++ b/spec/fixtures/vcr_cassettes/DataciteDoisController/GET_/dois_with_views_and_downloads/includes_events.yml @@ -0,0 +1,57 @@ +--- +http_interactions: +- request: + method: get + uri: https://doi.org/ra/10.14454 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Date: + - Fri, 23 Oct 2020 12:43:36 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d8559e224bfd5004db1259333058d89e11603457016; expires=Sun, 22-Nov-20 + 12:43:36 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 05f71578d400000629bb1fd000000001 + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Report-To: + - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?lkg-colo=71&lkg-time=1603457016"}],"group":"cf-nel","max_age":604800}' + Nel: + - '{"report_to":"cf-nel","max_age":604800}' + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Server: + - cloudflare + Cf-Ray: + - 5e6b8b6e1f570629-FRA + Alt-Svc: + - h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400 + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Fri, 23 Oct 2020 12:43:36 GMT +recorded_with: VCR 5.1.0