diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 67fe16ad0c..33f527d1e3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp` -# using RuboCop version 1.56.1. +# using RuboCop version 1.56.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -186,7 +186,7 @@ Metrics/BlockNesting: Exclude: - 'app/models/spree/payment/processing.rb' -# Offense count: 43 +# Offense count: 44 # Configuration parameters: CountComments, Max, CountAsOne. Metrics/ClassLength: Exclude: @@ -226,7 +226,6 @@ Metrics/ClassLength: - 'app/services/cart_service.rb' - 'app/services/order_cycle_form.rb' - 'app/services/order_syncer.rb' - - 'app/services/sets/product_set.rb' - 'engines/order_management/app/services/order_management/order/updater.rb' - 'lib/open_food_network/enterprise_fee_calculator.rb' - 'lib/open_food_network/order_cycle_form_applicator.rb' @@ -290,7 +289,7 @@ Metrics/MethodLength: - 'lib/spree/localized_number.rb' - 'lib/tasks/sample_data/product_factory.rb' -# Offense count: 49 +# Offense count: 48 # Configuration parameters: CountComments, Max, CountAsOne. Metrics/ModuleLength: Exclude: @@ -341,7 +340,6 @@ Metrics/ModuleLength: - 'spec/models/spree/tax_rate_spec.rb' - 'spec/services/permissions/order_spec.rb' - 'spec/services/variant_units/option_value_namer_spec.rb' - - 'spec/support/request/shop_workflow.rb' - 'spec/support/request/stripe_stubs.rb' # Offense count: 7 @@ -440,14 +438,12 @@ Rails/HasManyOrHasOneDependent: - 'app/models/spree/user.rb' - 'app/models/spree/variant.rb' -# Offense count: 59 +# Offense count: 26 # Configuration parameters: Include. # Include: app/helpers/**/*.rb Rails/HelperInstanceVariable: Exclude: - - 'app/helpers/application_helper.rb' - 'app/helpers/injection_helper.rb' - - 'app/helpers/order_cycles_helper.rb' - 'app/helpers/shared_helper.rb' - 'app/helpers/shop_helper.rb' - 'app/helpers/spree/admin/orders_helper.rb' @@ -523,7 +519,7 @@ Rails/NegateInclude: - 'lib/spree/localized_number.rb' - 'spec/support/matchers/table_matchers.rb' -# Offense count: 17 +# Offense count: 16 Rails/OutputSafety: Exclude: - 'app/helpers/angular_form_helper.rb' @@ -533,19 +529,16 @@ Rails/OutputSafety: - 'app/helpers/spree/admin/navigation_helper.rb' - 'app/helpers/spree/admin/orders_helper.rb' - 'app/helpers/spree/admin/zones_helper.rb' - - 'app/serializers/api/product_serializer.rb' - 'lib/reporting/queries/query_builder.rb' - 'lib/reporting/queries/query_interface.rb' - 'lib/spree/money.rb' -# Offense count: 29 +# Offense count: 31 # This cop supports unsafe autocorrection (--autocorrect-all). Rails/Pluck: Exclude: - 'app/controllers/admin/variant_overrides_controller.rb' - - 'app/helpers/shop_helper.rb' - 'app/services/cart_service.rb' - - 'app/services/sets/product_set.rb' - 'lib/reporting/report_headers_builder.rb' - 'spec/controllers/admin/bulk_line_items_controller_spec.rb' - 'spec/controllers/admin/subscriptions_controller_spec.rb' @@ -830,7 +823,7 @@ Style/HashLikeCase: Exclude: - 'app/models/enterprise.rb' -# Offense count: 1767 +# Offense count: 1769 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5f1fbe616b..223a4c8f41 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -55,10 +55,10 @@ module ApplicationHelper end end - def body_classes + def body_classes(hide_menu, shopfront_layout) classes = [] - classes << "off-canvas" unless @hide_menu - classes << @shopfront_layout + classes << "off-canvas" unless hide_menu + classes << shopfront_layout end def pdf_stylesheet_pack_tag(source) diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb index 8cea6426f4..778f8b7d4b 100644 --- a/app/helpers/injection_helper.rb +++ b/app/helpers/injection_helper.rb @@ -12,7 +12,7 @@ module InjectionHelper "enterprises", enterprises || default_enterprise_query, Api::EnterpriseSerializer, - enterprise_injection_data + enterprise_injection_data, ) end @@ -56,15 +56,16 @@ module InjectionHelper inject_json_array "enterprises", enterprises_and_relatives, - Api::EnterpriseSerializer, enterprise_injection_data + Api::EnterpriseSerializer, + enterprise_injection_data end - def inject_group_enterprises + def inject_group_enterprises(group) inject_json_array( "enterprises", - @group.enterprises.activated.visible.all, + group.enterprises.activated.visible.all, Api::EnterpriseSerializer, - enterprise_injection_data + enterprise_injection_data, ) end @@ -105,29 +106,18 @@ module InjectionHelper inject_json "openStreetMapConfig", {}, Api::OpenStreetMapConfigSerializer end - def inject_spree_api_key + def inject_spree_api_key(spree_api_key) render partial: "json/injection_ams", - locals: { name: 'spreeApiKey', json: "'#{@spree_api_key}'" } + locals: { name: 'spreeApiKey', json: "'#{spree_api_key}'" } end def inject_available_countries inject_json_array "availableCountries", available_countries, Api::CountrySerializer end - def inject_enterprise_attributes + def inject_enterprise_attributes(enterprise_attributes) render partial: "json/injection_ams", - locals: { name: 'enterpriseAttributes', json: @enterprise_attributes.to_json.to_s } - end - - def inject_orders - inject_json_array "orders", @orders.all, Api::OrderSerializer - end - - def inject_shops - customers = spree_current_user.customers - shops = Enterprise.where(id: @orders.pluck(:distributor_id).uniq | - customers.pluck(:enterprise_id)) - inject_json_array "shops", shops.all, Api::ShopForOrdersSerializer + locals: { name: 'enterpriseAttributes', json: enterprise_attributes.to_json.to_s } end def inject_saved_credit_cards diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 1e04dba995..1e8d3a506a 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -55,8 +55,8 @@ module OrderCyclesHelper end end - def active_order_cycle_for_distributor?(_distributor) - OrderCycle.active.with_distributor(@distributor).present? + def active_order_cycle_for_distributor?(distributor) + OrderCycle.active.with_distributor(distributor).present? end def simple_index diff --git a/app/helpers/shop_helper.rb b/app/helpers/shop_helper.rb index 79d279f82a..3b649b8af2 100644 --- a/app/helpers/shop_helper.rb +++ b/app/helpers/shop_helper.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module ShopHelper - def oc_select_options - @order_cycles.map { |oc| { time: pickup_time(oc), id: oc.id } } + def oc_select_options(order_cycles) + order_cycles.map { |oc| { time: pickup_time(oc), id: oc.id } } end def require_customer? @@ -40,20 +40,17 @@ module ShopHelper } end - def shop_tab_names - shop_tabs.map { |tab| tab[:name] } - end - def show_home_tab? require_customer? || current_distributor.preferred_shopfront_message.present? end - def shopfront_closed_message? - no_open_order_cycles? && current_distributor.preferred_shopfront_closed_message.present? + def shopfront_closed_message?(order_cycles) + no_open_order_cycles?(order_cycles) && \ + current_distributor.preferred_shopfront_closed_message.present? end - def no_open_order_cycles? - @no_open_order_cycles ||= @order_cycles&.empty? + def no_open_order_cycles?(order_cycles) + @no_open_order_cycles ||= order_cycles&.empty? end def show_shopping_cta? diff --git a/app/views/enterprises/_change_order_cycle.html.haml b/app/views/enterprises/_change_order_cycle.html.haml index 09528f2606..79d3bb8e52 100644 --- a/app/views/enterprises/_change_order_cycle.html.haml +++ b/app/views/enterprises/_change_order_cycle.html.haml @@ -14,15 +14,15 @@ .select-label %span= t :enterprises_ready_for - - if oc_select_options.count == 1 + - if oc_select_options(@order_cycles).count == 1 %p - = oc_select_options.first[:time] + = oc_select_options(@order_cycles).first[:time] - else %select.select2.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id", "ofn-change-order-cycle" => true, "disabled" => require_customer?, - "ng-options" => "oc.id as oc.time for oc in #{oc_select_options.to_json}"} + "ng-options" => "oc.id as oc.time for oc in #{oc_select_options(@order_cycles).to_json}"} - - if oc_select_options.count > 1 + - if oc_select_options(@order_cycles).count > 1 %option{value: "", disabled: "", selected: ""}= t :shopping_oc_select diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index 13966cba3f..fa1ac33498 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -10,7 +10,7 @@ - content_for :injection_data do = inject_available_countries - = inject_group_enterprises + = inject_group_enterprises(@group) = inject_open_street_map_config - cache(*CacheService::FragmentCaching.ams_all_taxons) do = inject_taxons diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index e28fb78bff..94f710fcd3 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -35,7 +35,7 @@ = action_cable_meta_tag - %body{ class: body_classes, "body-scroll": "true", "data-turbo": "false" } + %body{ class: body_classes(@hide_menu, @shopfront_layout), "body-scroll": "true", "data-turbo": "false" } .off-canvas-wrap{ offcanvas: true } .fixed.off-canvas-fixed = render "shared/menu/menu" unless @hide_menu diff --git a/app/views/registration/index.html.haml b/app/views/registration/index.html.haml index b29e3e8bc3..444e0afd16 100644 --- a/app/views/registration/index.html.haml +++ b/app/views/registration/index.html.haml @@ -5,9 +5,9 @@ = render partial: "shared/google_maps_js" - content_for :injection_data do - = inject_spree_api_key + = inject_spree_api_key(@spree_api_key) = inject_available_countries - = inject_enterprise_attributes + = inject_enterprise_attributes(@enterprise_attributes) - steps = %w{about contact details finished images introduction} - steps += %w{logo promo social steps type} diff --git a/app/views/shop/messages/_closed_shop.html.haml b/app/views/shop/messages/_closed_shop.html.haml index 70f234f3da..7c65eeaef4 100644 --- a/app/views/shop/messages/_closed_shop.html.haml +++ b/app/views/shop/messages/_closed_shop.html.haml @@ -16,7 +16,7 @@ .small-12.columns .content .shopfront_closed_message - - if shopfront_closed_message? + - if shopfront_closed_message?(@order_cycles) = current_distributor.preferred_shopfront_closed_message.html_safe - else = t :shopping_oc_closed_description diff --git a/app/views/shopping_shared/_order_cycles.html.haml b/app/views/shopping_shared/_order_cycles.html.haml index eb83cf70e7..5ee3342637 100644 --- a/app/views/shopping_shared/_order_cycles.html.haml +++ b/app/views/shopping_shared/_order_cycles.html.haml @@ -1,7 +1,7 @@ - content_for :injection_data do = inject_current_order_cycle -- unless no_open_order_cycles? || require_customer? +- unless no_open_order_cycles?(@order_cycles) || require_customer? %ordercycle{"ng-controller" => "OrderCycleCtrl", "ng-cloak" => true, "ng-class" => "{'requires-selection': !OrderCycle.selected()}"} %form.custom diff --git a/app/views/shopping_shared/tabs/_home.html.haml b/app/views/shopping_shared/tabs/_home.html.haml index 139e578033..33a8981a04 100644 --- a/app/views/shopping_shared/tabs/_home.html.haml +++ b/app/views/shopping_shared/tabs/_home.html.haml @@ -5,7 +5,7 @@ = render partial: "shop/messages/customer_required" - else - - if no_open_order_cycles? + - if no_open_order_cycles?(@order_cycles) = render partial: "shop/messages/closed_shop" - else diff --git a/app/views/shopping_shared/tabs/_shop.html.haml b/app/views/shopping_shared/tabs/_shop.html.haml index 4c54e8bdf7..27705467d6 100644 --- a/app/views/shopping_shared/tabs/_shop.html.haml +++ b/app/views/shopping_shared/tabs/_shop.html.haml @@ -2,7 +2,7 @@ = render partial: "shopping_shared/order_cycles" %div{"ng-controller" => "ProductsCtrl"} - - if no_open_order_cycles? + - if no_open_order_cycles?(@order_cycles) = render partial: "shop/messages/closed_shop" - else = render partial: "shop/messages/select_oc" diff --git a/app/views/spree/orders/order_cycle_expired.html.haml b/app/views/spree/orders/order_cycle_expired.html.haml index 6f69341794..e1f88724d5 100644 --- a/app/views/spree/orders/order_cycle_expired.html.haml +++ b/app/views/spree/orders/order_cycle_expired.html.haml @@ -2,7 +2,7 @@ = t :orders_oc_expired_headline %p - - if active_order_cycle_for_distributor? current_distributor + - if active_order_cycle_for_distributor? @distributor = t :orders_oc_expired_text_others_html, time: distance_of_time_in_words_to_now(@order_cycle.orders_close_at), link: link_to t(:orders_oc_expired_text_link), spree.clear_orders_path - else = t :orders_oc_expired_text, time: distance_of_time_in_words_to_now(@order_cycle.orders_close_at)