Sha256: 1794338bc78932dee2f20d4ab246e0df66f70b92cc0c98b79b74b0e384869170

Contents?: true

Size: 1.03 KB

Versions: 11

Compression:

Stored size: 1.03 KB

Contents

module Spree
  module Api
    class AddressesController < Spree::Api::BaseController
      before_filter :find_order

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

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

        if @address.update_attributes(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
          @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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_api-2.3.13 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.12 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.11 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.10 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.9 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.8 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.7 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.6 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.5 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.4 app/controllers/spree/api/addresses_controller.rb
spree_api-2.3.3 app/controllers/spree/api/addresses_controller.rb