From 1f2da3f32db4b17ed3614427a3492784f5e6c3d5 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 17 Jun 2019 17:42:08 +0200 Subject: [PATCH] require prefix for random dois. #235 --- app/controllers/dois_controller.rb | 6 +---- spec/requests/dois_spec.rb | 41 ------------------------------ 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 26004e13a..cc4a3f621 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -424,7 +424,7 @@ def get_dois authorize! :get_urls, Doi client = Client.where('datacentre.symbol = ?', current_user.uid.upcase).first - client_prefix = client.prefixes.where.not('prefix.prefix = ?', "10.5072").first + client_prefix = client.prefixes.first head :no_content and return unless client_prefix.present? dois = Doi.get_dois(prefix: client_prefix.prefix, username: current_user.uid.upcase, password: current_user.password) @@ -588,10 +588,6 @@ def safe_params # generate random DOI if no DOI is provided if p[:doi].blank? && p[:prefix].present? p[:doi] = generate_random_dois(p[:prefix]).first - elsif p[:doi].blank? && client_id.present? - client = Client.where('datacentre.symbol = ?', client_id).first - client_prefix = client.client_prefixes.joins(:prefix).first - p[:doi] = generate_random_dois(client_prefix.prefix.prefix).first if client_prefix end # replace DOI, but otherwise don't touch the XML diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index a81f8e738..72b484dca 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -872,47 +872,6 @@ end end - context 'when the request is valid random doi with client prefix' do - let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) } - let(:valid_attributes) do - { - "data" => { - "type" => "dois", - "attributes" => { - "url" => "http://www.bl.uk/pdf/patspec.pdf", - "xml" => xml, - "source" => "test", - "event" => "publish" - } - } - } - end - - it 'creates a Doi' do - post '/dois', valid_attributes, headers - - expect(last_response.status).to eq(201) - expect(json.dig('data', 'attributes', 'url')).to eq("http://www.bl.uk/pdf/patspec.pdf") - expect(json.dig('data', 'attributes', 'doi')).to start_with("10.14454") - expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Eating your own Dog Food"}]) - expect(json.dig('data', 'attributes', 'creators')).to eq([{"familyName"=>"Fenner", - "givenName"=>"Martin", - "name"=>"Fenner, Martin", - "nameIdentifiers"=> - [{"nameIdentifier"=>"https://orcid.org/0000-0003-1419-2405", - "nameIdentifierScheme"=>"ORCID", - "schemeUri"=>"https://orcid.org"}], - "nameType"=>"Personal"}]) - expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-4") - expect(json.dig('data', 'attributes', 'source')).to eq("test") - expect(json.dig('data', 'attributes', 'types')).to eq("bibtex"=>"article", "citeproc"=>"article-journal", "resourceType"=>"BlogPosting", "resourceTypeGeneral"=>"Text", "ris"=>"RPRT", "schemaOrg"=>"ScholarlyArticle") - expect(json.dig('data', 'attributes', 'state')).to eq("findable") - - doc = Nokogiri::XML(Base64.decode64(json.dig('data', 'attributes', 'xml')), nil, 'UTF-8', &:noblanks) - expect(doc.at_css("identifier").content).to start_with("10.14454") - end - end - context 'when the request is valid with attributes' do let(:valid_attributes) do {