Skip to content

Commit

Permalink
allow but ignore doi read-only attributes. #411
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 7, 2020
1 parent 13839fc commit 5876cc0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
25 changes: 21 additions & 4 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,22 @@ def safe_params
:fundingReferences,
{ fundingReferences: [:funderName, :funderIdentifier, :funderIdentifierType, :awardNumber, :awardUri, :awardTitle] },
:geoLocations,
{ geoLocations: [{ geoLocationPoint: [:pointLongitude, :pointLatitude] }, { geoLocationBox: [:westBoundLongitude, :eastBoundLongitude, :southBoundLatitude, :northBoundLatitude] }, :geoLocationPlace] }
{ geoLocations: [{ geoLocationPoint: [:pointLongitude, :pointLatitude] }, { geoLocationBox: [:westBoundLongitude, :eastBoundLongitude, :southBoundLatitude, :northBoundLatitude] }, :geoLocationPlace] },
:container,
{ container: [:type, :identifier, :identifierType, :title, :volume, :issue, :firstPage, :lastPage] },
:published,
:downloadsOverTime,
{ downloadsOverTime: [:yearMonth, :total] },
:viewsOverTime,
{ viewsOverTime: [:yearMonth, :total] },
:citationCount,
:downloadCount,
:partCount,
:partOfCount,
:referenceCount,
:versionCount,
:versionOfCount,
:viewCount,
]
relationships = [{ client: [data: [:type, :id]] }]

Expand Down Expand Up @@ -706,13 +721,15 @@ def safe_params
:confirmDoi, :prefix, :suffix, :publicationYear,
:rightsList, :relatedIdentifiers, :fundingReferences, :geoLocations,
:metadataVersion, :schemaVersion, :state, :mode, :isActive, :landingPage,
:created, :registered, :updated, :lastLandingPage, :version,
:created, :registered, :updated, :published, :lastLandingPage, :version,
:lastLandingPageStatus, :lastLandingPageStatusCheck,
:lastLandingPageStatusResult, :lastLandingPageContentType, :contentUrl)
:lastLandingPageStatusResult, :lastLandingPageContentType, :contentUrl,
:viewsOverTime, :downloadsOverTime, :citationCount, :downloadCount,
:partCount, :partOfCount, :referenceCount, :versionCount, :versionOfCount, :viewCount)
end

def set_raven_context
return nil unless params.dig(:data, :attributes, :xml).present?
return nil if params.dig(:data, :attributes, :xml).blank?

Raven.extra_context metadata: Base64.decode64(params.dig(:data, :attributes, :xml))
end
Expand Down
42 changes: 39 additions & 3 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe "dois", type: :request do
let(:admin) { create(:provider, symbol: "ADMIN") }
let(:admin_bearer) { Client.generate_token(role_id: "staff_admin", uid: admin.symbol, password: admin.password) }
let(:admin_headers) { { 'HTTP_ACCEPT'=>'application/vnd.api+json', 'HTTP_AUTHORIZATION' => 'Bearer ' + admin_bearer} }
let(:admin_headers) { { "HTTP_ACCEPT" => "application/vnd.api+json", "HTTP_AUTHORIZATION" => "Bearer " + admin_bearer} }

let(:provider) { create(:provider, symbol: "DATACITE") }
let(:client) { create(:client, provider: provider, symbol: ENV['MDS_USERNAME'], password: ENV['MDS_PASSWORD']) }
Expand All @@ -12,7 +12,7 @@

let(:doi) { create(:doi, client: client) }
let(:bearer) { Client.generate_token(role_id: "client_admin", uid: client.symbol, provider_id: provider.symbol.downcase, client_id: client.symbol.downcase, password: client.password) }
let(:headers) { { 'HTTP_ACCEPT'=>'application/vnd.api+json', 'HTTP_AUTHORIZATION' => 'Bearer ' + bearer }}
let(:headers) { { "HTTP_ACCEPT" => "application/vnd.api+json", "HTTP_AUTHORIZATION" => "Bearer " + bearer }}

describe "GET /dois", elasticsearch: true do
let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") }
Expand Down Expand Up @@ -363,7 +363,7 @@
end
end

describe 'state' do
describe "state" do
let(:doi_id) { "10.14454/4K3M-NYVG" }
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
let(:bearer) { User.generate_token(role_id: "client_admin", client_id: client.symbol.downcase) }
Expand Down Expand Up @@ -561,6 +561,42 @@
end
end

context 'read-only attributes' 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/pat.pdf",
"xml" => xml,
"container" => {},
"published" => nil,
"viewsOverTime" => {},
"downloadsOverTime" => {},
"viewCount" => 0,
"downloadCount" => 0,
"citationCount" => 0,
"partCount" => 0,
"partOfCount" => 0,
"referenceCount" => 0,
"versionCount" => 0,
"versionOfCount" => 0
}
}
}
end

it 'updates the record' do
patch "/dois/#{doi.doi}", valid_attributes, headers

expect(last_response.status).to eq(200)
expect(json.dig('data', 'attributes', 'url')).to eq("http://www.bl.uk/pdf/pat.pdf")
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Eating your own Dog Food"}])
end
end

context 'when the record exists no data attribute' do
let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) }
let(:valid_attributes) do
Expand Down

0 comments on commit 5876cc0

Please sign in to comment.