Sha256: ae3d90f6b3b1037c616766230ed0269e740c67abab63abff2bb6c112b692d9e6

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 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, :update_actor_stack)
      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']
        @csv_import.update_actor_stack = params['csv_import']['update_actor_stack']
      end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
zizia-6.0.1 app/controllers/zizia/csv_imports_controller.rb
zizia-6.0.0 app/controllers/zizia/csv_imports_controller.rb
zizia-5.5.0 app/controllers/zizia/csv_imports_controller.rb
zizia-5.4.0 app/controllers/zizia/csv_imports_controller.rb
zizia-5.3.0 app/controllers/zizia/csv_imports_controller.rb
zizia-5.2.0 app/controllers/zizia/csv_imports_controller.rb
zizia-5.1.0 app/controllers/zizia/csv_imports_controller.rb
zizia-5.0.1 app/controllers/zizia/csv_imports_controller.rb
zizia-5.0.0 app/controllers/zizia/csv_imports_controller.rb
zizia-4.6.0.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.5.4.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.5.3.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.5.2.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.5.1.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.4.1.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.4.0.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.3.1.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.2.0.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.1.0.alpha.01 app/controllers/zizia/csv_imports_controller.rb
zizia-4.0.4.alpha.01 app/controllers/zizia/csv_imports_controller.rb