Sha256: 62efc0c361a75894ecc8edc21efd7d4db333bceb42928885a71a07ef664011cc

Contents?: true

Size: 1.22 KB

Versions: 84

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

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

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

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

        if @order.update({ "#{@order_source}_attributes" => address_params })
          @address = @order.send(@order_source)
          respond_with(@address, default_template: :show)
        else
          @address = @order.send(@order_source)
          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_source = :bill_address
          @order.bill_address
        elsif @order.ship_address_id == params[:id].to_i
          @order_source = :ship_address
          @order.ship_address
        else
          raise CanCan::AccessDenied
        end
      end
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
solidus_api-4.4.1 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.4.0 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.3.4 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.2.4 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.1.5 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.3.3 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.3.2 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.1.4 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.3.1 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.3.0 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.2.3 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.1.3 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.0.4 app/controllers/spree/api/addresses_controller.rb
solidus_api-3.4.6 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.0.3 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.1.2 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.2.2 app/controllers/spree/api/addresses_controller.rb
solidus_api-3.4.5 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.2.1 app/controllers/spree/api/addresses_controller.rb
solidus_api-4.2.0 app/controllers/spree/api/addresses_controller.rb