Move spree/api/base_controller#find_product to api/product_controller where it is used exclusively

Also, product_scope stops being an override
This commit is contained in:
luisramos0
2019-08-01 23:04:07 +01:00
parent f840179573
commit 0d34b607c3
2 changed files with 6 additions and 22 deletions

View File

@@ -94,10 +94,13 @@ module Api
private
# Copied and modified from SpreeApi::BaseController to allow
# enterprise users to access inactive products
def find_product(id)
product_scope.find_by_permalink!(id.to_s)
rescue ActiveRecord::RecordNotFound
product_scope.find(id)
end
def product_scope
# This line modified
if current_api_user.has_spree_role?("admin") || current_api_user.enterprises.present?
scope = Spree::Product
if params[:show_deleted]

View File

@@ -69,25 +69,6 @@ module Spree
request.headers["X-Spree-Token"] || params[:token]
end
helper_method :api_key
def find_product(id)
product_scope.find_by_permalink!(id.to_s)
rescue ActiveRecord::RecordNotFound
product_scope.find(id)
end
def product_scope
if current_api_user.has_spree_role?("admin")
scope = Product
if params[:show_deleted]
scope = scope.with_deleted
end
else
scope = Product.active
end
scope.includes(:master)
end
end
end
end