From 9404aacfb2d27f5292d12e714c13e0b38b0d4126 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 10 Nov 2019 18:42:43 +0000 Subject: [PATCH 1/6] run rubocop --auto-correct --- app/controllers/admin/customers_controller.rb | 1 + .../admin/order_cycles_controller.rb | 18 ++- .../admin/product_import_controller.rb | 2 + app/controllers/admin/schedules_controller.rb | 6 + .../admin/stripe_accounts_controller.rb | 2 + .../stripe_connect_settings_controller.rb | 1 + .../subscription_line_items_controller.rb | 3 + .../admin/subscriptions_controller.rb | 4 + app/controllers/api/base_controller.rb | 1 + .../api/enterprise_attachment_controller.rb | 1 + app/controllers/api/products_controller.rb | 10 +- app/controllers/api/statuses_controller.rb | 2 +- app/controllers/api/taxons_controller.rb | 1 + app/controllers/api/variants_controller.rb | 18 +-- app/controllers/application_controller.rb | 1 + app/controllers/enterprises_controller.rb | 1 + app/controllers/line_items_controller.rb | 1 + .../spree/admin/base_controller_decorator.rb | 1 + .../admin/general_settings_controller.rb | 2 + .../spree/admin/mail_methods_controller.rb | 1 + .../customer_details_controller_decorator.rb | 1 + .../spree/admin/payment_methods_controller.rb | 2 + .../admin/payments_controller_decorator.rb | 4 +- .../admin/products_controller_decorator.rb | 8 +- .../admin/reports_controller_decorator.rb | 12 +- .../admin/resource_controller_decorator.rb | 2 +- .../admin/shipping_methods_controller.rb | 2 + .../spree/admin/taxonomies_controller.rb | 2 +- .../spree/admin/taxons_controller.rb | 10 +- .../spree/admin/users_controller.rb | 2 + app/controllers/spree/checkout_controller.rb | 2 +- .../spree/credit_cards_controller.rb | 2 + app/controllers/spree/orders_controller.rb | 4 +- .../spree/paypal_controller_decorator.rb | 1 + .../user_registrations_controller.rb | 4 +- app/helpers/admin/injection_helper.rb | 16 +-- app/helpers/admin/subscriptions_helper.rb | 1 + app/helpers/angular_form_builder.rb | 1 + app/helpers/enterprises_helper.rb | 3 + app/helpers/footer_links_helper.rb | 2 +- app/helpers/groups_helper.rb | 5 +- app/helpers/html_helper.rb | 2 +- app/helpers/serializer_helper.rb | 1 + .../admin/navigation_helper_decorator.rb | 1 + .../spree/admin/orders_helper_decorator.rb | 2 + app/helpers/spree/orders_helper.rb | 2 + app/jobs/heartbeat_job.rb | 2 +- app/jobs/subscription_confirm_job.rb | 2 + app/mailers/producer_mailer.rb | 1 + app/models/column_preference.rb | 1 + app/models/concerns/order_shipment.rb | 2 + app/models/concerns/product_stock.rb | 1 + app/models/customer.rb | 1 + app/models/enterprise.rb | 10 +- app/models/enterprise_group.rb | 9 +- app/models/order_cycle.rb | 2 + app/models/order_updater.rb | 3 +- app/models/product_import/entry_validator.rb | 10 +- app/models/product_import/product_importer.rb | 2 + app/models/product_import/reset_absent.rb | 1 + app/models/product_import/spreadsheet_data.rb | 1 + app/models/proxy_order.rb | 3 + .../spree/calculator/per_item_decorator.rb | 1 + app/models/spree/credit_card_decorator.rb | 1 + app/models/spree/gateway/stripe_connect.rb | 1 + app/models/spree/line_item_decorator.rb | 4 + app/models/spree/order_decorator.rb | 10 +- app/models/spree/payment_decorator.rb | 2 + app/models/spree/product_decorator.rb | 2 + app/models/spree/product_set.rb | 9 +- app/models/spree/shipment_decorator.rb | 1 + app/models/spree/tax_rate_decorator.rb | 1 + app/models/spree/user.rb | 3 + app/models/spree/variant_decorator.rb | 2 + app/models/subscription.rb | 2 + app/models/tag_rule/discount_order.rb | 1 + .../api/admin/customer_serializer.rb | 1 + .../supplied_product_serializer.rb | 2 +- .../api/admin/index_enterprise_serializer.rb | 1 + .../api/admin/line_item_serializer.rb | 1 + .../api/admin/order_cycle_serializer.rb | 2 +- app/serializers/api/admin/order_serializer.rb | 3 + .../api/admin/product_serializer.rb | 1 + .../api/admin/proxy_order_serializer.rb | 1 + .../api/admin/subscription_serializer.rb | 1 + .../api/admin/variant_serializer.rb | 4 + .../api/cached_enterprise_serializer.rb | 2 + .../api/enterprise_shopfront_serializer.rb | 2 + app/serializers/api/order_serializer.rb | 2 + app/serializers/api/variant_serializer.rb | 1 + app/services/advance_order_service.rb | 1 + app/services/embedded_page_service.rb | 6 + app/services/exchange_variant_bulk_updater.rb | 1 + .../order_cycle_distributed_variants.rb | 1 + app/services/order_cycle_form.rb | 4 + app/services/order_factory.rb | 2 + app/services/order_syncer.rb | 6 + app/services/product_tag_rules_filterer.rb | 2 + app/services/search_orders.rb | 2 + app/services/subscription_estimator.rb | 3 + app/services/subscription_form.rb | 1 + app/services/subscription_validator.rb | 10 ++ app/services/subscriptions_count.rb | 1 + app/services/tax_rate_finder.rb | 1 + .../data_representations/coordinator_fee.rb | 1 + .../enterprise_fee_summary/summarizer.rb | 1 + lib/discourse/single_sign_on.rb | 2 +- lib/open_food_network/address_finder.rb | 7 +- lib/open_food_network/bulk_coop_report.rb | 2 + .../column_preference_defaults.rb | 130 +++++++++--------- lib/open_food_network/customers_report.rb | 1 + .../enterprise_issue_validator.rb | 2 + lib/open_food_network/lettuce_share_report.rb | 1 + .../order_cycle_form_applicator.rb | 2 + .../order_cycle_permissions.rb | 4 + lib/open_food_network/packing_report.rb | 2 + lib/open_food_network/payments_report.rb | 1 + lib/open_food_network/permalink_generator.rb | 1 + lib/open_food_network/permissions.rb | 2 + .../products_and_inventory_report.rb | 2 + lib/open_food_network/proxy_order_syncer.rb | 3 + lib/open_food_network/rack_request_blocker.rb | 4 +- lib/open_food_network/sales_tax_report.rb | 2 + .../subscription_payment_updater.rb | 3 + .../subscription_summarizer.rb | 1 + lib/open_food_network/tag_rule_applicator.rb | 4 + .../users_and_enterprises_report.rb | 9 +- .../variant_and_line_item_naming.rb | 4 + lib/open_food_network/xero_invoices_report.rb | 1 + lib/spree/authentication_helpers.rb | 12 +- lib/spree/localized_number.rb | 2 + lib/stripe/webhook_handler.rb | 2 + lib/tasks/data.rake | 2 + lib/tasks/karma.rake | 1 + lib/tasks/sample_data/customer_factory.rb | 1 + lib/tasks/sample_data/fee_factory.rb | 1 + .../sample_data/payment_method_factory.rb | 1 + .../sample_data/shipping_method_factory.rb | 1 + lib/tasks/sample_data/taxon_factory.rb | 1 + .../api/products_controller_spec.rb | 4 +- .../api/statuses_controller_spec.rb | 2 +- .../controllers/api/taxons_controller_spec.rb | 2 +- .../api/variants_controller_spec.rb | 2 +- .../admin/image_settings_controller_spec.rb | 6 +- .../spree/orders_controller_spec.rb | 6 +- spec/factories/product_factory.rb | 1 + .../admin/bulk_product_update_spec.rb | 4 +- spec/features/admin/image_settings_spec.rb | 4 +- spec/features/admin/orders_spec.rb | 4 +- spec/features/admin/users_spec.rb | 10 +- spec/jobs/heartbeat_job_spec.rb | 2 +- .../products_and_inventory_report_spec.rb | 12 +- spec/mailers/order_mailer_spec.rb | 2 +- spec/mailers/subscription_mailer_spec.rb | 8 +- spec/models/column_preference_spec.rb | 9 +- spec/models/content_configuration_spec.rb | 2 +- spec/models/enterprise_relationship_spec.rb | 6 +- .../subscription_line_item_serializer_spec.rb | 2 +- .../api/admin/variant_serializer_spec.rb | 1 - .../api/product_serializer_spec.rb | 2 +- spec/services/embedded_page_service_spec.rb | 2 +- spec/services/order_syncer_spec.rb | 2 +- .../product_tag_rules_filterer_spec.rb | 1 - spec/services/subscription_form_spec.rb | 3 +- spec/spec_helper.rb | 4 +- spec/support/request/web_helper.rb | 1 + 166 files changed, 441 insertions(+), 206 deletions(-) diff --git a/app/controllers/admin/customers_controller.rb b/app/controllers/admin/customers_controller.rb index b1fdac2e5c..a2109c3fca 100644 --- a/app/controllers/admin/customers_controller.rb +++ b/app/controllers/admin/customers_controller.rb @@ -63,6 +63,7 @@ module Admin def collection return Customer.where("1=0") unless json_request? && params[:enterprise_id].present? + enterprise = Enterprise.managed_by(spree_current_user).find_by_id(params[:enterprise_id]) Customer.of(enterprise) end diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 03462e363e..b4ee2c3d63 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -12,7 +12,9 @@ module Admin respond_to do |format| format.html format.json do - render_as_json @collection, ams_prefix: params[:ams_prefix], current_user: spree_current_user, subscriptions_count: SubscriptionsCount.new(@collection) + render_as_json @collection, ams_prefix: params[:ams_prefix], + current_user: spree_current_user, + subscriptions_count: SubscriptionsCount.new(@collection) end end end @@ -62,7 +64,9 @@ module Admin def bulk_update if order_cycle_set.andand.save - render_as_json @order_cycles, ams_prefix: 'index', current_user: spree_current_user, subscriptions_count: SubscriptionsCount.new(@collection) + render_as_json @order_cycles, ams_prefix: 'index', + current_user: spree_current_user, + subscriptions_count: SubscriptionsCount.new(@collection) else order_cycle = order_cycle_set.collection.find{ |oc| oc.errors.present? } render json: { errors: order_cycle.errors.full_messages }, status: :unprocessable_entity @@ -72,14 +76,16 @@ module Admin def clone @order_cycle = OrderCycle.find params[:id] @order_cycle.clone! - redirect_to main_app.admin_order_cycles_path, notice: I18n.t(:order_cycles_clone_notice, name: @order_cycle.name) + redirect_to main_app.admin_order_cycles_path, + notice: I18n.t(:order_cycles_clone_notice, name: @order_cycle.name) end # Send notifications to all producers who are part of the order cycle def notify_producers Delayed::Job.enqueue OrderCycleNotificationJob.new(params[:id].to_i) - redirect_to main_app.admin_order_cycles_path, notice: I18n.t(:order_cycles_email_to_producers_notice) + redirect_to main_app.admin_order_cycles_path, + notice: I18n.t(:order_cycles_email_to_producers_notice) end protected @@ -87,6 +93,7 @@ module Admin def collection return Enterprise.where("1=0") unless json_request? return order_cycles_from_set if params[:order_cycle_set] + ocs = if params[:as] == "distributor" OrderCycle.preload(:schedules).ransack(params[:q]).result. involving_managed_distributors_of(spree_current_user).order('updated_at DESC') @@ -95,7 +102,7 @@ module Admin involving_managed_producers_of(spree_current_user).order('updated_at DESC') else OrderCycle.preload(:schedules).ransack(params[:q]).result.accessible_by(spree_current_user) - end + end ocs.undated | ocs.soonest_closing | @@ -181,6 +188,7 @@ module Admin def require_order_cycle_set_params return if params[:order_cycle_set] + render json: { errors: t('admin.order_cycles.bulk_update.no_data') }, status: :unprocessable_entity end diff --git a/app/controllers/admin/product_import_controller.rb b/app/controllers/admin/product_import_controller.rb index fd700d633f..f35c00a913 100644 --- a/app/controllers/admin/product_import_controller.rb +++ b/app/controllers/admin/product_import_controller.rb @@ -23,11 +23,13 @@ module Admin def validate_data return unless process_data('validate') + render json: @importer.import_results, response: 200 end def save_data return unless process_data('save') + render json: @importer.save_results, response: 200 end diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index a2e0aff384..580a6a9c72 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -31,6 +31,7 @@ module Admin def collection return Schedule.where("1=0") unless json_request? + if params[:enterprise_id] filter_schedules_by_enterprise_id(permissions.visible_schedules, params[:enterprise_id]) else @@ -49,6 +50,7 @@ module Admin def check_editable_order_cycle_ids return unless params[:schedule][:order_cycle_ids] + requested = params[:schedule][:order_cycle_ids] @existing_order_cycle_ids = @schedule.persisted? ? @schedule.order_cycle_ids : [] permitted = OrderCycle.where(id: params[:schedule][:order_cycle_ids] | @existing_order_cycle_ids).merge(OrderCycle.managed_by(spree_current_user)).pluck(:id) @@ -61,19 +63,23 @@ module Admin def check_dependent_subscriptions return if Subscription.where(schedule_id: @schedule).empty? + render json: { errors: [t('admin.schedules.destroy.associated_subscriptions_error')] }, status: :conflict end def permissions return @permissions unless @permission.nil? + @permissions = OpenFoodNetwork::Permissions.new(spree_current_user) end def sync_subscriptions return unless params[:schedule][:order_cycle_ids] + removed_ids = @existing_order_cycle_ids - @schedule.order_cycle_ids new_ids = @schedule.order_cycle_ids - @existing_order_cycle_ids return unless removed_ids.any? || new_ids.any? + subscriptions = Subscription.where(schedule_id: @schedule) syncer = OpenFoodNetwork::ProxyOrderSyncer.new(subscriptions) syncer.sync! diff --git a/app/controllers/admin/stripe_accounts_controller.rb b/app/controllers/admin/stripe_accounts_controller.rb index e0a72c093c..81e524ce6c 100644 --- a/app/controllers/admin/stripe_accounts_controller.rb +++ b/app/controllers/admin/stripe_accounts_controller.rb @@ -27,8 +27,10 @@ module Admin def status return render json: { status: :stripe_disabled } unless Spree::Config.stripe_connect_enabled + stripe_account = StripeAccount.find_by_enterprise_id(params[:enterprise_id]) return render json: { status: :account_missing } unless stripe_account + authorize! :status, stripe_account begin diff --git a/app/controllers/admin/stripe_connect_settings_controller.rb b/app/controllers/admin/stripe_connect_settings_controller.rb index 270ba91528..bbe75b7806 100644 --- a/app/controllers/admin/stripe_connect_settings_controller.rb +++ b/app/controllers/admin/stripe_connect_settings_controller.rb @@ -8,6 +8,7 @@ module Admin def edit return @stripe_account = { status: :empty_api_key_error_html } if Stripe.api_key.blank? + attrs = %i[id business_name charges_enabled] @obfuscated_secret_key = obfuscated_secret_key @stripe_account = Stripe::Account.retrieve.to_hash.slice(*attrs).merge(status: :ok) diff --git a/app/controllers/admin/subscription_line_items_controller.rb b/app/controllers/admin/subscription_line_items_controller.rb index 5267374539..b3649696ac 100644 --- a/app/controllers/admin/subscription_line_items_controller.rb +++ b/app/controllers/admin/subscription_line_items_controller.rb @@ -36,17 +36,20 @@ module Admin def ensure_shop return if @shop + render json: { errors: ['Unauthorised'] }, status: :unauthorized end def ensure_variant return if @variant + error = "#{@shop.name} is not permitted to sell the selected product" render json: { errors: [error] }, status: :unprocessable_entity end def price_estimate return unless @order_cycle + fee_calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(@shop, @order_cycle) OpenFoodNetwork::ScopeVariantToHub.new(@shop).scope(@variant) @variant.price + fee_calculator.indexed_fees_for(@variant) diff --git a/app/controllers/admin/subscriptions_controller.rb b/app/controllers/admin/subscriptions_controller.rb index 75225ee0cc..da99409469 100644 --- a/app/controllers/admin/subscriptions_controller.rb +++ b/app/controllers/admin/subscriptions_controller.rb @@ -80,6 +80,7 @@ module Admin def permissions return @permissions unless @permissions.nil? + @permissions = OpenFoodNetwork::Permissions.new(spree_current_user) end @@ -126,14 +127,17 @@ module Admin def check_for_open_orders return if params[:open_orders] == 'cancel' + @open_orders_to_keep = @subscription.proxy_orders.placed_and_open.pluck(:id) return if @open_orders_to_keep.empty? || params[:open_orders] == 'keep' + render json: { errors: { open_orders: t('admin.subscriptions.confirm_cancel_open_orders_msg') } }, status: :conflict end def check_for_canceled_orders return if params[:canceled_orders] == 'notified' return if @subscription.proxy_orders.active.canceled.empty? + render json: { errors: { canceled_orders: t('admin.subscriptions.resume_canceled_orders_msg') } }, status: :conflict end diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index d0ab8ddb72..51b7acbe5c 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -48,6 +48,7 @@ module Api # Use logged in user (spree_current_user) for API authentication (current_api_user) def authenticate_user return if @current_api_user = try_spree_current_user + if api_key.blank? # An anonymous user @current_api_user = Spree.user_class.new diff --git a/app/controllers/api/enterprise_attachment_controller.rb b/app/controllers/api/enterprise_attachment_controller.rb index 083d6946be..406b1988fe 100644 --- a/app/controllers/api/enterprise_attachment_controller.rb +++ b/app/controllers/api/enterprise_attachment_controller.rb @@ -27,6 +27,7 @@ module Api def load_enterprise @enterprise = Enterprise.find_by_permalink(params[:enterprise_id].to_s) raise UnknownEnterpriseAuthorizationActionError if enterprise_authorize_action.blank? + authorize!(enterprise_authorize_action, @enterprise) end diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb index 337c6158ef..d758bbbd09 100644 --- a/app/controllers/api/products_controller.rb +++ b/app/controllers/api/products_controller.rb @@ -19,7 +19,7 @@ module Api @product = Spree::Product.new(params[:product]) begin if @product.save - render json: @product, serializer: Api::Admin::ProductSerializer, status: 201 + render json: @product, serializer: Api::Admin::ProductSerializer, status: :created else invalid_resource!(@product) end @@ -33,7 +33,7 @@ module Api authorize! :update, Spree::Product @product = find_product(params[:id]) if @product.update_attributes(params[:product]) - render json: @product, serializer: Api::Admin::ProductSerializer, status: 200 + render json: @product, serializer: Api::Admin::ProductSerializer, status: :ok else invalid_resource!(@product) end @@ -44,7 +44,7 @@ module Api @product = find_product(params[:id]) @product.update_attribute(:deleted_at, Time.zone.now) @product.variants_including_master.update_all(deleted_at: Time.zone.now) - render json: @product, serializer: Api::Admin::ProductSerializer, status: 204 + render json: @product, serializer: Api::Admin::ProductSerializer, status: :no_content end def bulk_products @@ -76,7 +76,7 @@ module Api @product = find_product(params[:product_id]) authorize! :delete, @product @product.destroy - render json: @product, serializer: Api::Admin::ProductSerializer, status: 204 + render json: @product, serializer: Api::Admin::ProductSerializer, status: :no_content end # POST /api/products/:product_id/clone @@ -88,7 +88,7 @@ module Api @product = original_product.duplicate - render json: @product, serializer: Api::Admin::ProductSerializer, status: 201 + render json: @product, serializer: Api::Admin::ProductSerializer, status: :created end private diff --git a/app/controllers/api/statuses_controller.rb b/app/controllers/api/statuses_controller.rb index a2c0ea6350..24714b6a0d 100644 --- a/app/controllers/api/statuses_controller.rb +++ b/app/controllers/api/statuses_controller.rb @@ -10,7 +10,7 @@ module Api def job_queue_alive? Spree::Config.last_job_queue_heartbeat_at.present? && - Time.parse(Spree::Config.last_job_queue_heartbeat_at) > 6.minutes.ago + Time.parse(Spree::Config.last_job_queue_heartbeat_at).in_time_zone > 6.minutes.ago end end end diff --git a/app/controllers/api/taxons_controller.rb b/app/controllers/api/taxons_controller.rb index 13a079f568..a69642c6e8 100644 --- a/app/controllers/api/taxons_controller.rb +++ b/app/controllers/api/taxons_controller.rb @@ -61,6 +61,7 @@ module Api def taxonomy return if params[:taxonomy_id].blank? + @taxonomy ||= Spree::Taxonomy.find(params[:taxonomy_id]) end diff --git a/app/controllers/api/variants_controller.rb b/app/controllers/api/variants_controller.rb index b196270927..14575bbabc 100644 --- a/app/controllers/api/variants_controller.rb +++ b/app/controllers/api/variants_controller.rb @@ -19,7 +19,7 @@ module Api authorize! :create, Spree::Variant @variant = scope.new(params[:variant]) if @variant.save - render json: @variant, serializer: Api::VariantSerializer, status: 201 + render json: @variant, serializer: Api::VariantSerializer, status: :created else invalid_resource!(@variant) end @@ -29,7 +29,7 @@ module Api authorize! :update, Spree::Variant @variant = scope.find(params[:id]) if @variant.update_attributes(params[:variant]) - render json: @variant, serializer: Api::VariantSerializer, status: 200 + render json: @variant, serializer: Api::VariantSerializer, status: :ok else invalid_resource!(@product) end @@ -40,14 +40,14 @@ module Api authorize! :delete, @variant VariantDeleter.new.delete(@variant) - render json: @variant, serializer: Api::VariantSerializer, status: 204 + render json: @variant, serializer: Api::VariantSerializer, status: :no_content end def destroy authorize! :delete, Spree::Variant @variant = scope.find(params[:id]) @variant.destroy - render json: @variant, serializer: Api::VariantSerializer, status: 204 + render json: @variant, serializer: Api::VariantSerializer, status: :no_content end private @@ -58,11 +58,11 @@ module Api 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 + variants = if current_api_user.has_spree_role?("admin") || params[:show_deleted] + @product.variants_including_master.with_deleted + else + @product.variants_including_master + end else variants = Spree::Variant.scoped if current_api_user.has_spree_role?("admin") diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0edfdd76b7..cc03d95b43 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -47,6 +47,7 @@ class ApplicationController < ActionController::Base def after_sign_in_path_for(resource_or_scope) return session[:shopfront_redirect] if session[:shopfront_redirect] + stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope) end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index e95402456b..e5c30438d0 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -16,6 +16,7 @@ class EnterprisesController < BaseController def shop return redirect_to main_app.cart_path unless enough_stock? + set_noindex_meta_tag @enterprise = current_distributor diff --git a/app/controllers/line_items_controller.rb b/app/controllers/line_items_controller.rb index 9b0c588911..b2002b7c54 100644 --- a/app/controllers/line_items_controller.rb +++ b/app/controllers/line_items_controller.rb @@ -23,6 +23,7 @@ class LineItemsController < BaseController # List all items the user already ordered in the current order cycle def bought_items return [] unless current_order_cycle && spree_current_user && current_distributor + current_order_cycle.items_bought_by_user(spree_current_user, current_distributor) end diff --git a/app/controllers/spree/admin/base_controller_decorator.rb b/app/controllers/spree/admin/base_controller_decorator.rb index 7e5293024d..34bde0028e 100644 --- a/app/controllers/spree/admin/base_controller_decorator.rb +++ b/app/controllers/spree/admin/base_controller_decorator.rb @@ -54,6 +54,7 @@ Spree::Admin::BaseController.class_eval do if Spree.const_defined?(const_name) return "Spree::#{const_name}".constantize end + nil end diff --git a/app/controllers/spree/admin/general_settings_controller.rb b/app/controllers/spree/admin/general_settings_controller.rb index 7389ee0890..853ad929a1 100644 --- a/app/controllers/spree/admin/general_settings_controller.rb +++ b/app/controllers/spree/admin/general_settings_controller.rb @@ -13,6 +13,7 @@ module Spree def update params.each do |name, value| next unless Spree::Config.has_preference? name + Spree::Config[name] = value end flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:general_settings)) @@ -22,6 +23,7 @@ module Spree def dismiss_alert return unless request.xhr? && params[:alert_id] + dismissed = Spree::Config[:dismissed_spree_alerts] || '' Spree::Config.set(dismissed_spree_alerts: dismissed. split(','). diff --git a/app/controllers/spree/admin/mail_methods_controller.rb b/app/controllers/spree/admin/mail_methods_controller.rb index 867829c0bd..3bc52ce659 100644 --- a/app/controllers/spree/admin/mail_methods_controller.rb +++ b/app/controllers/spree/admin/mail_methods_controller.rb @@ -10,6 +10,7 @@ module Spree params.each do |name, value| next unless Spree::Config.has_preference? name + Spree::Config[name] = value end diff --git a/app/controllers/spree/admin/orders/customer_details_controller_decorator.rb b/app/controllers/spree/admin/orders/customer_details_controller_decorator.rb index 47e829d3cb..996e9a72fb 100644 --- a/app/controllers/spree/admin/orders/customer_details_controller_decorator.rb +++ b/app/controllers/spree/admin/orders/customer_details_controller_decorator.rb @@ -43,6 +43,7 @@ Spree::Admin::Orders::CustomerDetailsController.class_eval do params[:order][:guest_checkout] = registered_user.nil? return unless registered_user + @order.user_id = registered_user.id end end diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index a858c0d651..53bf22d06a 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -62,6 +62,7 @@ module Spree # ! Redundant code copied from Spree::Admin::ResourceController with modifications marked def collection return parent.public_send(controller_name) if parent_data.present? + collection = if model_class.respond_to?(:accessible_by) && !current_ability.has_block?(params[:action], model_class) @@ -116,6 +117,7 @@ module Spree def validate_payment_method_provider valid_payment_methods = Rails.application.config.spree.payment_methods.map(&:to_s) return if valid_payment_methods.include?(params[:payment_method][:type]) + flash[:error] = Spree.t(:invalid_payment_provider) redirect_to new_admin_payment_method_path end diff --git a/app/controllers/spree/admin/payments_controller_decorator.rb b/app/controllers/spree/admin/payments_controller_decorator.rb index 3c6effc8b7..41d43f2e56 100644 --- a/app/controllers/spree/admin/payments_controller_decorator.rb +++ b/app/controllers/spree/admin/payments_controller_decorator.rb @@ -43,8 +43,8 @@ Spree::Admin::PaymentsController.class_eval do else flash[:error] = t(:cannot_perform_operation) end - rescue Spree::Core::GatewayError => ge - flash[:error] = ge.message + rescue Spree::Core::GatewayError => e + flash[:error] = e.message ensure redirect_to request.referer end diff --git a/app/controllers/spree/admin/products_controller_decorator.rb b/app/controllers/spree/admin/products_controller_decorator.rb index 32b6b67b2b..9302a6696a 100644 --- a/app/controllers/spree/admin/products_controller_decorator.rb +++ b/app/controllers/spree/admin/products_controller_decorator.rb @@ -79,6 +79,7 @@ Spree::Admin::ProductsController.class_eval do # enterprise users. # TODO: There has to be a better way!!! return @collection if @collection.present? + params[:q] ||= {} params[:q][:deleted_at_null] ||= "1" @@ -147,6 +148,7 @@ Spree::Admin::ProductsController.class_eval do def strip_new_properties return if spree_current_user.admin? || params[:product][:product_properties_attributes].nil? + names = Spree::Property.pluck(:name) params[:product][:product_properties_attributes].each do |key, property| unless names.include? property[:property_name] @@ -170,9 +172,9 @@ Spree::Admin::ProductsController.class_eval do begin variant.on_demand = on_demand if on_demand.present? variant.on_hand = on_hand.to_i if on_hand.present? - rescue StandardError => error - notify_bugsnag(error, product, variant) - raise error + rescue StandardError => e + notify_bugsnag(e, product, variant) + raise e end end diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index b820d8d257..ddafac2733 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -259,12 +259,12 @@ Spree::Admin::ReportsController.class_eval do name = I18n.t(:name, scope: [:admin, :reports, report]) description = begin I18n.t!(:description, scope: [:admin, :reports, report]) - rescue I18n::MissingTranslationData - render_to_string( - partial: "#{report}_description", - layout: false, - locals: { report_types: report_types[report] } - ).html_safe + rescue I18n::MissingTranslationData + render_to_string( + partial: "#{report}_description", + layout: false, + locals: { report_types: report_types[report] } + ).html_safe end { name: name, url: url_for_report(report), description: description } end diff --git a/app/controllers/spree/admin/resource_controller_decorator.rb b/app/controllers/spree/admin/resource_controller_decorator.rb index e7ba7ceb5b..b1dbc4a383 100644 --- a/app/controllers/spree/admin/resource_controller_decorator.rb +++ b/app/controllers/spree/admin/resource_controller_decorator.rb @@ -16,5 +16,5 @@ end Spree::Admin::ResourceController.prepend(AuthorizeOnLoadResource) Spree::Admin::ResourceController.class_eval do - rescue_from CanCan::AccessDenied, :with => :unauthorized + rescue_from CanCan::AccessDenied, with: :unauthorized end diff --git a/app/controllers/spree/admin/shipping_methods_controller.rb b/app/controllers/spree/admin/shipping_methods_controller.rb index b561759757..902a028b5b 100644 --- a/app/controllers/spree/admin/shipping_methods_controller.rb +++ b/app/controllers/spree/admin/shipping_methods_controller.rb @@ -58,6 +58,7 @@ module Spree def set_shipping_category return true if params["shipping_method"][:shipping_categories] == "" + @shipping_method.shipping_categories = Spree::ShippingCategory.where(id: params["shipping_method"][:shipping_categories]) @shipping_method.save @@ -66,6 +67,7 @@ module Spree def set_zones return true if params["shipping_method"][:zones] == "" + @shipping_method.zones = Spree::Zone.where(id: params["shipping_method"][:zones]) @shipping_method.save params[:shipping_method].delete(:zones) diff --git a/app/controllers/spree/admin/taxonomies_controller.rb b/app/controllers/spree/admin/taxonomies_controller.rb index 3010db2a52..cbbf85e212 100644 --- a/app/controllers/spree/admin/taxonomies_controller.rb +++ b/app/controllers/spree/admin/taxonomies_controller.rb @@ -1,7 +1,7 @@ module Spree module Admin class TaxonomiesController < ResourceController - respond_to :json, :only => [:get_children] + respond_to :json, only: [:get_children] def get_children @taxons = Taxon.find(params[:parent_id]).children diff --git a/app/controllers/spree/admin/taxons_controller.rb b/app/controllers/spree/admin/taxons_controller.rb index 57ae146d2a..ddc1b63c70 100644 --- a/app/controllers/spree/admin/taxons_controller.rb +++ b/app/controllers/spree/admin/taxons_controller.rb @@ -4,11 +4,11 @@ module Spree respond_to :html, :json, :js def search - if params[:ids] - @taxons = Spree::Taxon.where(id: params[:ids].split(',')) - else - @taxons = Spree::Taxon.limit(20).search(name_cont: params[:q]).result - end + @taxons = if params[:ids] + Spree::Taxon.where(id: params[:ids].split(',')) + else + Spree::Taxon.limit(20).search(name_cont: params[:q]).result + end end def create diff --git a/app/controllers/spree/admin/users_controller.rb b/app/controllers/spree/admin/users_controller.rb index 7d87e1499d..e66ec7f4af 100644 --- a/app/controllers/spree/admin/users_controller.rb +++ b/app/controllers/spree/admin/users_controller.rb @@ -74,6 +74,7 @@ module Spree def collection return @collection if @collection.present? + if request.xhr? && params[:q].present? # Disabling proper nested include here due to rails 3.1 bug @collection = Spree::User. @@ -125,6 +126,7 @@ module Spree def sign_in_if_change_own_password return unless spree_current_user == @user && @user.password.present? + sign_in(@user, event: :authentication, bypass: true) end diff --git a/app/controllers/spree/checkout_controller.rb b/app/controllers/spree/checkout_controller.rb index e05ad99535..ca160c85fe 100644 --- a/app/controllers/spree/checkout_controller.rb +++ b/app/controllers/spree/checkout_controller.rb @@ -18,7 +18,7 @@ module Spree helper 'spree/orders' - rescue_from Spree::Core::GatewayError, :with => :rescue_from_spree_gateway_error + rescue_from Spree::Core::GatewayError, with: :rescue_from_spree_gateway_error def edit flash.keep diff --git a/app/controllers/spree/credit_cards_controller.rb b/app/controllers/spree/credit_cards_controller.rb index 942f3e28af..79f60b4323 100644 --- a/app/controllers/spree/credit_cards_controller.rb +++ b/app/controllers/spree/credit_cards_controller.rb @@ -19,6 +19,7 @@ module Spree def update @credit_card = Spree::CreditCard.find_by_id(params[:id]) return update_failed unless @credit_card + authorize! :update, @credit_card if @credit_card.update_attributes(params[:credit_card]) @@ -63,6 +64,7 @@ module Spree def stored_card_attributes return {} unless @customer.try(:default_source) + { month: params[:exp_month], year: params[:exp_year], diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index d2de15441c..400b6f4959 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -9,7 +9,7 @@ module Spree ssl_required :show before_filter :check_authorization - rescue_from ActiveRecord::RecordNotFound, :with => :render_404 + rescue_from ActiveRecord::RecordNotFound, with: :render_404 helper 'spree/products', 'spree/orders' respond_to :html @@ -200,6 +200,7 @@ module Spree def order_to_update return @order_to_update if defined? @order_to_update return @order_to_update = current_order unless params[:id] + @order_to_update = changeable_order_from_number end @@ -208,6 +209,7 @@ module Spree def changeable_order_from_number order = Spree::Order.complete.find_by_number(params[:id]) return nil unless order.andand.changes_allowed? && can?(:update, order) + order end diff --git a/app/controllers/spree/paypal_controller_decorator.rb b/app/controllers/spree/paypal_controller_decorator.rb index 03d2b17d2a..1512299198 100644 --- a/app/controllers/spree/paypal_controller_decorator.rb +++ b/app/controllers/spree/paypal_controller_decorator.rb @@ -38,6 +38,7 @@ Spree::PaypalController.class_eval do # the payment details have been confirmed, but before any payments have been processed def destroy_orphaned_paypal_payments return unless payment_method.is_a?(Spree::Gateway::PayPalExpress) + orphaned_payments = current_order.payments.where(payment_method_id: payment_method.id, source_id: nil) orphaned_payments.each(&:destroy) end diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index 787c8a9011..fa6cb32028 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -25,8 +25,8 @@ class UserRegistrationsController < Spree::UserRegistrationsController render json: { email: @user.email } end end - rescue StandardError => error - OpenFoodNetwork::ErrorLogger.notify(error) + rescue StandardError => e + OpenFoodNetwork::ErrorLogger.notify(e) render_error(message: I18n.t('unknown_error', scope: I18N_SCOPE)) end diff --git a/app/helpers/admin/injection_helper.rb b/app/helpers/admin/injection_helper.rb index ecb5e1c20b..bb04020f04 100644 --- a/app/helpers/admin/injection_helper.rb +++ b/app/helpers/admin/injection_helper.rb @@ -70,8 +70,8 @@ module Admin def admin_inject_enterprise_permissions permissions = { can_manage_shipping_methods: can?(:manage_shipping_methods, @enterprise), - can_manage_payment_methods: can?(:manage_payment_methods, @enterprise), - can_manage_enterprise_fees: can?(:manage_enterprise_fees, @enterprise) } + can_manage_payment_methods: can?(:manage_payment_methods, @enterprise), + can_manage_enterprise_fees: can?(:manage_enterprise_fees, @enterprise) } admin_inject_json "admin.enterprises", "enterprisePermissions", permissions end @@ -112,19 +112,19 @@ module Admin render partial: "admin/json/injection_ams", locals: { ngModule: 'admin.indexUtils', name: 'SpreeApiKey', json: "'#{@spree_api_key}'" } end - def admin_inject_json(ngModule, name, data) + def admin_inject_json(ng_module, name, data) json = data.to_json - render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json } + render partial: "admin/json/injection_ams", locals: { ngModule: ng_module, name: name, json: json } end - def admin_inject_json_ams(ngModule, name, data, serializer, opts = {}) + def admin_inject_json_ams(ng_module, name, data, serializer, opts = {}) json = serializer.new(data, { scope: spree_current_user }.merge(opts)).to_json - render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json } + render partial: "admin/json/injection_ams", locals: { ngModule: ng_module, name: name, json: json } end - def admin_inject_json_ams_array(ngModule, name, data, serializer, opts = {}) + def admin_inject_json_ams_array(ng_module, name, data, serializer, opts = {}) json = ActiveModel::ArraySerializer.new(data, { each_serializer: serializer, scope: spree_current_user }.merge(opts)).to_json - render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json } + render partial: "admin/json/injection_ams", locals: { ngModule: ng_module, name: name, json: json } end end end diff --git a/app/helpers/admin/subscriptions_helper.rb b/app/helpers/admin/subscriptions_helper.rb index 415eecf4a4..749584ea98 100644 --- a/app/helpers/admin/subscriptions_helper.rb +++ b/app/helpers/admin/subscriptions_helper.rb @@ -2,6 +2,7 @@ module Admin module SubscriptionsHelper def subscriptions_setup_complete?(shops) return false unless shops.any? + shops = shops.select{ |shop| shipping_and_payment_methods_ok?(shop) && customers_ok?(shop) } Schedule.joins(:order_cycles).where(order_cycles: { coordinator_id: shops }).any? end diff --git a/app/helpers/angular_form_builder.rb b/app/helpers/angular_form_builder.rb index cfb5cdf354..41611f7f56 100644 --- a/app/helpers/angular_form_builder.rb +++ b/app/helpers/angular_form_builder.rb @@ -1,6 +1,7 @@ class AngularFormBuilder < ActionView::Helpers::FormBuilder def ng_fields_for(record_name, *_args) raise "Nested ng_fields_for is not yet supported" if @fields_for_record_name.present? + @fields_for_record_name = record_name yield self @fields_for_record_name = nil diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 2a623f4bf1..64d78e7e93 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -7,11 +7,13 @@ module EnterprisesHelper def current_customer return nil unless spree_current_user && current_distributor + @current_customer ||= spree_current_user.customer_of(current_distributor) end def available_shipping_methods return [] if current_distributor.blank? + shipping_methods = current_distributor.shipping_methods applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterShippingMethods", current_customer.andand.tag_list) @@ -22,6 +24,7 @@ module EnterprisesHelper def available_payment_methods return [] if current_distributor.blank? + payment_methods = current_distributor.payment_methods.available(:front_end).all filter = OpenFoodNetwork::AvailablePaymentMethodFilter.new diff --git a/app/helpers/footer_links_helper.rb b/app/helpers/footer_links_helper.rb index 71e8683da0..14b8780089 100644 --- a/app/helpers/footer_links_helper.rb +++ b/app/helpers/footer_links_helper.rb @@ -6,6 +6,6 @@ module FooterLinksHelper end def privacy_policy_link - link_to( t( '.footer_data_privacy_policy' ), Spree::Config.privacy_policy_url, target: '_blank' ) + link_to( t( '.footer_data_privacy_policy' ), Spree::Config.privacy_policy_url, target: '_blank', rel: 'noopener' ) end end diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index 7a9b782a3e..28b10f87f1 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -1,6 +1,7 @@ module GroupsHelper def link_to_service(baseurl, name, html_options = {}) return if name.blank? + html_options = html_options.merge target: '_blank' link_to ext_url(baseurl, name), html_options do yield @@ -8,7 +9,7 @@ module GroupsHelper end def ext_url(prefix, url) - if url =~ /^https?:\/\//i + if url =~ %r{^https?://}i url else prefix + url @@ -16,6 +17,6 @@ module GroupsHelper end def strip_url(url) - url.andand.sub(/^https?:\/\//i, '') + url.andand.sub(%r{^https?://}i, '') end end diff --git a/app/helpers/html_helper.rb b/app/helpers/html_helper.rb index 95b7e5d0db..3342a8901a 100644 --- a/app/helpers/html_helper.rb +++ b/app/helpers/html_helper.rb @@ -11,7 +11,7 @@ module HtmlHelper # I know Cthulu is coming for me. Forgive me. # http://stackoverflow.com/a/1732454/2720566 html. - andand.gsub(/<\/h[^>]>|<\/p>|<\/div>/, "\\1\n\n"). + andand.gsub(%r{]>|

