From eab5474df8588fd2ddf500db9b13bf285fbd63c5 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 18 Jan 2017 13:29:02 -0800 Subject: [PATCH] Rename BatchUploadItem to BatchUpload to match rails conventions The controller is `BatchUploadsController`. Therefore the model should be `BatchUpload`. --- .../concerns/sufia/batch_uploads_controller_behavior.rb | 4 ++-- app/forms/sufia/forms/batch_upload_form.rb | 7 +------ app/models/{batch_upload_item.rb => batch_upload.rb} | 2 +- app/models/concerns/sufia/ability.rb | 4 ++-- spec/controllers/sufia/batch_uploads_controller_spec.rb | 6 +++--- spec/forms/sufia/forms/batch_upload_form_spec.rb | 2 +- 6 files changed, 10 insertions(+), 15 deletions(-) rename app/models/{batch_upload_item.rb => batch_upload.rb} (92%) diff --git a/app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb b/app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb index c84d24c251..63c142f00d 100644 --- a/app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb +++ b/app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb @@ -7,7 +7,7 @@ module BatchUploadsControllerBehavior included do self.work_form_service = BatchUploadFormService self.curation_concern_type = work_form_service.form_class.model_class # includes CanCan side-effects - # We use BatchUploadItem as a null stand-in curation_concern_type. + # We use BatchUpload as a null stand-in curation_concern_type. # The actual permission is checked dynamically during #create. end @@ -15,7 +15,7 @@ module BatchUploadsControllerBehavior # @note we don't call `authorize!` directly, since `authorized_models` already checks `user.can? :create, ...` def create authenticate_user! - unsafe_pc = params.fetch(:batch_upload_item, {})[:payload_concern] + unsafe_pc = params.fetch(:batch_upload, {})[:payload_concern] # Calling constantize on user params is disfavored (per brakeman), so we sanitize by matching it against an authorized model. safe_pc = Sufia::SelectTypeListPresenter.new(current_user).authorized_models.map(&:to_s).find { |x| x == unsafe_pc } raise CanCan::AccessDenied, "Cannot create an object of class '#{unsafe_pc}'" unless safe_pc diff --git a/app/forms/sufia/forms/batch_upload_form.rb b/app/forms/sufia/forms/batch_upload_form.rb index 9d0fa087fb..5d52fa760f 100644 --- a/app/forms/sufia/forms/batch_upload_form.rb +++ b/app/forms/sufia/forms/batch_upload_form.rb @@ -1,7 +1,7 @@ module Sufia module Forms class BatchUploadForm < Sufia::Forms::WorkForm - self.model_class = BatchUploadItem + self.model_class = BatchUpload include HydraEditor::Form::Permissions self.terms -= [:title, :resource_type] @@ -22,11 +22,6 @@ def primary_terms super - [:title] end - # # On the batch upload, title is set per-file. - # def secondary_terms - # super - [:title] - # end - # Override of ActiveModel::Model name that allows us to use our custom name class def self.model_name @_model_name ||= begin diff --git a/app/models/batch_upload_item.rb b/app/models/batch_upload.rb similarity index 92% rename from app/models/batch_upload_item.rb rename to app/models/batch_upload.rb index 7775562b67..83f84d5907 100644 --- a/app/models/batch_upload_item.rb +++ b/app/models/batch_upload.rb @@ -1,7 +1,7 @@ # This stands in for an object to be created from the BatchUploadForm. # It should never actually be persisted in the repository. # The properties on this form should be copied to a real work type. -class BatchUploadItem < ActiveFedora::Base +class BatchUpload < ActiveFedora::Base include ::CurationConcerns::WorkBehavior include ::CurationConcerns::BasicMetadata include Sufia::WorkBehavior diff --git a/app/models/concerns/sufia/ability.rb b/app/models/concerns/sufia/ability.rb index 1fb0213636..10717c2cbe 100644 --- a/app/models/concerns/sufia/ability.rb +++ b/app/models/concerns/sufia/ability.rb @@ -16,9 +16,9 @@ module Ability def uploaded_file_abilities return unless registered_user? - can :create, [UploadedFile, BatchUploadItem] + can :create, [UploadedFile, BatchUpload] can :destroy, UploadedFile, user: current_user - # BatchUploadItem permissions depend on the kind of objects being made by the batch, + # BatchUpload permissions depend on the kind of objects being made by the batch, # but it must be authorized directly in the controller, not here. # Note: cannot call `authorized_models` without going recursive. end diff --git a/spec/controllers/sufia/batch_uploads_controller_spec.rb b/spec/controllers/sufia/batch_uploads_controller_spec.rb index aebf60ca32..757bb98357 100644 --- a/spec/controllers/sufia/batch_uploads_controller_spec.rb +++ b/spec/controllers/sufia/batch_uploads_controller_spec.rb @@ -9,7 +9,7 @@ let(:expected_shared_params) do { 'keyword' => [], 'visibility' => 'open', :model => 'GenericWork' } end - let(:batch_upload_item) do + let(:batch_upload) do { keyword: [""], visibility: 'open', payload_concern: 'GenericWork' } end let(:post_params) do @@ -17,7 +17,7 @@ title: expected_individual_params, resource_type: expected_types, uploaded_files: ['1'], - batch_upload_item: batch_upload_item + batch_upload: batch_upload } end @@ -52,7 +52,7 @@ end describe "when submiting works on behalf of another user" do - let(:batch_upload_item) do + let(:batch_upload) do { payload_concern: Atlas, permissions_attributes: [ diff --git a/spec/forms/sufia/forms/batch_upload_form_spec.rb b/spec/forms/sufia/forms/batch_upload_form_spec.rb index 1db370ce56..12bd50abee 100644 --- a/spec/forms/sufia/forms/batch_upload_form_spec.rb +++ b/spec/forms/sufia/forms/batch_upload_form_spec.rb @@ -21,7 +21,7 @@ expect(subject.route_key).to eq 'batch_uploads' end it "has a param_key" do - expect(subject.param_key).to eq 'batch_upload_item' + expect(subject.param_key).to eq 'batch_upload' end end