Skip to content

Commit

Permalink
Rename BatchUploadItem to BatchUpload to match rails conventions
Browse files Browse the repository at this point in the history
The controller is `BatchUploadsController`.  Therefore the model should be
`BatchUpload`.
  • Loading branch information
atz committed Jan 18, 2017
1 parent a453e2c commit eab5474
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
Expand Up @@ -7,15 +7,15 @@ 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

# The permissions to create a batch are not as important as the permissions for the concern being batched.
# @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
Expand Down
7 changes: 1 addition & 6 deletions 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]
Expand All @@ -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
Expand Down
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/sufia/ability.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/sufia/batch_uploads_controller_spec.rb
Expand Up @@ -9,15 +9,15 @@
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
{
title: expected_individual_params,
resource_type: expected_types,
uploaded_files: ['1'],
batch_upload_item: batch_upload_item
batch_upload: batch_upload
}
end

Expand Down Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion spec/forms/sufia/forms/batch_upload_form_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit eab5474

Please sign in to comment.