diff --git a/app/controllers/concerns/curation_concerns/upload_sets_controller_behavior.rb b/app/controllers/concerns/curation_concerns/upload_sets_controller_behavior.rb deleted file mode 100644 index ffe2b821b..000000000 --- a/app/controllers/concerns/curation_concerns/upload_sets_controller_behavior.rb +++ /dev/null @@ -1,50 +0,0 @@ -module CurationConcerns - module UploadSetsControllerBehavior - extend ActiveSupport::Concern - include Hydra::Controller::ControllerBehavior - - included do - include CurationConcerns::ThemedLayoutController - with_themed_layout '1_column' - - class_attribute :edit_form_class - self.edit_form_class = CurationConcerns::UploadSetForm - end - - def edit - # TODO: redlock this line so that two processes don't attempt to create at the same time. - @upload_set = UploadSet.find_or_create(params[:id]) - @form = edit_form - end - - def update - authenticate_user! - @upload_set = UploadSet.find(params[:id]) - @upload_set.status = ["processing"] - @upload_set.save - create_update_job - flash[:notice] = 'Your files are being processed by ' + t('curation_concerns.product_name') + ' in the background. The metadata and access controls you specified are being applied. Files will be marked Private until this process is complete (shouldn\'t take too long, hang in there!). You may need to refresh your dashboard to see these updates.' - - redirect_after_update - end - - protected - - # Override this method if you want to go elsewhere - def redirect_after_update - redirect_to main_app.curation_concerns_generic_works_path - end - - def edit_form - edit_form_class.new(@upload_set, current_ability) - end - - def create_update_job - UploadSetUpdateJob.perform_later(current_user.user_key, - params[:id], - params[:title], - edit_form_class.model_attributes(params[:upload_set]), - params[:visibility]) - end - end -end diff --git a/app/controllers/upload_sets_controller.rb b/app/controllers/upload_sets_controller.rb deleted file mode 100644 index c7ab0950b..000000000 --- a/app/controllers/upload_sets_controller.rb +++ /dev/null @@ -1,3 +0,0 @@ -class UploadSetsController < ApplicationController - include CurationConcerns::UploadSetsControllerBehavior -end diff --git a/app/forms/curation_concerns/upload_set_form.rb b/app/forms/curation_concerns/upload_set_form.rb deleted file mode 100644 index dae3474a3..000000000 --- a/app/forms/curation_concerns/upload_set_form.rb +++ /dev/null @@ -1,43 +0,0 @@ -module CurationConcerns - class UploadSetForm - include HydraEditor::Form - - self.terms = CurationConcerns::GenericWorkForm.terms - - delegate :creator, :human_readable_type, :open_access?, :authenticated_only_access?, - :open_access_with_embargo_release_date?, :private_access?, - :embargo_release_date, :lease_expiration_date, :member_ids, to: :exemplar_work - - def initialize(upload_set, current_ability) - @current_ability = current_ability - super(upload_set) - # TODO: instead of using GenericWorkForm, this should be an UploadSetForm - # work = ::GenericWork.new(creator: [creator_display], title: titles) - end - - def exemplar_work - @exemplar_work ||= GenericWork.new(creator: [creator_display]) - end - - # @return [Array] a list of the first titles for each of the works. - def works - @works ||= model.works.sort { |w1, w2| w1.title.first.downcase <=> w2.title.first.downcase } - end - - def self.model_attributes(attrs) - CurationConcerns::GenericWorkForm.model_attributes(attrs) - end - - def self.multiple?(attrs) - CurationConcerns::GenericWorkForm.multiple?(attrs) - end - - private - - # Override this method if you want the creator to display something other than - # the user_key, e.g. "current_user.name" - def creator_display - @current_ability.current_user.user_key - end - end -end diff --git a/app/views/upload_sets/_base_metadata.html.erb b/app/views/upload_sets/_base_metadata.html.erb deleted file mode 100644 index 32a9edc63..000000000 --- a/app/views/upload_sets/_base_metadata.html.erb +++ /dev/null @@ -1,12 +0,0 @@ - <%#= f.input :resource_type, as: :select_with_help, collection: CurationConcerns.config.resource_types, - input_html: { class: 'form-control', multiple: true } %> - - <%= f.input :tag, as: :multi_value_with_help %> - - <%= f.input :creator, as: :multi_value_with_help %> - - <%= f.input :rights, as: :select_with_modal_help, collection: RightsService.select_options, - input_html: { class: 'form-control', multiple: true } %> - - <%= render "curation_concerns/file_sets/rights_modal" %> - diff --git a/app/views/upload_sets/_edit.js.erb b/app/views/upload_sets/_edit.js.erb deleted file mode 100644 index dda660465..000000000 --- a/app/views/upload_sets/_edit.js.erb +++ /dev/null @@ -1,15 +0,0 @@ -if (navigator.userAgent.match("MSIE")) - $("#new_file_set").validate(); - -$('#permissions_display').show(); - -confirmation_needed = true; -window.onbeforeunload = confirmExit; - -function confirmExit(){ - if(confirmation_needed){ - // if you return a string it will be displayed in between "don't navigate away" - // and "click Ok to navigate away or cancel to stay put" in the confirm dialog - return "Your metadata has not been saved."; - } -} diff --git a/app/views/upload_sets/_metadata.html.erb b/app/views/upload_sets/_metadata.html.erb deleted file mode 100644 index 39de35798..000000000 --- a/app/views/upload_sets/_metadata.html.erb +++ /dev/null @@ -1,40 +0,0 @@ -

