Sha256: 665e149b8cad29fa6d5ee05754e7f55bc3efcca9964bd91982f17a051e4682fc

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

module Sufia
  module BatchUploadsControllerBehavior
    extend ActiveSupport::Concern
    include Hydra::Controller::ControllerBehavior
    include CurationConcerns::CurationConcernController

    included do
      layout "sufia-one-column"
      self.curation_concern_type = GenericWork
      before_action :has_access?
    end

    def create
      authenticate_user!
      create_update_job
      flash[:notice] = t('sufia.generic_works.new.after_create_html', application_name: view_context.application_name)
      redirect_after_update
    end

    protected

      # Gives the class of the form.
      # This overrides CurationConcerns
      def form_class
        ::Sufia::Forms::BatchUploadForm
      end

      def redirect_after_update
        if uploading_on_behalf_of?
          redirect_to sufia.dashboard_shares_path
        else
          redirect_to sufia.dashboard_works_path
        end
      end

      def create_update_job
        log = BatchCreateOperation.create!(user: current_user,
                                           operation_type: "Batch Create")
        BatchCreateJob.perform_later(current_user,
                                     params[:title],
                                     params[:resource_type],
                                     params[:uploaded_files],
                                     attributes_for_actor,
                                     log)
      end

      def uploading_on_behalf_of?
        params.fetch(hash_key_for_curation_concern).key?(:on_behalf_of)
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sufia-7.0.0.beta3 app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb