run rubocop --auto-correct

This commit is contained in:
luisramos0
2019-11-10 18:42:43 +00:00
parent 5e99ecd9cc
commit 9404aacfb2
166 changed files with 441 additions and 206 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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!

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -61,6 +61,7 @@ module Api
def taxonomy
return if params[:taxonomy_id].blank?
@taxonomy ||= Spree::Taxonomy.find(params[:taxonomy_id])
end

View File

@@ -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")

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -54,6 +54,7 @@ Spree::Admin::BaseController.class_eval do
if Spree.const_defined?(const_name)
return "Spree::#{const_name}".constantize
end
nil
end

View File

@@ -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(',').

View File

@@ -10,6 +10,7 @@ module Spree
params.each do |name, value|
next unless Spree::Config.has_preference? name
Spree::Config[name] = value
end

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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],

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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{</h[^>]>|</p>|</div>}, "\\1\n\n").
andand.gsub(/<br[^>]*>/, "\\1\n")
end

View File

@@ -1,6 +1,7 @@
module SerializerHelper
def ids_to_objs(ids)
return [] if ids.blank?
ids.map { |id| { id: id } }
end

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)}$/, '')

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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!

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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))

View File

@@ -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) })
}

View File

@@ -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

View File

@@ -14,6 +14,7 @@ class TagRule::DiscountOrder < TagRule
def additional_requirements_met?
return false if already_applied?
true
end

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -26,6 +26,7 @@ class Api::Admin::ProductSerializer < ActiveModel::Serializer
def on_hand
return 0 if object.on_hand.nil?
object.on_hand
end

View File

@@ -6,6 +6,7 @@ module Api
def total
return if object.total.blank?
object.total.to_money.to_s
end

View File

@@ -38,6 +38,7 @@ module Api
def edit_path
return '' unless object.id
edit_admin_subscription_path(object)
end

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -23,6 +23,7 @@ class AdvanceOrderService
def advance_order(options)
until order.state == "complete"
break unless order.next
after_transition_hook(options)
end
end

View File

@@ -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

View File

@@ -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

View File

@@ -14,6 +14,7 @@ class OrderCycleDistributedVariants
def available_variants
return [] unless @order_cycle
@order_cycle.variants_distributed_by(@distributor)
end
end

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

Some files were not shown because too many files have changed in this diff Show More