Individual Titles

-
-
-
-

Applies to individual files uploaded

- <%= content_tag :p, t('curation_concerns.upload_set.help.title'), class: "help-block" %> - <% f.object.works.each_with_index do |work, index| %> -
- <%= f.input_label :title, as: :multi_value_with_help, label: "Title #{index + 1}" %> -
- <%= f.text_field :title, name: "title[#{work.id}][]", value: work.title, class: 'form-control', required: true %> -
-
- <% end %> -
- -
- -
-
-
- -<%= hidden_field_tag(:extra_description_count, "1") %> -
-

Bulk Descriptions

-
-
-
-

Applies to all files just uploaded

- <%= render 'base_metadata', f: f %> - - - - - <%= render 'more_metadata', f: f %> - -
-
-
-
diff --git a/app/views/upload_sets/_more_metadata.html.erb b/app/views/upload_sets/_more_metadata.html.erb deleted file mode 100644 index 93c06de75..000000000 --- a/app/views/upload_sets/_more_metadata.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -
- - <% (f.object.terms - [:title, :creator, :rights, :tag, :resource_type]).each do |term| %> - <%# <%= f.input term, as: :multi_value_with_help, input_html: { required: false} %> - <%= render_edit_field_partial(term, f: f) %> - <% end %> -
diff --git a/app/views/upload_sets/edit.html.erb b/app/views/upload_sets/edit.html.erb deleted file mode 100644 index c5e5951b1..000000000 --- a/app/views/upload_sets/edit.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -<%= javascript_tag do %> - <%= render partial: "edit", formats: [:js] %> -<% end %> - -

Apply Metadata

-

- The information you provide for Title will be applied to the corresponding file only; however all other - information you provide will be applied to the entire set of files that were uploaded together you have just - deposited into <%= t('curation_concerns.product_name') %>. You may edit individual files from - <%= link_to " #{t('curation_concerns.bread_crumb.works_list')}".html_safe, main_app.curation_concerns_generic_works_path %> - once this step is finished. * indicates required fields. -