|}, "\\1\n\n"). andand.gsub(/]*>/, "\\1\n") end diff --git a/app/helpers/serializer_helper.rb b/app/helpers/serializer_helper.rb index 539e826bfc..f30d998f73 100644 --- a/app/helpers/serializer_helper.rb +++ b/app/helpers/serializer_helper.rb @@ -1,6 +1,7 @@ module SerializerHelper def ids_to_objs(ids) return [] if ids.blank? + ids.map { |id| { id: id } } end diff --git a/app/helpers/spree/admin/navigation_helper_decorator.rb b/app/helpers/spree/admin/navigation_helper_decorator.rb index aa0a9324df..15869922cc 100644 --- a/app/helpers/spree/admin/navigation_helper_decorator.rb +++ b/app/helpers/spree/admin/navigation_helper_decorator.rb @@ -31,6 +31,7 @@ module Spree options = options.merge(args.last) end return '' if (klass = klass_for(options[:label])) && cannot?(:admin, klass) + tab_without_cancan_check(*args) end alias_method_chain :tab, :cancan_check diff --git a/app/helpers/spree/admin/orders_helper_decorator.rb b/app/helpers/spree/admin/orders_helper_decorator.rb index 074020e1d4..0d62c2caa0 100644 --- a/app/helpers/spree/admin/orders_helper_decorator.rb +++ b/app/helpers/spree/admin/orders_helper_decorator.rb @@ -19,6 +19,7 @@ module Spree def invoice_links return [] unless Spree::Config[:enable_invoices?] + [send_invoice_link, print_invoice_link] end @@ -32,6 +33,7 @@ module Spree def ticket_links return [] unless Spree::Config[:enable_receipt_printing?] + [print_ticket_link, select_ticket_printer_link] end diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 4231f29613..9062689191 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -18,6 +18,7 @@ module Spree return @changeable_orders unless @changeable_orders.nil? return @changeable_orders = [] unless spree_current_user && current_distributor && current_order_cycle return @changeable_orders = [] unless current_distributor.allow_order_changes? + @changeable_orders = Spree::Order.complete.where( state: 'complete', user_id: spree_current_user.id, @@ -32,6 +33,7 @@ module Spree def shop_changeable_orders_alert_html return "" unless changeable_orders.any? + t(:shop_changeable_orders_alert_html, count: changeable_orders.count, path: changeable_orders_link_path, diff --git a/app/jobs/heartbeat_job.rb b/app/jobs/heartbeat_job.rb index 93e835905f..9353e55a21 100644 --- a/app/jobs/heartbeat_job.rb +++ b/app/jobs/heartbeat_job.rb @@ -1,5 +1,5 @@ class HeartbeatJob def perform - Spree::Config.last_job_queue_heartbeat_at = Time.now + Spree::Config.last_job_queue_heartbeat_at = Time.now.in_time_zone end end diff --git a/app/jobs/subscription_confirm_job.rb b/app/jobs/subscription_confirm_job.rb index 898eb4382c..2e0b05e4fe 100644 --- a/app/jobs/subscription_confirm_job.rb +++ b/app/jobs/subscription_confirm_job.rb @@ -36,8 +36,10 @@ class SubscriptionConfirmJob record_order(@order) update_payment! if @order.payment_required? return send_failed_payment_email if @order.errors.present? + @order.process_payments! if @order.payment_required? return send_failed_payment_email if @order.errors.present? + send_confirm_email end diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index 058d5403ba..b772a1da62 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -16,6 +16,7 @@ class ProducerMailer < Spree::BaseMailer subject = "[#{Spree::Config.site_name}] #{order_cycle_subject}" return unless has_orders?(order_cycle, producer) + mail( to: @producer.contact.email, from: from_address, diff --git a/app/models/column_preference.rb b/app/models/column_preference.rb index 6cfdb0687d..9007cfca8e 100644 --- a/app/models/column_preference.rb +++ b/app/models/column_preference.rb @@ -48,6 +48,7 @@ class ColumnPreference < ActiveRecord::Base # Arbitrary filtering of default_preferences def self.filter(default_preferences, user, action_name) return unless action_name == 'order_cycles_index' + default_preferences.delete(:schedules) unless user.admin? || user.enterprises.where(enable_subscriptions: true).any? end end diff --git a/app/models/concerns/order_shipment.rb b/app/models/concerns/order_shipment.rb index a05383f7db..f03ecd2fcc 100644 --- a/app/models/concerns/order_shipment.rb +++ b/app/models/concerns/order_shipment.rb @@ -20,6 +20,7 @@ module OrderShipment # @return [ShippingMethod] def shipping_method return if shipments.blank? + shipments.first.shipping_method end @@ -31,6 +32,7 @@ module OrderShipment # empty or if it cannot find the given shipping_method_id in the order def select_shipping_method(shipping_method_id) return if shipping_method_id.blank? || shipments.empty? + shipment = shipments.first shipping_rate = shipment.shipping_rates.find_by_shipping_method_id(shipping_method_id) diff --git a/app/models/concerns/product_stock.rb b/app/models/concerns/product_stock.rb index f9ce20b177..4f01b3069f 100644 --- a/app/models/concerns/product_stock.rb +++ b/app/models/concerns/product_stock.rb @@ -6,6 +6,7 @@ module ProductStock def on_demand if has_variants? raise 'Cannot determine product on_demand value of product with multiple variants' if variants.size > 1 + variants.first.on_demand else master.on_demand diff --git a/app/models/customer.rb b/app/models/customer.rb index dfddd90c80..24564888ba 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -41,6 +41,7 @@ class Customer < ActiveRecord::Base def check_for_orders return true unless orders.any? + errors[:base] << I18n.t('admin.customers.destroy.has_associated_orders') false end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 42687dc167..ff95102781 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -63,7 +63,7 @@ class Enterprise < ActiveRecord::Base has_attached_file :logo, styles: { medium: "300x300>", small: "180x180>", thumb: "100x100>" }, - url: '/images/enterprises/logos/:id/:style/:basename.:extension', + url: '/images/enterprises/logos/:id/:style/:basename.:extension', path: 'public/images/enterprises/logos/:id/:style/:basename.:extension' has_attached_file :promo_image, @@ -72,11 +72,11 @@ class Enterprise < ActiveRecord::Base medium: ["720x156#", :jpg], thumb: ["100x100>", :jpg] }, - url: '/images/enterprises/promo_images/:id/:style/:basename.:extension', + url: '/images/enterprises/promo_images/:id/:style/:basename.:extension', path: 'public/images/enterprises/promo_images/:id/:style/:basename.:extension' - validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/ - validates_attachment_content_type :promo_image, content_type: /\Aimage\/.*\Z/ + validates_attachment_content_type :logo, content_type: %r{\Aimage/.*\Z} + validates_attachment_content_type :promo_image, content_type: %r{\Aimage/.*\Z} include Spree::Core::S3Support supports_s3 :logo @@ -394,7 +394,7 @@ class Enterprise < ActiveRecord::Base end def strip_url(url) - url.andand.sub(/(https?:\/\/)?/, '') + url.andand.sub(%r{(https?://)?}, '') end def set_unused_address_fields diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index 75478f8c84..7ffc9d3fb7 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -32,16 +32,16 @@ class EnterpriseGroup < ActiveRecord::Base has_attached_file :logo, styles: { medium: "100x100" }, - url: '/images/enterprise_groups/logos/:id/:style/:basename.:extension', + url: '/images/enterprise_groups/logos/:id/:style/:basename.:extension', path: 'public/images/enterprise_groups/logos/:id/:style/:basename.:extension' has_attached_file :promo_image, styles: { large: ["1200x260#", :jpg] }, - url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension', + url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension', path: 'public/images/enterprise_groups/promo_images/:id/:style/:basename.:extension' - validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/ - validates_attachment_content_type :promo_image, content_type: /\Aimage\/.*\Z/ + validates_attachment_content_type :logo, content_type: %r{\Aimage/.*\Z} + validates_attachment_content_type :promo_image, content_type: %r{\Aimage/.*\Z} include Spree::Core::S3Support supports_s3 :logo @@ -71,6 +71,7 @@ class EnterpriseGroup < ActiveRecord::Base def unset_undefined_address_fields return if address.blank? + address.phone.sub!(/^#{I18n.t(:undefined)}$/, '') address.address1.sub!(/^#{I18n.t(:undefined)}$/, '') address.city.sub!(/^#{I18n.t(:undefined)}$/, '') diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index ce931e5ea2..a237492a98 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -168,6 +168,7 @@ class OrderCycle < ActiveRecord::Base def variants_distributed_by(distributor) return Spree::Variant.where("1=0") if distributor.blank? + Spree::Variant. joins(:exchanges). merge(distributor.inventory_variants). @@ -262,6 +263,7 @@ class OrderCycle < ActiveRecord::Base def orders_close_at_after_orders_open_at? return if orders_open_at.blank? || orders_close_at.blank? return if orders_close_at > orders_open_at + errors.add(:orders_close_at, :after_orders_open_at) end end diff --git a/app/models/order_updater.rb b/app/models/order_updater.rb index 553c93ca74..20fa94e5b4 100644 --- a/app/models/order_updater.rb +++ b/app/models/order_updater.rb @@ -15,7 +15,7 @@ class OrderUpdater < SimpleDelegator track_payment_state_change(last_payment_state) order.payment_state - end + end def before_save_hook shipping_address_from_distributor @@ -68,6 +68,7 @@ class OrderUpdater < SimpleDelegator # @param last_payment_state [String] def track_payment_state_change(last_payment_state) return if last_payment_state == order.payment_state + order.state_changed('payment') end diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 2e7d66b6ba..30c14dc093 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -109,6 +109,7 @@ module ProductImport def name_presence_error(entry) return if entry.enterprise.present? + mark_as_invalid(entry, attribute: enterprise_field, error: I18n.t(:error_required)) @@ -117,6 +118,7 @@ module ProductImport def enterprise_not_found_error(entry) return if @spreadsheet_data.enterprises_index[entry.enterprise][:id] + mark_as_invalid(entry, attribute: enterprise_field, error: I18n.t(:error_not_found_in_database, @@ -126,6 +128,7 @@ module ProductImport def permissions_error(entry) return if permission_by_name?(entry.enterprise) + mark_as_invalid(entry, attribute: enterprise_field, error: I18n.t(:error_no_permission_for_enterprise, @@ -136,7 +139,7 @@ module ProductImport def primary_producer_error(entry) return if import_into_inventory? return if @spreadsheet_data. - enterprises_index[entry.enterprise][:is_primary_producer] + enterprises_index[entry.enterprise][:is_primary_producer] mark_as_invalid(entry, attribute: enterprise_field, @@ -174,15 +177,19 @@ module ProductImport def validate_unit_type_unchanged(entry) return if entry.unit_type.blank? + reference_entry = all_entries_for_product(entry).first return if entry.unit_type.to_s == reference_entry.unit_type.to_s + mark_as_not_updatable(entry, "unit_type") end def validate_variant_unit_name_unchanged(entry) return if entry.variant_unit_name.blank? + reference_entry = all_entries_for_product(entry).first return if entry.variant_unit_name.to_s == reference_entry.variant_unit_name.to_s + mark_as_not_updatable(entry, "variant_unit_name") end @@ -317,6 +324,7 @@ module ProductImport EntryValidator.non_updatable_fields.each do |display_name, attribute| next if attributes_match?(attribute, existing_product, entry) || attributes_blank?(attribute, existing_product, entry) next if ignore_when_updating_product?(attribute) + mark_as_invalid(entry, attribute: display_name, error: I18n.t('admin.product_import.model.not_updatable')) end end diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index fec8292298..3fc9b5c07c 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -223,6 +223,7 @@ module ProductImport def rows return [] unless @sheet && @sheet.last_row + (2..@sheet.last_row).map do |i| @sheet.row(i) end @@ -263,6 +264,7 @@ module ProductImport def delete_uploaded_file return unless @file.path == Rails.root.join('tmp', 'product_import').to_s + File.delete(@file) end diff --git a/app/models/product_import/reset_absent.rb b/app/models/product_import/reset_absent.rb index 549ea1e7de..5226b5a6d4 100644 --- a/app/models/product_import/reset_absent.rb +++ b/app/models/product_import/reset_absent.rb @@ -24,6 +24,7 @@ module ProductImport def authorized_enterprises settings.enterprises_to_reset.map do |enterprise_id| next unless entry_processor.permission_by_id?(enterprise_id) + enterprise_id.to_i end end diff --git a/app/models/product_import/spreadsheet_data.rb b/app/models/product_import/spreadsheet_data.rb index 1f8ff56ad3..7c433d49e4 100644 --- a/app/models/product_import/spreadsheet_data.rb +++ b/app/models/product_import/spreadsheet_data.rb @@ -58,6 +58,7 @@ module ProductImport @producers_index = {} @entries.each do |entry| next unless entry.producer + producer_name = entry.producer producer_id = @producers_index[producer_name] || Enterprise.find_by_name(producer_name, select: 'id, name').try(:id) @producers_index[producer_name] = producer_id diff --git a/app/models/proxy_order.rb b/app/models/proxy_order.rb index bcfa1b1cef..a7342c9702 100644 --- a/app/models/proxy_order.rb +++ b/app/models/proxy_order.rb @@ -30,6 +30,7 @@ class ProxyOrder < ActiveRecord::Base def cancel return false unless order_cycle.orders_close_at.andand > Time.zone.now + transaction do update_column(:canceled_at, Time.zone.now) order.cancel if order @@ -39,6 +40,7 @@ class ProxyOrder < ActiveRecord::Base def resume return false unless order_cycle.orders_close_at.andand > Time.zone.now + transaction do update_column(:canceled_at, nil) order.resume if order @@ -48,6 +50,7 @@ class ProxyOrder < ActiveRecord::Base def initialise_order! return order if order.present? + factory = OrderFactory.new(order_attrs, skip_stock_check: true) self.order = factory.create save! diff --git a/app/models/spree/calculator/per_item_decorator.rb b/app/models/spree/calculator/per_item_decorator.rb index 897b1217c4..1c5369b48a 100644 --- a/app/models/spree/calculator/per_item_decorator.rb +++ b/app/models/spree/calculator/per_item_decorator.rb @@ -12,6 +12,7 @@ module Spree def compute(object = nil) return 0 if object.nil? + preferred_amount * line_items_for(object).reduce(0) do |sum, value| value_to_add = if matching_products.blank? || matching_products.include?(value.product) value.quantity diff --git a/app/models/spree/credit_card_decorator.rb b/app/models/spree/credit_card_decorator.rb index d6c8904846..f1f4a5d71c 100644 --- a/app/models/spree/credit_card_decorator.rb +++ b/app/models/spree/credit_card_decorator.rb @@ -46,6 +46,7 @@ Spree::CreditCard.class_eval do def ensure_single_default_card return unless user return unless is_default? || (reusable? && default_missing?) + user.credit_cards.update_all(['is_default=(id=?)', id]) self.is_default = true end diff --git a/app/models/spree/gateway/stripe_connect.rb b/app/models/spree/gateway/stripe_connect.rb index 9684288a9f..052423e5e0 100644 --- a/app/models/spree/gateway/stripe_connect.rb +++ b/app/models/spree/gateway/stripe_connect.rb @@ -107,6 +107,7 @@ module Spree def ensure_enterprise_selected return if preferred_enterprise_id.andand > 0 + errors.add(:stripe_account_owner, I18n.t(:error_required)) end end diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index d76568119f..ee36d5d415 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -83,6 +83,7 @@ Spree::LineItem.class_eval do def cap_quantity_at_stock! scoper.scope(variant) return if variant.on_demand + update_attributes!(quantity: variant.on_hand) if quantity > variant.on_hand end @@ -102,6 +103,7 @@ Spree::LineItem.class_eval do # EnterpriseFee#create_adjustment applies adjustments on line items to their parent order, # so line_item.adjustments returns an empty array return 0 if quantity == 0 + (price + order.adjustments.where(source_id: id).sum(&:amount) / quantity).round(2) end @@ -127,6 +129,7 @@ Spree::LineItem.class_eval do def unit_value return variant.unit_value if quantity == 0 || !final_weight_volume + final_weight_volume / quantity end @@ -137,6 +140,7 @@ Spree::LineItem.class_eval do def sufficient_stock? return true if skip_stock_check return true if quantity <= 0 + scoper.scope(variant) variant.can_supply?(quantity) end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 22a44e26de..9ae51b2304 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -165,6 +165,7 @@ Spree::Order.class_eval do def update_shipping_fees! shipments.each do |shipment| next if shipment.shipped? + update_adjustment! shipment.adjustment if shipment.adjustment save_or_rescue_shipment(shipment) end @@ -172,14 +173,14 @@ Spree::Order.class_eval do def save_or_rescue_shipment(shipment) shipment.save # updates included tax - rescue ActiveRecord::RecordNotUnique => error + rescue ActiveRecord::RecordNotUnique => e # This error was seen in production on `shipment.save` above. # It caused lost payments and duplicate payments due to database rollbacks. # While we don't understand the cause of this error yet, we rescue here # because an outdated shipping fee is not as bad as a lost payment. # And the shipping fee is already up-to-date when this error occurs. # https://github.com/openfoodfoundation/openfoodnetwork/issues/3924 - Bugsnag.notify(error) do |report| + Bugsnag.notify(e) do |report| report.add_tab(:order, attributes) report.add_tab(:shipment, shipment.attributes) report.add_tab(:shipment_in_db, Spree::Shipment.find_by_id(shipment.id).attributes) @@ -192,6 +193,7 @@ Spree::Order.class_eval do def update_payment_fees! payments.each do |payment| next if payment.completed? + update_adjustment! payment.adjustment if payment.adjustment payment.save end @@ -257,6 +259,7 @@ Spree::Order.class_eval do # Show already bought line items of this order cycle def finalised_line_items return [] unless order_cycle && user && distributor + order_cycle.items_bought_by_user(user, distributor) end @@ -367,6 +370,7 @@ Spree::Order.class_eval do def customer_is_valid? return true unless require_customer? + customer.present? && customer.enterprise_id == distributor_id && customer.email == email_for_customer end @@ -376,6 +380,7 @@ Spree::Order.class_eval do def associate_customer return customer if customer.present? + self.customer = Customer.of(distributor).find_by_email(email_for_customer) end @@ -403,6 +408,7 @@ Spree::Order.class_eval do def charge_shipping_and_payment_fees! update_totals return unless payments.any? + payments.first.update_attribute :amount, total end end diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb index 29529d2d62..5bd3e5b326 100644 --- a/app/models/spree/payment_decorator.rb +++ b/app/models/spree/payment_decorator.rb @@ -93,6 +93,7 @@ module Spree return unless source.try(:save_requested_by_customer?) return unless source.number || source.gateway_payment_profile_id return unless source.gateway_customer_profile_id.nil? + payment_method.create_profile(self) rescue ActiveMerchant::ConnectionError => e gateway_error e @@ -105,6 +106,7 @@ module Spree def revoke_adjustment_eligibility return unless adjustment.try(:reload) return if adjustment.finalized? + adjustment.update_attribute(:eligible, false) adjustment.finalize! end diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index d6f6e31108..d136c2b681 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -123,6 +123,7 @@ Spree::Product.class_eval do scope :stockable_by, lambda { |enterprise| return where('1=0') if enterprise.blank? + permitted_producer_ids = EnterpriseRelationship.joins(:parent).permitting(enterprise.id) .with_permission(:add_to_order_cycle).where(enterprises: { is_primary_producer: true }).pluck(:parent_id) return where('spree_products.supplier_id IN (?)', [enterprise.id] | permitted_producer_ids) @@ -226,6 +227,7 @@ Spree::Product.class_eval do def remove_previous_primary_taxon_from_taxons return unless primary_taxon_id_changed? && primary_taxon_id_was + taxons.destroy(primary_taxon_id_was) end diff --git a/app/models/spree/product_set.rb b/app/models/spree/product_set.rb index 3e69c89bc7..c1d387c787 100644 --- a/app/models/spree/product_set.rb +++ b/app/models/spree/product_set.rb @@ -48,6 +48,7 @@ class Spree::ProductSet < ModelSet def update_product(product, attributes) original_supplier = product.supplier_id return false unless update_product_only_attributes(product, attributes) + ExchangeVariantDeleter.new.delete(product) if original_supplier != product.supplier_id update_product_variants(product, attributes) && @@ -81,11 +82,13 @@ class Spree::ProductSet < ModelSet def update_product_variants(product, attributes) return true unless attributes[:variants_attributes] + update_variants_attributes(product, attributes[:variants_attributes]) end def update_product_master(product, attributes) return true unless attributes[:master_attributes] + create_or_update_variant(product, attributes[:master_attributes]) end @@ -113,9 +116,9 @@ class Spree::ProductSet < ModelSet begin variant.on_demand = on_demand if on_demand.present? variant.on_hand = on_hand.to_i if on_hand.present? - rescue StandardError => error - notify_bugsnag(error, product, variant, variant_attributes) - raise error + rescue StandardError => e + notify_bugsnag(e, product, variant, variant_attributes) + raise e end end diff --git a/app/models/spree/shipment_decorator.rb b/app/models/spree/shipment_decorator.rb index be80102e5a..b9cb0d07f1 100644 --- a/app/models/spree/shipment_decorator.rb +++ b/app/models/spree/shipment_decorator.rb @@ -33,6 +33,7 @@ module Spree # without line items (ie. user invoices) to not have inventory units def require_inventory return false unless line_items.count > 0 # This line altered + order.completed? && !order.canceled? end end diff --git a/app/models/spree/tax_rate_decorator.rb b/app/models/spree/tax_rate_decorator.rb index 972cb72dab..4e256a2cce 100644 --- a/app/models/spree/tax_rate_decorator.rb +++ b/app/models/spree/tax_rate_decorator.rb @@ -3,6 +3,7 @@ module Spree class << self def match_with_sales_tax_registration(order) return [] if order.distributor && !order.distributor.charges_sales_tax + match_without_sales_tax_registration(order) end alias_method_chain :match, :sales_tax_registration diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index 9e33717c34..17d4dc2978 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -102,6 +102,7 @@ module Spree def customer_of(enterprise) return nil unless enterprise + customers.find_by_enterprise_id(enterprise) end @@ -109,6 +110,7 @@ module Spree # Send welcome email if we are confirming an user's email # Note: this callback only runs on email confirmation return unless confirmed? && unconfirmed_email.nil? && !unconfirmed_email_changed? + send_signup_confirmation end @@ -178,6 +180,7 @@ module Spree def limit_owned_enterprises return unless owned_enterprises.size > enterprise_limit + errors.add(:owned_enterprises, I18n.t(:spree_user_enterprise_limit_error, email: email, enterprise_limit: enterprise_limit)) diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 4c9d27d9b9..84750cbe94 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -58,6 +58,7 @@ Spree::Variant.class_eval do scope :not_hidden_for, lambda { |enterprise| return where("1=0") if enterprise.blank? + joins("LEFT OUTER JOIN (SELECT * from inventory_items WHERE enterprise_id = #{sanitize enterprise.andand.id}) AS o_inventory_items ON o_inventory_items.variant_id = spree_variants.id") .where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true) } @@ -66,6 +67,7 @@ Spree::Variant.class_eval do scope :stockable_by, lambda { |enterprise| return where("1=0") if enterprise.blank? + joins(:product).where(spree_products: { id: Spree::Product.stockable_by(enterprise).pluck(:id) }) } diff --git a/app/models/subscription.rb b/app/models/subscription.rb index f217bcb0ec..443a6ef7a4 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -65,11 +65,13 @@ class Subscription < ActiveRecord::Base def pending? return true unless begins_at + begins_at > Time.zone.now end def ended? return false unless ends_at + ends_at < Time.zone.now end end diff --git a/app/models/tag_rule/discount_order.rb b/app/models/tag_rule/discount_order.rb index 8b4a780cbd..5f9ca44b2f 100644 --- a/app/models/tag_rule/discount_order.rb +++ b/app/models/tag_rule/discount_order.rb @@ -14,6 +14,7 @@ class TagRule::DiscountOrder < TagRule def additional_requirements_met? return false if already_applied? + true end diff --git a/app/serializers/api/admin/customer_serializer.rb b/app/serializers/api/admin/customer_serializer.rb index 2bc9f5a7db..070e7927da 100644 --- a/app/serializers/api/admin/customer_serializer.rb +++ b/app/serializers/api/admin/customer_serializer.rb @@ -22,6 +22,7 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer def default_card_present? return unless object.user + object.user.default_card.present? end end diff --git a/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb b/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb index 9a7bf4861b..8ed387dd2e 100644 --- a/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb +++ b/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb @@ -18,7 +18,7 @@ class Api::Admin::ForOrderCycle::SuppliedProductSerializer < ActiveModel::Serial object.variants.visible_for(order_cycle.coordinator) else object.variants - end + end variants.map { |variant| { id: variant.id, label: variant.full_name } } end diff --git a/app/serializers/api/admin/index_enterprise_serializer.rb b/app/serializers/api/admin/index_enterprise_serializer.rb index 8946686c5f..9d050dabab 100644 --- a/app/serializers/api/admin/index_enterprise_serializer.rb +++ b/app/serializers/api/admin/index_enterprise_serializer.rb @@ -6,6 +6,7 @@ class Api::Admin::IndexEnterpriseSerializer < ActiveModel::Serializer def owned return true if options[:spree_current_user].admin? + object.owner == options[:spree_current_user] end diff --git a/app/serializers/api/admin/line_item_serializer.rb b/app/serializers/api/admin/line_item_serializer.rb index 63ae22a6fb..1a22d3ce86 100644 --- a/app/serializers/api/admin/line_item_serializer.rb +++ b/app/serializers/api/admin/line_item_serializer.rb @@ -23,6 +23,7 @@ class Api::Admin::LineItemSerializer < ActiveModel::Serializer def max_quantity return object.quantity unless object.max_quantity.present? && object.max_quantity > object.quantity + object.max_quantity end end diff --git a/app/serializers/api/admin/order_cycle_serializer.rb b/app/serializers/api/admin/order_cycle_serializer.rb index 52e6f52711..a782c26048 100644 --- a/app/serializers/api/admin/order_cycle_serializer.rb +++ b/app/serializers/api/admin/order_cycle_serializer.rb @@ -79,7 +79,7 @@ class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer permissions. visible_variants_for_outgoing_exchanges_to(enterprise). not_hidden_for(enterprise) - end.pluck(:id) + end.pluck(:id) visible[enterprise.id] = variants if variants.any? end visible diff --git a/app/serializers/api/admin/order_serializer.rb b/app/serializers/api/admin/order_serializer.rb index 83707e8af5..342490d90e 100644 --- a/app/serializers/api/admin/order_serializer.rb +++ b/app/serializers/api/admin/order_serializer.rb @@ -18,11 +18,13 @@ class Api::Admin::OrderSerializer < ActiveModel::Serializer def edit_path return '' unless object.id + spree_routes_helper.edit_admin_order_path(object) end def payments_path return '' unless object.payment_state + spree_routes_helper.admin_order_payments_path(object) end @@ -33,6 +35,7 @@ class Api::Admin::OrderSerializer < ActiveModel::Serializer def payment_capture_path pending_payment = object.pending_payments.first return '' unless object.payment_required? && pending_payment + spree_routes_helper.fire_admin_order_payment_path(object, pending_payment.id, e: 'capture') end diff --git a/app/serializers/api/admin/product_serializer.rb b/app/serializers/api/admin/product_serializer.rb index 5ef3a27d4e..c4b9f15a34 100644 --- a/app/serializers/api/admin/product_serializer.rb +++ b/app/serializers/api/admin/product_serializer.rb @@ -26,6 +26,7 @@ class Api::Admin::ProductSerializer < ActiveModel::Serializer def on_hand return 0 if object.on_hand.nil? + object.on_hand end diff --git a/app/serializers/api/admin/proxy_order_serializer.rb b/app/serializers/api/admin/proxy_order_serializer.rb index 00f87e3f5d..cc7ac48eee 100644 --- a/app/serializers/api/admin/proxy_order_serializer.rb +++ b/app/serializers/api/admin/proxy_order_serializer.rb @@ -6,6 +6,7 @@ module Api def total return if object.total.blank? + object.total.to_money.to_s end diff --git a/app/serializers/api/admin/subscription_serializer.rb b/app/serializers/api/admin/subscription_serializer.rb index 10b2634772..dc8cab70c3 100644 --- a/app/serializers/api/admin/subscription_serializer.rb +++ b/app/serializers/api/admin/subscription_serializer.rb @@ -38,6 +38,7 @@ module Api def edit_path return '' unless object.id + edit_admin_subscription_path(object) end diff --git a/app/serializers/api/admin/variant_serializer.rb b/app/serializers/api/admin/variant_serializer.rb index 4ab886b270..cfa2d98293 100644 --- a/app/serializers/api/admin/variant_serializer.rb +++ b/app/serializers/api/admin/variant_serializer.rb @@ -16,6 +16,7 @@ class Api::Admin::VariantSerializer < ActiveModel::Serializer def on_hand return 0 if object.on_hand.nil? + object.on_hand end @@ -30,6 +31,7 @@ class Api::Admin::VariantSerializer < ActiveModel::Serializer def image return if object.product.images.empty? + object.product.images.first.mini_url end @@ -39,11 +41,13 @@ class Api::Admin::VariantSerializer < ActiveModel::Serializer def stock_location_id return if object.stock_items.empty? + object.stock_items.first.stock_location.id end def stock_location_name return if object.stock_items.empty? + object.stock_items.first.stock_location.name end end diff --git a/app/serializers/api/cached_enterprise_serializer.rb b/app/serializers/api/cached_enterprise_serializer.rb index 4e421ff48e..26a6f351d8 100644 --- a/app/serializers/api/cached_enterprise_serializer.rb +++ b/app/serializers/api/cached_enterprise_serializer.rb @@ -86,6 +86,7 @@ module Api .select('DISTINCT spree_properties.*') return properties.merge(OrderCycle.active) if active + properties end @@ -101,6 +102,7 @@ module Api .select('DISTINCT spree_properties.*') return properties.merge(OrderCycle.active) if active + properties end diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb index 89c5e68f5b..693f7442f5 100644 --- a/app/serializers/api/enterprise_shopfront_serializer.rb +++ b/app/serializers/api/enterprise_shopfront_serializer.rb @@ -97,6 +97,7 @@ module Api .select('DISTINCT spree_properties.*') return properties.merge(OrderCycle.active) if active + properties end @@ -110,6 +111,7 @@ module Api .select('DISTINCT spree_properties.*') return properties.merge(OrderCycle.active) if active + properties end diff --git a/app/serializers/api/order_serializer.rb b/app/serializers/api/order_serializer.rb index 017f32bbf5..f90f6ef572 100644 --- a/app/serializers/api/order_serializer.rb +++ b/app/serializers/api/order_serializer.rb @@ -25,6 +25,7 @@ module Api def changes_allowed_until return I18n.t(:not_allowed) unless object.changes_allowed? + I18n.l(object.order_cycle.andand.orders_close_at, format: "%b %d, %Y %H:%M") end @@ -46,6 +47,7 @@ module Api def cancel_path return nil unless object.changes_allowed? + Spree::Core::Engine.routes_url_helpers.cancel_order_path(object) end diff --git a/app/serializers/api/variant_serializer.rb b/app/serializers/api/variant_serializer.rb index 54eae7aed5..e824db8406 100644 --- a/app/serializers/api/variant_serializer.rb +++ b/app/serializers/api/variant_serializer.rb @@ -27,6 +27,7 @@ class Api::VariantSerializer < ActiveModel::Serializer # Used for showing/hiding variants in shopfront based on tag rules def tag_list return [] unless object.respond_to?(:tag_list) + object.tag_list end end diff --git a/app/services/advance_order_service.rb b/app/services/advance_order_service.rb index 08113bd862..1377c36147 100644 --- a/app/services/advance_order_service.rb +++ b/app/services/advance_order_service.rb @@ -23,6 +23,7 @@ class AdvanceOrderService def advance_order(options) until order.state == "complete" break unless order.next + after_transition_hook(options) end end diff --git a/app/services/embedded_page_service.rb b/app/services/embedded_page_service.rb index 55c0bf79ab..9164ac4d94 100644 --- a/app/services/embedded_page_service.rb +++ b/app/services/embedded_page_service.rb @@ -63,28 +63,34 @@ class EmbeddedPageService def set_logout_redirect return unless enterprise_slug + @session[:shopfront_redirect] = '/' + enterprise_slug + '/shop?embedded_shopfront=true' end def enterprise_slug return false unless @params[:controller] == 'enterprises' && @params[:action] == 'shop' && @params[:id] + @params[:id] end def current_referer return if @request.referer.blank? + uri = URI(@request.referer) return if uri.host.blank? + uri.host.downcase end def current_referer_without_www return unless current_referer + current_referer.start_with?('www.') ? current_referer[4..-1] : current_referer end def set_embedded_layout return unless @session[:embedded_shopfront] + @use_embedded_layout = true end diff --git a/app/services/exchange_variant_bulk_updater.rb b/app/services/exchange_variant_bulk_updater.rb index 330425852e..a617649c81 100644 --- a/app/services/exchange_variant_bulk_updater.rb +++ b/app/services/exchange_variant_bulk_updater.rb @@ -17,6 +17,7 @@ class ExchangeVariantBulkUpdater def disassociate_variants!(variant_ids) return if variant_ids.blank? + @exchange.exchange_variants.where(variant_id: variant_ids).delete_all end diff --git a/app/services/order_cycle_distributed_variants.rb b/app/services/order_cycle_distributed_variants.rb index 73d999b536..6a53b7a092 100644 --- a/app/services/order_cycle_distributed_variants.rb +++ b/app/services/order_cycle_distributed_variants.rb @@ -14,6 +14,7 @@ class OrderCycleDistributedVariants def available_variants return [] unless @order_cycle + @order_cycle.variants_distributed_by(@distributor) end end diff --git a/app/services/order_cycle_form.rb b/app/services/order_cycle_form.rb index d463badfa4..2ab5d109de 100644 --- a/app/services/order_cycle_form.rb +++ b/app/services/order_cycle_form.rb @@ -14,6 +14,7 @@ class OrderCycleForm build_schedule_ids order_cycle.assign_attributes(params[:order_cycle]) return false unless order_cycle.valid? + order_cycle.transaction do order_cycle.save! apply_exchange_changes @@ -30,6 +31,7 @@ class OrderCycleForm def apply_exchange_changes return if exchanges_unchanged? + OpenFoodNetwork::OrderCycleFormApplicator.new(order_cycle, user).go! end @@ -45,6 +47,7 @@ class OrderCycleForm def build_schedule_ids return unless schedule_ids? + result = existing_schedule_ids result |= (requested_schedule_ids & permitted_schedule_ids) # Add permitted and requested result -= ((result & permitted_schedule_ids) - requested_schedule_ids) # Remove permitted but not requested @@ -54,6 +57,7 @@ class OrderCycleForm def sync_subscriptions return unless schedule_ids? return unless schedule_sync_required? + OpenFoodNetwork::ProxyOrderSyncer.new(subscriptions_to_sync).sync! end diff --git a/app/services/order_factory.rb b/app/services/order_factory.rb index 19c579e15b..1a2aeba1b3 100644 --- a/app/services/order_factory.rb +++ b/app/services/order_factory.rb @@ -47,6 +47,7 @@ class OrderFactory def build_line_items attrs[:line_items].each do |li| next unless variant = Spree::Variant.find_by_id(li[:variant_id]) + scoper.scope(variant) li[:quantity] = stock_limited_quantity(variant.on_demand, variant.on_hand, li[:quantity]) li[:price] = variant.price @@ -83,6 +84,7 @@ class OrderFactory def stock_limited_quantity(variant_on_demand, variant_on_hand, requested) return requested if opts[:skip_stock_check] || variant_on_demand + [variant_on_hand, requested].min end diff --git a/app/services/order_syncer.rb b/app/services/order_syncer.rb index 1f3608bd22..97f8066a03 100644 --- a/app/services/order_syncer.rb +++ b/app/services/order_syncer.rb @@ -39,6 +39,7 @@ class OrderSyncer def orders_in_order_cycles_not_closed return @orders_in_order_cycles_not_closed unless @orders_in_order_cycles_not_closed.nil? + @orders_in_order_cycles_not_closed = orders.joins(:order_cycle). merge(OrderCycle.not_closed).readonly(false) end @@ -47,6 +48,7 @@ class OrderSyncer unless addresses_match?(order.bill_address, bill_address) return order_update_issues.add(order, I18n.t('bill_address')) end + order.bill_address.update_attributes(bill_address.attributes.slice(*relevant_address_attrs)) end @@ -101,6 +103,7 @@ class OrderSyncer return true if force_ship_address_required?(order) return false unless order.shipping_method.require_ship_address? return true if addresses_match?(order.ship_address, ship_address) + order_update_issues.add(order, I18n.t('ship_address')) false end @@ -110,6 +113,7 @@ class OrderSyncer # address on the order matches the shop's address def force_ship_address_required?(order) return false unless shipping_method.require_ship_address? + distributor_address = order.address_from_distributor relevant_address_attrs.all? do |attr| order.ship_address[attr] == distributor_address[attr] @@ -118,11 +122,13 @@ class OrderSyncer def save_ship_address_in_order(order) return unless ship_address_updatable?(order) + order.ship_address.update_attributes(ship_address.attributes.slice(*relevant_address_attrs)) end def pending_shipment_with?(order, shipping_method_id) return false unless order.shipment.present? && order.shipment.state == "pending" + order.shipping_method.id == shipping_method_id end end diff --git a/app/services/product_tag_rules_filterer.rb b/app/services/product_tag_rules_filterer.rb index b58cbc2c43..fcb678a672 100644 --- a/app/services/product_tag_rules_filterer.rb +++ b/app/services/product_tag_rules_filterer.rb @@ -45,11 +45,13 @@ class ProductTagRulesFilterer def override_not_hidden_by_rule return "FALSE" unless overrides_to_hide.any? + "variant_overrides.id NOT IN (#{overrides_to_hide.join(',')})" end def override_shown_by_rule return "FALSE" unless overrides_to_show.any? + "variant_overrides.id IN (#{overrides_to_show.join(',')})" end diff --git a/app/services/search_orders.rb b/app/services/search_orders.rb index c1120ffb19..5d4f834cc0 100644 --- a/app/services/search_orders.rb +++ b/app/services/search_orders.rb @@ -10,6 +10,7 @@ class SearchOrders def pagination_data return unless using_pagination? + { results: @orders.total_count, pages: @orders.num_pages, @@ -26,6 +27,7 @@ class SearchOrders @search = OpenFoodNetwork::Permissions.new(current_user).editable_orders.ransack(params[:q]) return paginated_results if using_pagination? + @search.result(distinct: true) end diff --git a/app/services/subscription_estimator.rb b/app/services/subscription_estimator.rb index 8e69e310ac..6e4d7b0938 100644 --- a/app/services/subscription_estimator.rb +++ b/app/services/subscription_estimator.rb @@ -29,6 +29,7 @@ class SubscriptionEstimator def price_estimate_for(variant, fallback) return fallback unless fee_calculator && variant + scoper.scope(variant) fees = fee_calculator.indexed_fees_for(variant) (variant.price + fees).to_d @@ -36,8 +37,10 @@ class SubscriptionEstimator def fee_calculator return @fee_calculator unless @fee_calculator.nil? + next_oc = subscription.schedule.andand.current_or_next_order_cycle return nil unless shop && next_oc + @fee_calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(shop, next_oc) end diff --git a/app/services/subscription_form.rb b/app/services/subscription_form.rb index 6b20dd700c..da82063b5c 100644 --- a/app/services/subscription_form.rb +++ b/app/services/subscription_form.rb @@ -17,6 +17,7 @@ class SubscriptionForm def save subscription.assign_attributes(params) return false unless valid? + subscription.transaction do estimator.estimate! proxy_order_syncer.sync! diff --git a/app/services/subscription_validator.rb b/app/services/subscription_validator.rb index 1ca035dfc7..8d9a678f9a 100644 --- a/app/services/subscription_validator.rb +++ b/app/services/subscription_validator.rb @@ -40,18 +40,21 @@ class SubscriptionValidator def shipping_method_allowed? return unless shipping_method return if shipping_method.distributors.include?(shop) + errors.add(:shipping_method, :not_available_to_shop, shop: shop.name) end def payment_method_allowed? return unless payment_method return if payment_method.distributors.include?(shop) + errors.add(:payment_method, :not_available_to_shop, shop: shop.name) end def payment_method_type_allowed? return unless payment_method return if Subscription::ALLOWED_PAYMENT_METHOD_TYPES.include? payment_method.type + errors.add(:payment_method, :invalid_type) end @@ -59,18 +62,21 @@ class SubscriptionValidator # Only validates ends_at if it is present return if begins_at.blank? || ends_at.blank? return if ends_at > begins_at + errors.add(:ends_at, :after_begins_at) end def customer_allowed? return unless customer return if customer.enterprise == shop + errors.add(:customer, :does_not_belong_to_shop, shop: shop.name) end def schedule_allowed? return unless schedule return if schedule.coordinators.include?(shop) + errors.add(:schedule, :not_coordinated_by_shop, shop: shop.name) end @@ -79,11 +85,13 @@ class SubscriptionValidator return unless payment_method.type == "Spree::Gateway::StripeConnect" return errors.add(:payment_method, :charges_not_allowed) unless customer.allow_charges return if customer.user.andand.default_card.present? + errors.add(:payment_method, :no_default_card) end def subscription_line_items_present? return if subscription_line_items.reject(&:marked_for_destruction?).any? + errors.add(:subscription_line_items, :at_least_one_product) end @@ -93,6 +101,7 @@ class SubscriptionValidator def verify_availability_of(variant) return if available_variant_ids.include? variant.id + name = "#{variant.product.name} - #{variant.full_name}" errors.add(:subscription_line_items, :not_available, name: name) end @@ -107,6 +116,7 @@ class SubscriptionValidator def build_msg_from(k, msg) return msg[1..-1] if msg.starts_with?("^") + errors.full_message(k, msg) end end diff --git a/app/services/subscriptions_count.rb b/app/services/subscriptions_count.rb index 6afbe15dae..ee1126c0d2 100644 --- a/app/services/subscriptions_count.rb +++ b/app/services/subscriptions_count.rb @@ -14,6 +14,7 @@ class SubscriptionsCount def active return @active unless @active.nil? return @active = [] if order_cycles.blank? + @active ||= ProxyOrder.not_canceled.group(:order_cycle_id).where(order_cycle_id: order_cycles).count end end diff --git a/app/services/tax_rate_finder.rb b/app/services/tax_rate_finder.rb index 3f7397af94..f27a42ef85 100644 --- a/app/services/tax_rate_finder.rb +++ b/app/services/tax_rate_finder.rb @@ -76,6 +76,7 @@ class TaxRateFinder def find_closest_tax_rates_from_included_tax(amount, included_tax) approximation = (included_tax / (amount - included_tax)) return [] if approximation.infinite? || approximation.zero? + [Spree::TaxRate.order("ABS(amount - #{approximation})").first] end end diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb index c186b9aae3..8eb14c44cf 100644 --- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb @@ -14,6 +14,7 @@ module OrderManagement def tax_category_name return data["tax_category_name"] if data["tax_category_name"].present? + i18n_translate("tax_category_various") if inherits_tax_category? end diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb index ad678dc33b..a58b549490 100644 --- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb +++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb @@ -28,6 +28,7 @@ module OrderManagement def representation_klass return DataRepresentations::PaymentMethodFee if for_payment_method? return DataRepresentations::ShippingMethodFee if for_shipping_method? + enterprise_fee_adjustment_presentation_klass if for_enterprise_fee? end diff --git a/lib/discourse/single_sign_on.rb b/lib/discourse/single_sign_on.rb index dd4567338d..31d5d06989 100644 --- a/lib/discourse/single_sign_on.rb +++ b/lib/discourse/single_sign_on.rb @@ -26,7 +26,7 @@ module Discourse parsed = Rack::Utils.parse_query(payload) if sso.sign(parsed["sso"]) != parsed["sig"] diags = "\n\nsso: #{parsed['sso']}\n\nsig: #{parsed['sig']}\n\nexpected sig: #{sso.sign(parsed['sso'])}" - if parsed["sso"] =~ /[^a-zA-Z0-9=\r\n\/+]/m + if parsed["sso"] =~ %r{[^a-zA-Z0-9=\r\n/+]}m raise "The SSO field should be Base64 encoded, using only A-Z, a-z, 0-9, +, /, and = characters. Your input contains characters we don't understand as Base64, see http://en.wikipedia.org/wiki/Base64 #{diags}" else raise "Bad signature for payload #{diags}" diff --git a/lib/open_food_network/address_finder.rb b/lib/open_food_network/address_finder.rb index fdccecf1cb..c2313b9693 100644 --- a/lib/open_food_network/address_finder.rb +++ b/lib/open_food_network/address_finder.rb @@ -12,6 +12,7 @@ module OpenFoodNetwork args.each do |arg| type = types[arg.class] next unless type + public_send("#{type}=", arg) end end @@ -40,8 +41,8 @@ module OpenFoodNetwork def types { - String => "email", - Customer => "customer", + String => "email", + Customer => "customer", Spree::User => "user" } end @@ -72,6 +73,7 @@ module OpenFoodNetwork def last_used_bill_address return nil unless allow_search_by_email? + Spree::Order.joins(:bill_address).order('id DESC') .complete.where(email: email) .first.andand.bill_address @@ -79,6 +81,7 @@ module OpenFoodNetwork def last_used_ship_address return nil unless allow_search_by_email? + Spree::Order.complete.joins(:ship_address, shipments: :shipping_methods).order('id DESC') .where(email: email, spree_shipping_methods: { require_ship_address: true }) .first.andand.ship_address diff --git a/lib/open_food_network/bulk_coop_report.rb b/lib/open_food_network/bulk_coop_report.rb index 05bd9aca41..d6ff3c9548 100644 --- a/lib/open_food_network/bulk_coop_report.rb +++ b/lib/open_food_network/bulk_coop_report.rb @@ -51,6 +51,7 @@ module OpenFoodNetwork def table_items return [] unless @render_table + Reports::LineItems.list(permissions, params) end @@ -123,6 +124,7 @@ module OpenFoodNetwork def permissions return @permissions unless @permissions.nil? + @permissions = OpenFoodNetwork::Permissions.new(@user) end end diff --git a/lib/open_food_network/column_preference_defaults.rb b/lib/open_food_network/column_preference_defaults.rb index 3b28d7e9ce..273d8d03df 100644 --- a/lib/open_food_network/column_preference_defaults.rb +++ b/lib/open_food_network/column_preference_defaults.rb @@ -10,107 +10,107 @@ module OpenFoodNetwork def variant_overrides_index_columns node = 'admin.variant_overrides.index' { - producer: { name: I18n.t("admin.producer"), visible: true }, - product: { name: I18n.t("admin.product"), visible: true }, - sku: { name: I18n.t("admin.sku"), visible: false }, - price: { name: I18n.t("admin.price"), visible: true }, - on_hand: { name: I18n.t("admin.on_hand"), visible: true }, - on_demand: { name: I18n.t("admin.on_demand?"), visible: true }, - reset: { name: I18n.t("#{node}.enable_reset?"), visible: false }, - inheritance: { name: I18n.t("#{node}.inherit?"), visible: false }, - tags: { name: I18n.t("admin.tags"), visible: false }, - visibility: { name: I18n.t("#{node}.hide"), visible: false }, - import_date: { name: I18n.t("#{node}.import_date"), visible: false } + producer: { name: I18n.t("admin.producer"), visible: true }, + product: { name: I18n.t("admin.product"), visible: true }, + sku: { name: I18n.t("admin.sku"), visible: false }, + price: { name: I18n.t("admin.price"), visible: true }, + on_hand: { name: I18n.t("admin.on_hand"), visible: true }, + on_demand: { name: I18n.t("admin.on_demand?"), visible: true }, + reset: { name: I18n.t("#{node}.enable_reset?"), visible: false }, + inheritance: { name: I18n.t("#{node}.inherit?"), visible: false }, + tags: { name: I18n.t("admin.tags"), visible: false }, + visibility: { name: I18n.t("#{node}.hide"), visible: false }, + import_date: { name: I18n.t("#{node}.import_date"), visible: false } } end def customers_index_columns node = 'admin.customers.index' { - email: { name: I18n.t("admin.email"), visible: true }, - name: { name: I18n.t("admin.name"), visible: true }, - code: { name: I18n.t("#{node}.code"), visible: true }, - tags: { name: I18n.t("admin.tags"), visible: true }, - bill_address: { name: I18n.t("#{node}.bill_address"), visible: true }, - ship_address: { name: I18n.t("#{node}.ship_address"), visible: true } + email: { name: I18n.t("admin.email"), visible: true }, + name: { name: I18n.t("admin.name"), visible: true }, + code: { name: I18n.t("#{node}.code"), visible: true }, + tags: { name: I18n.t("admin.tags"), visible: true }, + bill_address: { name: I18n.t("#{node}.bill_address"), visible: true }, + ship_address: { name: I18n.t("#{node}.ship_address"), visible: true } } end def orders_bulk_management_columns node = "admin.orders.bulk_management" { - order_no: { name: I18n.t("#{node}.order_no"), visible: false }, - full_name: { name: I18n.t("admin.name"), visible: true }, - email: { name: I18n.t("admin.email"), visible: false }, - phone: { name: I18n.t("admin.phone"), visible: false }, - order_date: { name: I18n.t("#{node}.order_date"), visible: true }, - producer: { name: I18n.t("admin.producer"), visible: true }, - order_cycle: { name: I18n.t("admin.order_cycle"), visible: false }, - hub: { name: I18n.t("admin.shop"), visible: false }, - variant: { name: I18n.t("#{node}.product_unit"), visible: true }, - quantity: { name: I18n.t("admin.quantity"), visible: true }, - max: { name: I18n.t("#{node}.max"), visible: true }, - final_weight_volume: { name: I18n.t("#{node}.weight_volume"), visible: false }, - price: { name: I18n.t("admin.price"), visible: false } + order_no: { name: I18n.t("#{node}.order_no"), visible: false }, + full_name: { name: I18n.t("admin.name"), visible: true }, + email: { name: I18n.t("admin.email"), visible: false }, + phone: { name: I18n.t("admin.phone"), visible: false }, + order_date: { name: I18n.t("#{node}.order_date"), visible: true }, + producer: { name: I18n.t("admin.producer"), visible: true }, + order_cycle: { name: I18n.t("admin.order_cycle"), visible: false }, + hub: { name: I18n.t("admin.shop"), visible: false }, + variant: { name: I18n.t("#{node}.product_unit"), visible: true }, + quantity: { name: I18n.t("admin.quantity"), visible: true }, + max: { name: I18n.t("#{node}.max"), visible: true }, + final_weight_volume: { name: I18n.t("#{node}.weight_volume"), visible: false }, + price: { name: I18n.t("admin.price"), visible: false } } end def products_index_columns node = "spree.admin.products.index.products_head" { - image: { name: I18n.t("admin.image"), visible: true }, - producer: { name: I18n.t("admin.producer"), visible: true }, - sku: { name: I18n.t("admin.sku"), visible: false }, - name: { name: I18n.t("admin.name"), visible: true }, - unit: { name: I18n.t("#{node}.unit"), visible: true }, - price: { name: I18n.t("admin.price"), visible: true }, - on_hand: { name: I18n.t("admin.on_hand"), visible: true }, - on_demand: { name: I18n.t("admin.on_demand"), visible: true }, - category: { name: I18n.t("#{node}.category"), visible: false }, - tax_category: { name: I18n.t("#{node}.tax_category"), visible: false }, - inherits_properties: { name: I18n.t("#{node}.inherits_properties?"), visible: false }, - available_on: { name: I18n.t("#{node}.available_on"), visible: false }, - import_date: { name: I18n.t("#{node}.import_date"), visible: false } + image: { name: I18n.t("admin.image"), visible: true }, + producer: { name: I18n.t("admin.producer"), visible: true }, + sku: { name: I18n.t("admin.sku"), visible: false }, + name: { name: I18n.t("admin.name"), visible: true }, + unit: { name: I18n.t("#{node}.unit"), visible: true }, + price: { name: I18n.t("admin.price"), visible: true }, + on_hand: { name: I18n.t("admin.on_hand"), visible: true }, + on_demand: { name: I18n.t("admin.on_demand"), visible: true }, + category: { name: I18n.t("#{node}.category"), visible: false }, + tax_category: { name: I18n.t("#{node}.tax_category"), visible: false }, + inherits_properties: { name: I18n.t("#{node}.inherits_properties?"), visible: false }, + available_on: { name: I18n.t("#{node}.available_on"), visible: false }, + import_date: { name: I18n.t("#{node}.import_date"), visible: false } } end def enterprises_index_columns node = "admin.enterprises.index" { - name: { name: I18n.t("admin.name"), visible: true }, - producer: { name: I18n.t("#{node}.producer?"), visible: true }, - package: { name: I18n.t("#{node}.package"), visible: true }, - status: { name: I18n.t("#{node}.status"), visible: true }, - manage: { name: I18n.t("#{node}.manage"), visible: true } + name: { name: I18n.t("admin.name"), visible: true }, + producer: { name: I18n.t("#{node}.producer?"), visible: true }, + package: { name: I18n.t("#{node}.package"), visible: true }, + status: { name: I18n.t("#{node}.status"), visible: true }, + manage: { name: I18n.t("#{node}.manage"), visible: true } } end def order_cycles_index_columns node = "admin.order_cycles.index" { - name: { name: I18n.t("admin.name"), visible: true }, - schedules: { name: I18n.t("#{node}.schedules"), visible: true }, - open: { name: I18n.t("open"), visible: true }, - close: { name: I18n.t("close"), visible: true }, - producers: { name: I18n.t("label_producers"), visible: false }, - coordinator: { name: I18n.t("coordinator"), visible: true }, - shops: { name: I18n.t("label_shops"), visible: false }, - products: { name: I18n.t("products"), visible: true } + name: { name: I18n.t("admin.name"), visible: true }, + schedules: { name: I18n.t("#{node}.schedules"), visible: true }, + open: { name: I18n.t("open"), visible: true }, + close: { name: I18n.t("close"), visible: true }, + producers: { name: I18n.t("label_producers"), visible: false }, + coordinator: { name: I18n.t("coordinator"), visible: true }, + shops: { name: I18n.t("label_shops"), visible: false }, + products: { name: I18n.t("products"), visible: true } } end def subscriptions_index_columns _node = "admin.subscriptions.index" { - customer: { name: I18n.t("admin.customer"), visible: true }, - schedule: { name: I18n.t("admin.schedule"), visible: true }, - items: { name: I18n.t("items"), visible: true }, - orders: { name: I18n.t("orders"), visible: true }, - state: { name: I18n.t("admin.status_state"), visible: true }, - begins_on: { name: I18n.t("admin.begins_on"), visible: false }, - ends_on: { name: I18n.t("admin.ends_on"), visible: false }, - payment_method: { name: I18n.t("admin.payment_method"), visible: false }, - shipping_method: { name: I18n.t("admin.shipping_method"), visible: false } + customer: { name: I18n.t("admin.customer"), visible: true }, + schedule: { name: I18n.t("admin.schedule"), visible: true }, + items: { name: I18n.t("items"), visible: true }, + orders: { name: I18n.t("orders"), visible: true }, + state: { name: I18n.t("admin.status_state"), visible: true }, + begins_on: { name: I18n.t("admin.begins_on"), visible: false }, + ends_on: { name: I18n.t("admin.ends_on"), visible: false }, + payment_method: { name: I18n.t("admin.payment_method"), visible: false }, + shipping_method: { name: I18n.t("admin.shipping_method"), visible: false } } end end diff --git a/lib/open_food_network/customers_report.rb b/lib/open_food_network/customers_report.rb index 92d2013ca6..e7b17e9063 100644 --- a/lib/open_food_network/customers_report.rb +++ b/lib/open_food_network/customers_report.rb @@ -27,6 +27,7 @@ module OpenFoodNetwork def table return [] unless @compile_table + orders.map do |order| if is_mailing_list? [order.email, diff --git a/lib/open_food_network/enterprise_issue_validator.rb b/lib/open_food_network/enterprise_issue_validator.rb index 0b81db7381..885905f32b 100644 --- a/lib/open_food_network/enterprise_issue_validator.rb +++ b/lib/open_food_network/enterprise_issue_validator.rb @@ -55,11 +55,13 @@ module OpenFoodNetwork def shipping_methods_ok? # Refactor into boolean return true unless @enterprise.is_distributor + @enterprise.shipping_methods.any? end def payment_methods_ok? return true unless @enterprise.is_distributor + @enterprise.payment_methods.available.any? end end diff --git a/lib/open_food_network/lettuce_share_report.rb b/lib/open_food_network/lettuce_share_report.rb index 18f6482173..c04a7b3adb 100644 --- a/lib/open_food_network/lettuce_share_report.rb +++ b/lib/open_food_network/lettuce_share_report.rb @@ -20,6 +20,7 @@ module OpenFoodNetwork def table return [] unless @render_table + variants.select(&:in_stock?) .map do |variant| [ diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index 2217f99ae5..611f120f62 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -119,12 +119,14 @@ module OpenFoodNetwork def permitted_enterprises return @permitted_enterprises unless @permitted_enterprises.nil? + @permitted_enterprises = OpenFoodNetwork::OrderCyclePermissions. new(@spree_current_user, @order_cycle).visible_enterprises end def manages_coordinator? return @manages_coordinator unless @manages_coordinator.nil? + @manages_coordinator = Enterprise.managed_by(@spree_current_user).include? @order_cycle.coordinator end diff --git a/lib/open_food_network/order_cycle_permissions.rb b/lib/open_food_network/order_cycle_permissions.rb index 4d503ed37a..73264ce414 100644 --- a/lib/open_food_network/order_cycle_permissions.rb +++ b/lib/open_food_network/order_cycle_permissions.rb @@ -13,6 +13,7 @@ module OpenFoodNetwork # relationships of their enterprises to the coordinator of the OC, rather than on the OC itself def visible_enterprises return Enterprise.where("1=0") if @coordinator.blank? + if managed_enterprises.include? @coordinator coordinator_permitted_ids = [@coordinator] all_active_ids = [] @@ -268,17 +269,20 @@ module OpenFoodNetwork def managed_participating_enterprises return @managed_participating_enterprises unless @managed_participating_enterprises.nil? + @managed_participating_enterprises = managed_enterprises. where(id: @order_cycle.suppliers | @order_cycle.distributors) end def managed_participating_hubs return @managed_participating_hubs unless @managed_participating_hubs.nil? + @managed_participating_hubs = managed_participating_enterprises.is_hub end def managed_participating_producers return @managed_participating_producers unless @managed_participating_producers.nil? + @managed_participating_producers = managed_participating_enterprises.is_primary_producer end diff --git a/lib/open_food_network/packing_report.rb b/lib/open_food_network/packing_report.rb index c46911e363..c7dd175d09 100644 --- a/lib/open_food_network/packing_report.rb +++ b/lib/open_food_network/packing_report.rb @@ -43,6 +43,7 @@ module OpenFoodNetwork def table_items return [] unless @render_table + Reports::LineItems.list(permissions, params) end @@ -122,6 +123,7 @@ module OpenFoodNetwork def permissions return @permissions unless @permissions.nil? + @permissions = OpenFoodNetwork::Permissions.new(@user) end diff --git a/lib/open_food_network/payments_report.rb b/lib/open_food_network/payments_report.rb index b57b457693..f9f536171f 100644 --- a/lib/open_food_network/payments_report.rb +++ b/lib/open_food_network/payments_report.rb @@ -39,6 +39,7 @@ module OpenFoodNetwork def table_items return [] unless @render_table + orders = search.result payments = orders.map { |o| o.payments.select(&:completed?) }.flatten # Only select completed payments case params[:report_type] diff --git a/lib/open_food_network/permalink_generator.rb b/lib/open_food_network/permalink_generator.rb index efcd496234..3c5babc750 100644 --- a/lib/open_food_network/permalink_generator.rb +++ b/lib/open_food_network/permalink_generator.rb @@ -13,6 +13,7 @@ module PermalinkGenerator module ClassMethods def find_available_value(existing, requested) return requested unless existing.include?(requested) + used_indices = existing.map do |p| p.slice!(/^#{requested}/) p.match(/^\d+$/).to_s.to_i diff --git a/lib/open_food_network/permissions.rb b/lib/open_food_network/permissions.rb index ee6f301d80..5864f0f534 100644 --- a/lib/open_food_network/permissions.rb +++ b/lib/open_food_network/permissions.rb @@ -189,11 +189,13 @@ module OpenFoodNetwork def managed_enterprises return @managed_enterprises unless @managed_enterprises.nil? + @managed_enterprises = Enterprise.managed_by(@user) end def coordinated_order_cycles return @coordinated_order_cycles unless @coordinated_order_cycles.nil? + @coordinated_order_cycles = OrderCycle.managed_by(@user) end diff --git a/lib/open_food_network/products_and_inventory_report.rb b/lib/open_food_network/products_and_inventory_report.rb index 53ee7d1c65..0e89434abd 100644 --- a/lib/open_food_network/products_and_inventory_report.rb +++ b/lib/open_food_network/products_and_inventory_report.rb @@ -19,6 +19,7 @@ module OpenFoodNetwork def table return [] unless @render_table + variants.map do |variant| [ variant.product.supplier.name, @@ -37,6 +38,7 @@ module OpenFoodNetwork def sku_for(variant) return variant.sku if variant.sku.present? + variant.product.sku end end diff --git a/lib/open_food_network/proxy_order_syncer.rb b/lib/open_food_network/proxy_order_syncer.rb index c187fde2a4..416774d506 100644 --- a/lib/open_food_network/proxy_order_syncer.rb +++ b/lib/open_food_network/proxy_order_syncer.rb @@ -19,6 +19,7 @@ module OpenFoodNetwork def sync! return sync_all! if @subscriptions return initialise_proxy_orders! unless @subscription.id + create_proxy_orders! remove_orphaned_proxy_orders! end @@ -41,6 +42,7 @@ module OpenFoodNetwork def create_proxy_orders! return unless not_closed_in_range_order_cycles.any? + query = "INSERT INTO proxy_orders (subscription_id, order_cycle_id, updated_at, created_at)" query << " VALUES #{insert_values}" query << " ON CONFLICT DO NOTHING" @@ -60,6 +62,7 @@ module OpenFoodNetwork orphaned = proxy_orders.where(placed_at: nil) order_cycle_ids = in_range_order_cycles.pluck(:id) return orphaned unless order_cycle_ids.any? + orphaned.where('order_cycle_id NOT IN (?)', order_cycle_ids) end diff --git a/lib/open_food_network/rack_request_blocker.rb b/lib/open_food_network/rack_request_blocker.rb index 99ec116b2e..485564b225 100644 --- a/lib/open_food_network/rack_request_blocker.rb +++ b/lib/open_food_network/rack_request_blocker.rb @@ -43,10 +43,10 @@ class RackRequestBlocker block_requests! max_wait_time = 30 polling_interval = 0.01 - wait_until = Time.now + max_wait_time.seconds + wait_until = Time.now.in_time_zone + max_wait_time.seconds loop do return if num_active_requests == 0 - if Time.now > wait_until + if Time.now.in_time_zone > wait_until raise "Failed waiting for completing requests, #{num_active_requests} running." else sleep(polling_interval) diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index 4763c4ebff..af6ef44bf7 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -44,6 +44,7 @@ module OpenFoodNetwork def table return [] unless @render_table + case params[:report_type] when "tax_rates" orders.map do |order| @@ -67,6 +68,7 @@ module OpenFoodNetwork def relevant_rates return @relevant_rates unless @relevant_rates.nil? + @relevant_rates = Spree::TaxRate.uniq end diff --git a/lib/open_food_network/subscription_payment_updater.rb b/lib/open_food_network/subscription_payment_updater.rb index bdf437c963..1c4d275db1 100644 --- a/lib/open_food_network/subscription_payment_updater.rb +++ b/lib/open_food_network/subscription_payment_updater.rb @@ -22,6 +22,7 @@ module OpenFoodNetwork def create_payment return if payment.present? + @payment = order.payments.create( payment_method_id: order.subscription.payment_method_id, amount: order.outstanding_balance @@ -38,11 +39,13 @@ module OpenFoodNetwork def ensure_payment_source return unless card_required? && !card_set? + ensure_credit_card || order.errors.add(:base, :no_card) end def ensure_credit_card return false if saved_credit_card.blank? || !allow_charges? + payment.update_attributes(source: saved_credit_card) end diff --git a/lib/open_food_network/subscription_summarizer.rb b/lib/open_food_network/subscription_summarizer.rb index 193e5f7b63..7a429a9e3b 100644 --- a/lib/open_food_network/subscription_summarizer.rb +++ b/lib/open_food_network/subscription_summarizer.rb @@ -22,6 +22,7 @@ module OpenFoodNetwork def record_and_log_error(type, order) return record_issue(type, order) unless order.errors.any? + error = "Subscription#{type.to_s.camelize}Error" line1 = "#{error}: Cannot process order #{order.number} due to errors" line2 = "Errors: #{order.errors.full_messages.join(', ')}" diff --git a/lib/open_food_network/tag_rule_applicator.rb b/lib/open_food_network/tag_rule_applicator.rb index fe5584f6b7..fa5f1b6c49 100644 --- a/lib/open_food_network/tag_rule_applicator.rb +++ b/lib/open_food_network/tag_rule_applicator.rb @@ -13,6 +13,7 @@ module OpenFoodNetwork def filter!(subject) return unless subject.respond_to?(:any?) && subject.any? + subject.reject! do |element| if rule_class.respond_to?(:tagged_children_for) children = rule_class.tagged_children_for(element) @@ -26,6 +27,7 @@ module OpenFoodNetwork def rules return @rules unless @rules.nil? + @rules = rule_class.prioritised.for(enterprise) end @@ -45,11 +47,13 @@ module OpenFoodNetwork def customer_rules return @customer_matched_rules unless @customer_matched_rules.nil? + @customer_matched_rules = rules.select{ |rule| customer_tags_match?(rule) } end def default_rules return @default_rules unless @default_rules.nil? + @default_rules = rules.select(&:is_default?) end diff --git a/lib/open_food_network/users_and_enterprises_report.rb b/lib/open_food_network/users_and_enterprises_report.rb index c110453be2..15de41a883 100644 --- a/lib/open_food_network/users_and_enterprises_report.rb +++ b/lib/open_food_network/users_and_enterprises_report.rb @@ -24,6 +24,7 @@ module OpenFoodNetwork def table return [] unless @compile_table + users_and_enterprises.map do |uae| [ uae["user_email"], @@ -78,7 +79,8 @@ module OpenFoodNetwork created_at: x.created_at.utc.iso8601, relationship_type: relationship_type, user_email: x.user_email - }.stringify_keys } + }.stringify_keys + } end def users_and_enterprises @@ -102,8 +104,8 @@ module OpenFoodNetwork [(a["created_at"].nil? ? 0 : 1), a["name"], b["relationship_type"], a["user_email"]] <=> [(b["created_at"].nil? ? 0 : 1), b["name"], a["relationship_type"], b["user_email"]] else - [DateTime.parse(b["created_at"]), a["name"], b["relationship_type"], a["user_email"]] <=> - [DateTime.parse(a["created_at"]), b["name"], a["relationship_type"], b["user_email"]] + [DateTime.parse(b["created_at"]).in_time_zone, a["name"], b["relationship_type"], a["user_email"]] <=> + [DateTime.parse(a["created_at"]).in_time_zone, b["name"], a["relationship_type"], b["user_email"]] end end end @@ -114,6 +116,7 @@ module OpenFoodNetwork def to_local_datetime(date) return "" if date.nil? + date.to_datetime.in_time_zone.strftime "%Y-%m-%d %H:%M" end end diff --git a/lib/open_food_network/variant_and_line_item_naming.rb b/lib/open_food_network/variant_and_line_item_naming.rb index cf6778a3e9..a962dd6893 100644 --- a/lib/open_food_network/variant_and_line_item_naming.rb +++ b/lib/open_food_network/variant_and_line_item_naming.rb @@ -17,6 +17,7 @@ module OpenFoodNetwork def product_and_full_name return "#{product.name} - #{full_name}" unless full_name.start_with? product.name + full_name end @@ -30,16 +31,19 @@ module OpenFoodNetwork return unit_to_display if display_name.blank? return display_name if display_name.downcase.include? unit_to_display.downcase return unit_to_display if unit_to_display.downcase.include? display_name.downcase + "#{display_name} (#{unit_to_display})" end def name_to_display return product.name if display_name.blank? + display_name end def unit_to_display return options_text if !has_attribute?(:display_as) || display_as.blank? + display_as end diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb index 34d3c93fb9..3ccf7dd25f 100644 --- a/lib/open_food_network/xero_invoices_report.rb +++ b/lib/open_food_network/xero_invoices_report.rb @@ -29,6 +29,7 @@ module OpenFoodNetwork def table return [] unless @compile_table + rows = [] orders.each_with_index do |order, i| diff --git a/lib/spree/authentication_helpers.rb b/lib/spree/authentication_helpers.rb index 3754bb0e2a..49bd97542a 100644 --- a/lib/spree/authentication_helpers.rb +++ b/lib/spree/authentication_helpers.rb @@ -11,16 +11,10 @@ module Spree current_spree_user end - def spree_login_path - spree.login_path - end + delegate :login_path, to: :spree, prefix: true - def spree_signup_path - spree.signup_path - end + delegate :signup_path, to: :spree, prefix: true - def spree_logout_path - spree.logout_path - end + delegate :logout_path, to: :spree, prefix: true end end diff --git a/lib/spree/localized_number.rb b/lib/spree/localized_number.rb index e1f0e39072..4cf3786be0 100644 --- a/lib/spree/localized_number.rb +++ b/lib/spree/localized_number.rb @@ -31,6 +31,7 @@ module Spree define_method(:validate_localizable_number) do return unless Spree::Config.enable_localized_number? + @invalid_localized_number.andand.each do |error_attribute| errors.set(error_attribute, [I18n.t('spree.localized_number.invalid_format')]) end @@ -40,6 +41,7 @@ module Spree def self.valid_localizable_number?(number) return true unless number.is_a?(String) || number.respond_to?(:to_d) return false if number =~ /[\.,]\d{2}[\.,]/ + true end diff --git a/lib/stripe/webhook_handler.rb b/lib/stripe/webhook_handler.rb index 24121afe19..d7f49b186f 100644 --- a/lib/stripe/webhook_handler.rb +++ b/lib/stripe/webhook_handler.rb @@ -6,6 +6,7 @@ module Stripe def handle return :unknown unless known_event? + __send__(event_mappings[@event.type]) end @@ -23,6 +24,7 @@ module Stripe def deauthorize return :ignored unless @event.respond_to?(:account) + destroyed = destroy_stripe_accounts_linked_to(@event.account) destroyed.any? ? :success : :ignored end diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index d8224d05eb..33ac11f020 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -9,6 +9,7 @@ namespace :ofn do # Cycle through the incoming exchanges order_cycle.exchanges.incoming.each do |exchange| next if exchange.sender == exchange.receiver + # Ensure that an enterprise relationship from the producer to the coordinator exists relationship = EnterpriseRelationship.where(parent_id: exchange.sender_id, child_id: exchange.receiver_id).first if relationship.blank? @@ -43,6 +44,7 @@ namespace :ofn do producers = Enterprise.joins(:supplied_products).where("spree_products.id IN (?)", products).uniq producers.each do |producer| next if producer == exchange.receiver + # Ensure that an enterprise relationship from the producer to the hub exists relationship = EnterpriseRelationship.where(parent_id: producer.id, child_id: exchange.receiver_id).first if relationship.blank? diff --git a/lib/tasks/karma.rake b/lib/tasks/karma.rake index 4f57d21220..2755a3f6a8 100644 --- a/lib/tasks/karma.rake +++ b/lib/tasks/karma.rake @@ -34,6 +34,7 @@ namespace :karma do def i18n_file raise "I18n::JS module is missing" unless defined?(I18n::JS) + I18n::JS::DEFAULT_EXPORT_DIR_PATH.replace('tmp/javascripts') I18n::JS.export "#{Rails.root.join(I18n::JS::DEFAULT_EXPORT_DIR_PATH)}/translations.js" diff --git a/lib/tasks/sample_data/customer_factory.rb b/lib/tasks/sample_data/customer_factory.rb index 4c1904f2cd..9a49289e37 100644 --- a/lib/tasks/sample_data/customer_factory.rb +++ b/lib/tasks/sample_data/customer_factory.rb @@ -8,6 +8,7 @@ class CustomerFactory jane = users["Jane Customer"] maryse_shop = Enterprise.find_by_name("Maryse's Private Shop") return if Customer.where(user_id: jane, enterprise_id: maryse_shop).exists? + log "- #{jane.email}" Customer.create!( email: jane.email, diff --git a/lib/tasks/sample_data/fee_factory.rb b/lib/tasks/sample_data/fee_factory.rb index 72d062e852..8427290a85 100644 --- a/lib/tasks/sample_data/fee_factory.rb +++ b/lib/tasks/sample_data/fee_factory.rb @@ -7,6 +7,7 @@ class FeeFactory log "Creating fees:" enterprises.each do |enterprise| next if enterprise.enterprise_fees.present? + log "- #{enterprise.name} charges markup" calculator = Calculator::FlatPercentPerItem.new(preferred_flat_percent: 10) create_fee(enterprise, calculator) diff --git a/lib/tasks/sample_data/payment_method_factory.rb b/lib/tasks/sample_data/payment_method_factory.rb index 2b3899a662..27dc5404cf 100644 --- a/lib/tasks/sample_data/payment_method_factory.rb +++ b/lib/tasks/sample_data/payment_method_factory.rb @@ -17,6 +17,7 @@ class PaymentMethodFactory def create_payment_methods(enterprise) return if enterprise.payment_methods.present? + log "- #{enterprise.name}" create_cash_method(enterprise) create_card_method(enterprise) diff --git a/lib/tasks/sample_data/shipping_method_factory.rb b/lib/tasks/sample_data/shipping_method_factory.rb index 1e05109210..dfa3cd8556 100644 --- a/lib/tasks/sample_data/shipping_method_factory.rb +++ b/lib/tasks/sample_data/shipping_method_factory.rb @@ -17,6 +17,7 @@ class ShippingMethodFactory def create_shipping_methods(enterprise) return if enterprise.shipping_methods.present? + log "- #{enterprise.name}" create_pickup(enterprise) create_delivery(enterprise) diff --git a/lib/tasks/sample_data/taxon_factory.rb b/lib/tasks/sample_data/taxon_factory.rb index 912b426114..f6d4bf3945 100644 --- a/lib/tasks/sample_data/taxon_factory.rb +++ b/lib/tasks/sample_data/taxon_factory.rb @@ -16,6 +16,7 @@ class TaxonFactory def create_taxon(taxonomy, taxon_name) return if Spree::Taxon.where(name: taxon_name).exists? + log "- #{taxon_name}" Spree::Taxon.create!( name: taxon_name, diff --git a/spec/controllers/api/products_controller_spec.rb b/spec/controllers/api/products_controller_spec.rb index 0f2ef1a495..861c12eaea 100644 --- a/spec/controllers/api/products_controller_spec.rb +++ b/spec/controllers/api/products_controller_spec.rb @@ -248,12 +248,12 @@ describe Api::ProductsController, type: :controller do end it "filters results by supplier" do - api_get :bulk_products, { page: 1, per_page: 15, q: {supplier_id_eq: supplier.id} }, format: :json + api_get :bulk_products, { page: 1, per_page: 15, q: { supplier_id_eq: supplier.id } }, format: :json expect(returned_product_ids).to eq [product2.id, inactive_product.id, product.id] end it "filters results by product category" do - api_get :bulk_products, { page: 1, per_page: 15, q: {primary_taxon_id_eq: taxon.id} }, format: :json + api_get :bulk_products, { page: 1, per_page: 15, q: { primary_taxon_id_eq: taxon.id } }, format: :json expect(returned_product_ids).to eq [product3.id, product2.id] end diff --git a/spec/controllers/api/statuses_controller_spec.rb b/spec/controllers/api/statuses_controller_spec.rb index b0082ca696..ed3d779bf5 100644 --- a/spec/controllers/api/statuses_controller_spec.rb +++ b/spec/controllers/api/statuses_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe "job queue status" do it "returns alive when up to date" do - Spree::Config.last_job_queue_heartbeat_at = Time.now + Spree::Config.last_job_queue_heartbeat_at = Time.now.in_time_zone spree_get :job_queue expect(response).to be_success expect(response.body).to eq({ alive: true }.to_json) diff --git a/spec/controllers/api/taxons_controller_spec.rb b/spec/controllers/api/taxons_controller_spec.rb index 94b32ab6d7..7f04a42d31 100644 --- a/spec/controllers/api/taxons_controller_spec.rb +++ b/spec/controllers/api/taxons_controller_spec.rb @@ -113,5 +113,5 @@ describe Api::TaxonsController do expect(response.status).to eq(204) end - end + end end diff --git a/spec/controllers/api/variants_controller_spec.rb b/spec/controllers/api/variants_controller_spec.rb index 857254ca15..f0aa0d8da4 100644 --- a/spec/controllers/api/variants_controller_spec.rb +++ b/spec/controllers/api/variants_controller_spec.rb @@ -69,7 +69,7 @@ describe Api::VariantsController, type: :controller do api_get :show, id: variant.to_param keys = json_response.keys.map(&:to_sym) - expect((attributes).all?{ |attr| keys.include? attr }).to eq(true) + expect(attributes.all?{ |attr| keys.include? attr }).to eq(true) end it "cannot create a new variant if not an admin" do diff --git a/spec/controllers/spree/admin/image_settings_controller_spec.rb b/spec/controllers/spree/admin/image_settings_controller_spec.rb index 8582b19eeb..89ccac822c 100644 --- a/spec/controllers/spree/admin/image_settings_controller_spec.rb +++ b/spec/controllers/spree/admin/image_settings_controller_spec.rb @@ -38,10 +38,10 @@ describe Spree::Admin::ImageSettingsController do it "should be able to update s3 settings" do spree_put :update, preferences: { - "use_s3" => "1", + "use_s3" => "1", "s3_access_key" => "a_valid_key", - "s3_secret" => "a_secret", - "s3_bucket" => "some_bucket" + "s3_secret" => "a_secret", + "s3_bucket" => "some_bucket" } expect(Spree::Config[:use_s3]).to be_truthy expect(Spree::Config[:s3_access_key]).to eq("a_valid_key") diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 8c73e38a05..c018a98873 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -287,7 +287,8 @@ describe Spree::OrdersController, type: :controller do let(:params) { { order: { line_items_attributes: { "0" => { id: order.line_items.first.id, quantity: 2 } - } } } } + } } } + } before do allow(subject).to receive(:spree_current_user) { order.user } @@ -311,7 +312,8 @@ describe Spree::OrdersController, type: :controller do { order: { line_items_attributes: { "0" => { id: order.line_items.first.id, quantity: 1 }, "1" => { id: order.line_items.second.id, quantity: 0 } - } } } } + } } } + } before { allow(subject).to receive(:order_to_update) { order } } diff --git a/spec/factories/product_factory.rb b/spec/factories/product_factory.rb index 897d95d477..e546abbac4 100644 --- a/spec/factories/product_factory.rb +++ b/spec/factories/product_factory.rb @@ -32,6 +32,7 @@ FactoryBot.define do after(:create) do |product, proxy| raise "taxed_product factory requires a zone" unless proxy.zone + create(:tax_rate, amount: proxy.tax_rate_amount, tax_category: product.tax_category, included_in_price: true, diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index b378631702..906695dc44 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -516,7 +516,7 @@ feature ' it "shows an edit button for products, which takes the user to the standard edit page for that product in a new window" do expect(page).to have_selector "a.edit-product", count: 2 - new_window = window_opened_by do + new_window = window_opened_by do within "tr#p_#{p1.id}" do find("a.edit-product").click end @@ -534,7 +534,7 @@ feature ' expect(page).to have_selector "a.edit-variant", count: 2 - new_window = window_opened_by do + new_window = window_opened_by do within "tr#v_#{v1.id}" do find("a.edit-variant").click end diff --git a/spec/features/admin/image_settings_spec.rb b/spec/features/admin/image_settings_spec.rb index b7d23da422..9ef2860cd4 100644 --- a/spec/features/admin/image_settings_spec.rb +++ b/spec/features/admin/image_settings_spec.rb @@ -9,9 +9,9 @@ feature ' before(:all) do styles = { "mini" => "48x48>", - "small" => "100x100>", + "small" => "100x100>", "product" => "240x240>", - "large" => "600x600>" } + "large" => "600x600>" } Spree::Config[:attachment_styles] = ActiveSupport::JSON.encode(styles) Spree::Image.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index c555a684e7..3776079136 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -366,9 +366,7 @@ feature ' context "when an included variant has been deleted" do let!(:deleted_variant) do - order.line_items.first.variant.tap do |record| - record.delete - end + order.line_items.first.variant.tap(&:delete) end it "still lists the variant in the order page" do diff --git a/spec/features/admin/users_spec.rb b/spec/features/admin/users_spec.rb index 3e4ea4c609..b84196e8fe 100644 --- a/spec/features/admin/users_spec.rb +++ b/spec/features/admin/users_spec.rb @@ -12,8 +12,8 @@ feature "Managing users" do context "from the index page" do before do - create(:user, :email => "a@example.com") - create(:user, :email => "b@example.com") + create(:user, email: "a@example.com") + create(:user, email: "b@example.com") visit spree.admin_path click_link "Users" @@ -43,7 +43,7 @@ feature "Managing users" do context "searching users" do it "should display the correct results for a user search" do - fill_in "q_email_cont", :with => "a@example" + fill_in "q_email_cont", with: "a@example" click_button "Search" within("table#listing_users") do expect(page).to have_content("a@example") @@ -58,8 +58,8 @@ feature "Managing users" do end it "should allow editing the user password" do - fill_in "user_password", :with => "welcome" - fill_in "user_password_confirmation", :with => "welcome" + fill_in "user_password", with: "welcome" + fill_in "user_password_confirmation", with: "welcome" click_button "Update" expect(page).to have_content("Account updated") diff --git a/spec/jobs/heartbeat_job_spec.rb b/spec/jobs/heartbeat_job_spec.rb index 4744eaeb38..a21760d3c8 100644 --- a/spec/jobs/heartbeat_job_spec.rb +++ b/spec/jobs/heartbeat_job_spec.rb @@ -12,7 +12,7 @@ describe HeartbeatJob do it "updates the last_job_queue_heartbeat_at config var" do run_job - expect(Time.parse(Spree::Config.last_job_queue_heartbeat_at)).to eq(run_time) + expect(Time.parse(Spree::Config.last_job_queue_heartbeat_at).in_time_zone).to eq(run_time) end end diff --git a/spec/lib/open_food_network/products_and_inventory_report_spec.rb b/spec/lib/open_food_network/products_and_inventory_report_spec.rb index 7457e2ed0c..4c34fa204a 100644 --- a/spec/lib/open_food_network/products_and_inventory_report_spec.rb +++ b/spec/lib/open_food_network/products_and_inventory_report_spec.rb @@ -78,19 +78,19 @@ module OpenFoodNetwork describe "fetching child variants" do it "returns some variants" do product1 = create(:simple_product, supplier: supplier) - variant_1 = product1.variants.first - variant_2 = create(:variant, product: product1) + variant1 = product1.variants.first + variant2 = create(:variant, product: product1) - expect(subject.child_variants).to match_array [variant_1, variant_2] + expect(subject.child_variants).to match_array [variant1, variant2] end it "should only return variants managed by the user" do product1 = create(:simple_product, supplier: create(:supplier_enterprise)) product2 = create(:simple_product, supplier: supplier) - variant_1 = product1.variants.first - variant_2 = product2.variants.first + variant1 = product1.variants.first + variant2 = product2.variants.first - expect(subject.child_variants).to eq([variant_2]) + expect(subject.child_variants).to eq([variant2]) end end diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index 5e68289273..deb5230f81 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -11,7 +11,7 @@ describe Spree::OrderMailer do let(:ship_address) { create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234") } let(:order) { create(:order_with_line_items, distributor: distributor, bill_address: bill_address, ship_address: ship_address, - special_instructions: shipping_instructions) + special_instructions: shipping_instructions) } after do diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb index 9d28299827..1f5a6e21bf 100644 --- a/spec/mailers/subscription_mailer_spec.rb +++ b/spec/mailers/subscription_mailer_spec.rb @@ -61,16 +61,16 @@ describe SubscriptionMailer, type: :mailer do let(:customer) { create(:customer, enterprise: shop) } it "provides link to make changes" do - expect(body).to match /make changes<\/a>/ - expect(body).to_not match /view details of this order<\/a>/ + expect(body).to match %r{make changes} + expect(body).to_not match %r{view details of this order} end context "when the distributor does not allow changes to the order" do let(:shop) { create(:enterprise, allow_order_changes: false) } it "provides link to view details" do - expect(body).to_not match /make changes<\/a>/ - expect(body).to match /view details of this order<\/a>/ + expect(body).to_not match %r{make changes} + expect(body).to match %r{view details of this order} end end end diff --git a/spec/models/column_preference_spec.rb b/spec/models/column_preference_spec.rb index 264bc3af93..94c5c1810c 100644 --- a/spec/models/column_preference_spec.rb +++ b/spec/models/column_preference_spec.rb @@ -12,10 +12,11 @@ describe ColumnPreference, type: :model do let!(:col2_pref) { ColumnPreference.create(user_id: user.id, action_name: 'some_action', column_name: 'col2', visible: false) } let(:defaults) { { - col1: { name: "col1", visible: false }, - col2: { name: "col2", visible: true }, - col3: { name: "col3", visible: false }, - } } + col1: { name: "col1", visible: false }, + col2: { name: "col2", visible: true }, + col3: { name: "col3", visible: false }, + } + } context "when the user has preferences stored for the given action" do before do diff --git a/spec/models/content_configuration_spec.rb b/spec/models/content_configuration_spec.rb index 3de4fdfdfe..7ac8877b83 100644 --- a/spec/models/content_configuration_spec.rb +++ b/spec/models/content_configuration_spec.rb @@ -10,7 +10,7 @@ describe ContentConfiguration do end def image_exist?(default_url) - image_path = default_url.gsub(/\/assets\//, '/assets/images/') + image_path = default_url.gsub(%r{/assets/}, '/assets/images/') File.exist?(File.join(Rails.root, 'app', image_path)) end end diff --git a/spec/models/enterprise_relationship_spec.rb b/spec/models/enterprise_relationship_spec.rb index d014ba963e..6a7560d09e 100644 --- a/spec/models/enterprise_relationship_spec.rb +++ b/spec/models/enterprise_relationship_spec.rb @@ -190,9 +190,9 @@ describe EnterpriseRelationship do context "when variant_override permission is not present" do let!(:er) { create(:enterprise_relationship, child: hub, parent: producer, permissions_list: [:add_to_order_cycles] ) } let!(:some_other_er) { create(:enterprise_relationship, child: hub, parent: some_other_producer, permissions_list: [:add_to_order_cycles] ) } - let!(:vo1) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now) } - let!(:vo2) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now) } - let!(:vo3) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: some_other_producer)), permission_revoked_at: Time.now) } + let!(:vo1) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now.in_time_zone) } + let!(:vo2) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now.in_time_zone) } + let!(:vo3) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: some_other_producer)), permission_revoked_at: Time.now.in_time_zone) } context "and is then added" do before { er.permissions_list = [:add_to_order_cycles, :create_variant_overrides]; er.save! } diff --git a/spec/serializers/api/admin/subscription_line_item_serializer_spec.rb b/spec/serializers/api/admin/subscription_line_item_serializer_spec.rb index 5542c5d482..198f67ead3 100644 --- a/spec/serializers/api/admin/subscription_line_item_serializer_spec.rb +++ b/spec/serializers/api/admin/subscription_line_item_serializer_spec.rb @@ -4,7 +4,7 @@ module Api module Admin describe SubscriptionLineItemSerializer do let(:subscription_line_item) { create(:subscription_line_item) } - + it "serializes a subscription line item with the product name" do serializer = described_class.new(subscription_line_item) diff --git a/spec/serializers/api/admin/variant_serializer_spec.rb b/spec/serializers/api/admin/variant_serializer_spec.rb index d6eec1c1c5..61c8b84f4d 100644 --- a/spec/serializers/api/admin/variant_serializer_spec.rb +++ b/spec/serializers/api/admin/variant_serializer_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Api::Admin::VariantSerializer do - let(:variant) { create(:variant) } it "serializes the variant name" do diff --git a/spec/serializers/api/product_serializer_spec.rb b/spec/serializers/api/product_serializer_spec.rb index 083b534ec8..4a39eafe43 100644 --- a/spec/serializers/api/product_serializer_spec.rb +++ b/spec/serializers/api/product_serializer_spec.rb @@ -33,7 +33,7 @@ describe Api::ProductSerializer do end it "serializes product properties" do - product_property = {id: property.id, name: property.presentation, value: nil} + product_property = { id: property.id, name: property.presentation, value: nil } expect(serializer.serializable_hash[:properties_with_values]).to include product_property end diff --git a/spec/services/embedded_page_service_spec.rb b/spec/services/embedded_page_service_spec.rb index ecaf79f05c..0a688e5372 100644 --- a/spec/services/embedded_page_service_spec.rb +++ b/spec/services/embedded_page_service_spec.rb @@ -61,7 +61,7 @@ describe EmbeddedPageService do end context "when the request's referer is malformed" do - let(:request) { ActionController::TestRequest.new('HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello')} + let(:request) { ActionController::TestRequest.new('HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello') } before do service.embed! end diff --git a/spec/services/order_syncer_spec.rb b/spec/services/order_syncer_spec.rb index abb6ee58c5..49622dfc68 100644 --- a/spec/services/order_syncer_spec.rb +++ b/spec/services/order_syncer_spec.rb @@ -525,7 +525,7 @@ describe OrderSyncer do expect(line_items.map(&:quantity)).to eq [] subscription.save # this is necessary to get an id on the subscription_line_items - params = { subscription_line_items_attributes: [{ id: subscription.subscription_line_items.last.id, quantity: 2 }] } + params = { subscription_line_items_attributes: [{ id: subscription.subscription_line_items.last.id, quantity: 2 }] } subscription.assign_attributes(params) expect(syncer.sync!).to be true diff --git a/spec/services/product_tag_rules_filterer_spec.rb b/spec/services/product_tag_rules_filterer_spec.rb index 458ca55820..7d3f0ac2b1 100644 --- a/spec/services/product_tag_rules_filterer_spec.rb +++ b/spec/services/product_tag_rules_filterer_spec.rb @@ -82,7 +82,6 @@ describe ProductTagRulesFilterer do expect(overrides_to_hide).to include variant_hidden_by_default.id, variant_hidden_by_rule.id end end - end describe "#overrides_to_show" do diff --git a/spec/services/subscription_form_spec.rb b/spec/services/subscription_form_spec.rb index ebd66f55b3..9a06ef7164 100644 --- a/spec/services/subscription_form_spec.rb +++ b/spec/services/subscription_form_spec.rb @@ -41,7 +41,8 @@ describe SubscriptionForm do { variant_id: variant2.id, quantity: 2, price_estimate: 8.0 }, { variant_id: variant3.id, quantity: 3, price_estimate: 9.0 } ] - } } + } + } let(:form) { SubscriptionForm.new(subscription, params) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 71be37ba93..983a80d9e6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,10 +28,10 @@ require 'webdrivers' # when connecting to external sites require 'webmock/rspec' WebMock.enable! -WebMock.disable_net_connect!({ +WebMock.disable_net_connect!( allow_localhost: true, allow: 'chromedriver.storage.googleapis.com' -}) +) # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index 803e70a832..b03f7d9d39 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -143,6 +143,7 @@ module WebHelper def select_select2_result_async(value) while page.has_selector? "div.select2-searching" return if page.has_selector? "div.select2-no-results" + sleep 0.2 end page.execute_script(%{$("div.select2-result-label:contains('#{value}')").mouseup()}) From 71ea281424b56cf236529fc7a5ab9ed92904b676 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 10 Nov 2019 18:54:45 +0000 Subject: [PATCH 2/6] Regenerate rubocop todo files after last large fix of issues --- .rubocop_manual_todo.yml | 185 +++++++------------ .rubocop_todo.yml | 372 +-------------------------------------- 2 files changed, 70 insertions(+), 487 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index c0e1d0427e..3264b8a389 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -25,11 +25,11 @@ Metrics/LineLength: - app/controllers/admin/bulk_line_items_controller.rb - app/controllers/admin/contents_controller.rb - app/controllers/admin/customers_controller.rb - - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/enterprise_fees_controller.rb - app/controllers/admin/enterprise_groups_controller.rb - app/controllers/admin/enterprise_relationships_controller.rb - app/controllers/admin/enterprise_roles_controller.rb + - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/inventory_items_controller.rb - app/controllers/admin/manager_invitations_controller.rb - app/controllers/admin/order_cycles_controller.rb @@ -39,7 +39,6 @@ Metrics/LineLength: - app/controllers/admin/subscriptions_controller.rb - app/controllers/admin/variant_overrides_controller.rb - app/controllers/api/enterprise_attachment_controller.rb - - app/controllers/api/order_cycles_controller.rb - app/controllers/api/product_images_controller.rb - app/controllers/application_controller.rb - app/controllers/checkout_controller.rb @@ -48,9 +47,7 @@ Metrics/LineLength: - app/controllers/spree/admin/orders_controller_decorator.rb - app/controllers/spree/admin/payments_controller_decorator.rb - app/controllers/spree/admin/reports_controller_decorator.rb - - app/controllers/spree/api/products_controller_decorator.rb - app/controllers/spree/credit_cards_controller.rb - - app/controllers/spree/orders_controller_decorator.rb - app/controllers/spree/paypal_controller_decorator.rb - app/controllers/stripe/callbacks_controller.rb - app/helpers/admin/injection_helper.rb @@ -87,7 +84,6 @@ Metrics/LineLength: - app/models/proxy_order.rb - app/models/schedule.rb - app/models/spree/ability_decorator.rb - - app/models/spree/adjustment_decorator.rb - app/models/spree/app_configuration_decorator.rb - app/models/spree/calculator/default_tax_decorator.rb - app/models/spree/classification_decorator.rb @@ -98,16 +94,14 @@ Metrics/LineLength: - app/models/spree/payment_decorator.rb - app/models/spree/payment_method_decorator.rb - app/models/spree/product_decorator.rb - - app/models/spree/shipment_decorator.rb - app/models/spree/shipping_method_decorator.rb - app/models/spree/tax_rate_decorator.rb - app/models/spree/taxon_decorator.rb - - app/models/spree/user_decorator.rb + - app/models/spree/user.rb - app/models/spree/variant_decorator.rb - app/models/subscription.rb - app/models/variant_override.rb - app/models/variant_override_set.rb - - app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb - app/services/cart_service.rb - app/services/default_stock_location.rb - app/services/embedded_page_service.rb @@ -115,11 +109,6 @@ Metrics/LineLength: - app/services/order_factory.rb - app/services/subscriptions_count.rb - app/services/variants_stock_levels.rb - - app/views/json/_groups.rabl - - app/views/json/_producer.rabl - - app/views/json/partials/_enterprise.rabl - - app/views/spree/api/products/bulk_show.v1.rabl - - app/views/spree/api/variants/bulk_show.v1.rabl - engines/web/app/helpers/web/cookies_policy_helper.rb - lib/discourse/single_sign_on.rb - lib/open_food_network/available_payment_method_filter.rb @@ -133,10 +122,7 @@ Metrics/LineLength: - lib/open_food_network/order_and_distributor_report.rb - lib/open_food_network/order_cycle_form_applicator.rb - lib/open_food_network/order_cycle_management_report.rb - - lib/open_food_network/order_grouper.rb - lib/open_food_network/payments_report.rb - - lib/open_food_network/permalink_generator.rb - - lib/open_food_network/products_cache.rb - lib/open_food_network/reports/bulk_coop_allocation_report.rb - lib/open_food_network/reports/line_items.rb - lib/open_food_network/sales_tax_report.rb @@ -147,7 +133,6 @@ Metrics/LineLength: - lib/spree/localized_number.rb - lib/spree/product_filters.rb - lib/stripe/profile_storer.rb - - lib/tasks/cache.rake - lib/tasks/data.rake - lib/tasks/enterprises.rake - spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -164,11 +149,15 @@ Metrics/LineLength: - spec/controllers/admin/subscription_line_items_controller_spec.rb - spec/controllers/admin/subscriptions_controller_spec.rb - spec/controllers/admin/variant_overrides_controller_spec.rb + - spec/controllers/api/base_controller_spec.rb - spec/controllers/api/logos_controller_spec.rb - spec/controllers/api/order_cycles_controller_spec.rb - spec/controllers/api/orders_controller_spec.rb - spec/controllers/api/product_images_controller_spec.rb + - spec/controllers/api/products_controller_spec.rb - spec/controllers/api/promo_images_controller_spec.rb + - spec/controllers/api/shipments_controller_spec.rb + - spec/controllers/api/variants_controller_spec.rb - spec/controllers/cart_controller_spec.rb - spec/controllers/checkout_controller_spec.rb - spec/controllers/enterprises_controller_spec.rb @@ -181,12 +170,9 @@ Metrics/LineLength: - spec/controllers/spree/admin/orders_controller_spec.rb - spec/controllers/spree/admin/payment_methods_controller_spec.rb - spec/controllers/spree/admin/payments_controller_spec.rb + - spec/controllers/spree/admin/products_controller_spec.rb - spec/controllers/spree/admin/reports_controller_spec.rb - spec/controllers/spree/admin/variants_controller_spec.rb - - spec/controllers/spree/api/line_items_controller_spec.rb - - spec/controllers/spree/api/products_controller_spec.rb - - spec/controllers/spree/api/shipments_controller_spec.rb - - spec/controllers/spree/api/variants_controller_spec.rb - spec/controllers/spree/credit_cards_controller_spec.rb - spec/controllers/spree/orders_controller_spec.rb - spec/controllers/spree/user_sessions_controller_spec.rb @@ -194,7 +180,6 @@ Metrics/LineLength: - spec/controllers/stripe/callbacks_controller_spec.rb - spec/controllers/stripe/webhooks_controller_spec.rb - spec/controllers/user_confirmations_controller_spec.rb - - spec/controllers/user_registrations_controller_spec.rb - spec/features/admin/adjustments_spec.rb - spec/features/admin/bulk_order_management_spec.rb - spec/features/admin/bulk_product_update_spec.rb @@ -219,6 +204,7 @@ Metrics/LineLength: - spec/features/admin/shipping_methods_spec.rb - spec/features/admin/subscriptions_spec.rb - spec/features/admin/tag_rules_spec.rb + - spec/features/admin/users_spec.rb - spec/features/admin/variant_overrides_spec.rb - spec/features/consumer/account/cards_spec.rb - spec/features/consumer/account/settings_spec.rb @@ -253,7 +239,6 @@ Metrics/LineLength: - spec/lib/open_food_network/customers_report_spec.rb - spec/lib/open_food_network/enterprise_fee_applicator_spec.rb - spec/lib/open_food_network/enterprise_fee_calculator_spec.rb - - spec/lib/open_food_network/enterprise_injection_data_spec.rb - spec/lib/open_food_network/group_buy_report_spec.rb - spec/lib/open_food_network/lettuce_share_report_spec.rb - spec/lib/open_food_network/option_value_namer_spec.rb @@ -265,7 +250,6 @@ Metrics/LineLength: - spec/lib/open_food_network/packing_report_spec.rb - spec/lib/open_food_network/permissions_spec.rb - spec/lib/open_food_network/products_and_inventory_report_spec.rb - - spec/lib/open_food_network/products_cache_spec.rb - spec/lib/open_food_network/proxy_order_syncer_spec.rb - spec/lib/open_food_network/scope_variant_to_hub_spec.rb - spec/lib/open_food_network/subscription_payment_updater_spec.rb @@ -278,6 +262,7 @@ Metrics/LineLength: - spec/mailers/order_mailer_spec.rb - spec/mailers/producer_mailer_spec.rb - spec/mailers/subscription_mailer_spec.rb + - spec/models/calculator/weight_spec.rb - spec/models/column_preference_spec.rb - spec/models/concerns/order_shipment_spec.rb - spec/models/concerns/product_stock_spec.rb @@ -299,11 +284,11 @@ Metrics/LineLength: - spec/models/spree/calculator/price_sack_spec.rb - spec/models/spree/classification_spec.rb - spec/models/spree/gateway/stripe_connect_spec.rb - - spec/models/spree/image_spec.rb - spec/models/spree/line_item_spec.rb - spec/models/spree/order_spec.rb - spec/models/spree/payment_method_spec.rb - spec/models/spree/payment_spec.rb + - spec/models/spree/product_set_spec.rb - spec/models/spree/product_spec.rb - spec/models/spree/property_spec.rb - spec/models/spree/shipping_method_spec.rb @@ -322,22 +307,24 @@ Metrics/LineLength: - spec/performance/shop_controller_spec.rb - spec/requests/checkout/failed_checkout_spec.rb - spec/requests/embedded_shopfronts_headers_spec.rb - - spec/requests/shop_spec.rb - - spec/serializers/admin/customer_serializer_spec.rb - - spec/serializers/admin/exchange_serializer_spec.rb - - spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb - - spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb - - spec/serializers/admin/subscription_customer_serializer_spec.rb - - spec/serializers/admin/variant_override_serializer_spec.rb + - spec/serializers/api/admin/customer_serializer_spec.rb + - spec/serializers/api/admin/exchange_serializer_spec.rb + - spec/serializers/api/admin/for_order_cycle/enterprise_serializer_spec.rb + - spec/serializers/api/admin/for_order_cycle/supplied_product_serializer_spec.rb + - spec/serializers/api/admin/subscription_customer_serializer_spec.rb + - spec/serializers/api/admin/variant_override_serializer_spec.rb + - spec/serializers/api/current_order_serializer_spec.rb - spec/serializers/api/enterprise_shopfront_serializer_spec.rb - - spec/serializers/current_order_serializer_spec.rb - - spec/serializers/order_serializer_spec.rb + - spec/serializers/api/order_serializer_spec.rb - spec/services/cart_service_spec.rb - spec/services/embedded_page_service_spec.rb + - spec/services/order_cycle_distributed_products_spec.rb - spec/services/order_cycle_distributed_variants_spec.rb - spec/services/order_cycle_form_spec.rb - spec/services/order_factory_spec.rb - spec/services/order_syncer_spec.rb + - spec/services/product_tag_rules_filterer_spec.rb + - spec/services/products_renderer_spec.rb - spec/services/subscription_estimator_spec.rb - spec/services/subscription_form_spec.rb - spec/services/subscription_validator_spec.rb @@ -352,35 +339,14 @@ Metrics/LineLength: - spec/support/request/shop_workflow.rb - spec/support/request/web_helper.rb - spec/support/seeds.rb - - app/models/spree/user.rb - - spec/controllers/api/base_controller_spec.rb - - spec/controllers/api/products_controller_spec.rb - - spec/controllers/api/shipments_controller_spec.rb - - spec/controllers/api/variants_controller_spec.rb - - spec/controllers/spree/admin/products_controller_spec.rb - - spec/features/admin/users_spec.rb - - spec/lib/open_food_network/order_cycle_management_report_spec.rb - - spec/models/calculator/weight_spec.rb - - spec/models/spree/product_set_spec.rb - - spec/serializers/api/admin/customer_serializer_spec.rb - - spec/serializers/api/admin/exchange_serializer_spec.rb - - spec/serializers/api/admin/for_order_cycle/enterprise_serializer_spec.rb - - spec/serializers/api/admin/for_order_cycle/supplied_product_serializer_spec.rb - - spec/serializers/api/admin/subscription_customer_serializer_spec.rb - - spec/serializers/api/admin/variant_override_serializer_spec.rb - - spec/serializers/api/current_order_serializer_spec.rb - - spec/serializers/api/order_serializer_spec.rb - - spec/services/order_cycle_distributed_products_spec.rb - - spec/services/products_renderer_spec.rb - - spec/services/product_tag_rules_filterer_spec.rb Metrics/AbcSize: Max: 15 Exclude: - app/controllers/admin/bulk_line_items_controller.rb - app/controllers/admin/customers_controller.rb - - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/enterprise_fees_controller.rb + - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/order_cycles_controller.rb - app/controllers/admin/product_import_controller.rb - app/controllers/admin/schedules_controller.rb @@ -388,14 +354,18 @@ Metrics/AbcSize: - app/controllers/admin/subscription_line_items_controller.rb - app/controllers/admin/subscriptions_controller.rb - app/controllers/api/enterprises_controller.rb - - app/controllers/api/order_cycles_controller.rb - app/controllers/api/product_images_controller.rb + - app/controllers/api/products_controller.rb + - app/controllers/api/shipments_controller.rb + - app/controllers/api/taxons_controller.rb + - app/controllers/api/variants_controller.rb - app/controllers/base_controller.rb - app/controllers/cart_controller.rb - app/controllers/checkout_controller.rb - app/controllers/discourse_sso_controller.rb - app/controllers/enterprises_controller.rb - app/controllers/spree/admin/adjustments_controller_decorator.rb + - app/controllers/spree/admin/image_settings_controller.rb - app/controllers/spree/admin/orders/customer_details_controller_decorator.rb - app/controllers/spree/admin/orders_controller_decorator.rb - app/controllers/spree/admin/overview_controller_decorator.rb @@ -404,12 +374,16 @@ Metrics/AbcSize: - app/controllers/spree/admin/products_controller_decorator.rb - app/controllers/spree/admin/reports_controller_decorator.rb - app/controllers/spree/admin/search_controller_decorator.rb + - app/controllers/spree/admin/taxons_controller.rb + - app/controllers/spree/admin/users_controller.rb - app/controllers/spree/admin/variants_controller_decorator.rb - - app/controllers/spree/api/products_controller_decorator.rb - - app/controllers/spree/api/shipments_controller_decorator.rb + - app/controllers/spree/checkout_controller.rb - app/controllers/spree/credit_cards_controller.rb - - app/controllers/spree/orders_controller_decorator.rb - - app/controllers/spree/user_sessions_controller_decorator.rb + - app/controllers/spree/orders_controller.rb + - app/controllers/spree/user_passwords_controller.rb + - app/controllers/spree/user_registrations_controller.rb + - app/controllers/spree/user_sessions_controller.rb + - app/controllers/spree/users_controller.rb - app/controllers/stripe/callbacks_controller.rb - app/controllers/user_confirmations_controller.rb - app/controllers/user_passwords_controller.rb @@ -417,6 +391,7 @@ Metrics/AbcSize: - app/helpers/checkout_helper.rb - app/helpers/i18n_helper.rb - app/helpers/order_cycles_helper.rb + - app/helpers/spree/admin/navigation_helper_decorator.rb - app/helpers/spree/orders_helper.rb - app/jobs/subscription_placement_job.rb - app/mailers/producer_mailer.rb @@ -438,6 +413,7 @@ Metrics/AbcSize: - app/models/spree/product_decorator.rb - app/models/spree/taxon_decorator.rb - app/serializers/api/admin/enterprise_serializer.rb + - app/serializers/api/admin/order_cycle_serializer.rb - app/serializers/api/product_serializer.rb - app/serializers/api/variant_serializer.rb - app/services/cart_service.rb @@ -464,38 +440,21 @@ Metrics/AbcSize: - lib/open_food_network/users_and_enterprises_report.rb - lib/open_food_network/variant_and_line_item_naming.rb - lib/open_food_network/xero_invoices_report.rb + - lib/spree/api/controller_setup.rb - lib/spree/core/controller_helpers/respond_with_decorator.rb - lib/spree/localized_number.rb - lib/stripe/account_connector.rb - lib/tasks/enterprises.rake - lib/tasks/sample_data/product_factory.rb - - spec/controllers/spree/api/shipments_controller_spec.rb - spec/features/admin/product_import_spec.rb - spec/features/admin/reports_spec.rb - spec/features/admin/subscriptions_spec.rb - - spec/features/consumer/shopping/checkout_spec.rb + - spec/features/consumer/shopping/checkout_paypal_spec.rb - spec/features/consumer/shopping/variant_overrides_spec.rb - spec/models/enterprise_spec.rb - spec/models/product_importer_spec.rb - - spec/support/performance_helper.rb - - app/controllers/api/products_controller.rb - - app/controllers/api/shipments_controller.rb - - app/controllers/api/taxons_controller.rb - - app/controllers/api/variants_controller.rb - - app/controllers/spree/admin/image_settings_controller.rb - - app/controllers/spree/admin/taxons_controller.rb - - app/controllers/spree/admin/users_controller.rb - - app/controllers/spree/checkout_controller.rb - - app/controllers/spree/orders_controller.rb - - app/controllers/spree/user_passwords_controller.rb - - app/controllers/spree/user_registrations_controller.rb - - app/controllers/spree/users_controller.rb - - app/controllers/spree/user_sessions_controller.rb - - lib/spree/api/controller_setup.rb - - spec/features/consumer/shopping/checkout_paypal_spec.rb - spec/services/restart_checkout_spec.rb - - app/helpers/spree/admin/navigation_helper_decorator.rb - - app/serializers/api/admin/order_cycle_serializer.rb + - spec/support/performance_helper.rb Metrics/BlockLength: Max: 25 @@ -514,16 +473,15 @@ Metrics/BlockLength: ] Exclude: - lib/tasks/data.rake - - lib/tasks/dev.rake - spec/controllers/spree/admin/invoices_controller_spec.rb - spec/factories.rb - spec/factories/enterprise_factory.rb - spec/factories/order_cycle_factory.rb - - spec/factories/shipping_method_factory.rb - spec/factories/order_factory.rb + - spec/factories/product_factory.rb + - spec/factories/shipping_method_factory.rb - spec/factories/subscription_factory.rb - spec/factories/variant_factory.rb - - spec/factories/product_factory.rb - spec/features/admin/orders_spec.rb - spec/features/consumer/shopping/embedded_shopfronts_spec.rb - spec/lib/open_food_network/group_buy_report_spec.rb @@ -536,11 +494,12 @@ Metrics/BlockLength: Metrics/CyclomaticComplexity: Max: 6 Exclude: - - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/enterprise_fees_controller.rb + - app/controllers/admin/enterprises_controller.rb - app/controllers/checkout_controller.rb - app/controllers/spree/admin/payments_controller_decorator.rb - - app/controllers/spree/orders_controller_decorator.rb + - app/controllers/spree/admin/taxons_controller.rb + - app/controllers/spree/orders_controller.rb - app/helpers/checkout_helper.rb - app/helpers/i18n_helper.rb - app/helpers/order_cycles_helper.rb @@ -561,16 +520,16 @@ Metrics/CyclomaticComplexity: - lib/spree/core/controller_helpers/respond_with_decorator.rb - lib/spree/localized_number.rb - spec/models/product_importer_spec.rb - - app/controllers/spree/admin/taxons_controller.rb - - app/controllers/spree/orders_controller.rb Metrics/PerceivedComplexity: Max: 7 Exclude: - app/controllers/admin/enterprises_controller.rb + - app/controllers/api/variants_controller.rb - app/controllers/checkout_controller.rb - app/controllers/spree/admin/payments_controller_decorator.rb - - app/controllers/spree/orders_controller_decorator.rb + - app/controllers/spree/admin/taxons_controller.rb + - app/controllers/spree/orders_controller.rb - app/helpers/checkout_helper.rb - app/helpers/i18n_helper.rb - app/helpers/order_cycles_helper.rb @@ -587,33 +546,39 @@ Metrics/PerceivedComplexity: - lib/spree/core/controller_helpers/respond_with_decorator.rb - lib/spree/localized_number.rb - spec/models/product_importer_spec.rb - - app/controllers/api/variants_controller.rb - - app/controllers/spree/admin/taxons_controller.rb - - app/controllers/spree/orders_controller.rb Metrics/MethodLength: Max: 10 Exclude: - app/controllers/admin/customers_controller.rb - - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/enterprise_fees_controller.rb + - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/manager_invitations_controller.rb - app/controllers/admin/order_cycles_controller.rb - app/controllers/admin/stripe_accounts_controller.rb - app/controllers/admin/subscriptions_controller.rb + - app/controllers/api/products_controller.rb + - app/controllers/api/shipments_controller.rb + - app/controllers/api/taxons_controller.rb + - app/controllers/api/variants_controller.rb - app/controllers/base_controller.rb - app/controllers/cart_controller.rb - app/controllers/checkout_controller.rb - app/controllers/shop_controller.rb + - app/controllers/spree/admin/image_settings_controller.rb - app/controllers/spree/admin/orders/customer_details_controller_decorator.rb - app/controllers/spree/admin/payment_methods_controller.rb - app/controllers/spree/admin/payments_controller_decorator.rb - app/controllers/spree/admin/products_controller_decorator.rb - app/controllers/spree/admin/reports_controller_decorator.rb - app/controllers/spree/admin/search_controller_decorator.rb + - app/controllers/spree/admin/tax_categories_controller.rb + - app/controllers/spree/admin/taxons_controller.rb + - app/controllers/spree/admin/users_controller.rb - app/controllers/spree/credit_cards_controller.rb - - app/controllers/spree/orders_controller_decorator.rb - - app/controllers/spree/user_sessions_controller_decorator.rb + - app/controllers/spree/orders_controller.rb + - app/controllers/spree/user_registrations_controller.rb + - app/controllers/spree/user_sessions_controller.rb - app/controllers/stripe/callbacks_controller.rb - app/controllers/user_confirmations_controller.rb - app/controllers/user_passwords_controller.rb @@ -666,27 +631,15 @@ Metrics/MethodLength: - lib/open_food_network/sales_tax_report.rb - lib/open_food_network/users_and_enterprises_report.rb - lib/open_food_network/xero_invoices_report.rb + - lib/spree/api/controller_setup.rb - lib/spree/core/controller_helpers/respond_with_decorator.rb - lib/spree/localized_number.rb - lib/stripe/profile_storer.rb - lib/tasks/sample_data/product_factory.rb - - spec/features/consumer/shopping/checkout_spec.rb + - spec/features/consumer/shopping/checkout_paypal_spec.rb - spec/features/consumer/shopping/variant_overrides_spec.rb - spec/models/product_importer_spec.rb - spec/support/request/authentication_workflow.rb - - app/controllers/api/products_controller.rb - - app/controllers/api/shipments_controller.rb - - app/controllers/api/taxons_controller.rb - - app/controllers/api/variants_controller.rb - - app/controllers/spree/admin/image_settings_controller.rb - - app/controllers/spree/admin/tax_categories_controller.rb - - app/controllers/spree/admin/taxons_controller.rb - - app/controllers/spree/admin/users_controller.rb - - app/controllers/spree/orders_controller.rb - - app/controllers/spree/user_registrations_controller.rb - - app/controllers/spree/user_sessions_controller.rb - - lib/spree/api/controller_setup.rb - - spec/features/consumer/shopping/checkout_paypal_spec.rb Metrics/ClassLength: Max: 100 @@ -694,14 +647,18 @@ Metrics/ClassLength: - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/order_cycles_controller.rb - app/controllers/admin/subscriptions_controller.rb + - app/controllers/api/products_controller.rb - app/controllers/checkout_controller.rb - app/controllers/spree/admin/payment_methods_controller.rb + - app/controllers/spree/admin/users_controller.rb + - app/controllers/spree/orders_controller.rb - app/models/enterprise.rb - app/models/order_cycle.rb - app/models/product_import/entry_processor.rb - app/models/product_import/entry_validator.rb - app/models/product_import/product_importer.rb - app/models/spree/ability_decorator.rb + - app/models/spree/user.rb - app/serializers/api/cached_enterprise_serializer.rb - app/serializers/api/enterprise_shopfront_serializer.rb - app/services/cart_service.rb @@ -714,23 +671,18 @@ Metrics/ClassLength: - lib/open_food_network/packing_report.rb - lib/open_food_network/payments_report.rb - lib/open_food_network/permissions.rb - - lib/open_food_network/products_cache.rb - lib/open_food_network/xero_invoices_report.rb - - app/controllers/api/products_controller.rb - - app/controllers/spree/admin/users_controller.rb - - app/controllers/spree/orders_controller.rb - - app/models/spree/user.rb Metrics/ModuleLength: Max: 100 Exclude: + - app/helpers/injection_helper.rb - lib/open_food_network/column_preference_defaults.rb - spec/controllers/admin/enterprises_controller_spec.rb - spec/controllers/admin/order_cycles_controller_spec.rb - spec/controllers/api/order_cycles_controller_spec.rb - spec/controllers/api/orders_controller_spec.rb - spec/controllers/spree/admin/payment_methods_controller_spec.rb - - spec/controllers/spree/api/products_controller_spec.rb - spec/lib/open_food_network/address_finder_spec.rb - spec/lib/open_food_network/customers_report_spec.rb - spec/lib/open_food_network/enterprise_fee_calculator_spec.rb @@ -740,7 +692,6 @@ Metrics/ModuleLength: - spec/lib/open_food_network/order_grouper_spec.rb - spec/lib/open_food_network/permissions_spec.rb - spec/lib/open_food_network/products_and_inventory_report_spec.rb - - spec/lib/open_food_network/products_cache_spec.rb - spec/lib/open_food_network/proxy_order_syncer_spec.rb - spec/lib/open_food_network/scope_variant_to_hub_spec.rb - spec/lib/open_food_network/subscription_payment_updater_spec.rb @@ -753,13 +704,11 @@ Metrics/ModuleLength: - spec/models/spree/product_spec.rb - spec/models/spree/variant_spec.rb - spec/support/request/web_helper.rb - - app/helpers/injection_helper.rb Metrics/ParameterLists: Max: 5 Exclude: - app/helpers/angular_form_builder.rb - app/models/product_import/entry_processor.rb - - app/models/product_import/entry_validator.rb - lib/open_food_network/xero_invoices_report.rb - spec/features/admin/reports_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ce6748f0a5..1e83f1c304 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,253 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 1400` -# on 2019-11-08 17:02:54 +0000 using RuboCop version 0.68.1. +# on 2019-11-10 18:40:51 +0000 using RuboCop version 0.68.1. # 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 # versions of RuboCop, may require this file to be generated again. -# Offense count: 81 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/AlignHash: - Exclude: - - 'app/helpers/admin/injection_helper.rb' - - 'app/models/enterprise.rb' - - 'app/models/enterprise_group.rb' - - 'lib/open_food_network/address_finder.rb' - - 'lib/open_food_network/column_preference_defaults.rb' - - 'spec/controllers/spree/admin/image_settings_controller_spec.rb' - - 'spec/features/admin/image_settings_spec.rb' - - 'spec/mailers/order_mailer_spec.rb' - - 'spec/models/column_preference_spec.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -Layout/BlockEndNewline: - Exclude: - - 'lib/open_food_network/users_and_enterprises_report.rb' - - 'spec/controllers/spree/orders_controller_spec.rb' - - 'spec/models/column_preference_spec.rb' - - 'spec/services/subscription_form_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. -# SupportedStylesAlignWith: start_of_line, def -Layout/DefEndAlignment: - Exclude: - - 'app/models/order_updater.rb' - -# Offense count: 234 -# Cop supports --auto-correct. -Layout/EmptyLineAfterGuardClause: - Exclude: - - 'app/controllers/admin/customers_controller.rb' - - 'app/controllers/admin/order_cycles_controller.rb' - - 'app/controllers/admin/product_import_controller.rb' - - 'app/controllers/admin/schedules_controller.rb' - - 'app/controllers/admin/stripe_accounts_controller.rb' - - 'app/controllers/admin/stripe_connect_settings_controller.rb' - - 'app/controllers/admin/subscription_line_items_controller.rb' - - 'app/controllers/admin/subscriptions_controller.rb' - - 'app/controllers/api/base_controller.rb' - - 'app/controllers/api/enterprise_attachment_controller.rb' - - 'app/controllers/api/taxons_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/controllers/enterprises_controller.rb' - - 'app/controllers/line_items_controller.rb' - - 'app/controllers/spree/admin/base_controller_decorator.rb' - - 'app/controllers/spree/admin/general_settings_controller.rb' - - 'app/controllers/spree/admin/mail_methods_controller.rb' - - 'app/controllers/spree/admin/orders/customer_details_controller_decorator.rb' - - 'app/controllers/spree/admin/payment_methods_controller.rb' - - 'app/controllers/spree/admin/products_controller_decorator.rb' - - 'app/controllers/spree/admin/shipping_methods_controller.rb' - - 'app/controllers/spree/admin/users_controller.rb' - - 'app/controllers/spree/credit_cards_controller.rb' - - 'app/controllers/spree/orders_controller.rb' - - 'app/controllers/spree/paypal_controller_decorator.rb' - - 'app/helpers/admin/subscriptions_helper.rb' - - 'app/helpers/angular_form_builder.rb' - - 'app/helpers/enterprises_helper.rb' - - 'app/helpers/groups_helper.rb' - - 'app/helpers/serializer_helper.rb' - - 'app/helpers/spree/admin/navigation_helper_decorator.rb' - - 'app/helpers/spree/admin/orders_helper_decorator.rb' - - 'app/helpers/spree/orders_helper.rb' - - 'app/jobs/subscription_confirm_job.rb' - - 'app/mailers/producer_mailer.rb' - - 'app/models/column_preference.rb' - - 'app/models/concerns/order_shipment.rb' - - 'app/models/concerns/product_stock.rb' - - 'app/models/customer.rb' - - 'app/models/enterprise_group.rb' - - 'app/models/order_cycle.rb' - - 'app/models/order_updater.rb' - - 'app/models/product_import/entry_validator.rb' - - 'app/models/product_import/product_importer.rb' - - 'app/models/product_import/reset_absent.rb' - - 'app/models/product_import/spreadsheet_data.rb' - - 'app/models/proxy_order.rb' - - 'app/models/spree/calculator/per_item_decorator.rb' - - 'app/models/spree/credit_card_decorator.rb' - - 'app/models/spree/gateway/stripe_connect.rb' - - 'app/models/spree/line_item_decorator.rb' - - 'app/models/spree/order_decorator.rb' - - 'app/models/spree/payment_decorator.rb' - - 'app/models/spree/product_decorator.rb' - - 'app/models/spree/product_set.rb' - - 'app/models/spree/shipment_decorator.rb' - - 'app/models/spree/tax_rate_decorator.rb' - - 'app/models/spree/user.rb' - - 'app/models/spree/variant_decorator.rb' - - 'app/models/subscription.rb' - - 'app/models/tag_rule/discount_order.rb' - - 'app/serializers/api/admin/customer_serializer.rb' - - 'app/serializers/api/admin/index_enterprise_serializer.rb' - - 'app/serializers/api/admin/line_item_serializer.rb' - - 'app/serializers/api/admin/order_serializer.rb' - - 'app/serializers/api/admin/product_serializer.rb' - - 'app/serializers/api/admin/proxy_order_serializer.rb' - - 'app/serializers/api/admin/subscription_serializer.rb' - - 'app/serializers/api/admin/variant_serializer.rb' - - 'app/serializers/api/cached_enterprise_serializer.rb' - - 'app/serializers/api/enterprise_shopfront_serializer.rb' - - 'app/serializers/api/order_serializer.rb' - - 'app/serializers/api/variant_serializer.rb' - - 'app/services/advance_order_service.rb' - - 'app/services/embedded_page_service.rb' - - 'app/services/exchange_variant_bulk_updater.rb' - - 'app/services/order_cycle_distributed_variants.rb' - - 'app/services/order_cycle_form.rb' - - 'app/services/order_factory.rb' - - 'app/services/order_syncer.rb' - - 'app/services/product_tag_rules_filterer.rb' - - 'app/services/search_orders.rb' - - 'app/services/subscription_estimator.rb' - - 'app/services/subscription_form.rb' - - 'app/services/subscription_validator.rb' - - 'app/services/subscriptions_count.rb' - - 'app/services/tax_rate_finder.rb' - - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb' - - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb' - - 'lib/open_food_network/address_finder.rb' - - 'lib/open_food_network/bulk_coop_report.rb' - - 'lib/open_food_network/customers_report.rb' - - 'lib/open_food_network/enterprise_issue_validator.rb' - - 'lib/open_food_network/lettuce_share_report.rb' - - 'lib/open_food_network/order_cycle_form_applicator.rb' - - 'lib/open_food_network/order_cycle_permissions.rb' - - 'lib/open_food_network/packing_report.rb' - - 'lib/open_food_network/payments_report.rb' - - 'lib/open_food_network/permalink_generator.rb' - - 'lib/open_food_network/permissions.rb' - - 'lib/open_food_network/products_and_inventory_report.rb' - - 'lib/open_food_network/proxy_order_syncer.rb' - - 'lib/open_food_network/sales_tax_report.rb' - - 'lib/open_food_network/subscription_payment_updater.rb' - - 'lib/open_food_network/subscription_summarizer.rb' - - 'lib/open_food_network/tag_rule_applicator.rb' - - 'lib/open_food_network/users_and_enterprises_report.rb' - - 'lib/open_food_network/variant_and_line_item_naming.rb' - - 'lib/open_food_network/xero_invoices_report.rb' - - 'lib/spree/localized_number.rb' - - 'lib/stripe/webhook_handler.rb' - - 'lib/tasks/data.rake' - - 'lib/tasks/karma.rake' - - 'lib/tasks/sample_data/customer_factory.rb' - - 'lib/tasks/sample_data/fee_factory.rb' - - 'lib/tasks/sample_data/payment_method_factory.rb' - - 'lib/tasks/sample_data/shipping_method_factory.rb' - - 'lib/tasks/sample_data/taxon_factory.rb' - - 'spec/factories/product_factory.rb' - - 'spec/support/request/web_helper.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/serializers/api/admin/variant_serializer_spec.rb' - - 'spec/services/product_tag_rules_filterer_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Layout/EndAlignment: - Exclude: - - 'app/controllers/admin/order_cycles_controller.rb' - - 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb' - - 'app/serializers/api/admin/order_cycle_serializer.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'spec/services/order_syncer_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/IndentFirstHashElement: - EnforcedStyle: consistent - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: aligned, indented, indented_relative_to_receiver -Layout/MultilineMethodCallIndentation: - Exclude: - - 'app/models/product_import/entry_validator.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/RescueEnsureAlignment: - Exclude: - - 'app/controllers/spree/admin/reports_controller_decorator.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Layout/SpaceAroundOperators: - Exclude: - - 'spec/services/order_syncer_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'spec/services/embedded_page_service_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'spec/controllers/api/products_controller_spec.rb' - - 'spec/serializers/api/product_serializer_spec.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: - Exclude: - - 'spec/controllers/api/taxons_controller_spec.rb' - - 'spec/features/admin/bulk_product_update_spec.rb' - - 'spec/serializers/api/admin/subscription_line_item_serializer_spec.rb' - # Offense count: 4 Lint/AmbiguousOperator: Exclude: @@ -293,12 +51,6 @@ Lint/UnderscorePrefixedVariableName: Exclude: - 'spec/support/cancan_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Lint/UnneededCopDisableDirective: - Exclude: - - 'app/models/product_import/entry_validator.rb' - # Offense count: 5 # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. Lint/UselessAccessModifier: @@ -371,23 +123,11 @@ Naming/PredicateName: - 'lib/open_food_network/packing_report.rb' - 'lib/tasks/data.rake' -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: PreferredName. -Naming/RescuedExceptionsVariableName: - Exclude: - - 'app/controllers/spree/admin/payments_controller_decorator.rb' - - 'app/controllers/spree/admin/products_controller_decorator.rb' - - 'app/controllers/user_registrations_controller.rb' - - 'app/models/spree/order_decorator.rb' - - 'app/models/spree/product_set.rb' - -# Offense count: 11 +# Offense count: 8 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. # AllowedNames: io, id, to, by, on, in, at, ip, db Naming/UncommunicativeMethodParamName: Exclude: - - 'app/helpers/admin/injection_helper.rb' - 'app/helpers/spree/admin/base_helper_decorator.rb' - 'app/helpers/spree/base_helper_decorator.rb' - 'app/services/subscription_validator.rb' @@ -396,20 +136,6 @@ Naming/UncommunicativeMethodParamName: - 'spec/lib/open_food_network/reports/report_spec.rb' - 'spec/mailers/producer_mailer_spec.rb' -# Offense count: 3 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: snake_case, camelCase -Naming/VariableName: - Exclude: - - 'app/helpers/admin/injection_helper.rb' - -# Offense count: 4 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: snake_case, normalcase, non_integer -Naming/VariableNumber: - Exclude: - - 'spec/lib/open_food_network/products_and_inventory_report_spec.rb' - # Offense count: 1 # Configuration parameters: EnforcedStyle. # SupportedStyles: strict, flexible @@ -417,13 +143,6 @@ Rails/Date: Exclude: - 'app/models/order_cycle.rb' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforceForPrefixed. -Rails/Delegate: - Exclude: - - 'lib/spree/authentication_helpers.rb' - # Offense count: 7 # Configuration parameters: EnforcedStyle. # SupportedStyles: slashes, arguments @@ -465,21 +184,6 @@ Rails/HasManyOrHasOneDependent: - 'app/models/spree/variant_decorator.rb' - 'app/models/subscription.rb' -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: numeric, symbolic -Rails/HttpStatus: - Exclude: - - 'app/controllers/api/products_controller.rb' - - 'app/controllers/api/variants_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Rails/LinkToBlank: - Exclude: - - 'app/helpers/footer_links_helper.rb' - # Offense count: 6 Rails/OutputSafety: Exclude: @@ -498,20 +202,6 @@ Rails/ReflectionClassName: - 'app/models/enterprise_role.rb' - 'app/models/subscription.rb' -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: strict, flexible -Rails/TimeZone: - Exclude: - - 'app/controllers/api/statuses_controller.rb' - - 'app/jobs/heartbeat_job.rb' - - 'lib/open_food_network/rack_request_blocker.rb' - - 'lib/open_food_network/users_and_enterprises_report.rb' - - 'spec/controllers/api/statuses_controller_spec.rb' - - 'spec/jobs/heartbeat_job_spec.rb' - - 'spec/models/enterprise_relationship_spec.rb' - # Offense count: 1 # Configuration parameters: Environments. # Environments: development, test, production @@ -519,14 +209,6 @@ Rails/UnknownEnv: Exclude: - 'app/models/spree/app_configuration_decorator.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: braces, no_braces, context_dependent -Style/BracesAroundHashParameters: - Exclude: - - 'spec/spec_helper.rb' - # Offense count: 2 Style/CaseEquality: Exclude: @@ -623,15 +305,13 @@ Style/CommentedKeyword: Exclude: - 'app/controllers/application_controller.rb' -# Offense count: 4 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition Style/ConditionalAssignment: Exclude: - 'app/controllers/api/taxons_controller.rb' - - 'app/controllers/api/variants_controller.rb' - - 'app/controllers/spree/admin/taxons_controller.rb' # Offense count: 5 # Configuration parameters: EnforcedStyle. @@ -680,18 +360,6 @@ Style/GuardClause: - 'spec/support/request/distribution_helper.rb' - 'spec/support/request/shop_workflow.rb' -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Exclude: - - 'app/controllers/spree/admin/resource_controller_decorator.rb' - - 'app/controllers/spree/admin/taxonomies_controller.rb' - - 'app/controllers/spree/checkout_controller.rb' - - 'app/controllers/spree/orders_controller.rb' - - 'spec/features/admin/users_spec.rb' - # Offense count: 4 Style/IfInsideElse: Exclude: @@ -734,26 +402,6 @@ Style/NumericPredicate: - 'lib/open_food_network/xero_invoices_report.rb' - 'lib/spree/money_decorator.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantParentheses: - Exclude: - - 'spec/controllers/api/variants_controller_spec.rb' - -# Offense count: 14 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'app/helpers/groups_helper.rb' - - 'app/helpers/html_helper.rb' - - 'app/models/enterprise.rb' - - 'app/models/enterprise_group.rb' - - 'lib/discourse/single_sign_on.rb' - - 'spec/mailers/subscription_mailer_spec.rb' - - 'spec/models/content_configuration_spec.rb' - # Offense count: 235 Style/Send: Exclude: @@ -802,17 +450,3 @@ Style/Send: Style/StructInheritance: Exclude: - 'lib/open_food_network/enterprise_fee_applicator.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to, define_method -Style/SymbolProc: - Exclude: - - 'spec/features/admin/orders_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/UnlessElse: - Exclude: - - 'app/controllers/api/variants_controller.rb' From c9177feb196903b4d1b93cfcd3e968f3f9fc0516 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 10 Nov 2019 19:14:12 +0000 Subject: [PATCH 3/6] Fix a few more rubocop issues manually --- .rubocop_manual_todo.yml | 1 - app/helpers/footer_links_helper.rb | 11 +++++++++-- app/models/product_import/entry_validator.rb | 3 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index 3264b8a389..d0f81abb78 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -55,7 +55,6 @@ Metrics/LineLength: - app/helpers/angular_form_helper.rb - app/helpers/checkout_helper.rb - app/helpers/enterprises_helper.rb - - app/helpers/footer_links_helper.rb - app/helpers/injection_helper.rb - app/helpers/markdown_helper.rb - app/helpers/order_cycles_helper.rb diff --git a/app/helpers/footer_links_helper.rb b/app/helpers/footer_links_helper.rb index 14b8780089..a4caad2abd 100644 --- a/app/helpers/footer_links_helper.rb +++ b/app/helpers/footer_links_helper.rb @@ -2,10 +2,17 @@ require 'web/cookies_consent' module FooterLinksHelper def cookies_policy_link - link_to( t( '.footer_data_cookies_policy' ), '', 'cookies-policy-modal' => true, 'cookies-banner' => !Web::CookiesConsent.new(cookies, request.host).exists? && Spree::Config.cookies_consent_banner_toggle) + link_to( t( '.footer_data_cookies_policy' ), + '', + 'cookies-policy-modal' => true, + 'cookies-banner' => !Web::CookiesConsent.new(cookies, request.host).exists? && + Spree::Config.cookies_consent_banner_toggle) end def privacy_policy_link - link_to( t( '.footer_data_privacy_policy' ), Spree::Config.privacy_policy_url, target: '_blank', rel: 'noopener' ) + link_to( t( '.footer_data_privacy_policy' ), + Spree::Config.privacy_policy_url, + target: '_blank', + rel: 'noopener' ) end end diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 30c14dc093..475dae953c 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -138,8 +138,7 @@ module ProductImport def primary_producer_error(entry) return if import_into_inventory? - return if @spreadsheet_data. - enterprises_index[entry.enterprise][:is_primary_producer] + return if @spreadsheet_data.enterprises_index[entry.enterprise][:is_primary_producer] mark_as_invalid(entry, attribute: enterprise_field, From 73ee14cc7c58e52cc0ec881a95e6558d1e06f541 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 10 Nov 2019 19:21:08 +0000 Subject: [PATCH 4/6] Fix long line in injection helper --- .rubocop_manual_todo.yml | 1 - app/helpers/admin/injection_helper.rb | 139 ++++++++++++++++++++------ 2 files changed, 111 insertions(+), 29 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index d0f81abb78..c050bda9de 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -50,7 +50,6 @@ Metrics/LineLength: - app/controllers/spree/credit_cards_controller.rb - app/controllers/spree/paypal_controller_decorator.rb - app/controllers/stripe/callbacks_controller.rb - - app/helpers/admin/injection_helper.rb - app/helpers/angular_form_builder.rb - app/helpers/angular_form_helper.rb - app/helpers/checkout_helper.rb diff --git a/app/helpers/admin/injection_helper.rb b/app/helpers/admin/injection_helper.rb index bb04020f04..6b57512676 100644 --- a/app/helpers/admin/injection_helper.rb +++ b/app/helpers/admin/injection_helper.rb @@ -1,70 +1,118 @@ module Admin module InjectionHelper def admin_inject_enterprise - admin_inject_json_ams "admin.enterprises", "enterprise", @enterprise, Api::Admin::EnterpriseSerializer + admin_inject_json_ams "admin.enterprises", + "enterprise", + @enterprise, + Api::Admin::EnterpriseSerializer end def admin_inject_enterprises - admin_inject_json_ams_array("ofn.admin", "my_enterprises", @my_enterprises, Api::Admin::BasicEnterpriseSerializer) + - admin_inject_json_ams_array("ofn.admin", "all_enterprises", @all_enterprises, Api::Admin::BasicEnterpriseSerializer) + admin_inject_json_ams_array("ofn.admin", + "my_enterprises", + @my_enterprises, + Api::Admin::BasicEnterpriseSerializer) + + admin_inject_json_ams_array("ofn.admin", + "all_enterprises", + @all_enterprises, + Api::Admin::BasicEnterpriseSerializer) end def admin_inject_enterprise_relationships - admin_inject_json_ams_array "ofn.admin", "enterprise_relationships", @enterprise_relationships, Api::Admin::EnterpriseRelationshipSerializer + admin_inject_json_ams_array "ofn.admin", + "enterprise_relationships", + @enterprise_relationships, + Api::Admin::EnterpriseRelationshipSerializer end def admin_inject_enterprise_roles - admin_inject_json_ams_array "ofn.admin", "enterpriseRoles", @enterprise_roles, Api::Admin::EnterpriseRoleSerializer + admin_inject_json_ams_array "ofn.admin", + "enterpriseRoles", + @enterprise_roles, + Api::Admin::EnterpriseRoleSerializer end def admin_inject_payment_methods - admin_inject_json_ams_array "admin.paymentMethods", "paymentMethods", @payment_methods, Api::Admin::IdNameSerializer + admin_inject_json_ams_array "admin.paymentMethods", + "paymentMethods", + @payment_methods, + Api::Admin::IdNameSerializer end def admin_inject_payment_method - admin_inject_json_ams "admin.paymentMethods", "paymentMethod", @payment_method, Api::Admin::PaymentMethodSerializer + admin_inject_json_ams "admin.paymentMethods", + "paymentMethod", + @payment_method, + Api::Admin::PaymentMethodSerializer end def admin_inject_shipping_methods - admin_inject_json_ams_array "admin.shippingMethods", "shippingMethods", @shipping_methods, Api::Admin::IdNameSerializer + admin_inject_json_ams_array "admin.shippingMethods", + "shippingMethods", + @shipping_methods, + Api::Admin::IdNameSerializer end def admin_inject_shipping_method - admin_inject_json_ams "admin.shippingMethods", "shippingMethod", @shipping_method, Api::Admin::ShippingMethodSerializer + admin_inject_json_ams "admin.shippingMethods", + "shippingMethod", + @shipping_method, + Api::Admin::ShippingMethodSerializer end def admin_inject_shops(opts = {}) opts.reverse_merge!(module: 'admin.customers') - admin_inject_json_ams_array opts[:module], "shops", @shops, Api::Admin::IdNameSerializer + admin_inject_json_ams_array opts[:module], + "shops", + @shops, + Api::Admin::IdNameSerializer end def admin_inject_available_countries(opts = {}) opts.reverse_merge!(module: 'admin.customers') - admin_inject_json_ams_array opts[:module], 'availableCountries', available_countries, Api::CountrySerializer + admin_inject_json_ams_array opts[:module], + 'availableCountries', + available_countries, + Api::CountrySerializer end def admin_inject_hubs(opts = {}) opts.reverse_merge!(module: 'ofn.admin') - admin_inject_json_ams_array opts[:module], "hubs", @hubs, Api::Admin::IdNameSerializer + admin_inject_json_ams_array opts[:module], + "hubs", + @hubs, + Api::Admin::IdNameSerializer end def admin_inject_producers(opts = {}) opts.reverse_merge!(module: 'ofn.admin') - admin_inject_json_ams_array opts[:module], "producers", @producers, Api::Admin::IdNameSerializer + admin_inject_json_ams_array opts[:module], + "producers", + @producers, + Api::Admin::IdNameSerializer end def admin_inject_inventory_items(opts = { module: 'ofn.admin' }) - admin_inject_json_ams_array opts[:module], "inventoryItems", @inventory_items, Api::Admin::InventoryItemSerializer + admin_inject_json_ams_array opts[:module], + "inventoryItems", + @inventory_items, + Api::Admin::InventoryItemSerializer end def admin_inject_column_preferences(opts = {}) opts.reverse_merge!(module: 'ofn.admin', action: "#{controller_name}_#{action_name}") column_preferences = ColumnPreference.for(spree_current_user, opts[:action]) - admin_inject_json_ams_array opts[:module], "columns", column_preferences, Api::Admin::ColumnPreferenceSerializer + admin_inject_json_ams_array opts[:module], + "columns", + column_preferences, + Api::Admin::ColumnPreferenceSerializer end def admin_inject_currency_config - admin_inject_json_ams 'admin.utils', "currencyConfig", {}, Api::CurrencyConfigSerializer + admin_inject_json_ams 'admin.utils', + "currencyConfig", + {}, + Api::CurrencyConfigSerializer end def admin_inject_enterprise_permissions @@ -77,7 +125,9 @@ module Admin end def admin_inject_hub_permissions - render partial: "admin/json/injection_ams", locals: { ngModule: "admin.variantOverrides", name: "hubPermissions", json: @hub_permissions.to_json } + render partial: "admin/json/injection_ams", locals: { ngModule: "admin.variantOverrides", + name: "hubPermissions", + json: @hub_permissions.to_json } end def admin_inject_products @@ -85,46 +135,79 @@ module Admin end def admin_inject_tax_categories(opts = { module: 'ofn.admin' }) - admin_inject_json_ams_array opts[:module], "tax_categories", @tax_categories, Api::Admin::TaxCategorySerializer + admin_inject_json_ams_array opts[:module], + "tax_categories", + @tax_categories, + Api::Admin::TaxCategorySerializer end def admin_inject_taxons - admin_inject_json_ams_array "admin.taxons", "taxons", @taxons, Api::Admin::TaxonSerializer + admin_inject_json_ams_array "admin.taxons", + "taxons", + @taxons, + Api::Admin::TaxonSerializer end def admin_inject_users - admin_inject_json_ams_array "ofn.admin", "users", @users, Api::Admin::UserSerializer + admin_inject_json_ams_array "ofn.admin", + "users", + @users, + Api::Admin::UserSerializer end def admin_inject_variant_overrides - admin_inject_json_ams_array "admin.variantOverrides", "variantOverrides", @variant_overrides, Api::Admin::VariantOverrideSerializer + admin_inject_json_ams_array "admin.variantOverrides", + "variantOverrides", + @variant_overrides, + Api::Admin::VariantOverrideSerializer end def admin_inject_order_cycle_instance - render partial: "admin/json/injection_ams", locals: { ngModule: 'admin.orderCycles', name: 'ocInstance', json: "{coordinator_id: '#{@order_cycle.coordinator.id}'}" } + render partial: "admin/json/injection_ams", + locals: { ngModule: 'admin.orderCycles', + name: 'ocInstance', + json: "{coordinator_id: '#{@order_cycle.coordinator.id}'}" } end def admin_inject_order_cycles - admin_inject_json_ams_array "admin.orders", "orderCycles", @order_cycles, Api::Admin::BasicOrderCycleSerializer, current_user: spree_current_user + admin_inject_json_ams_array "admin.orders", + "orderCycles", + @order_cycles, + Api::Admin::BasicOrderCycleSerializer, + current_user: spree_current_user end def admin_inject_spree_api_key - render partial: "admin/json/injection_ams", locals: { ngModule: 'admin.indexUtils', name: 'SpreeApiKey', json: "'#{@spree_api_key}'" } + render partial: "admin/json/injection_ams", + locals: { ngModule: 'admin.indexUtils', + name: 'SpreeApiKey', + json: "'#{@spree_api_key}'" } end def admin_inject_json(ng_module, name, data) json = data.to_json - render partial: "admin/json/injection_ams", locals: { ngModule: ng_module, name: name, json: json } + render partial: "admin/json/injection_ams", + locals: { ngModule: ng_module, + name: name, + json: json } end def admin_inject_json_ams(ng_module, name, data, serializer, opts = {}) json = serializer.new(data, { scope: spree_current_user }.merge(opts)).to_json - render partial: "admin/json/injection_ams", locals: { ngModule: ng_module, name: name, json: json } + render partial: "admin/json/injection_ams", + locals: { ngModule: ng_module, + name: name, + json: json } end def admin_inject_json_ams_array(ng_module, name, data, serializer, opts = {}) - json = ActiveModel::ArraySerializer.new(data, { each_serializer: serializer, scope: spree_current_user }.merge(opts)).to_json - render partial: "admin/json/injection_ams", locals: { ngModule: ng_module, name: name, json: json } + json = ActiveModel::ArraySerializer. + new(data, { each_serializer: serializer, scope: spree_current_user }.merge(opts)).to_json + + render partial: "admin/json/injection_ams", + locals: { ngModule: ng_module, + name: name, + json: json } end end end From 553d4ebaa082560cc1de736552de5632a7f388e3 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 10 Nov 2019 19:27:41 +0000 Subject: [PATCH 5/6] Fix a few rubocop issues in reports code --- .rubocop_manual_todo.yml | 1 - .../spree/admin/reports_controller_decorator.rb | 4 ++-- .../users_and_enterprises_report.rb | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index c050bda9de..11f3be06ea 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -124,7 +124,6 @@ Metrics/LineLength: - lib/open_food_network/reports/bulk_coop_allocation_report.rb - lib/open_food_network/reports/line_items.rb - lib/open_food_network/sales_tax_report.rb - - lib/open_food_network/users_and_enterprises_report.rb - lib/open_food_network/variant_and_line_item_naming.rb - lib/open_food_network/xero_invoices_report.rb - lib/spree/core/controller_helpers/respond_with_decorator.rb diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index ddafac2733..3a7f5217fc 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -258,14 +258,14 @@ Spree::Admin::ReportsController.class_eval do def describe_report(report) name = I18n.t(:name, scope: [:admin, :reports, report]) description = begin - I18n.t!(:description, scope: [:admin, :reports, report]) + I18n.t!(:description, scope: [:admin, :reports, report]) rescue I18n::MissingTranslationData render_to_string( partial: "#{report}_description", layout: false, locals: { report_types: report_types[report] } ).html_safe - end + end { name: name, url: url_for_report(report), description: description } end diff --git a/lib/open_food_network/users_and_enterprises_report.rb b/lib/open_food_network/users_and_enterprises_report.rb index 15de41a883..74e328ee20 100644 --- a/lib/open_food_network/users_and_enterprises_report.rb +++ b/lib/open_food_network/users_and_enterprises_report.rb @@ -6,7 +6,9 @@ module OpenFoodNetwork @compile_table = compile_table # Convert arrays of ids to comma delimited strings - @params[:enterprise_id_in] = @params[:enterprise_id_in].join(',') if @params[:enterprise_id_in].is_a? Array + if @params[:enterprise_id_in].is_a? Array + @params[:enterprise_id_in] = @params[:enterprise_id_in].join(',') + end @params[:user_id_in] = @params[:user_id_in].join(',') if @params[:user_id_in].is_a? Array end @@ -104,8 +106,17 @@ module OpenFoodNetwork [(a["created_at"].nil? ? 0 : 1), a["name"], b["relationship_type"], a["user_email"]] <=> [(b["created_at"].nil? ? 0 : 1), b["name"], a["relationship_type"], b["user_email"]] else - [DateTime.parse(b["created_at"]).in_time_zone, a["name"], b["relationship_type"], a["user_email"]] <=> - [DateTime.parse(a["created_at"]).in_time_zone, b["name"], a["relationship_type"], b["user_email"]] + [ + DateTime.parse(b["created_at"]).in_time_zone, + a["name"], + b["relationship_type"], + a["user_email"] + ] <=> [ + DateTime.parse(a["created_at"]).in_time_zone, + b["name"], + a["relationship_type"], + b["user_email"] + ] end end end From 555ae12b3577a9f58def4b7d01ee5a9fa873fd1e Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 10 Nov 2019 19:32:11 +0000 Subject: [PATCH 6/6] Add exceptions to some unresolved rubocop issues --- .rubocop_manual_todo.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index 11f3be06ea..c4ff990180 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -432,6 +432,7 @@ Metrics/AbcSize: - lib/open_food_network/payments_report.rb - lib/open_food_network/permissions.rb - lib/open_food_network/products_and_inventory_report.rb + - lib/open_food_network/rack_request_blocker.rb - lib/open_food_network/reports/line_items.rb - lib/open_food_network/sales_tax_report.rb - lib/open_food_network/users_and_enterprises_report.rb @@ -668,11 +669,13 @@ Metrics/ClassLength: - lib/open_food_network/packing_report.rb - lib/open_food_network/payments_report.rb - lib/open_food_network/permissions.rb + - lib/open_food_network/users_and_enterprises_report.rb - lib/open_food_network/xero_invoices_report.rb Metrics/ModuleLength: Max: 100 Exclude: + - app/helpers/admin/injection_helper.rb - app/helpers/injection_helper.rb - lib/open_food_network/column_preference_defaults.rb - spec/controllers/admin/enterprises_controller_spec.rb