<commit_before>module Spree
  module Api
    class LineItemsController < Spree::Api::BaseController
      def create
        variant = Spree::Variant.find(params[:line_item][:variant_id])
        @line_item = order.contents.add(variant, params[:line_item][:quantity] || 1)

        if @line_item.errors.empty?
          respond_with(@line_item, status: 201, default_template: :show)
        else
          invalid_resource!(@line_item)
        end
      end

      def update
        @line_item = find_line_item
        if @order.contents.update_cart(line_items_attributes)
          @line_item.reload
          respond_with(@line_item, default_template: :show)
        else
          invalid_resource!(@line_item)
        end
      end

      def destroy
        @line_item = find_line_item
        variant = Spree::Variant.with_deleted.find(@line_item.variant_id)
        @order.contents.remove(variant, @line_item.quantity)
        respond_with(@line_item, status: 204)
      end

      private
        def order
          @order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
          authorize! :update, @order, order_token
        end

        def find_line_item
          id = params[:id].to_i
          order.line_items.detect {|line_item| line_item.id == id} or
            raise ActiveRecord::RecordNotFound
        end

        def line_items_attributes
          { line_items_attributes: {
            id: params[:id],
            quantity: params[:line_item][:quantity]
          } }
        end

        def line_item_params
          whitelisted_params = [:quantity, :variant_id]
          whitelisted_params += [:price, :estimated_ship_date] if current_api_user.admin?
          params.require(:line_item).permit whitelisted_params
        end
    end
  end
end<commit_msg>more whitelist on line_items_attributes<commit_after>module Spree
  module Api
    class LineItemsController < Spree::Api::BaseController
      def create
        variant = Spree::Variant.find(params[:line_item][:variant_id])
        @line_item = order.contents.add(variant, params[:line_item][:quantity] || 1)

        if @line_item.errors.empty?
          respond_with(@line_item, status: 201, default_template: :show)
        else
          invalid_resource!(@line_item)
        end
      end

      def update
        @line_item = find_line_item
        if @order.contents.update_cart(line_items_attributes)
          @line_item.reload
          respond_with(@line_item, default_template: :show)
        else
          invalid_resource!(@line_item)
        end
      end

      def destroy
        @line_item = find_line_item
        variant = Spree::Variant.with_deleted.find(@line_item.variant_id)
        @order.contents.remove(variant, @line_item.quantity)
        respond_with(@line_item, status: 204)
      end

      private
        def order
          @order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
          authorize! :update, @order, order_token
        end

        def find_line_item
          id = params[:id].to_i
          order.line_items.detect {|line_item| line_item.id == id} or
            raise ActiveRecord::RecordNotFound
        end

        def line_items_attributes
          whitelisted_params = [:quantity, :variant_id]
          whitelisted_params += [:price, :estimated_ship_date] if current_api_user.admin?
          li_attrs = params.require(:line_item).permit whitelisted_params
          li_attrs[:id] = params[:id]
          { line_items_attributes: li_attrs }
        end

        def line_item_params
          whitelisted_params = [:quantity, :variant_id]
          whitelisted_params += [:price, :estimated_ship_date] if current_api_user.admin?
          params.require(:line_item).permit whitelisted_params
        end
    end
  end
end
{'fraction_non_alphanumeric': 0.09119496855345911, 'fraction_numerical': 0.003668763102725367, 'mean_word_length': 2.4418394950405773, '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': '4225600', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1112, 'n_words': 210}