From d8bd6876f80bea66b12ab3c13f6909851b18eb00 Mon Sep 17 00:00:00 2001 From: Adam Wead Date: Wed, 12 Apr 2017 11:13:18 -0400 Subject: [PATCH] Default visibility to public, ref #729 Defaults visibility to public at the form level. Also includes refactoring feature tests to accommodate the change. --- .rubocop.yml | 1 + app/forms/batch_upload_form.rb | 1 + app/forms/concerns/with_open_access.rb | 12 +++++ .../curation_concerns/generic_work_form.rb | 1 + .../generic_work/upload_and_delete_spec.rb | 49 ++++++++++++++----- spec/forms/batch_upload_form_spec.rb | 2 + spec/forms/generic_work_form_spec.rb | 11 +++++ spec/support/helpers/generic_works.rb | 17 ------- spec/support/shared/forms.rb | 9 ++++ 9 files changed, 73 insertions(+), 30 deletions(-) create mode 100644 app/forms/concerns/with_open_access.rb create mode 100644 spec/support/shared/forms.rb diff --git a/.rubocop.yml b/.rubocop.yml index bf9998c64..8f85fc439 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -166,3 +166,4 @@ RSpec/DescribeClass: - 'spec/config/**/*' - 'spec/models/batch_spec.rb' - 'spec/features/**/*' + - 'spec/support/**/*' diff --git a/app/forms/batch_upload_form.rb b/app/forms/batch_upload_form.rb index 99ca78bcb..a735a5e98 100644 --- a/app/forms/batch_upload_form.rb +++ b/app/forms/batch_upload_form.rb @@ -4,6 +4,7 @@ class BatchUploadForm < Sufia::Forms::BatchUploadForm include WithCreator include WithCleanerAttributes + include WithOpenAccess def self.multiple?(term) CurationConcerns::GenericWorkForm.multiple?(term) diff --git a/app/forms/concerns/with_open_access.rb b/app/forms/concerns/with_open_access.rb new file mode 100644 index 000000000..90dcce83e --- /dev/null +++ b/app/forms/concerns/with_open_access.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +# When included in a form class, this defaults any new record to public visibility +module WithOpenAccess + extend ActiveSupport::Concern + + included do + def visibility + return Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC if model.new_record? + model.visibility + end + end +end diff --git a/app/forms/curation_concerns/generic_work_form.rb b/app/forms/curation_concerns/generic_work_form.rb index 240873e87..f3115cb80 100644 --- a/app/forms/curation_concerns/generic_work_form.rb +++ b/app/forms/curation_concerns/generic_work_form.rb @@ -10,6 +10,7 @@ class GenericWorkForm < Sufia::Forms::WorkForm include HydraEditor::Form::Permissions include WithCreator include WithCleanerAttributes + include WithOpenAccess def self.multiple?(term) return false if term == :rights diff --git a/spec/features/generic_work/upload_and_delete_spec.rb b/spec/features/generic_work/upload_and_delete_spec.rb index 6c6b4a429..d56c97e03 100644 --- a/spec/features/generic_work/upload_and_delete_spec.rb +++ b/spec/features/generic_work/upload_and_delete_spec.rb @@ -37,6 +37,20 @@ attach_file('files[]', test_file_path(filename), visible: false) check 'agreement' + # Check visibility + within("#savewidget") do + expect(page).to have_content("Visibility") + expect(page).to have_content("Public") + expect(page).to have_content("Embargo") + expect(page).to have_content("Private") + expect(page).to have_content("Penn State") + expect(page).to have_checked_field("Public") + expect(page).to have_content("marking this as Public") + sleep(1.second) + choose 'generic_work_visibility_restricted' + expect(page).not_to have_content("marking this as Public") + end + # Enter required metadata click_link("Metadata") fill_in 'generic_work_title', with: 'Upload test' @@ -73,15 +87,6 @@ find('#new_user_permission_skel').find(:xpath, 'option[2]').select_option click_on('add_new_user_skel') within("#share") { expect(page).to have_content(other_user.user_key) } - - # Check visibility - within("#savewidget") do - expect(page).to have_content("Visibility") - expect(page).to have_content("Public") - expect(page).to have_content("Embargo") - expect(page).to have_content("Private") - expect(page).to have_content("Penn State") - end end end @@ -119,6 +124,9 @@ within "tr.template-download" do expect(page).to have_content "Markdown Test.txt" end + within("#savewidget") do + choose 'generic_work_visibility_restricted' + end check 'agreement' click_on 'Metadata' fill_in 'generic_work_title', with: 'Markdown Test' @@ -127,7 +135,9 @@ select 'Attribution-NonCommercial-NoDerivatives 4.0 International', from: 'generic_work_rights' fill_in 'generic_work_description', with: 'My description' select 'Audio', from: 'generic_work_resource_type' + sleep(1.second) click_on 'Save' + expect(page).to have_content 'Your files are being processed' expect(page).to have_css('h1', 'Markdown Test') click_on "Notifications" expect(page).to have_content "The file (Markdown Test.txt) was successfully imported" @@ -137,12 +147,25 @@ context 'user does not need help' do context 'with a single file' do - before do - create_work_and_upload_file(filename) - allow(ShareNotifyDeleteJob).to receive(:perform_later) - end + before { allow(ShareNotifyDeleteJob).to receive(:perform_later) } specify 'uploading, deleting and notifications' do + visit '/concern/generic_works/new' + click_on 'Files' + attach_file('files[]', test_file_path(filename), visible: false) + click_on 'Metadata' + fill_in 'generic_work_title', with: filename + '_title' + fill_in 'generic_work_keyword', with: filename + '_keyword' + fill_in 'generic_work_creator', with: filename + '_creator' + fill_in 'generic_work_description', with: filename + '_description' + select 'Audio', from: 'generic_work_resource_type' + select 'Attribution-NonCommercial-NoDerivatives 4.0 International', from: 'generic_work_rights' + within("#savewidget") do + choose 'generic_work_visibility_restricted' + end + check 'agreement' + click_on 'Save' + expect(page).to have_css('h1', filename + '_title') click_link "My Dashboard" expect(page).to have_css "table#activity" within("table#activity") do diff --git a/spec/forms/batch_upload_form_spec.rb b/spec/forms/batch_upload_form_spec.rb index c5bce9ab0..42cf4263a 100644 --- a/spec/forms/batch_upload_form_spec.rb +++ b/spec/forms/batch_upload_form_spec.rb @@ -26,4 +26,6 @@ let(:raw_attrs) { ActionController::Parameters.new("creator" => ["Santy, Lorraine C", ""], "keyword" => ["hhh"], "rights" => "https://creativecommons.org/licenses/by/4.0/", "description" => ["ghjg"], "contributor" => [""], "publisher" => [""], "date_created" => [""], "subject" => [""], "language" => [""], "identifier" => [""], "based_near" => [""], "related_url" => [""], "source" => [""], "admin_set_id" => "", "collection_ids" => [""], "visibility_during_embargo" => "restricted", "embargo_release_date" => "2017-01-24", "visibility_after_embargo" => "open", "visibility_during_lease" => "open", "lease_expiration_date" => "2017-01-24", "visibility_after_lease" => "restricted", "visibility" => "restricted") } it { is_expected.to eq("creator" => ["Santy, Lorraine C"], "keyword" => ["hhh"], "rights" => "https://creativecommons.org/licenses/by/4.0/", "description" => ["ghjg"], "contributor" => [], "publisher" => [], "date_created" => [], "subject" => [], "language" => [], "identifier" => [], "based_near" => [], "related_url" => [], "source" => [], "admin_set_id" => "", "collection_ids" => [], "visibility_during_embargo" => "restricted", "embargo_release_date" => "2017-01-24", "visibility_after_embargo" => "open", "visibility_during_lease" => "open", "lease_expiration_date" => "2017-01-24", "visibility_after_lease" => "restricted", "visibility" => "restricted") } end + + it_behaves_like "a standard work form" end diff --git a/spec/forms/generic_work_form_spec.rb b/spec/forms/generic_work_form_spec.rb index 5977f75d7..b240dc44a 100644 --- a/spec/forms/generic_work_form_spec.rb +++ b/spec/forms/generic_work_form_spec.rb @@ -18,4 +18,15 @@ it { is_expected.to include(title: ["I am in a space"], rights: "url") } end end + + it_behaves_like "a standard work form" + + describe "#visibility" do + subject { work } + context "with an existing work" do + let(:work) { build(:private_work) } + before { allow(work).to receive(:new_record?).and_return(false) } + its(:visibility) { is_expected.to eq("restricted") } + end + end end diff --git a/spec/support/helpers/generic_works.rb b/spec/support/helpers/generic_works.rb index e2476b65c..3c7105c27 100644 --- a/spec/support/helpers/generic_works.rb +++ b/spec/support/helpers/generic_works.rb @@ -6,23 +6,6 @@ def wait_for_page(redirect_url) end end - def create_work_and_upload_file(filename) - allow(ShareNotifyJob).to receive(:perform_later) - visit '/concern/generic_works/new' - check 'agreement' - click_on 'Files' - attach_file('files[]', test_file_path(filename), visible: false) - click_on 'Metadata' - fill_in 'generic_work_title', with: filename + '_title' - fill_in 'generic_work_keyword', with: filename + '_keyword' - fill_in 'generic_work_creator', with: filename + '_creator' - fill_in 'generic_work_description', with: filename + '_description' - select 'Audio', from: 'generic_work_resource_type' - select 'Attribution-NonCommercial-NoDerivatives 4.0 International', from: 'generic_work_rights' - click_on 'Save' - expect(page).to have_css('h1', filename + '_title') - end - def find_work_by_title(title) GenericWork.where(Solrizer.solr_name("title", :stored_searchable, type: :string) => title).first end diff --git a/spec/support/shared/forms.rb b/spec/support/shared/forms.rb new file mode 100644 index 000000000..da76e5712 --- /dev/null +++ b/spec/support/shared/forms.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true +shared_examples "a standard work form" do + describe "#visibility" do + subject { form } + context "with a new work" do + its(:visibility) { is_expected.to eq("open") } + end + end +end