Sha256: fe9fe1c4e5a667d198980d4d5d0f103f6688812f7bc86321f3af9f40677808d0

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true
module Zizia
  class CsvImportsController < ::ApplicationController
    load_and_authorize_resource
    before_action :load_and_authorize_preview, only: [:preview]

    with_themed_layout 'dashboard'

    def index; end

    def show; end

    def new; end

    # Validate the CSV file and display errors or
    # warnings to the user.
    def preview; end

    def create
      @csv_import.user = current_user
      preserve_cache

      if @csv_import.save
        @csv_import.queue_start_job
        redirect_to @csv_import
      else
        render :new
      end
    end

    private

      def load_and_authorize_preview
        @csv_import = CsvImport.new(create_params)
        authorize! :create, @csv_import
      end

      def create_params
        params.fetch(:csv_import, {}).permit(:manifest, :fedora_collection_id)
      end

      # Since we are re-rendering the form (once for
      # :new and again for :preview), we need to
      # manually set the cache, otherwise the record
      # will lose the manifest file between the preview
      # and the record save.
      def preserve_cache
        return unless params['csv_import']
        @csv_import.manifest_cache = params['csv_import']['manifest_cache']
        @csv_import.fedora_collection_id = params['csv_import']['fedora_collection_id']
      end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
zizia-3.1.0.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-3.0.0.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.09 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.08 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.07 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.06 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.05 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.04 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.03 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.02 app/controllers/zizia/csv_imports_controller.rb
zizia-2.1.0.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-2.0.0.alpha.01 app/controllers/zizia/csv_imports_controller.rb