mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-02 06:51:40 +00:00
Compare commits
14 Commits
master
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b88cf10da | ||
|
|
046bbc3cf8 | ||
|
|
2722112125 | ||
|
|
4d79dcdd2d | ||
|
|
846a59873e | ||
|
|
2601b55a6f | ||
|
|
190e9a79b2 | ||
|
|
ba3e9279bd | ||
|
|
26e0f4b09b | ||
|
|
91588ad94e | ||
|
|
fb73144172 | ||
|
|
d1c045cbf0 | ||
|
|
473fff1bb8 | ||
|
|
baf390eade |
@@ -1,11 +1,26 @@
|
||||
# This configuration was generated by
|
||||
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp`
|
||||
# using RuboCop version 1.81.7.
|
||||
# using RuboCop version 1.86.0.
|
||||
# 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: 8
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
# Configuration parameters: Width, EnforcedStyleAlignWith, AllowedPatterns.
|
||||
# SupportedStylesAlignWith: start_of_line, relative_to_receiver
|
||||
Layout/IndentationWidth:
|
||||
Exclude:
|
||||
- 'app/models/spree/taxon.rb'
|
||||
- 'app/services/dfc_catalog_importer.rb'
|
||||
- 'lib/reporting/reports/customers/base.rb'
|
||||
- 'lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_order.rb'
|
||||
- 'spec/models/spree/order/state_machine_spec.rb'
|
||||
- 'spec/services/orders/compare_invoice_service_spec.rb'
|
||||
- 'spec/system/admin/bulk_order_management_spec.rb'
|
||||
- 'spec/system/consumer/checkout/payment_spec.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
# Configuration parameters: RequireParenthesesForMethodChains.
|
||||
@@ -35,6 +50,7 @@ Lint/UselessConstantScoping:
|
||||
- 'lib/reporting/report_metadata_builder.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
Lint/UselessOr:
|
||||
Exclude:
|
||||
- 'app/models/product_import/entry_validator.rb'
|
||||
@@ -62,14 +78,13 @@ Metrics/AbcSize:
|
||||
- 'lib/spree/core/controller_helpers/order.rb'
|
||||
- 'spec/services/orders/checkout_restart_service_spec.rb'
|
||||
|
||||
# Offense count: 9
|
||||
# Offense count: 7
|
||||
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
|
||||
# AllowedMethods: refine
|
||||
Metrics/BlockLength:
|
||||
Exclude:
|
||||
- 'app/models/spree/order/checkout.rb'
|
||||
- 'app/models/spree/payment.rb'
|
||||
- 'app/models/spree/payment/processing.rb'
|
||||
- 'app/models/spree/shipment.rb'
|
||||
- 'lib/spree/core/controller_helpers/common.rb'
|
||||
- 'lib/tasks/data.rake'
|
||||
@@ -80,7 +95,7 @@ Metrics/BlockNesting:
|
||||
Exclude:
|
||||
- 'app/models/spree/payment/processing.rb'
|
||||
|
||||
# Offense count: 49
|
||||
# Offense count: 48
|
||||
# Configuration parameters: CountComments, Max, CountAsOne.
|
||||
Metrics/ClassLength:
|
||||
Exclude:
|
||||
@@ -105,7 +120,6 @@ Metrics/ClassLength:
|
||||
- 'app/models/product_import/product_importer.rb'
|
||||
- 'app/models/spree/ability.rb'
|
||||
- 'app/models/spree/address.rb'
|
||||
- 'app/models/spree/credit_card.rb'
|
||||
- 'app/models/spree/gateway/stripe_sca.rb'
|
||||
- 'app/models/spree/line_item.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
@@ -134,11 +148,12 @@ Metrics/ClassLength:
|
||||
- 'lib/reporting/reports/enterprise_fee_summary/scope.rb'
|
||||
- 'lib/reporting/reports/xero_invoices/base.rb'
|
||||
|
||||
# Offense count: 37
|
||||
# Offense count: 33
|
||||
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
||||
Metrics/CyclomaticComplexity:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/enterprises_controller.rb'
|
||||
- 'app/controllers/concerns/respond_with.rb'
|
||||
- 'app/controllers/spree/admin/payments_controller.rb'
|
||||
- 'app/controllers/spree/orders_controller.rb'
|
||||
- 'app/helpers/checkout_helper.rb'
|
||||
@@ -159,16 +174,12 @@ Metrics/CyclomaticComplexity:
|
||||
- 'lib/open_food_network/enterprise_issue_validator.rb'
|
||||
- 'lib/reporting/reports/orders_and_fulfillment/order_cycle_customer_totals.rb'
|
||||
- 'lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb'
|
||||
- 'lib/reporting/reports/payments/itemised_payment_totals.rb'
|
||||
- 'lib/reporting/reports/payments/payment_totals.rb'
|
||||
- 'lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb'
|
||||
- 'lib/reporting/reports/xero_invoices/base.rb'
|
||||
- 'lib/spree/core/controller_helpers/order.rb'
|
||||
- 'lib/spree/core/controller_helpers/respond_with.rb'
|
||||
- 'lib/spree/localized_number.rb'
|
||||
- 'spec/models/product_importer_spec.rb'
|
||||
|
||||
# Offense count: 22
|
||||
# Offense count: 20
|
||||
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
|
||||
Metrics/MethodLength:
|
||||
Exclude:
|
||||
@@ -178,7 +189,6 @@ Metrics/MethodLength:
|
||||
- 'app/models/spree/ability.rb'
|
||||
- 'app/models/spree/gateway/pay_pal_express.rb'
|
||||
- 'app/models/spree/order/checkout.rb'
|
||||
- 'app/models/spree/payment/processing.rb'
|
||||
- 'app/models/spree/preferences/preferable_class_methods.rb'
|
||||
- 'lib/open_food_network/order_cycle_form_applicator.rb'
|
||||
- 'lib/open_food_network/order_cycle_permissions.rb'
|
||||
@@ -187,12 +197,11 @@ Metrics/MethodLength:
|
||||
- 'lib/spree/localized_number.rb'
|
||||
- 'lib/tasks/sample_data/product_factory.rb'
|
||||
|
||||
# Offense count: 10
|
||||
# Offense count: 9
|
||||
# Configuration parameters: CountComments, Max, CountAsOne.
|
||||
Metrics/ModuleLength:
|
||||
Exclude:
|
||||
- 'app/helpers/admin/injection_helper.rb'
|
||||
- 'app/helpers/checkout_helper.rb'
|
||||
- 'app/helpers/injection_helper.rb'
|
||||
- 'app/helpers/spree/admin/base_helper.rb'
|
||||
- 'app/helpers/spree/admin/navigation_helper.rb'
|
||||
@@ -238,7 +247,7 @@ Naming/MethodParameterName:
|
||||
# Offense count: 60
|
||||
# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
|
||||
# AllowedMethods: call
|
||||
# WaywardPredicates: nonzero?
|
||||
# WaywardPredicates: infinite?, nonzero?
|
||||
Naming/PredicateMethod:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/product_import_controller.rb'
|
||||
@@ -336,16 +345,14 @@ Rails/OrderArguments:
|
||||
- 'spec/services/orders/generate_invoice_service_spec.rb'
|
||||
- 'spec/system/admin/order_cycles/simple_spec.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Offense count: 1
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
Rails/Presence:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/enterprises_controller.rb'
|
||||
- 'app/models/spree/product.rb'
|
||||
|
||||
# Offense count: 6
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
# Configuration parameters: Severity.
|
||||
Rails/RedirectBackOrTo:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/order_cycles_controller.rb'
|
||||
@@ -373,7 +380,7 @@ Style/BitwisePredicate:
|
||||
Exclude:
|
||||
- 'app/helpers/admin/enterprises_helper.rb'
|
||||
|
||||
# Offense count: 23
|
||||
# Offense count: 22
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
# Configuration parameters: EnforcedStyle, EnforcedStyleForClasses, EnforcedStyleForModules.
|
||||
# SupportedStyles: nested, compact
|
||||
|
||||
@@ -576,7 +576,7 @@ GEM
|
||||
parallel (1.27.0)
|
||||
paranoia (2.6.4)
|
||||
activerecord (>= 5.1, < 7.2)
|
||||
parser (3.3.10.2)
|
||||
parser (3.3.11.1)
|
||||
ast (~> 2.4.1)
|
||||
racc
|
||||
paypal-sdk-core (0.3.4)
|
||||
@@ -776,7 +776,7 @@ GEM
|
||||
rswag-ui (2.17.0)
|
||||
actionpack (>= 5.2, < 8.2)
|
||||
railties (>= 5.2, < 8.2)
|
||||
rubocop (1.84.2)
|
||||
rubocop (1.86.0)
|
||||
json (~> 2.3)
|
||||
language_server-protocol (~> 3.17.0.2)
|
||||
lint_roller (~> 1.1.0)
|
||||
@@ -787,7 +787,7 @@ GEM
|
||||
rubocop-ast (>= 1.49.0, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 2.4.0, < 4.0)
|
||||
rubocop-ast (1.49.0)
|
||||
rubocop-ast (1.49.1)
|
||||
parser (>= 3.3.7.2)
|
||||
prism (~> 1.7)
|
||||
rubocop-capybara (2.22.1)
|
||||
|
||||
@@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base
|
||||
include CablecarResponses
|
||||
include Pagy::Backend
|
||||
include RequestTimeouts
|
||||
include RespondWith
|
||||
|
||||
self.responder = ApplicationResponder
|
||||
respond_to :html
|
||||
|
||||
@@ -44,6 +44,7 @@ module CheckoutCallbacks
|
||||
@order.checkout_processing = true
|
||||
|
||||
redirect_to(main_app.shop_path) && return if redirect_to_shop?
|
||||
|
||||
redirect_to_cart_path && return unless valid_order_line_items?
|
||||
end
|
||||
|
||||
|
||||
49
app/controllers/concerns/respond_with.rb
Normal file
49
app/controllers/concerns/respond_with.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "spree/responder"
|
||||
|
||||
module RespondWith
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def respond_with(*resources, &)
|
||||
if self.class.mimes_for_respond_to.empty?
|
||||
raise "In order to use respond_with, first you need to declare the formats your " \
|
||||
"controller responds to in the class level"
|
||||
end
|
||||
|
||||
return unless (collector = retrieve_collector_from_mimes(&))
|
||||
|
||||
options = resources.size == 1 ? {} : resources.extract_options!
|
||||
|
||||
# Fix spree issues #3531 and #2210 (patch provided by leiyangyou)
|
||||
if (defined_response = collector.response) &&
|
||||
!ApplicationController.spree_responders[self.class.to_s.to_sym]
|
||||
.try(:[], action_name.to_sym)
|
||||
|
||||
if action = options.delete(:action)
|
||||
render(action:)
|
||||
else
|
||||
defined_response.call
|
||||
end
|
||||
else
|
||||
# The action name is needed for processing
|
||||
options[:action_name] = action_name.to_sym
|
||||
# If responder is not specified then pass in Spree::Responder
|
||||
(options.delete(:responder) || Spree::Responder).call(self, resources, options)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def retrieve_collector_from_mimes(mimes = nil, &block)
|
||||
mimes ||= collect_mimes_from_class_level
|
||||
collector = ActionController::Base::Collector.new(mimes, request.variant)
|
||||
block.call(collector) if block_given?
|
||||
format = collector.negotiate_format(request)
|
||||
|
||||
raise ActionController::UnknownFormat unless format
|
||||
|
||||
_process_format(format)
|
||||
collector
|
||||
end
|
||||
end
|
||||
@@ -133,8 +133,8 @@ class Invoice
|
||||
end
|
||||
|
||||
def tax_rate_by_id
|
||||
all_tax_adjustments.each_with_object({}) do |adjustment, tax_rates|
|
||||
tax_rates[adjustment.originator.id] = adjustment.originator
|
||||
all_tax_adjustments.to_h do |adjustment|
|
||||
[adjustment.originator.id, adjustment.originator]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
module Spree
|
||||
class DefaultTaxZoneValidator < ActiveModel::Validator
|
||||
def validate(record)
|
||||
return unless record.included_in_price
|
||||
|
||||
return if Zone.default_tax
|
||||
|
||||
record.errors.add(:included_in_price, Spree.t("errors.messages.included_price_validation"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Spree
|
||||
class TaxRate < ApplicationRecord
|
||||
class DefaultTaxZoneValidator < ActiveModel::Validator
|
||||
def validate(record)
|
||||
return unless record.included_in_price
|
||||
|
||||
return if Zone.default_tax
|
||||
|
||||
record.errors.add(:included_in_price, Spree.t("errors.messages.included_price_validation"))
|
||||
end
|
||||
end
|
||||
|
||||
acts_as_paranoid
|
||||
include CalculatedAdjustments
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ module Spree
|
||||
taxons
|
||||
.pluck('spree_taxons.id, enterprises.id AS enterprise_id')
|
||||
.each_with_object({}) do |(taxon_id, enterprise_id), collection|
|
||||
collection[enterprise_id.to_i] ||= Set.new
|
||||
collection[enterprise_id.to_i] << taxon_id
|
||||
collection[enterprise_id.to_i] ||= Set.new
|
||||
collection[enterprise_id.to_i] << taxon_id
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
class TagRuleSerializer < ActiveModel::Serializer
|
||||
delegate :serializable_hash, to: :rule_specific_serializer
|
||||
|
||||
def rule_specific_serializer
|
||||
"Api::Admin::#{object.class}Serializer".constantize.new(object)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Api
|
||||
module Admin
|
||||
module TagRule
|
||||
|
||||
@@ -6,7 +6,7 @@ module Orders
|
||||
|
||||
delegate :distributor, :order_cycle, to: :order
|
||||
|
||||
FeeValue = Struct.new(:fee, :role, keyword_init: true)
|
||||
FeeValue = Struct.new(:fee, :role)
|
||||
|
||||
def initialize(order)
|
||||
@order = order
|
||||
|
||||
@@ -41,8 +41,8 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def fees_name_by_type_for(variant)
|
||||
per_item_enterprise_fee_applicators_for(variant).each_with_object({}) do |applicator, fees|
|
||||
fees[applicator.enterprise_fee.fee_type.to_sym] = applicator.enterprise_fee.name
|
||||
per_item_enterprise_fee_applicators_for(variant).to_h do |applicator|
|
||||
[applicator.enterprise_fee.fee_type.to_sym, applicator.enterprise_fee.name]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -10,6 +10,4 @@ module OpenFoodNetwork::Locking
|
||||
end
|
||||
end
|
||||
|
||||
class ActiveRecord::Base
|
||||
extend OpenFoodNetwork::Locking
|
||||
end
|
||||
ActiveSupport.on_load(:active_record) { extend OpenFoodNetwork::Locking }
|
||||
|
||||
@@ -1,52 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spree/responder'
|
||||
|
||||
module ActionController
|
||||
class Base
|
||||
def respond_with(*resources, &)
|
||||
if self.class.mimes_for_respond_to.empty?
|
||||
raise "In order to use respond_with, first you need to declare the formats your " \
|
||||
"controller responds to in the class level"
|
||||
end
|
||||
|
||||
return unless (collector = retrieve_collector_from_mimes(&))
|
||||
|
||||
options = resources.size == 1 ? {} : resources.extract_options!
|
||||
|
||||
# Fix spree issues #3531 and #2210 (patch provided by leiyangyou)
|
||||
if (defined_response = collector.response) &&
|
||||
!ApplicationController.spree_responders[self.class.to_s.to_sym].try(:[],
|
||||
action_name.to_sym)
|
||||
if action = options.delete(:action)
|
||||
render(action:)
|
||||
else
|
||||
defined_response.call
|
||||
end
|
||||
else
|
||||
# The action name is needed for processing
|
||||
options[:action_name] = action_name.to_sym
|
||||
# If responder is not specified then pass in Spree::Responder
|
||||
(options.delete(:responder) || Spree::Responder).call(self, resources, options)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def retrieve_collector_from_mimes(mimes = nil, &block)
|
||||
mimes ||= collect_mimes_from_class_level
|
||||
collector = Collector.new(mimes, request.variant)
|
||||
block.call(collector) if block_given?
|
||||
format = collector.negotiate_format(request)
|
||||
|
||||
raise ActionController::UnknownFormat unless format
|
||||
|
||||
_process_format(format)
|
||||
collector
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Spree
|
||||
module Core
|
||||
module ControllerHelpers
|
||||
|
||||
@@ -145,7 +145,7 @@ RSpec.describe "Customers", swagger_doc: "v1.yaml", feature: :api_v1 do
|
||||
it "adds balance to each customer" do
|
||||
get "/api/v1/customers", params: { extra_fields: { customer: :balance } }
|
||||
balances = json_response[:data].map{ |c| c[:attributes][:balance] }
|
||||
expect(balances.all?{ |b| b.is_a? Numeric }).to eq(true)
|
||||
expect(balances.all?(Numeric)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user