-<%= simple_form_for [main_app, @form], html: { multipart: true }, builder: CurationConcerns::FormBuilder do |f| %> - - <%= render 'metadata', f: f %> - - <%#= render 'file_sets/permission_form', f: f, upload_set: @upload_set %> - -
- <%= button_tag type: 'submit', class: 'btn btn-primary btn-lg', - onclick: "confirmation_needed = false;", id: "upload_submit", name: "update_permission" do %> - Save - <% end %> -
- -<% end %> diff --git a/curation_concerns-models/app/jobs/upload_set_update_job.rb b/curation_concerns-models/app/jobs/upload_set_update_job.rb deleted file mode 100644 index 78d46266a..000000000 --- a/curation_concerns-models/app/jobs/upload_set_update_job.rb +++ /dev/null @@ -1,77 +0,0 @@ -class UploadSetUpdateJob < ActiveJob::Base - include Hydra::PermissionsQuery - include CurationConcerns::Messages - - queue_as :upload_set_update - - attr_accessor :saved, :denied - - # This copies metadata from the passed in attribute to all of the works that - # are members of the given upload set - def perform(login, upload_set_id, titles, attributes, visibility) - @login = login - @saved = [] - @denied = [] - @upload_set_id = upload_set_id - - titles ||= {} - attributes = attributes.merge(visibility: visibility) - - update(upload_set, titles, attributes) - send_user_message - end - - private - - def upload_set - @upload_set ||= UploadSet.find_or_create(@upload_set_id) - end - - def update(upload_set, titles, attributes) - upload_set.works.each do |work| - title = titles[work.id] if titles[work.id] - next unless update_work(work, title, attributes) - # TODO: stop assuming that files only belong to one work - saved << work - end - - upload_set.update(status: ["Complete"]) - end - - def send_user_success_message - return unless CurationConcerns.config.callback.set?(:after_upload_set_update_success) - CurationConcerns.config.callback.run(:after_upload_set_update_success, user, upload_set) - end - - def send_user_failure_message - return unless CurationConcerns.config.callback.set?(:after_upload_set_update_failure) - CurationConcerns.config.callback.run(:after_upload_set_update_failure, user, upload_set) - end - - def send_user_message - if denied.empty? - send_user_success_message unless saved.empty? - else - send_user_failure_message - end - end - - def user - @user ||= User.find_by_user_key(@login) - end - - def update_work(work, title, attributes) - unless user.can? :edit, work - ActiveFedora::Base.logger.error "User #{user.user_key} DENIED access to #{work.id}!" - denied << work - return - end - - work.title = title if title - work_actor(work, attributes).update - end - - def work_actor(work, attributes) - CurationConcerns::GenericWorkActor.new(work, user, attributes) - end -end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/belongs_to_upload_sets.rb b/curation_concerns-models/app/models/concerns/curation_concerns/belongs_to_upload_sets.rb deleted file mode 100644 index 6e34bf2a4..000000000 --- a/curation_concerns-models/app/models/concerns/curation_concerns/belongs_to_upload_sets.rb +++ /dev/null @@ -1,13 +0,0 @@ -module CurationConcerns - module BelongsToUploadSets - extend ActiveSupport::Concern - included do - belongs_to :upload_set, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf - end - - # Is this file in the middle of being processed by an UploadSet? - def processing? - try(:upload_set).try(:status) == ['processing'.freeze] - end - end -end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/upload_set_behavior.rb b/curation_concerns-models/app/models/concerns/curation_concerns/upload_set_behavior.rb deleted file mode 100644 index cb9a21eca..000000000 --- a/curation_concerns-models/app/models/concerns/curation_concerns/upload_set_behavior.rb +++ /dev/null @@ -1,29 +0,0 @@ -module CurationConcerns - module UploadSetBehavior - extend ActiveSupport::Concern - include Hydra::AccessControls::Permissions - include CurationConcerns::Noid - - included do - has_many :works, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base' - - property :title, predicate: ::RDF::DC.title - property :status, predicate: ::RDF::DC.type - end - - module ClassMethods - include CurationConcerns::Lockable - - # This method handles most race conditions gracefully. - def find_or_create(id) - acquire_lock_for(id) do - begin - UploadSet.find(id) - rescue ActiveFedora::ObjectNotFoundError - UploadSet.create(id: id) - end - end - end - end - end -end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/work_behavior.rb b/curation_concerns-models/app/models/concerns/curation_concerns/work_behavior.rb index 0226fde30..156040c56 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/work_behavior.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/work_behavior.rb @@ -12,7 +12,6 @@ module CurationConcerns::WorkBehavior include CurationConcerns::WithFileSets include CurationConcerns::Naming include CurationConcerns::RequiredMetadata - include CurationConcerns::BelongsToUploadSets include Hydra::AccessControls::Embargoable included do diff --git a/curation_concerns-models/app/models/upload_set.rb b/curation_concerns-models/app/models/upload_set.rb deleted file mode 100644 index 5f653e17f..000000000 --- a/curation_concerns-models/app/models/upload_set.rb +++ /dev/null @@ -1,3 +0,0 @@ -class UploadSet < ActiveFedora::Base - include CurationConcerns::UploadSetBehavior -end diff --git a/spec/controllers/upload_sets_controller_spec.rb b/spec/controllers/upload_sets_controller_spec.rb deleted file mode 100644 index aac208fc4..000000000 --- a/spec/controllers/upload_sets_controller_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require 'spec_helper' - -describe UploadSetsController do - let(:user) { create(:user) } - let(:other_user) { create(:user) } - before do - sign_in user - allow_any_instance_of(User).to receive(:groups).and_return([]) - allow(UploadSet).to receive(:acquire_lock_for).and_yield if $in_travis - end - describe "#update" do - let(:upload_set_update_message) { double('upload_set update message') } - let(:upload_set) { UploadSet.create } - context "when successful" do - it "enqueues a upload_set job and redirects to generic_works list with a flash message" do - expect(UploadSetUpdateJob).to receive(:perform_later).with(user.user_key, upload_set.id, { '1' => 'foo' }, - { tag: [] }, 'open').once - post :update, id: upload_set.id, title: { '1' => 'foo' }, visibility: 'open', upload_set: { tag: [""] } - expect(response).to redirect_to routes.url_helpers.curation_concerns_generic_works_path - expect(flash[:notice]).to include("Your files are being processed") - end - end - - describe "when user has edit permissions on a file" do - # TODO: all these tests could move to upload_set_update_job_spec.rb - let!(:work) { create(:generic_work, user: user, upload_set: upload_set) } - - it "they can set public read access" do - post :update, id: upload_set, visibility: "open", upload_set: { tag: [""] } - expect(work.reload.read_groups).to eq ['public'] - end - - it "they can set metadata like title" do - post :update, id: upload_set, upload_set: { tag: ["footag", "bartag"] }, title: { work.id => ["New Title"] } - work.reload - expect(work.title).to eq ["New Title"] - # TODO: is order important? - expect(work.tag).to include("footag", "bartag") - end - - it "they cannot set any tags" do - post :update, id: upload_set, upload_set: { tag: [""] } - expect(work.reload.tag).to be_empty - end - end - - describe "when user does not have edit permissions on a file" do - # TODO: all these tests could move to upload_set_update_job_spec.rb - let!(:work) { create(:generic_work, title: ['Original Title'], upload_set: upload_set) } - - it "they cannot modify the object" do - post :update, id: upload_set, upload_set: { "tag" => [""] }, - title: { work.id => "Title Won't Change" } - work.reload - expect(work.title).to eq ["Original Title"] - end - end - end - - describe "#edit" do - let(:us1) { UploadSet.create } - - it "sets up attributes for the form" do - get :edit, id: us1 - expect(assigns[:form]).to be_kind_of CurationConcerns::UploadSetForm - expect(assigns[:form].model).to eq us1 - expect(response).to be_success - end - end -end diff --git a/spec/forms/upload_set_form_spec.rb b/spec/forms/upload_set_form_spec.rb deleted file mode 100644 index 472dd9a5b..000000000 --- a/spec/forms/upload_set_form_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'spec_helper' - -describe CurationConcerns::UploadSetForm do - let(:form) { described_class.new(upload_set, ability) } - let(:user) { build(:user) } - let(:ability) { Ability.new(user) } - let(:upload_set) { UploadSet.create } - let!(:work1) { create(:work, upload_set: upload_set) } - let!(:work2) { create(:work, upload_set: upload_set) } - - describe "#to_param" do - subject { form.to_param } - it { is_expected.to eq upload_set.id } - end - - describe "#terms" do - subject { form.terms } - it { is_expected.to eq [:title, - :creator, - :contributor, - :description, - :tag, - :rights, - :publisher, - :date_created, - :subject, - :language, - :identifier, - :based_near, - :related_url, - :representative_id, - :thumbnail_id, - :files, - :visibility_during_embargo, - :embargo_release_date, - :visibility_after_embargo, - :visibility_during_lease, - :lease_expiration_date, - :visibility_after_lease, - :visibility] } - end - - describe "works" do - let!(:work1) { create(:work_with_one_file, upload_set: upload_set, title: ['B title']) } - let!(:work2) { create(:work_with_one_file, upload_set: upload_set, title: ['A title']) } - subject { form.works } - it { is_expected.to eq [work2, work1] } - end - - describe "creator" do - let(:user) { build(:user, email: 'bob@example.com') } - subject { form.creator } - it { is_expected.to eq ['bob@example.com'] } - end -end diff --git a/spec/jobs/import_url_job_spec.rb b/spec/jobs/import_url_job_spec.rb index 71e067af0..b9151b62e 100644 --- a/spec/jobs/import_url_job_spec.rb +++ b/spec/jobs/import_url_job_spec.rb @@ -41,9 +41,6 @@ let(:title) { { file_set.id => ['File One'] } } let(:metadata) { {} } let(:visibility) { nil } - - let(:upload_set) { UploadSet.create } - let(:upload_set_job) { UploadSetUpdateJob.perform_now(user.user_key, upload_set.id, title, metadata, visibility) } let(:file_set_id) { file_set.id } before do diff --git a/spec/jobs/upload_set_update_job_spec.rb b/spec/jobs/upload_set_update_job_spec.rb deleted file mode 100644 index dfa9a87ae..000000000 --- a/spec/jobs/upload_set_update_job_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'spec_helper' - -describe UploadSetUpdateJob do - let(:user) { create(:user) } - let(:upload_set) { UploadSet.create } - - let(:work) { create(:work, user: user, upload_set: upload_set) } - let(:work2) { create(:work, user: user, upload_set: upload_set) } - - before do - allow(CurationConcerns.config.callback).to receive(:run) - allow(CurationConcerns.config.callback).to receive(:set?) - .with(:after_upload_set_update_success) - .and_return(true) - allow(CurationConcerns.config.callback).to receive(:set?) - .with(:after_upload_set_update_failure) - .and_return(true) - end - - describe "#perform" do - before do - allow(UploadSet).to receive(:acquire_lock_for).and_yield if $in_travis - end - - let(:title) { { work.id => ['File One'], work2.id => ['File Two'] } } - let(:metadata) { { tag: [''] } } - let(:visibility) { nil } - - subject { described_class.perform_now(user.user_key, upload_set.id, title, metadata, visibility) } - - it "updates work metadata" do - expect(CurationConcerns.config.callback).to receive(:run).with(:after_upload_set_update_success, user, upload_set) - subject - expect(work.reload.title).to eq ['File One'] - expect(work2.reload.title).to eq ['File Two'] - end - - context "when user does not have permission to edit all of the works" do - it "sends the failure message" do - expect_any_instance_of(User).to receive(:can?).with(:edit, work).and_return(true) - expect_any_instance_of(User).to receive(:can?).with(:edit, work2).and_return(false) - expect(CurationConcerns.config.callback).to receive(:run).with(:after_upload_set_update_failure, user, upload_set) - subject - end - end - end -end diff --git a/spec/models/upload_set_spec.rb b/spec/models/upload_set_spec.rb deleted file mode 100644 index f7ec999b4..000000000 --- a/spec/models/upload_set_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe UploadSet do - let(:user) { create(:user) } - let(:upload_set) { described_class.create(title: ["test collection"]) } - subject { upload_set } - - it "has dc metadata" do - expect(subject.title).to eq ["test collection"] - end - - it "responds to #works" do - expect(subject).to respond_to(:works) - end - - it "supports to_solr" do - expect(subject.to_solr).to_not be_nil - expect(subject.to_solr["upload_set__title_t"]).to be_nil - end - - describe "find_or_create" do - before do - allow(described_class).to receive(:acquire_lock_for).and_yield if $in_travis - end - describe "when the object exists" do - let!(:upload_set) { described_class.create(title: ["test collection"]) } - it "finds upload_set instead of creating" do - expect(described_class).to_not receive(:create) - described_class.find_or_create(subject.id) - end - end - describe "when the object does not exist" do - it "creates a new UploadSet" do - expect { described_class.find("upload_set-123") }.to raise_error(ActiveFedora::ObjectNotFoundError) - expect(described_class).to receive(:create).once.and_return("the upload_set") - expect(described_class.find_or_create("upload_set-123")).to eq "the upload_set" - end - end - end -end diff --git a/spec/views/upload_sets/_metadata.html.erb_spec.rb b/spec/views/upload_sets/_metadata.html.erb_spec.rb deleted file mode 100644 index 177ecd419..000000000 --- a/spec/views/upload_sets/_metadata.html.erb_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'spec_helper' - -describe 'upload_sets/_metadata.html.erb' do - let(:user) { build(:user) } - let(:ability) { Ability.new(user) } - let(:upload_set) { UploadSet.create } - let(:form) { CurationConcerns::UploadSetForm.new(upload_set, ability) } - let(:work1) { build(:work, id: 'work1', title: ['First work']) } - let(:work2) { build(:work, id: 'work2', title: ['Second work']) } - - let(:f) do - allow(upload_set).to receive(:works).and_return([work1, work2]) - view.simple_form_for(form, url: '/update', builder: CurationConcerns::FormBuilder) do |fs_form| - return fs_form - end - end - - before do - allow(view).to receive(:f).and_return(f) - render - end - - it "draws the form" do - expect(rendered).to have_text 'Applies to all files just uploaded' - expect(rendered).to have_css 'input[name="title[work1][]"][value="First work"]' - expect(rendered).to have_css 'input[name="title[work2][]"][value="Second work"]' - end -end