mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Inspecting 1481 files
.........................................C.................C.........................................................CC........C..........C.C.........C..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Offenses:
app/controllers/admin/resource_controller.rb:39:5: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def update
^^^^^^^^^^
app/controllers/admin/resource_controller.rb:39:5: C: [Corrected] Rails/ActionOrder: Action create should appear before update.
def create ...
^^^^^^^^^^
app/controllers/admin/resource_controller.rb:51:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/admin/resource_controller.rb:52:5: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def update_positions
^^^^^^^^^^^^^^^^^^^^
app/controllers/api/v0/orders_controller.rb:13:7: C: [Corrected] Rails/ActionOrder: Action index should appear before show.
def index ...
^^^^^^^^^
app/controllers/api/v0/orders_controller.rb:23:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def show
^^^^^^^^
app/controllers/api/v0/orders_controller.rb:28:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/api/v0/orders_controller.rb:29:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def update
^^^^^^^^^^
app/controllers/spree/admin/images_controller.rb:26:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def create
^^^^^^^^^^
app/controllers/spree/admin/images_controller.rb:37:7: C: [Corrected] Rails/ActionOrder: Action edit should appear before create.
def edit ...
^^^^^^^^
app/controllers/spree/admin/images_controller.rb:40:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/images_controller.rb:41:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def update
^^^^^^^^^^
app/controllers/spree/admin/invoices_controller.rb:19:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def create
^^^^^^^^^^
app/controllers/spree/admin/invoices_controller.rb:43:7: C: [Corrected] Rails/ActionOrder: Action show should appear before create.
def show ...
^^^^^^^^
app/controllers/spree/admin/invoices_controller.rb:49:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/invoices_controller.rb:50:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def poll
^^^^^^^^
app/controllers/spree/admin/products_controller.rb:23:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def new
^^^^^^^
app/controllers/spree/admin/products_controller.rb:23:7: C: [Corrected] Rails/ActionOrder: Action show should appear before new.
def show ...
^^^^^^^^
app/controllers/spree/admin/products_controller.rb:24:7: C: [Corrected] Rails/ActionOrder: Action index should appear before show.
def index ...
^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:27:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/products_controller.rb:27:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def create
^^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:28:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/products_controller.rb:28:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def new
^^^^^^^
app/controllers/spree/admin/products_controller.rb:28:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def index
^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:28:7: C: [Corrected] Rails/ActionOrder: Action index should appear before new.
def index ...
^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:29:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def new
^^^^^^^
app/controllers/spree/admin/products_controller.rb:32:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/products_controller.rb:32:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def create
^^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:33:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def edit
^^^^^^^^
app/controllers/spree/admin/products_controller.rb:36:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def create
^^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:38:7: C: [Corrected] Rails/ActionOrder: Action show should appear before create.
def show ...
^^^^^^^^
app/controllers/spree/admin/products_controller.rb:42:7: C: [Corrected] Rails/ActionOrder: Action index should appear before create.
def index ...
^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:43:7: C: [Corrected] Rails/ActionOrder: Action index should appear before create.
def index ...
^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:43:7: C: [Corrected] Rails/ActionOrder: Action index should appear before show.
def index ...
^^^^^^^^^
app/controllers/spree/admin/products_controller.rb:47:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/products_controller.rb:48:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def edit
^^^^^^^^
app/controllers/spree/admin/products_controller.rb:48:7: C: [Corrected] Rails/ActionOrder: Action edit should appear before create.
def edit ...
^^^^^^^^
app/controllers/spree/admin/products_controller.rb:51:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/products_controller.rb:52:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def update
^^^^^^^^^^
app/controllers/spree/admin/taxons_controller.rb:13:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def create
^^^^^^^^^^
app/controllers/spree/admin/taxons_controller.rb:29:7: C: [Corrected] Rails/ActionOrder: Action edit should appear before create.
def edit ...
^^^^^^^^
app/controllers/spree/admin/taxons_controller.rb:34:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/taxons_controller.rb:35:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def update
^^^^^^^^^^
app/controllers/spree/admin/variants_controller.rb:17:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def edit
^^^^^^^^
app/controllers/spree/admin/variants_controller.rb:18:7: C: [Corrected] Rails/ActionOrder: Action new should appear before edit.
def new ...
^^^^^^^
app/controllers/spree/admin/variants_controller.rb:21:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/variants_controller.rb:21:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def update
^^^^^^^^^^
app/controllers/spree/admin/variants_controller.rb:22:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def create
^^^^^^^^^^
app/controllers/spree/admin/variants_controller.rb:31:7: C: [Corrected] Rails/ActionOrder: Action new should appear before update.
def new ...
^^^^^^^
app/controllers/spree/admin/variants_controller.rb:34:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/variants_controller.rb:35:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def create
^^^^^^^^^^
app/controllers/spree/admin/variants_controller.rb:35:7: C: [Corrected] Rails/ActionOrder: Action create should appear before update.
def create ...
^^^^^^^^^^
app/controllers/spree/admin/variants_controller.rb:42:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def update
^^^^^^^^^^
app/controllers/spree/admin/variants_controller.rb:55:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/spree/admin/variants_controller.rb:56:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def search
^^^^^^^^^^
app/controllers/user_confirmations_controller.rb:14:3: C: [Corrected] Rails/ActionOrder: Action show should appear before new.
def show ...
^^^^^^^^
app/controllers/user_confirmations_controller.rb:15:3: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def new
^^^^^^^
app/controllers/user_confirmations_controller.rb:19:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/user_confirmations_controller.rb:20:3: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 0.
def create
^^^^^^^^^^
app/controllers/user_confirmations_controller.rb:21:3: C: [Corrected] Layout/EmptyLineBetweenDefs: Expected 1 empty line between method definitions; found 2.
def create
^^^^^^^^^^
app/controllers/user_confirmations_controller.rb:37:3: C: [Corrected] Rails/ActionOrder: Action show should appear before create.
def show ...
^^^^^^^^
app/controllers/user_confirmations_controller.rb:42:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
app/controllers/user_confirmations_controller.rb:43:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
1481 files inspected, 63 offenses detected, 63 offenses corrected
113 lines
3.5 KiB
Ruby
113 lines
3.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'open_food_network/scope_variants_for_search'
|
|
|
|
module Spree
|
|
module Admin
|
|
class VariantsController < ::Admin::ResourceController
|
|
belongs_to 'spree/product'
|
|
|
|
def index
|
|
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
|
|
end
|
|
|
|
def new
|
|
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
|
|
end
|
|
|
|
def edit
|
|
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
|
|
end
|
|
|
|
def create
|
|
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
|
|
|
|
on_demand = params[:variant].delete(:on_demand)
|
|
on_hand = params[:variant].delete(:on_hand)
|
|
|
|
@object.attributes = permitted_resource_params
|
|
if @object.save
|
|
flash[:success] = flash_message_for(@object, :successfully_created)
|
|
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
|
|
else
|
|
flash[:error] = @object.errors.full_messages.to_sentence if @object.errors.any?
|
|
redirect_to spree.new_admin_product_variant_url(params[:product_id], @url_filters)
|
|
end
|
|
|
|
return unless @object.present? && @object.valid?
|
|
|
|
@object.on_demand = on_demand if on_demand.present?
|
|
@object.on_hand = on_hand.to_i if on_hand.present?
|
|
end
|
|
|
|
def update
|
|
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
|
|
|
|
if @object.update(permitted_resource_params)
|
|
flash[:success] = flash_message_for(@object, :successfully_updated)
|
|
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
|
|
else
|
|
redirect_to spree.edit_admin_product_variant_url(params[:product_id],
|
|
@object,
|
|
@url_filters)
|
|
end
|
|
end
|
|
|
|
def search
|
|
scoper = OpenFoodNetwork::ScopeVariantsForSearch.new(variant_search_params)
|
|
@variants = scoper.search
|
|
render json: @variants, each_serializer: ::Api::Admin::VariantSerializer
|
|
end
|
|
|
|
def destroy
|
|
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
|
|
|
|
@variant = Spree::Variant.find(params[:id])
|
|
flash[:success] = delete_variant
|
|
|
|
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
|
|
end
|
|
|
|
protected
|
|
|
|
def delete_variant
|
|
if VariantDeleter.new.delete(@variant)
|
|
Spree.t('notice_messages.variant_deleted')
|
|
else
|
|
Spree.t('notice_messages.variant_not_deleted')
|
|
end
|
|
end
|
|
|
|
def create_before
|
|
@object.save
|
|
end
|
|
|
|
def collection
|
|
@deleted = params.key?(:deleted) && params[:deleted] == "on" ? "checked" : ""
|
|
|
|
@collection ||= if @deleted.blank?
|
|
super
|
|
else
|
|
Variant.unscoped.where(product_id: parent.id).deleted
|
|
end
|
|
@collection
|
|
end
|
|
|
|
def variant_params
|
|
params.require(:variant).permit(::PermittedAttributes::Variant.attributes)
|
|
end
|
|
|
|
def permitted_resource_params
|
|
variant_params
|
|
end
|
|
|
|
def variant_search_params
|
|
params.permit(
|
|
:q, :distributor_id, :order_cycle_id, :schedule_id, :eligible_for_subscriptions,
|
|
:include_out_of_stock
|
|
).to_h.with_indifferent_access
|
|
end
|
|
end
|
|
end
|
|
end
|