Sha256: e844f56fb26364051459f19967544b66ac40d2b53b979a43be6b9442c33b8cdc

Contents?: true

Size: 1.08 KB

Versions: 61

Compression:

Stored size: 1.08 KB

Contents

module Spree
  module Api
    module V1
      class AddressesController < Spree::Api::BaseController
        before_action :find_order

        def show
          authorize! :show, @order, order_token
          @address = find_address
          respond_with(@address)
        end

        def update
          authorize! :update, @order, order_token
          @address = find_address

          if @address.update(address_params)
            respond_with(@address, default_template: :show)
          else
            invalid_resource!(@address)
          end
        end

        private

        def address_params
          params.require(:address).permit(permitted_address_attributes)
        end

        def find_order
          @order = Spree::Order.find_by!(number: order_id)
        end

        def find_address
          if @order.bill_address_id == params[:id].to_i
            @order.bill_address
          elsif @order.ship_address_id == params[:id].to_i
            @order.ship_address
          else
            raise CanCan::AccessDenied
          end
        end
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
spree_api-4.1.13.1 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.0.7.1 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.3 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.2 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.1 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.0.7 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.0 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.0.rc5 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.0.rc4 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.0.rc3 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.1.13 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.0.6 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.0.rc2 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.0.5 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.1.12 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.0.rc1 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.0.4 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.1.11 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.1.10 app/controllers/spree/api/v1/addresses_controller.rb
spree_api-4.2.0.beta app/controllers/spree/api/v1/addresses_controller.rb