Class: Spree::Api::BaseController

Inherits:
ActionController::Metal
  • Object
show all
Includes:
ActionController::ConditionalGet, ActionController::Head, ActionController::Redirecting, ActionController::StrongParameters, ControllerSetup, Core::ControllerHelpers::SSL, Core::ControllerHelpers::StrongParameters
Defined in:
app/controllers/spree/api/base_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ControllerSetup

included

Instance Attribute Details

#current_api_userObject

Returns the value of attribute current_api_user.



19
20
21
# File 'app/controllers/spree/api/base_controller.rb', line 19

def current_api_user
  @current_api_user
end

Instance Method Details

#map_nested_attributes_keys(klass, attributes) ⇒ Object



42
43
44
45
46
47
48
49
# File 'app/controllers/spree/api/base_controller.rb', line 42

def map_nested_attributes_keys(klass, attributes)
  nested_keys = klass.nested_attributes_options.keys
  attributes.inject({}) do |h, (k,v)|
    key = nested_keys.include?(k.to_sym) ? "#{k}_attributes" : k
    h[key] = v
    h
  end.with_indifferent_access
end

#permitted_line_item_attributesObject

users should be able to set price when importing orders via api



52
53
54
55
56
57
58
# File 'app/controllers/spree/api/base_controller.rb', line 52

def permitted_line_item_attributes
  if current_api_user.has_spree_role?("admin")
    super << [:price, :variant_id, :sku]
  else
    super
  end
end

#set_jsonp_formatObject



35
36
37
38
39
40
# File 'app/controllers/spree/api/base_controller.rb', line 35

def set_jsonp_format
  if params[:callback] && request.get?
    self.response_body = "#{params[:callback]}(#{response.body})"
    headers["Content-Type"] = 'application/javascript'
  end
end