diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index fac859e7c..7524c559a 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -378,7 +378,11 @@ def update @doi.assign_attributes(safe_params.slice(:client_id)) else authorize! :update, @doi - @doi.assign_attributes(safe_params.except(:doi, :client_id)) + if safe_params[:schema_version].blank? + @doi.assign_attributes(safe_params.except(:doi, :client_id).merge(schema_version: @doi[:schema_version] || LAST_SCHEMA_VERSION)) + else + @doi.assign_attributes(safe_params.except(:doi, :client_id)) + end end else doi_id = validate_doi(params[:id]) @@ -647,7 +651,7 @@ def safe_params meta = xml.present? ? parse_xml(xml, doi: p[:doi]) : {} p[:schemaVersion] = METADATA_FORMATS.include?(meta["from"]) ? LAST_SCHEMA_VERSION : p[:schemaVersion] xml = meta["string"] - + # if metadata for DOIs from other registration agencies are not found fail ActiveRecord::RecordNotFound if meta["state"] == "not_found" @@ -686,7 +690,7 @@ def safe_params p[:version_info] = p[:version] || meta["version_info"] if p.has_key?(:version) || meta["version_info"].present? # only update landing_page info if something is received via API to not overwrite existing data p.merge!(landing_page: p[:landingPage]) if p[:landingPage].present? - + p.merge( regenerate: p[:regenerate] || regenerate ).except( diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index 85b1fdf93..b8d469d32 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -2859,6 +2859,55 @@ # end end + context 'mds doi' do + let(:xml) { Base64.strict_encode64(file_fixture('datacite_schema_3.xml').read) } + let(:valid_attributes) do + { + "data" => { + "type" => "dois", + "attributes" => { + "url" => "http://www.bl.uk/pdf/patspec.pdf", + "should_validate" => "true", + "source" => "mds", + "event" => "publish" + } + } + } + end + + let(:update_attributes) do + { + "data" => { + "type" => "dois", + "attributes" => { + "doi" => "10.14454/10703", + "should_validate" => "true", + "xml" => xml, + "source" => "mds", + "event" => "show" + } + } + } + end + + + it 'add metadata' do + puts "####FIRST ROUND" + put "/dois/10.14454/10703", update_attributes, headers + + puts json + expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703") + expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-3") + + puts "####SECOND ROUND" + put '/dois/10.14454/10703', valid_attributes, headers + + expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703") + expect(json.dig('data', 'attributes', 'schemaVersion')).to eq("http://datacite.org/schema/kernel-3") + expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Data from: A new malaria agent in African hominids."}]) + end + end + context 'update rightsList' do let(:rights_list) { [{ "rights" => "Creative Commons Attribution 3.0", "rightsUri" => "http://creativecommons.org/licenses/by/3.0/", "lang" => "en"}] } let(:update_attributes) do