Skip to content

Commit

Permalink
validate contributor roles. datacite/bracco#454
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 8, 2020
1 parent 1846afd commit 2ff7784
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,9 @@ def check_creators
def check_contributors
Array.wrap(contributors).each do |c|
errors.add(:contributors, "Contributor '#{c}' should be an object instead of a string.") unless c.is_a?(Hash)
if schema_version == "http://datacite.org/schema/kernel-4"
errors.add(:contributors, "Contributor type #{c["contributorType"]} is not supported in schema 4.") unless %w(ContactPerson DataCollector DataCurator DataManager Distributor Editor HostingInstitution Other Producer ProjectLeader ProjectManager ProjectMember RegistrationAgency RegistrationAuthority RelatedPerson ResearchGroup RightsHolder Researcher Sponsor Supervisor WorkPackageLeader).include?(c["contributorType"])
end
end
end

Expand Down
47 changes: 47 additions & 0 deletions spec/requests/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,32 @@
end
end

context 'when the request creates schema 3 with funder contributor type' do
let(:xml) { Base64.strict_encode64(file_fixture('datacite_schema_3.xml').read) }
let(:valid_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"doi" => "10.14454/10703",
"url" => "http://www.bl.uk/pdf/patspec.pdf",
"xml" => xml,
"contributors" => [{"contributorType"=>"Funder", "name"=>"Wellcome Trust", "nameType"=>"Organizational"}],
"source" => "test",
"event" => "publish"
}
}
}
end

it 'creates a Doi' do
post '/dois', valid_attributes, headers

expect(last_response.status).to eq(422)
expect(json.fetch('errors', nil)).to eq([{"source"=>"xml", "title"=>"Schema http://datacite.org/schema/kernel-2.2 is no longer supported"}])
end
end

context 'when the request has wrong object in nameIDentifiers' do
let(:valid_attributes) { JSON.parse(file_fixture('datacite_wrong_nameIdentifiers.json').read) }

Expand Down Expand Up @@ -2990,6 +3016,27 @@
end
end

# Funder has been removed as valid contributor type in schema 4.0
context 'update contributor type with funder', elasticsearch: true do
let(:update_attributes) do
{
"data" => {
"type" => "dois",
"attributes" => {
"contributors" => [{"contributorType"=>"Funder", "name"=>"Wellcome Trust", "nameType"=>"Organizational"}],
}
}
}
end

it 'updates the Doi' do
patch "/dois/#{doi.doi}", update_attributes, headers
puts last_response.body
expect(last_response.status).to eq(422)
expect(json["errors"]).to eq([{"source"=>"contributors", "title"=>"Contributor type Funder is not supported in schema 4."}])
end
end

context 'update rightsList', elasticsearch: true do
let(:rights_list) { [{ "rightsIdentifier"=>"CC0-1.0" }] }
let(:update_attributes) do
Expand Down

0 comments on commit 2ff7784

Please sign in to comment.