Class: Spree::AgentTools::ResourceWrite

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

Overview

Shared by the generic writes, which dispatch to the Admin API's own create, update and destroy operations.

The controller behind each decides everything that matters: which attributes it accepts, whether it writes through a workflow, what the refusal reads like. So these three are correct for every resource, and the rule that a resource with a workflow refuses the generic write is gone — there was only ever one way to write a record, and now these take it.

Direct Known Subclasses

CreateResource, DeleteResource, UpdateResource

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, #call, description, destructive?, #initialize, input_schema, mutating!, mutating?, param, params, permission, #summary, tool_name, #unknown_resource

Constructor Details

This class inherits a constructor from Spree::AgentTool

Instance Method Details

#permitted? ⇒ Boolean

Offered only to a caller who can write something.

The endpoint would refuse anyway, but a tool a credential can never use should not be named to the model: the server promises that a tool you cannot see is one the store has not granted.

Returns:

  • (Boolean)


23
24
25
26
27
# File 'app/tools/spree/agent_tools/resource_write.rb', line 23

def permitted?
  ResourceMap.all.any? do |entry|
    entry.write_permission.present? && context.permitted?(entry.write_permission)
  end
end