mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Fix the easy rubocop issues in the new spree api controllers
This commit is contained in:
@@ -7,7 +7,7 @@ module Spree
|
||||
|
||||
def index
|
||||
if params[:ids]
|
||||
@products = product_scope.where(:id => params[:ids])
|
||||
@products = product_scope.where(id: params[:ids])
|
||||
else
|
||||
@products = product_scope.ransack(params[:q]).result
|
||||
end
|
||||
@@ -22,16 +22,15 @@ module Spree
|
||||
respond_with(@product)
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
def new; end
|
||||
|
||||
def create
|
||||
authorize! :create, Product
|
||||
params[:product][:available_on] ||= Time.now
|
||||
params[:product][:available_on] ||= Time.zone.now
|
||||
@product = Product.new(params[:product])
|
||||
begin
|
||||
if @product.save
|
||||
respond_with(@product, :status => 201, :default_template => :show)
|
||||
respond_with(@product, status: 201, default_template: :show)
|
||||
else
|
||||
invalid_resource!(@product)
|
||||
end
|
||||
@@ -45,7 +44,7 @@ module Spree
|
||||
authorize! :update, Product
|
||||
@product = find_product(params[:id])
|
||||
if @product.update_attributes(params[:product])
|
||||
respond_with(@product, :status => 200, :default_template => :show)
|
||||
respond_with(@product, status: 200, default_template: :show)
|
||||
else
|
||||
invalid_resource!(@product)
|
||||
end
|
||||
@@ -54,16 +53,17 @@ module Spree
|
||||
def destroy
|
||||
authorize! :delete, Product
|
||||
@product = find_product(params[:id])
|
||||
@product.update_attribute(:deleted_at, Time.now)
|
||||
@product.variants_including_master.update_all(:deleted_at => Time.now)
|
||||
respond_with(@product, :status => 204)
|
||||
@product.update_attribute(:deleted_at, Time.zone.now)
|
||||
@product.variants_including_master.update_all(deleted_at: Time.zone.now)
|
||||
respond_with(@product, status: 204)
|
||||
end
|
||||
|
||||
def managed
|
||||
authorize! :admin, Spree::Product
|
||||
authorize! :read, Spree::Product
|
||||
|
||||
@products = product_scope.ransack(params[:q]).result.managed_by(current_api_user).page(params[:page]).per(params[:per_page])
|
||||
@products = product_scope.
|
||||
ransack(params[:q]).result.managed_by(current_api_user).page(params[:page]).per(params[:per_page])
|
||||
respond_with(@products, default_template: :index)
|
||||
end
|
||||
|
||||
@@ -112,7 +112,8 @@ module Spree
|
||||
# Copied and modified from Spree::Api::BaseController to allow
|
||||
# enterprise users to access inactive products
|
||||
def product_scope
|
||||
if current_api_user.has_spree_role?("admin") || current_api_user.enterprises.present? # This line modified
|
||||
# This line modified
|
||||
if current_api_user.has_spree_role?("admin") || current_api_user.enterprises.present?
|
||||
scope = Spree::Product
|
||||
if params[:show_deleted]
|
||||
scope = scope.with_deleted
|
||||
|
||||
@@ -6,7 +6,7 @@ module Spree
|
||||
respond_to :json
|
||||
|
||||
before_filter :find_order
|
||||
before_filter :find_and_update_shipment, :only => [:ship, :ready, :add, :remove]
|
||||
before_filter :find_and_update_shipment, only: [:ship, :ready, :add, :remove]
|
||||
|
||||
def create
|
||||
variant = scoped_variant(params[:variant_id])
|
||||
@@ -38,7 +38,7 @@ module Spree
|
||||
end
|
||||
|
||||
@shipment.reload
|
||||
respond_with(@shipment, :default_template => :show)
|
||||
respond_with(@shipment, default_template: :show)
|
||||
end
|
||||
|
||||
def ready
|
||||
@@ -47,10 +47,11 @@ module Spree
|
||||
if @shipment.can_ready?
|
||||
@shipment.ready!
|
||||
else
|
||||
render "spree/api/shipments/cannot_ready_shipment", :status => 422 and return
|
||||
render "spree/api/shipments/cannot_ready_shipment", status: :unprocessable_entity
|
||||
return
|
||||
end
|
||||
end
|
||||
respond_with(@shipment, :default_template => :show)
|
||||
respond_with(@shipment, default_template: :show)
|
||||
end
|
||||
|
||||
def ship
|
||||
@@ -58,7 +59,7 @@ module Spree
|
||||
unless @shipment.shipped?
|
||||
@shipment.ship!
|
||||
end
|
||||
respond_with(@shipment, :default_template => :show)
|
||||
respond_with(@shipment, default_template: :show)
|
||||
end
|
||||
|
||||
def add
|
||||
|
||||
@@ -16,14 +16,13 @@ module Spree
|
||||
respond_with(@variant)
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
def new; end
|
||||
|
||||
def create
|
||||
authorize! :create, Variant
|
||||
@variant = scope.new(params[:variant])
|
||||
if @variant.save
|
||||
respond_with(@variant, :status => 201, :default_template => :show)
|
||||
respond_with(@variant, status: 201, default_template: :show)
|
||||
else
|
||||
invalid_resource!(@variant)
|
||||
end
|
||||
@@ -33,7 +32,7 @@ module Spree
|
||||
authorize! :update, Variant
|
||||
@variant = scope.find(params[:id])
|
||||
if @variant.update_attributes(params[:variant])
|
||||
respond_with(@variant, :status => 200, :default_template => :show)
|
||||
respond_with(@variant, status: 200, default_template: :show)
|
||||
else
|
||||
invalid_resource!(@product)
|
||||
end
|
||||
@@ -51,33 +50,34 @@ module Spree
|
||||
authorize! :delete, Variant
|
||||
@variant = scope.find(params[:id])
|
||||
@variant.destroy
|
||||
respond_with(@variant, :status => 204)
|
||||
respond_with(@variant, status: 204)
|
||||
end
|
||||
|
||||
private
|
||||
def product
|
||||
@product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
|
||||
end
|
||||
|
||||
def scope
|
||||
if @product
|
||||
unless current_api_user.has_spree_role?("admin") || params[:show_deleted]
|
||||
variants = @product.variants_including_master
|
||||
else
|
||||
variants = @product.variants_including_master.with_deleted
|
||||
def product
|
||||
@product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
|
||||
end
|
||||
|
||||
def scope
|
||||
if @product
|
||||
unless current_api_user.has_spree_role?("admin") || params[:show_deleted]
|
||||
variants = @product.variants_including_master
|
||||
else
|
||||
variants = @product.variants_including_master.with_deleted
|
||||
end
|
||||
else
|
||||
variants = Variant.scoped
|
||||
if current_api_user.has_spree_role?("admin")
|
||||
unless params[:show_deleted]
|
||||
variants = Variant.active
|
||||
end
|
||||
else
|
||||
variants = Variant.scoped
|
||||
if current_api_user.has_spree_role?("admin")
|
||||
unless params[:show_deleted]
|
||||
variants = Variant.active
|
||||
end
|
||||
else
|
||||
variants = variants.active
|
||||
end
|
||||
variants = variants.active
|
||||
end
|
||||
variants
|
||||
end
|
||||
variants
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user