diff --git a/Gemfile b/Gemfile index fec895da4..3743be39b 100644 --- a/Gemfile +++ b/Gemfile @@ -50,9 +50,10 @@ gem "rack-cors", "~> 1.0", require: "rack/cors" gem "strip_attributes", "~> 1.8" gem "slack-notifier", "~> 2.1" gem "mini_magick", "~> 4.8" -gem "elasticsearch", "~> 7.1.0" -gem "elasticsearch-model", "~> 7.0", require: "elasticsearch/model" -gem "elasticsearch-rails", "~> 7.0" +gem "elasticsearch", "7.5" +gem 'elasticsearch-transport', '7.5' +gem 'elasticsearch-model', '~> 7.1', '>= 7.1.1', require: "elasticsearch/model" +gem 'elasticsearch-rails', '~> 7.1', '>= 7.1.1' gem "faraday", "~> 0.17.3" gem "faraday_middleware-aws-sigv4", "~> 0.3.0" gem "rack-utf8_sanitizer", "~> 1.6" diff --git a/Gemfile.lock b/Gemfile.lock index 08edeb5a6..88e04fba6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,8 +60,8 @@ GEM audited (4.9.0) activerecord (>= 4.2, < 6.1) aws-eventstream (1.1.0) - aws-partitions (1.381.0) - aws-sdk-core (3.109.1) + aws-partitions (1.393.0) + aws-sdk-core (3.109.2) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) @@ -69,7 +69,7 @@ GEM aws-sdk-kms (1.39.0) aws-sdk-core (~> 3, >= 3.109.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.83.0) + aws-sdk-s3 (1.84.1) aws-sdk-core (~> 3, >= 3.109.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.1) @@ -94,15 +94,15 @@ GEM oj (>= 2.8.3) pandoc-ruby (~> 2.0, >= 2.0.0) safe_yaml (~> 1.0, >= 1.0.4) - better_errors (2.8.3) + better_errors (2.9.1) coderay (>= 1.0.0) erubi (>= 1.0.0) rack (>= 0.9.0) - bibtex-ruby (5.1.4) + bibtex-ruby (5.1.5) latex-decode (~> 0.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bolognese (1.8.13) + bolognese (1.8.18) activesupport (>= 4.2.5) benchmark_methods (~> 0.7) bibtex-ruby (>= 5.1.0) @@ -127,7 +127,7 @@ GEM rdf-rdfxml (~> 3.1) rdf-turtle (~> 3.1) thor (>= 0.19) - bootsnap (1.4.8) + bootsnap (1.5.1) msgpack (~> 1.0) builder (3.2.4) bullet (6.1.0) @@ -147,7 +147,7 @@ GEM activesupport citeproc (1.0.10) namae (~> 1.0) - citeproc-ruby (1.1.12) + citeproc-ruby (1.1.13) citeproc (~> 1.0, >= 1.0.9) csl (~> 1.5) climate_control (0.2.0) @@ -167,10 +167,9 @@ GEM sort_alphabetical (~> 1.0) crack (0.4.4) crass (1.0.6) - crawler_detect (1.0.2) - oj (>= 3.0) + crawler_detect (1.1.0) qonfig (~> 0.24) - csl (1.5.1) + csl (1.5.2) namae (~> 1.0) csl-styles (1.0.1.10) csl (~> 1.0) @@ -192,17 +191,17 @@ GEM domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) dotenv (2.7.6) - ebnf (2.1.1) + ebnf (2.1.2) htmlentities (~> 4.3) rdf (~> 3.1) scanf (~> 1.0) sxp (~> 1.1) - edtf (3.0.5) + edtf (3.0.6) activesupport (>= 3.0, < 7.0) - elasticsearch (7.1.0) - elasticsearch-api (= 7.1.0) - elasticsearch-transport (= 7.1.0) - elasticsearch-api (7.1.0) + elasticsearch (7.5.0) + elasticsearch-api (= 7.5.0) + elasticsearch-transport (= 7.5.0) + elasticsearch-api (7.5.0) multi_json elasticsearch-extensions (0.0.31) ansi @@ -212,12 +211,12 @@ GEM elasticsearch (> 1) hashie elasticsearch-rails (7.1.1) - elasticsearch-transport (7.1.0) - faraday + elasticsearch-transport (7.5.0) + faraday (>= 0.14, < 1) multi_json equivalent-xml (0.6.0) nokogiri (>= 1.4.3) - erubi (1.9.0) + erubi (1.10.0) excon (0.71.1) facets (3.1.0) factory_bot (4.11.1) @@ -310,7 +309,7 @@ GEM mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) - latex-decode (0.3.1) + latex-decode (0.3.2) link_header (0.0.8) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) @@ -349,9 +348,9 @@ GEM method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2020.0512) + mime-types-data (3.2020.1104) mimemagic (0.3.5) - mini_magick (4.10.1) + mini_magick (4.11.0) mini_mime (1.0.2) mini_portile2 (2.4.0) minitest (5.14.2) @@ -368,11 +367,11 @@ GEM nio4r (2.5.4) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) - oj (3.10.14) + oj (3.10.16) oj_mimic_json (1.0.1) optimist (3.0.1) pandoc-ruby (2.1.4) - parallel (1.19.2) + parallel (1.20.0) parser (2.7.2.0) ast (~> 2.4.1) postrank-uri (1.0.24) @@ -470,7 +469,7 @@ GEM rspec (>= 3.0.0, < 4.0.0) rspec-core (3.9.3) rspec-support (~> 3.9.3) - rspec-expectations (3.9.2) + rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-graphql_matchers (1.3.0) @@ -486,7 +485,7 @@ GEM rspec-expectations (~> 3.9.0) rspec-mocks (~> 3.9.0) rspec-support (~> 3.9.0) - rspec-support (3.9.3) + rspec-support (3.9.4) rubocop (0.77.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) @@ -570,7 +569,7 @@ GEM rack (>= 1.3, < 3) rack-accept (~> 0.4) tilt (>= 1.4, < 3) - tzinfo (1.2.7) + tzinfo (1.2.8) thread_safe (~> 0.1) unf (0.1.4) unf_ext @@ -581,7 +580,7 @@ GEM uuid (2.3.9) macaddr (~> 1.0) vcr (5.1.0) - webmock (3.9.2) + webmock (3.10.0) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -623,10 +622,11 @@ DEPENDENCIES departure (~> 6.2) diffy (~> 3.2, >= 3.2.1) dotenv - elasticsearch (~> 7.1.0) + elasticsearch (= 7.5) elasticsearch-extensions (~> 0.0.29) - elasticsearch-model (~> 7.0) - elasticsearch-rails (~> 7.0) + elasticsearch-model (~> 7.1, >= 7.1.1) + elasticsearch-rails (~> 7.1, >= 7.1.1) + elasticsearch-transport (= 7.5) equivalent-xml (~> 0.6.0) facets factory_bot_rails (~> 4.8, >= 4.8.2) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index a841cd4ed..3e713aec5 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -471,7 +471,21 @@ def create_alias(options={}) if client.indices.exists_alias?(name: alias_name, index: [index_name]) "Alias #{alias_name} for index #{index_name} already exists." else - client.indices.put_alias index: index_name, name: alias_name + # alias index is writeable unless it is for OtherDoi index + client.indices.update_aliases( + body: { + actions: [ + { + add: { + index: index_name, + alias: alias_name, + is_write_index: self.name != "OtherDoi" + } + } + ] + } + ) + "Created alias #{alias_name} for index #{index_name}." end # end @@ -649,7 +663,15 @@ def index_stats(options={}) stats = client.indices.stats index: [active_index, inactive_index], docs: true active_index_count = stats.dig("indices", active_index, "primaries", "docs", "count") inactive_index_count = stats.dig("indices", inactive_index, "primaries", "docs", "count") - database_count = self.all.count + + # workaround until STI is enabled + if self.name == "DataCiteDoi" + database_count = self.where(type: "DataCiteDoi").count + elsif self.name == "OtherDoi" + database_count = self.where(type: "OtherDoi").count + else + database_count = self.all.count + end "Active index #{active_index} has #{active_index_count} documents, " \ "inactive index #{inactive_index} has #{inactive_index_count} documents, " \ @@ -658,10 +680,13 @@ def index_stats(options={}) end # switch between the two indexes, i.e. the index that is aliased + # alias index for OtherDoi by default is not writeable, + # as we also have DataciteDoi alias def switch_index(options={}) alias_name = options[:alias] || self.index_name index_name = (options[:index] || self.index_name) + "_v1" alternate_index_name = (options[:index] || self.index_name) + "_v2" + is_write_index = options[:is_write_index] || self.name != "OtherDoi" client = Elasticsearch::Model.client @@ -669,7 +694,7 @@ def switch_index(options={}) client.indices.update_aliases body: { actions: [ { remove: { index: index_name, alias: alias_name } }, - { add: { index: alternate_index_name, alias: alias_name } } + { add: { index: alternate_index_name, alias: alias_name, is_write_index: is_write_index } } ] } diff --git a/app/models/datacite_doi.rb b/app/models/datacite_doi.rb index 4d7a9f7a2..0436b7f31 100644 --- a/app/models/datacite_doi.rb +++ b/app/models/datacite_doi.rb @@ -18,9 +18,10 @@ class DataciteDoi < Doi # index_name "dois-datacite" # end + # TODO remove query for type once STI is enabled def self.import_by_ids(options={}) - from_id = (options[:from_id] || DataciteDoi.minimum(:id)).to_i - until_id = (options[:until_id] || DataciteDoi.maximum(:id)).to_i + from_id = (options[:from_id] || DataciteDoi.where(type: "DataciteDoi").minimum(:id)).to_i + until_id = (options[:until_id] || DataciteDoi.where(type: "DataciteDoi").maximum(:id)).to_i # get every id between from_id and end_id (from_id..until_id).step(500).each do |id| @@ -45,7 +46,8 @@ def self.import_by_id(options={}) errors = 0 count = 0 - DataciteDoi.where(id: id..(id + 499)).find_in_batches(batch_size: 500) do |dois| + # TODO remove query for type once STI is enabled + DataciteDoi.where(type: "DataciteDoi").where(id: id..(id + 499)).find_in_batches(batch_size: 500) do |dois| response = DataciteDoi.__elasticsearch__.client.bulk \ index: index, type: DataciteDoi.document_type, @@ -75,7 +77,8 @@ def self.import_by_id(options={}) count = 0 - DataciteDoi.where(id: id..(id + 499)).find_each do |doi| + # TODO remove query for type once STI is enabled + DataciteDoi.where(type: "DataciteDoi").where(id: id..(id + 499)).find_each do |doi| IndexJob.perform_later(doi) count += 1 end diff --git a/app/models/other_doi.rb b/app/models/other_doi.rb index e7c85946c..8e1e843d1 100644 --- a/app/models/other_doi.rb +++ b/app/models/other_doi.rb @@ -22,8 +22,9 @@ def set_defaults end def self.import_by_ids(options={}) - from_id = (options[:from_id] || OtherDoi.minimum(:id)).to_i - until_id = (options[:until_id] || OtherDoi.maximum(:id)).to_i + # TODO remove query for type once STI is enabled + from_id = (options[:from_id] || OtherDoi.where(type: "OtherDoi").minimum(:id)).to_i + until_id = (options[:until_id] || OtherDoi.where(type: "OtherDoi").maximum(:id)).to_i # get every id between from_id and end_id (from_id..until_id).step(500).each do |id| @@ -48,7 +49,8 @@ def self.import_by_id(options={}) errors = 0 count = 0 - OtherDoi.where(id: id..(id + 499)).find_in_batches(batch_size: 500) do |dois| + # TODO remove query for type once STI is enabled + OtherDoi.where(type: "OtherDoi").where(id: id..(id + 499)).find_in_batches(batch_size: 500) do |dois| response = OtherDoi.__elasticsearch__.client.bulk \ index: index, type: OtherDoi.document_type, @@ -78,7 +80,8 @@ def self.import_by_id(options={}) count = 0 - OtherDoi.where(id: id..(id + 499)).find_each do |doi| + # TODO remove query for type once STI is enabled + OtherDoi.where(type: "OtherDoi").where(id: id..(id + 499)).find_each do |doi| IndexJob.perform_later(doi) count += 1 end diff --git a/spec/concerns/helpable_spec.rb b/spec/concerns/helpable_spec.rb index 8066d4808..8b420abcc 100644 --- a/spec/concerns/helpable_spec.rb +++ b/spec/concerns/helpable_spec.rb @@ -164,24 +164,6 @@ expect(response.body.dig("data", "values")).to eq([{"index"=>1, "type"=>"URL", "data"=>{"format"=>"string", "value"=>"https://blog.datacite.org/re3data-science-europe/"}, "ttl"=>86400, "timestamp"=>"2020-07-26T08:55:35Z"}]) end - it 'wrong domain' do - client = create(:client, provider: provider, symbol: ENV['MDS_USERNAME'], password: ENV['MDS_PASSWORD'], domains: "example.org") - subject = build(:doi, doi: "10.5438/mcnv-ga6n", url: "https://blog.datacite.org/", client: client, aasm_state: "findable") - expect { subject.register_url }.to raise_error(ActionController::BadRequest, "[Handle] Error updating DOI 10.5438/MCNV-GA6N: URL not allowed by repository domains settings.") - end - - it 'wrong subdomain' do - client = create(:client, provider: provider, symbol: ENV['MDS_USERNAME'], password: ENV['MDS_PASSWORD'], domains: "datacite.org") - subject = build(:doi, doi: "10.5438/mcnv-ga6n", url: "https://blog.datacite.org/", client: client, aasm_state: "findable") - expect { subject.register_url }.to raise_error(ActionController::BadRequest, "[Handle] Error updating DOI 10.5438/MCNV-GA6N: URL not allowed by repository domains settings.") - end - - it 'wildcard for subdomain but using naked domain' do - client = create(:client, provider: provider, symbol: ENV['MDS_USERNAME'], password: ENV['MDS_PASSWORD'], domains: "*.datacite.org") - subject = build(:doi, doi: "10.5438/mcnv-ga6n", url: "https://datacite.org/", client: client, aasm_state: "findable") - expect { subject.register_url }.to raise_error(ActionController::BadRequest, "[Handle] Error updating DOI 10.5438/MCNV-GA6N: URL not allowed by repository domains settings.") - end - it 'draft doi' do subject = build(:doi, doi: "10.5438/mcnv-ga6n", url: "https://blog.datacite.org/", client: client, aasm_state: "draft") expect { subject.register_url }.to raise_error(ActionController::BadRequest, "DOI is not registered or findable.") diff --git a/spec/factories/default.rb b/spec/factories/default.rb index ebc7861ec..7dd716595 100644 --- a/spec/factories/default.rb +++ b/spec/factories/default.rb @@ -244,6 +244,7 @@ ]} schema_version { "http://datacite.org/schema/kernel-4" } source { "test" } + type { "DataciteDoi" } regenerate { true } created { Faker::Time.backward(14, :evening) } minted { Faker::Time.backward(15, :evening) } diff --git a/spec/fixtures/vcr_cassettes/DatasetType/query_with_references/returns_all_datasets_with_counts.yml b/spec/fixtures/vcr_cassettes/DatasetType/query_with_references/returns_all_datasets_with_counts.yml new file mode 100644 index 000000000..7dc9294e5 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/DatasetType/query_with_references/returns_all_datasets_with_counts.yml @@ -0,0 +1,211 @@ +--- +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: + - Sun, 15 Nov 2020 09:57:10 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=da09580bd289e408e7969a5e0ba0f23011605434230; expires=Tue, 15-Dec-20 + 09:57:10 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cef60520000c2e5c62ea000000001 + 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?s=eSIA460qMhJY71kazThKQnSBTTzDh%2FvXd2R748WDsIx6fuHVx966tiF3%2BRJMWT8%2B0cxTgQ5KDjQZ81mdE5AwvDMesPQ%2FCGpj"}],"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: + - 5f281b46e848c2e5-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:10 GMT +- 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: + - Sun, 15 Nov 2020 09:57:11 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=dd14110b07190403c97fb04236a56a1c51605434231; expires=Tue, 15-Dec-20 + 09:57:11 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cef60fd00000629ff0a3000000001 + 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?s=FagH3dAnvkPtjmtu4O6YO5tBkKGnunGxuTgRfthAel77pBnRATkgEvLrQzAdk%2BK1%2FFj70qY5akpDWmIdFE7J3tscSSkwCzaG"}],"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: + - 5f281b47fa3a0629-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:11 GMT +- 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: + - Sun, 15 Nov 2020 09:57:11 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=df1f70f8f3c43dcba5ce8a965780122bf1605434231; expires=Tue, 15-Dec-20 + 09:57:11 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cef6315000005c4b78dd000000001 + 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?s=zK0B1WPCXxCdXam7b8jdq98nLePKQ6ngkm3JsoJT4fj%2FVvA4YWn%2FGhjDcdQmOXF2DFyxryZ9zMUoqv62vj1P%2F5Q1SB%2F2Iwtb"}],"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: + - 5f281b4b5a5005c4-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:11 GMT +- 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: + - Sun, 15 Nov 2020 09:57:11 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=ddb2622937e7bc8c8912fcbd8a6b3e9371605434231; expires=Tue, 15-Dec-20 + 09:57:11 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cef63a700001f4db83d9000000001 + 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?s=T%2Bo2yQVR%2BezZaSYkShSAniV9S8uaOHAiJg2ffJswkDzShR68GsdztRmDK8ZNLs2VJAlVLDBrnMPodwwF8KH7Y89tEaQ%2B%2B73a"}],"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: + - 5f281b4c3a041f4d-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:11 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/DatasetType/query_with_version_of/returns_all_datasets_with_counts.yml b/spec/fixtures/vcr_cassettes/DatasetType/query_with_version_of/returns_all_datasets_with_counts.yml new file mode 100644 index 000000000..0d61aa73a --- /dev/null +++ b/spec/fixtures/vcr_cassettes/DatasetType/query_with_version_of/returns_all_datasets_with_counts.yml @@ -0,0 +1,107 @@ +--- +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: + - Sun, 15 Nov 2020 09:57:56 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d50f386c4b8c55fbea034a393062e4b5d1605434276; expires=Tue, 15-Dec-20 + 09:57:56 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cf011110000c295d0b8c000000001 + 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?s=DDOL74eEHFjdKKXF6Re%2Blj2vlFh7Dq7BssgkzBpF1BmpCD5MLpW4JSVEIW2QH8s3JhGGD%2BcslYXk4nfQizVcpvpyBzLKCDHa"}],"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: + - 5f281c61bcb5c295-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:56 GMT +- 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: + - Sun, 15 Nov 2020 09:57:56 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d6ef3fdce643065afcf947dfc80b489251605434276; expires=Tue, 15-Dec-20 + 09:57:56 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cf0119b00002bf6ce3a2000000001 + 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?s=C54P%2FfbQK8CrlqmoqkeEYG2rIDokUuemIKm36BYzLTDJmFirKSqw41ZLH5%2B%2Fkq3SYmN8g%2BAfVoEGMPXFLmhmQBa5j7Doyaqq"}],"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: + - 5f281c629ac92bf6-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:56 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/DatasetType/query_with_versions/returns_all_datasets_with_counts.yml b/spec/fixtures/vcr_cassettes/DatasetType/query_with_versions/returns_all_datasets_with_counts.yml new file mode 100644 index 000000000..cb1516005 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/DatasetType/query_with_versions/returns_all_datasets_with_counts.yml @@ -0,0 +1,107 @@ +--- +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: + - Sun, 15 Nov 2020 09:57:23 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d9574b139ddd70b3955e4424e811a9c331605434243; expires=Tue, 15-Dec-20 + 09:57:23 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cef90c20000bee748a9d000000001 + 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?s=ApSX87Wfh6TS0UnLRb313jRiYngkTUL3d8e8da0Cm8Jl%2FeN3rG74raYoZzuVq7i368XiTfobtcOv%2FZtHz%2BRrLjLosyheGbro"}],"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: + - 5f281b946d89bee7-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:23 GMT +- 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: + - Sun, 15 Nov 2020 09:57:23 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=dd7ae2dc520fd305e768ff8ab222e48ed1605434243; expires=Tue, 15-Dec-20 + 09:57:23 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cef914d0000dfd3e3327000000001 + 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?s=d5S04Rbqv8%2FXiKabfAaubWuv%2Bz58QYNRw%2BEewQ8jcJnj4n%2B58tYyfTQDcC2QZlVRhXUsP79b36aaC94zDBLsX2YPqU%2FWPwYS"}],"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: + - 5f281b953dd3dfd3-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:23 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/DatasetType/query_with_views/returns_all_datasets_with_counts.yml b/spec/fixtures/vcr_cassettes/DatasetType/query_with_views/returns_all_datasets_with_counts.yml new file mode 100644 index 000000000..8795b81ec --- /dev/null +++ b/spec/fixtures/vcr_cassettes/DatasetType/query_with_views/returns_all_datasets_with_counts.yml @@ -0,0 +1,107 @@ +--- +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: + - Sun, 15 Nov 2020 09:57:28 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d2e8769caf2a2a2fffb7ebf3c6d73b3301605434248; expires=Tue, 15-Dec-20 + 09:57:28 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cefa5be00001f1da3a3e000000001 + 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?s=iHyE3IHANyGkqvK%2FWpmdP2fWTOpgxpgNJNxXVNAW4IKKbIOwz79jWVjRP5z5ZvdbZpBVzxgytIwvPzK05EvEsbnn4tUshGbk"}],"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: + - 5f281bb5fb3b1f1d-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:28 GMT +- 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: + - Sun, 15 Nov 2020 09:57:29 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Set-Cookie: + - __cfduid=df54a268978d3313e4796f9457c4e40b31605434249; expires=Tue, 15-Dec-20 + 09:57:29 GMT; path=/; domain=.doi.org; HttpOnly; SameSite=Lax; Secure + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - 066cefa758000064315c8a1000000001 + 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?s=pKPBNtuOBV3TzKogv%2Fal2LRgZulBcX2BbS8TcJK1x%2Fu%2FaQBlv9sjAixbzDJISbAW6N5Eo8KFdkjLp%2B10J3MQwg9Kc6hulMCx"}],"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: + - 5f281bb8886f6431-FRA + body: + encoding: ASCII-8BIT + string: |- + [ + { + "DOI": "10.14454", + "RA": "DataCite" + } + ] + http_version: null + recorded_at: Sun, 15 Nov 2020 09:57:29 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/WorkType/create_claim/returns_claim.yml b/spec/fixtures/vcr_cassettes/WorkType/create_claim/returns_claim.yml index 4b094ff2b..cf409e822 100644 --- a/spec/fixtures/vcr_cassettes/WorkType/create_claim/returns_claim.yml +++ b/spec/fixtures/vcr_cassettes/WorkType/create_claim/returns_claim.yml @@ -5,7 +5,7 @@ http_interactions: uri: https://api.stage.datacite.org/claims body: encoding: UTF-8 - string: '{"claim":{"uuid":"d140d44e-af70-43ec-a90b-49878a954487","orcid":"0000-0001-6528-2027","doi":"10.5438/4hr0-d640","claim_action":"create","source_id":"auto_update"}}' + string: '{"claim":{"uuid":"d140d44e-af70-43ec-a90b-49878a954487","orcid":"0000-0001-6528-2027","doi":"10.5438/4hr0-d640","claim_action":"create","source_id":"orcid_update"}}' headers: User-Agent: - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) @@ -14,14 +14,14 @@ http_interactions: Content-Type: - application/json;charset=UTF-8 Authorization: - - Bearer eyJhbGciOiJSUzI1NiJ9.eyJ1aWQiOiIwMDAwLTAwMDEtNjUyOC0yMDI3IiwibmFtZSI6Ik1hcnRpbiBGZW5uZXIiLCJyb2xlX2lkIjoic3RhZmZfYWRtaW4iLCJoYXNfb3JjaWRfdG9rZW4iOnRydWUsImF1ZCI6InRlc3QiLCJpYXQiOjE2MDM3MDMxMzQsImV4cCI6MTYwMzcwMzE2NH0.p8viyoRTYngMFSM00aJ4xdLviYI2uW_eUw66X3pND0Vlkd8Eskn4uL7YAQOrp1dmmJ7kHqa-OxouXhTNnT1dazp36sozHEX0YNw_kEHOmnKwPi0lGoLz8rvlhhPm8u07Oqep31hLiwaiZ7mf1Xkgz6ClRImOiI74_FCS8vwX4pXMYpCZB_TguQcparIzMF6AJyfHwsRhcvr_jpnbdAJ05rvLiTDDUse1zKM8L7DG_R5gcv8B4J3oe74V1eNKd2Cjw-NbHJ4Bws5KtiUwB4IIkGWinaN2guXJS-k2jTd9o1iUGmScjdFG87MlfF5oG3wqyNrIMkxhqatgT-1QBt3fUj9-UgvPs0Bf5PcizkzLnQBihvCFHORcYDFUhP7yFmIIM4aOpSMXLYIVozwNCmIwc2NnGPr_DiT4kmCH9XmK9VOf255ix6XsoUlH-kutZcNteQgtZeHTyH59f8HJySI8w6FilXuhHWMRioNv41VDLLQrkbvs8txR-wzww1o0IKyXGhUGrLoVTKCGvJx9krzwILMvE2Ugdt9G8MOe1zS3K_m29-WQOgyrVw3rNyGNyhR5E9jo_P34cMZLU0-4WnhKT0VdrKtfdRK6h1mFY6ixGfWZ6WeTfhraSAeotFThaJ3bF6-6Fs5Z81koEHhWsEsTK0AgyRccT6OWplXqjRA6vTE + - Bearer eyJhbGciOiJSUzI1NiJ9.eyJ1aWQiOiIwMDAwLTAwMDEtNjUyOC0yMDI3IiwibmFtZSI6Ik1hcnRpbiBGZW5uZXIiLCJyb2xlX2lkIjoic3RhZmZfYWRtaW4iLCJoYXNfb3JjaWRfdG9rZW4iOnRydWUsImF1ZCI6InRlc3QiLCJpYXQiOjE2MDU0MzY3MDIsImV4cCI6MTYwNTQzNjczMn0.vnV-0oddBLkXO94Kz_OTYkx30ocheRcdIHew0arFvr0i7XrRGBR09kOuUIEFqavCQjefMcJnh29TTFtuj98jfVIB74UtCeBfMOe0kM8hBdeouF2RWYr1YaoD3CZZwAIDfUAndfIYvU3MmGSFjFqSre9It-Bgt47BoQHDcPegsl7_eWZeP5JYF_ASs5x9Sny4M8fjM9gYE7cywPjfjYEku9dQraveMc5559ZsvCOJtOPNopeADqv9S_EhScjHBGKITYbMGYgQK_39d3Q4sBGLkHcxXbZu8mt7FfXBiD3EIUGFKtvqswop2MT2IBv4e4AtuGGLcWkxf3yuZcVJTg8Q4Z5eKA7R0gWdPStLy7ICaVDv_9ZqMmGml6qT7MBAmeTzGAWtCuG3gSc-z4R0wp3dKFH7Mgq5WBaL3xkjVtKTajQtF5S9MHIxFWDmygtOoxl2OZPQ_fmeVbYyhzI847d6nwqAiD21P7RYAVxl4Aq0RESX0sXPzCvSp0TW7qT2mQtZOePmSmuj9lkoOGDAcrsB02vDopvnIY1rZfKgOq7SJMSBMcu9dGE3Q_chmac2GALMoLUsyNhG7NciWLcgf2mKk0BWH19zjU-iv7LY2vFmDSYoGZynU2EVmMcAe_0ibh8Qif7LWN7ycBxA9RtHNTMoXV0FfmGb4w0p1ST81RaYs58 response: status: code: 202 message: Accepted headers: Date: - - Mon, 26 Oct 2020 09:05:41 GMT + - Sun, 15 Nov 2020 10:38:31 GMT Content-Type: - application/json; charset=utf-8 Connection: @@ -41,11 +41,11 @@ http_interactions: X-Credential-Username: - 0000-0001-6528-2027 X-Request-Id: - - 67f20cae-400f-4b19-8223-5116829c2d27 + - 3ad069be-d279-4916-b250-eb0e2c9e0bc8 X-Download-Options: - noopen X-Runtime: - - '0.054676' + - '0.130132' X-Frame-Options: - SAMEORIGIN X-Content-Type-Options: @@ -56,9 +56,9 @@ http_interactions: - nginx/1.14.0 + Phusion Passenger 6.0.6 body: encoding: ASCII-8BIT - string: '{"data":{"id":"d140d44e-af70-43ec-a90b-49878a954487","type":"claims","attributes":{"orcid":"https://orcid.org/0000-0001-6528-2027","doi":"https://doi.org/10.5438/4hr0-d640","sourceId":"auto_update","state":"failed","claimAction":"create","errorMessages":[{"title":"Missing - data"}],"putCode":null,"claimed":null,"created":"2020-10-26T09:03:02.000Z","updated":"2020-10-26T09:03:04.000Z"},"relationships":{"user":{"data":{"id":"0000-0001-6528-2027","type":"users"}}}},"included":[{"id":"0000-0001-6528-2027","type":"users","attributes":{"givenName":"Martin","familyName":"Fenner","name":"Martin + string: '{"data":{"id":"d140d44e-af70-43ec-a90b-49878a954487","type":"claims","attributes":{"orcid":"https://orcid.org/0000-0001-6528-2027","doi":"https://doi.org/10.5438/4hr0-d640","sourceId":"orcid_update","state":"failed","claimAction":"create","errorMessages":[{"title":"Missing + data"}],"putCode":null,"claimed":null,"created":"2020-10-26T09:03:02.000Z","updated":"2020-11-15T10:38:31.000Z"},"relationships":{"user":{"data":{"id":"0000-0001-6528-2027","type":"users"}}}},"included":[{"id":"0000-0001-6528-2027","type":"users","attributes":{"givenName":"Martin","familyName":"Fenner","name":"Martin Fenner","orcid":"https://orcid.org/0000-0001-6528-2027","github":null,"roleId":"staff_admin","isActive":false,"created":"2018-08-20T16:40:54.000Z","updated":"2019-08-31T07:28:05.000Z"},"relationships":{}}]}' http_version: null - recorded_at: Mon, 26 Oct 2020 09:05:41 GMT + recorded_at: Sun, 15 Nov 2020 10:38:31 GMT recorded_with: VCR 5.1.0 diff --git a/spec/graphql/types/dataset_type_spec.rb b/spec/graphql/types/dataset_type_spec.rb index 9e0d9cbec..ba392ff9f 100644 --- a/spec/graphql/types/dataset_type_spec.rb +++ b/spec/graphql/types/dataset_type_spec.rb @@ -207,7 +207,7 @@ before do Doi.import Event.import - sleep 2 + sleep 3 @dois = Doi.gql_query(nil, page: { cursor: [], size: 3 }).results.to_a end diff --git a/spec/graphql/types/work_type_spec.rb b/spec/graphql/types/work_type_spec.rb index ec4084d7a..c327c8e7d 100644 --- a/spec/graphql/types/work_type_spec.rb +++ b/spec/graphql/types/work_type_spec.rb @@ -526,7 +526,7 @@ response = LupoSchema.execute(query, context: { current_user: current_user }).as_json expect(response.dig("data", "createClaim", "claim", "id")).to eq("d140d44e-af70-43ec-a90b-49878a954487") - expect(response.dig("data", "createClaim", "claim", "sourceId")).to eq("auto_update") + expect(response.dig("data", "createClaim", "claim", "sourceId")).to eq("orcid_update") expect(response.dig("data", "createClaim", "claim", "state")).to eq("failed") expect(response.dig("data", "createClaim", "claim", "errorMessages")).to eq([{"title"=>"Missing data"}]) expect(response.dig("data", "createClaim", "errors")).to be_empty diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index da1bc7d9c..b7b55293e 100644 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -1561,8 +1561,9 @@ it 'fails to create a Doi' do post '/dois', valid_attributes, headers - puts last_response.body + expect(last_response.status).to eq(422) + expect(json.fetch('errors', nil)).to eq([{"source"=>"url", "title"=>"URL is not allowed by repository domain settings."}]) end end