Class: Spree::AgentTools::DeleteResource
- Inherits:
-
ResourceWrite
- Object
- Spree::AgentTool
- ResourceWrite
- Spree::AgentTools::DeleteResource
- Defined in:
- app/tools/spree/agent_tools/delete_resource.rb
Overview
Removes a record, through the Admin API's own destroy operation — which soft-deletes, archives or refuses exactly as the dashboard does.
Constant Summary
Constants inherited from Spree::AgentTool
Spree::AgentTool::PARENT_ID_DESCRIPTION
Instance Attribute Summary
Attributes inherited from Spree::AgentTool
Instance Method Summary collapse
Methods inherited from ResourceWrite
Methods inherited from Spree::AgentTool
additive!, audience, description, destructive?, #initialize, input_schema, mutating!, mutating?, param, params, permission, #permitted?, tool_name, #unknown_resource
Constructor Details
This class inherits a constructor from Spree::AgentTool
Instance Method Details
#call(resource:, id:, parent_id: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/tools/spree/agent_tools/delete_resource.rb', line 14 def call(resource:, id:, parent_id: nil) entry, refusal = writable_entry(resource, :destroy) return refusal if refusal path, missing = write_path(entry, :destroy, id: id, parent_id: parent_id) return missing if missing response = dispatch.call(method: :delete, path: path) return { error: response. } unless response.success? { summary: summary(resource: resource, id: id, parent_id: parent_id) } end |
#summary(arguments) ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/tools/spree/agent_tools/delete_resource.rb', line 27 def summary(arguments) line = "Delete #{arguments[:resource].to_s.singularize.tr('_', ' ')} #{arguments[:id]}" # The approval card is all a merchant sees, so a nested delete names # the record it runs under, as a nested create does. nested = arguments[:parent_id].present? && ResourceMap.find(arguments[:resource])&.parent_param(:destroy) nested ? "#{line} under #{arguments[:parent_id]}" : line end |