From db634ca06813bf5ca77fe42a0845963ee733f40b Mon Sep 17 00:00:00 2001 From: val99erie Date: Wed, 19 Jun 2019 15:13:42 -0500 Subject: [PATCH] Add visibility field to importer. Story 679 * There is a list of allowed values for visibility. * If the CSV file doesn't specify visibility, it defaults to the most restricted level of access. * Out of scope: The importer cannot handle visibility values of 'embargo' or 'lease'. If we need that functionality in the future, we can add that code later. --- app/assets/markdown/importer_guide.md | 15 +++++ app/importers/californica_mapper.rb | 22 +++++++- app/uploaders/csv_manifest_validator.rb | 3 +- spec/fixtures/coordinates_example.csv | 4 +- spec/importers/californica_mapper_spec.rb | 67 +++++++++++++++++++++-- 5 files changed, 101 insertions(+), 10 deletions(-) diff --git a/app/assets/markdown/importer_guide.md b/app/assets/markdown/importer_guide.md index a425904a..f822c2bc 100644 --- a/app/assets/markdown/importer_guide.md +++ b/app/assets/markdown/importer_guide.md @@ -36,6 +36,7 @@ * [Subject](#subject) * [Type.genre](#type.genre) * [Type.typeOfResource](#type.typeofresource) +* [Visibility](#visibility) ## Required Fields @@ -139,3 +140,17 @@ accepts AltTitle.translated ### Subject ### Type.genre ### Type.typeOfResource + +### Visibility + +A single-value field that must contain one of the allowed values. + +This field is not required. If you omit this column or leave the value blank, it will default to `private` visibility (to avoid accidentally exposing records that should be restricted). + +Examples: + +* `public` - All users can view the record +* `authenticated` - Logged in users can view the record +* `discovery` - All users can view the metadata, but not the files +* `private` - Only admin users or users who have been granted special permission may view the record + diff --git a/app/importers/californica_mapper.rb b/app/importers/californica_mapper.rb index 7d9c8870..8d88a7fb 100644 --- a/app/importers/californica_mapper.rb +++ b/app/importers/californica_mapper.rb @@ -49,7 +49,7 @@ def initialize(attributes = {}) # What columns are allowed in the CSV def self.allowed_headers CALIFORNICA_TERMS_MAP.values + - ['File Name', 'Parent ARK', 'Project Name', 'Object Type', 'Item Sequence'] + ['File Name', 'Parent ARK', 'Project Name', 'Object Type', 'Item Sequence', 'Visibility'] end # What columns must exist in the CSV @@ -101,7 +101,25 @@ def remote_files end def visibility - Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC + value_from_csv = metadata['Visibility']&.squish&.downcase + visibility_mapping.fetch(value_from_csv, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE) + end + + # The visibility values have different values when + # they are calculated or indexed in solr than the + # values that appear in the UI edit form. We should + # accept both. + def visibility_mapping + { + 'private' => Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, + 'restricted' => Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, + 'discovery' => ::Work::VISIBILITY_TEXT_VALUE_DISCOVERY, + 'authenticated' => Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED, + 'registered' => Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED, + 'ucla' => Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED, + 'open' => Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, + 'public' => Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC + }.freeze end def ark diff --git a/app/uploaders/csv_manifest_validator.rb b/app/uploaders/csv_manifest_validator.rb index cee66aa7..7337faaf 100644 --- a/app/uploaders/csv_manifest_validator.rb +++ b/app/uploaders/csv_manifest_validator.rb @@ -62,7 +62,8 @@ 'Rights.servicesContact', 'Subject', 'Type.genre', - 'Type.typeOfResource' + 'Type.typeOfResource', + 'Visibility' ].freeze CONTROLLED_VOCABULARIES = { diff --git a/spec/fixtures/coordinates_example.csv b/spec/fixtures/coordinates_example.csv index a46c0115..802ac5e1 100644 --- a/spec/fixtures/coordinates_example.csv +++ b/spec/fixtures/coordinates_example.csv @@ -1,2 +1,2 @@ -Project Name,Parent ARK,Item ARK,Subject,Type.typeOfResource,Rights.copyrightStatus,Type.genre,Name.subject,Coverage.geographic,Relation.isPartOf,Publisher.publisherName,Rights.countryCreation,Rights.rightsHolderContact,Name.architect,Name.photographer,Name.repository,Date.normalized,AltIdentifier.local,Title,Date.creation,Format.extent,Format.medium,Format.dimensions,Description.note,Description.fundingNote,Description.longitude,Description.latitude,Description.caption,File Name,AltTitle.other,AltTitle.translated,Place of origin,AltTitle.uniform -Los Angeles Daily News Negatives,111/222,13030/hb338nb26f,"Altars|~|Mass|~|Communion table|~|Mexican American Catholics|~|Festivals|~|Guadalupe, Our Lady of|~|Historic buildings $z California $z Los Angeles|~|Churches $z California $z Los Angeles|~|Religion|~|Catholic churches $z California $z Los Angeles ",still image,copyrighted,news photographs,"Plaza Church (Los Angeles, Calif.)",Los Angeles (Calif.)|~|Los Angeles (Calif.),"Los Angeles Daily News Negatives. Department of Special Collections, Charles E. Young Research Library, University of California at Los Angeles.",Los Angeles Daily News,US,"UCLA Charles E. Young Research Library Department of Special Collections, A1713 Young Research Library, Box 951575, Los Angeles, CA 90095-1575. E-mail: spec-coll@library.ucla.edu. Phone: (310)825-4988",Imhotep,Famous Photographer,,1942/1952,uclamss_1387_b112_40911-1,"Communion at Plaza Church, Los Angeles, 1942-1952",[between 1942-1947],Fake Extent,Fake Medium,200x200,"A woman takes Communion during a Plaza Church mass for the fiesta of Nuestra Senora de Guadalupe.|~|Our Lady Queen of Los Angeles Catholic Church, (aka La Iglesia de Nuestra Señora la Reina de Los Ángeles, and The Church of Our Lady the Queen of the Angels), was built in 1822 and is the oldest church in Los Angeles.",Fake Funding Note,-118.239577,34.05707,Fake Caption,clusc_1_1_00010432a.tif,"Communion table","Mesa de Comunión",Los Angeles,Mexican American Catholics +Project Name,Parent ARK,Item ARK,Visibility,Subject,Type.typeOfResource,Rights.copyrightStatus,Type.genre,Name.subject,Coverage.geographic,Relation.isPartOf,Publisher.publisherName,Rights.countryCreation,Rights.rightsHolderContact,Name.architect,Name.photographer,Name.repository,Date.normalized,AltIdentifier.local,Title,Date.creation,Format.extent,Format.medium,Format.dimensions,Description.note,Description.fundingNote,Description.longitude,Description.latitude,Description.caption,File Name,AltTitle.other,AltTitle.translated,Place of origin,AltTitle.uniform +Los Angeles Daily News Negatives,111/222,13030/hb338nb26f,public,"Altars|~|Mass|~|Communion table|~|Mexican American Catholics|~|Festivals|~|Guadalupe, Our Lady of|~|Historic buildings $z California $z Los Angeles|~|Churches $z California $z Los Angeles|~|Religion|~|Catholic churches $z California $z Los Angeles ",still image,copyrighted,news photographs,"Plaza Church (Los Angeles, Calif.)",Los Angeles (Calif.)|~|Los Angeles (Calif.),"Los Angeles Daily News Negatives. Department of Special Collections, Charles E. Young Research Library, University of California at Los Angeles.",Los Angeles Daily News,US,"UCLA Charles E. Young Research Library Department of Special Collections, A1713 Young Research Library, Box 951575, Los Angeles, CA 90095-1575. E-mail: spec-coll@library.ucla.edu. Phone: (310)825-4988",Imhotep,Famous Photographer,,1942/1952,uclamss_1387_b112_40911-1,"Communion at Plaza Church, Los Angeles, 1942-1952",[between 1942-1947],Fake Extent,Fake Medium,200x200,"A woman takes Communion during a Plaza Church mass for the fiesta of Nuestra Senora de Guadalupe.|~|Our Lady Queen of Los Angeles Catholic Church, (aka La Iglesia de Nuestra Señora la Reina de Los Ángeles, and The Church of Our Lady the Queen of the Angels), was built in 1822 and is the oldest church in Los Angeles.",Fake Funding Note,-118.239577,34.05707,Fake Caption,clusc_1_1_00010432a.tif,Communion table,Mesa de Comunión,Los Angeles,Mexican American Catholics diff --git a/spec/importers/californica_mapper_spec.rb b/spec/importers/californica_mapper_spec.rb index 007ebbe6..655ee29f 100644 --- a/spec/importers/californica_mapper_spec.rb +++ b/spec/importers/californica_mapper_spec.rb @@ -54,11 +54,6 @@ .to contain_exactly(url: match(/clusc_1_1_00010432a\.tif/)) end - it "maps visibility to open" do - expect(mapper.visibility) - .to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC - end - context 'with a blank filename' do let(:metadata) do { "Item ARK" => "21198/zz0002nq4w", @@ -323,4 +318,66 @@ end end end + + describe '#visibility' do + subject { mapper.visibility } + + let(:private_vis) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE } + let(:disc_vis) { ::Work::VISIBILITY_TEXT_VALUE_DISCOVERY } + let(:auth_vis) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED } + let(:public_vis) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC } + + context 'when visibility field is blank' do + let(:metadata) { {} } + + it 'defaults to private visibility' do + expect(mapper.visibility).to eq private_vis + end + end + + context 'visibility: private' do + let(:metadata) { { 'Visibility' => 'private' } } + it { is_expected.to eq private_vis } + end + + context 'visibility: restricted' do + let(:metadata) { { 'Visibility' => 'restricted' } } + it { is_expected.to eq private_vis } + end + + context 'visibility: discovery' do + let(:metadata) { { 'Visibility' => 'discovery' } } + it { is_expected.to eq disc_vis } + end + + context 'visibility: authenticated' do + let(:metadata) { { 'Visibility' => 'authenticated' } } + it { is_expected.to eq auth_vis } + end + + context 'visibility: registered' do + let(:metadata) { { 'Visibility' => 'registered' } } + it { is_expected.to eq auth_vis } + end + + context 'visibility: UCLA' do + let(:metadata) { { 'Visibility' => 'UCLA' } } + it { is_expected.to eq auth_vis } + end + + context 'visibility: public' do + let(:metadata) { { 'Visibility' => 'public' } } + it { is_expected.to eq public_vis } + end + + context 'visibility: open' do + let(:metadata) { { 'Visibility' => 'open' } } + it { is_expected.to eq public_vis } + end + + context 'with different capitalization and whitespace' do + let(:metadata) { { 'Visibility' => ' Public ' } } + it { is_expected.to eq public_vis } + end + end end