Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Deprecated code from API component #5020

Merged
merged 7 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions api/app/controllers/spree/api/customer_returns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ def build_customer_return
return_items_params = customer_return_attributes.
delete(:return_items_attributes)

if return_items_params.is_a? ActionController::Parameters
return_items_params = return_items_params.values
Spree::Deprecation.warn(
"Passing `return_items_attributes` as a hash of hashes is \
deprecated and will be removed in future versions of Solidus."
)
end

@customer_return = CustomerReturn.new(customer_return_attributes)

@customer_return.return_items = return_items_params.map do |item_params|
Expand Down
21 changes: 0 additions & 21 deletions api/app/controllers/spree/api/option_values_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,11 @@ def index
end

def show
warn_if_nested_member_route

@option_value = scope.find(params[:id])
respond_with(@option_value)
end

def create
Spree::Deprecation.warn <<~MSG unless request.path.include?('/option_types/')
This route is deprecated, as it'll be no longer possible to create an
option_value without an associated option_type. Please, use instead:

POST api/option_types/{option_type_id}/option_values
MSG

authorize! :create, Spree::OptionValue
@option_value = scope.new(option_value_params)
if @option_value.save
Expand All @@ -37,8 +28,6 @@ def create
end

def update
warn_if_nested_member_route

@option_value = scope.accessible_by(current_ability, :update).find(params[:id])
if @option_value.update(option_value_params)
render :show
Expand All @@ -48,8 +37,6 @@ def update
end

def destroy
warn_if_nested_member_route

@option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
@option_value.destroy
render plain: nil, status: 204
Expand All @@ -68,14 +55,6 @@ def scope
def option_value_params
params.require(:option_value).permit(permitted_option_value_attributes)
end

def warn_if_nested_member_route
Spree::Deprecation.warn <<~MSG if request.path.include?('/option_types/')
This route is deprecated. Use shallow version instead:

#{request.method.upcase} api/option_values/:id
MSG
end
end
end
end
102 changes: 0 additions & 102 deletions api/app/controllers/spree/api/resource_controller.rb

This file was deleted.

26 changes: 0 additions & 26 deletions api/app/controllers/spree/api/shipments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,8 @@ def select_shipping_method

def create
authorize! :create, Shipment

@shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))

if passing_deprecated_params_on_create?
Spree::Deprecation.warn <<~MSG
Passing `quantity` or `variant_id` to

POST /api/shipments

is deprecated and won't be allowed anymore starting from Solidus 4.0.
Instead, create an empty shipment and add items to it subsequently using
the dedicated endpoint:

PUT /api/shipments/{shipment_number}/add

MSG

quantity = params[:quantity].to_i
variant = Spree::Variant.unscoped.find(params[:variant_id])
@order.contents.add(variant, quantity, { shipment: @shipment })
@shipment.save!
@shipment.reload
end

respond_with(@shipment, default_template: :show)
end

Expand Down Expand Up @@ -149,10 +127,6 @@ def load_transfer_params
authorize! :create, Shipment
end

def passing_deprecated_params_on_create?
params[:variant_id] || params[:quantity]
end

def find_order_on_create
@order = Spree::Order.find_by!(number: params[:shipment][:order_id])
authorize! :show, @order
Expand Down
20 changes: 0 additions & 20 deletions api/app/controllers/spree/api/variants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ class VariantsController < Spree::Api::BaseController
before_action :product

def create
Spree::Deprecation.warn <<~MSG unless request.path.include?('/products/')
This route is deprecated. Use the route nested within the product resource:

POST api/products/{product_id}/variants
MSG

authorize! :create, Variant
@variant = scope.new(variant_params)
if @variant.save
Expand All @@ -22,8 +16,6 @@ def create
end

def destroy
warn_if_nested_member_route

@variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
@variant.discard
respond_with(@variant, status: 204)
Expand All @@ -50,16 +42,12 @@ def new
end

def show
warn_if_nested_member_route

@variant = scope.includes(include_list)
.find(params[:id])
respond_with(@variant)
end

def update
warn_if_nested_member_route

@variant = scope.accessible_by(current_ability, :update).find(params[:id])
if @variant.update(variant_params)
respond_with(@variant, status: 200, default_template: :show)
Expand All @@ -70,14 +58,6 @@ def update

private

def warn_if_nested_member_route
Spree::Deprecation.warn <<~MSG if request.path.include?('/products/')
This route is deprecated. Use shallow version instead:

#{request.method.upcase} api/variants/:id
MSG
end

def product
@product ||= Spree::Product.accessible_by(current_ability, :show).friendly.find(params[:product_id]) if params[:product_id]
end
Expand Down
5 changes: 0 additions & 5 deletions api/app/helpers/spree/api/api_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ module ApiHelpers
define_method attribute do
Spree::Api::Config.send(attribute)
end

define_singleton_method attribute do
Spree::Deprecation.warn("Please use Spree::Api::Config::#{attribute} instead.")
Spree::Api::Config.send(attribute)
end
end

def required_fields_for(model)
Expand Down
7 changes: 2 additions & 5 deletions api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@
end

resources :option_types do
# TODO: Use shallow option on Solidus v4.0
resources :option_values
resources :option_values, shallow: true
end
# TODO: Use only: :index on Solidus v4.0 and use shallow option on the nested routes
# within option_types
resources :option_values
resources :option_values, only: :index

get '/orders/mine', to: 'orders#mine', as: 'my_orders'
get "/orders/current", to: "orders#current", as: "current_order"
Expand Down
Loading