Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Default visibility to public, ref #729
Browse files Browse the repository at this point in the history
Defaults visibility to public at the form level.

Also includes refactoring feature tests to accommodate the change.
  • Loading branch information
awead authored and carolyncole committed Apr 14, 2017
1 parent ae05ab4 commit d8bd687
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 30 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ RSpec/DescribeClass:
- 'spec/config/**/*'
- 'spec/models/batch_spec.rb'
- 'spec/features/**/*'
- 'spec/support/**/*'
1 change: 1 addition & 0 deletions app/forms/batch_upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class BatchUploadForm < Sufia::Forms::BatchUploadForm

include WithCreator
include WithCleanerAttributes
include WithOpenAccess

def self.multiple?(term)
CurationConcerns::GenericWorkForm.multiple?(term)
Expand Down
12 changes: 12 additions & 0 deletions app/forms/concerns/with_open_access.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/forms/curation_concerns/generic_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 36 additions & 13 deletions spec/features/generic_work/upload_and_delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand All @@ -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"
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/forms/batch_upload_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions spec/forms/generic_work_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 0 additions & 17 deletions spec/support/helpers/generic_works.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/support/shared/forms.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d8bd687

Please sign in to comment.