<commit_before># frozen_string_literal: true

module Spree
  module Admin
    module Orders
      class CustomerDetailsController < Spree::Admin::BaseController
        before_action :load_order
        before_action :check_authorization
        before_action :set_guest_checkout_status, only: :update

        def show
          edit
          render action: :edit
        end

        def edit
          build_addresses
        end

        def update
          if @order.update(order_params)
            if params[:guest_checkout] == "false"
              @order.associate_user!(Spree::User.find_by(email: @order.email))
            end

            refresh_shipment_rates
            recalculate_taxes
            OrderWorkflow.new(@order).advance_to_payment

            flash[:success] = Spree.t('customer_details_updated')
            redirect_to spree.admin_order_customer_path(@order)
          else
            render action: :edit
          end
        end

        # Inherit CanCan permissions for the current order
        def model_class
          load_order unless @order
          @order
        end

        private

        def build_addresses
          country_id = Address.default.country.id
          @order.build_bill_address(country_id: country_id) if @order.bill_address.nil?
          @order.build_ship_address(country_id: country_id) if @order.ship_address.nil?
        end

        def refresh_shipment_rates
          @order.shipments.map(&:refresh_rates)
        end

        def recalculate_taxes
          # If the order's address has been changed, the tax zone could be different,
          # which means a different set of tax rates might be applicable.
          @order.create_tax_charge!
          Spree::TaxRate.adjust(@order, @order.adjustments.admin)

          @order.updater.update_totals_and_states
        end

        def order_params
          params.require(:order).permit(
            :email,
            :use_billing,
            bill_address_attributes: ::PermittedAttributes::Address.attributes,
            ship_address_attributes: ::PermittedAttributes::Address.attributes
          )
        end

        def load_order
          @order = Order.find_by!({ number: params[:order_id] }, include: :adjustments)
        end

        def check_authorization
          load_order
          session[:access_token] ||= params[:token]

          resource = @order
          action = params[:action].to_sym
          action = :edit if action == :show # show route renders :edit for this controller

          authorize! action, resource, session[:access_token]
        end<commit_msg>Remove reference to params[:token] in Admin::Orders::CustomerDetailsController<commit_after># frozen_string_literal: true

module Spree
  module Admin
    module Orders
      class CustomerDetailsController < Spree::Admin::BaseController
        before_action :load_order
        before_action :check_authorization
        before_action :set_guest_checkout_status, only: :update

        def show
          edit
          render action: :edit
        end

        def edit
          build_addresses
        end

        def update
          if @order.update(order_params)
            if params[:guest_checkout] == "false"
              @order.associate_user!(Spree::User.find_by(email: @order.email))
            end

            refresh_shipment_rates
            recalculate_taxes
            OrderWorkflow.new(@order).advance_to_payment

            flash[:success] = Spree.t('customer_details_updated')
            redirect_to spree.admin_order_customer_path(@order)
          else
            render action: :edit
          end
        end

        # Inherit CanCan permissions for the current order
        def model_class
          load_order unless @order
          @order
        end

        private

        def build_addresses
          country_id = Address.default.country.id
          @order.build_bill_address(country_id: country_id) if @order.bill_address.nil?
          @order.build_ship_address(country_id: country_id) if @order.ship_address.nil?
        end

        def refresh_shipment_rates
          @order.shipments.map(&:refresh_rates)
        end

        def recalculate_taxes
          # If the order's address has been changed, the tax zone could be different,
          # which means a different set of tax rates might be applicable.
          @order.create_tax_charge!
          Spree::TaxRate.adjust(@order, @order.adjustments.admin)

          @order.updater.update_totals_and_states
        end

        def order_params
          params.require(:order).permit(
            :email,
            :use_billing,
            bill_address_attributes: ::PermittedAttributes::Address.attributes,
            ship_address_attributes: ::PermittedAttributes::Address.attributes
          )
        end

        def load_order
          @order = Order.find_by!({ number: params[:order_id] }, include: :adjustments)
        end

        def check_authorization
          action = params[:action].to_sym
          action = :edit if action == :show # show route renders :edit for this controller

          authorize! action, @order
        end
{'fraction_non_alphanumeric': 0.06957024474850645, 'fraction_numerical': 0.0, 'mean_word_length': 2.0911256700416914, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '374584', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1344, 'n_words': 322}