Class: Spree::AgentTools::CreateImport

Inherits:
Spree::AgentTool show all
Defined in:
app/tools/spree/agent_tools/create_import.rb

Overview

Starts a CSV import from a file the merchant provided.

Gated on the WRITE scope of what is being imported, computed per call — a customers import needs write_customers, a products import write_products. A single class-level key could not say that, which is why the resource reached the map read-only; create_export answers the same question the same way.

Creating the import reads the file's header row and proposes a column mapping. Nothing is written to the catalog until that mapping is confirmed, so this is the safe half of the wizard: the merchant still sees what the columns were taken to mean before any row lands.

Constant Summary

Constants inherited from Spree::AgentTool

Spree::AgentTool::PARENT_ID_DESCRIPTION

Instance Attribute Summary

Attributes inherited from Spree::AgentTool

#context

Instance Method Summary collapse

Methods inherited from Spree::AgentTool

additive!, audience, description, destructive?, #initialize, input_schema, mutating!, mutating?, param, params, permission, #permitted?, tool_name

Constructor Details

This class inherits a constructor from Spree::AgentTool

Instance Method Details

#call(resource:, file_id:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'app/tools/spree/agent_tools/create_import.rb', line 30

def call(resource:, file_id:)
  import_class = import_class_for(resource)
  return unknown_resource(resource) if import_class.nil?

  required = "write_#{import_class.required_scope}"
  unless context.holds?(required)
    return { error: "You do not have permission to import #{resource.to_s.tr('_', ' ')}." }
  end

  start(import_class, resource, file_id)
end

#summary(arguments) ⇒ Object



42
43
44
# File 'app/tools/spree/agent_tools/create_import.rb', line 42

def summary(arguments)
  "Start a #{arguments[:resource].to_s.tr('_', ' ')} import"
end