Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spree Upgrade] Merging master into 2-0-stable (second run in October2018) #2926

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
06b28c1
Better docs for Stripe.publishable_key and Stripe.endpoint_secret.
Sep 30, 2018
372ae8e
updated the spacing to be consistent.
Sep 30, 2018
3ae3817
Move query from variant_overrides_controller to its model scope
nikobozi Oct 4, 2018
f65d3c2
fix rubocop issue
nikobozi Oct 4, 2018
b78716c
Fix missing local variable
Matt-Yorkley Oct 8, 2018
3e39f3e
Disable logout on password change
Matt-Yorkley Oct 8, 2018
55411af
Improve user account spec
Matt-Yorkley Oct 8, 2018
4760ebb
Use global config
Matt-Yorkley Oct 11, 2018
57c6530
DRY code and use more flexible I18n
Matt-Yorkley Oct 11, 2018
b109f6d
Remove temporary reporting code
mkllnk Oct 16, 2018
c4437a6
Style address decorator
mkllnk Oct 16, 2018
34849c4
Reduce complexity and duplication
mkllnk Oct 16, 2018
5021ed9
Simplify by using Rails tools
mkllnk Oct 16, 2018
a8705ca
Simplify address methods
mkllnk Oct 16, 2018
61797ff
Restrict deletion of address explicitely
mkllnk Oct 16, 2018
8fb81bb
Configure Geocoder with API key as required by Google
mkllnk Oct 16, 2018
590091c
Merge pull request #2842 from Matt-Yorkley/pi/missing_variable
sauloperez Oct 16, 2018
e96cab9
Convert specs to RSpec 3.7.1 syntax with Transpec
mkllnk Oct 17, 2018
d197c85
Test address deletion
mkllnk Oct 18, 2018
9698fd3
Style spec
mkllnk Oct 18, 2018
c911462
Updating translations for config/locales/en_GB.yml
Transifex-Openfoodnetwork Oct 19, 2018
a1bbf53
Merge pull request #2872 from mkllnk/2765-fix-geocoding
sauloperez Oct 22, 2018
42c1584
Fix pagination conflict with LineItemsCtrl requests
Matt-Yorkley Oct 22, 2018
6f5289c
Merge pull request #2894 from openfoodfoundation/transifex
mkllnk Oct 23, 2018
7651ee0
Merge pull request #2798 from as1729/as1729-update-docs-Stripe-publis…
sauloperez Oct 24, 2018
9ef4852
Merge pull request #2818 from nikobozi/refactor-variant-overrides-query
sauloperez Oct 24, 2018
ce93c52
Merge pull request #2850 from Matt-Yorkley/password_change_logout
sauloperez Oct 24, 2018
c179396
Updating translations for config/locales/en_US.yml
Transifex-Openfoodnetwork Oct 24, 2018
51a1787
Merge pull request #2908 from Matt-Yorkley/bulk_orders_bug
mkllnk Oct 25, 2018
cd5c239
Update rubocop todo list
mkllnk Oct 25, 2018
3cab3d1
Merge pull request #2921 from openfoodfoundation/transifex
mkllnk Oct 25, 2018
acb8ec7
Merge pull request #2922 from mkllnk/update-rubocop-todo
mkllnk Oct 25, 2018
90d7b7f
Merge branch 'master' into 2-0-stable-oct-25
luisramos0 Oct 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 87 additions & 68 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions app/controllers/admin/variant_overrides_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ def load_data

def inventory_import_dates
import_dates = VariantOverride.
select('DISTINCT variant_overrides.import_date').
where('variant_overrides.hub_id IN (?)
AND variant_overrides.import_date IS NOT NULL', editable_enterprises.collect(&:id)).
order('import_date DESC')
distinct_import_dates.
for_hubs(editable_enterprises.collect(&:id))

options = [{ id: '0', name: 'All' }]
import_dates.collect(&:import_date).map { |i| options.push(id: i.to_date, name: i.to_date.to_formatted_s(:long)) }
Expand Down
32 changes: 25 additions & 7 deletions app/controllers/spree/admin/orders_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ def index
format.json do
render json: {
orders: ActiveModel::ArraySerializer.new(@orders, each_serializer: Api::Admin::OrderSerializer),
pagination: {
results: @orders.total_count,
pages: @orders.num_pages.to_i,
page: params[:page].to_i,
per_page: params[:per_page].to_i
}
pagination: pagination_data
}
end
end
Expand Down Expand Up @@ -115,7 +110,30 @@ def orders
@search.result.includes([:user, :shipments, :payments]).distributed_by_user(spree_current_user)
end

@search.result.page(params[:page]).per(params[:per_page] || Spree::Config[:orders_per_page])
search_results
end

def search_results
if using_pagination?
@search.result.page(params[:page]).per(params[:per_page] || Spree::Config[:orders_per_page])
else
@search.result
end
end

def using_pagination?
params[:per_page]
end

def pagination_data
if using_pagination?
{
results: @orders.total_count,
pages: @orders.num_pages,
page: params[:page].to_i,
per_page: params[:per_page].to_i
}
end
end

def require_distributor_abn
Expand Down
16 changes: 12 additions & 4 deletions app/models/product_import/entry_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def save_new_inventory_item(entry)
@inventory_created += 1
@updated_ids.push new_item.id
else
@importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", new_item.errors.full_messages)
assign_errors new_item.errors.full_messages, entry.line_number
end
end

Expand All @@ -149,7 +149,7 @@ def save_existing_inventory_item(entry)
@inventory_updated += 1
@updated_ids.push existing_item.id
else
@importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", existing_item.errors.full_messages)
assign_errors existing_item.errors.full_messages, entry.line_number
end
end

Expand All @@ -173,7 +173,7 @@ def save_new_product(entry)
@products_created += 1
@updated_ids.push product.variants.first.id
else
@importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", product.errors.full_messages)
assign_errors product.errors.full_messages, entry.line_number
end

@already_created[entry.supplier_id] = { entry.name => product.id }
Expand All @@ -188,11 +188,19 @@ def save_variant(entry)
@updated_ids.push variant.id
true
else
@importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", variant.errors.full_messages)
assign_errors variant.errors.full_messages, entry.line_number
false
end
end

def assign_errors(errors, line_number)
@importer.errors.add(
I18n.t('admin.product_import.model.line_number',
number: line_number),
errors
)
end

def assign_defaults(object, entry)
# Assigns a default value for a specified field e.g. category='Vegetables', setting this value
# either for all entries (overwrite_all), or only for those entries where the field was blank
Expand Down
43 changes: 8 additions & 35 deletions app/models/spree/address_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
Spree::Address.class_eval do
has_one :enterprise
has_one :enterprise, dependent: :restrict
belongs_to :country, class_name: "Spree::Country"

after_save :touch_enterprise

geocoded_by :geocode_address

delegate :name, :to => :state, :prefix => true, :allow_nil => true
delegate :name, to: :state, prefix: true, allow_nil: true

def geocode_address
geocode_address = [address1, address2, zipcode, city, country.andand.name, state.andand.name]
filtered_address = geocode_address.select{ |field| !field.nil? && field != '' }
filtered_address.compact.join(', ')
render_address([address1, address2, zipcode, city, country.andand.name, state.andand.name])
end

def full_address
full_address = [address1, address2, city, zipcode, state.andand.name]
filtered_address = full_address.select{ |field| !field.nil? && field != '' }
filtered_address.compact.join(', ')
render_address([address1, address2, city, zipcode, state.andand.name])
end

def address_part1
address_part1 = [address1, address2]
filtered_address = address_part1.select{ |field| !field.nil? && field != '' }
filtered_address.compact.join(', ')
render_address([address1, address2])
end

def address_part2
address_part2= [city, zipcode, state.andand.name]
filtered_address = address_part2.select{ |field| !field.nil? && field != '' }
filtered_address.compact.join(', ')
render_address([city, zipcode, state.andand.name])
end

private
Expand All @@ -38,26 +30,7 @@ def touch_enterprise
enterprise.andand.touch
end

# We have a hard-to-track-down bug around invalid addresses with all-nil fields finding
# their way into the database. I don't know what the source of them is, so this patch
# is designed to track them down.
# This is intended to be a temporary investigative measure, and should be removed from the
# code base shortly. If it's past 17-10-2013, take it out.
#
#-- Rohan, 17-9-2913
def create
if self.zipcode.nil?
Bugsnag.notify RuntimeError.new('Creating a Spree::Address with nil values')
end

super
end

def update(attribute_names = @attributes.keys)
if self.zipcode.nil?
Bugsnag.notify RuntimeError.new('Updating a Spree::Address with nil values')
end

super(attribute_names)
def render_address(parts)
parts.select(&:present?).join(', ')
end
end
8 changes: 6 additions & 2 deletions app/models/variant_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ class VariantOverride < ActiveRecord::Base

acts_as_taggable

attr_accessor :import_date

belongs_to :hub, class_name: 'Enterprise'
belongs_to :variant, class_name: 'Spree::Variant'

Expand All @@ -21,6 +19,12 @@ class VariantOverride < ActiveRecord::Base
where(hub_id: hubs)
}

scope :distinct_import_dates, lambda {
select('DISTINCT variant_overrides.import_date').
where('variant_overrides.import_date IS NOT NULL').
order('import_date DESC')
}

localize_number :price

def self.indexed(hub)
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/geocoder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Google requires an API key with a billing account to use their API.
# The key is stored in config/application.yml.
Geocoder.configure(
use_https: true,
api_key: ENV.fetch('GOOGLE_MAPS_API_KEY', nil)
)
3 changes: 3 additions & 0 deletions config/initializers/spree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
config.order_updater_decorator = OrderUpdater
end

# Don't log users out when setting a new password
Spree::Auth::Config[:signout_after_password_change] = false

# TODO Work out why this is necessary
# Seems like classes within OFN module become 'uninitialized' when server reloads
# unless the empty module is explicity 'registered' here. Something to do with autoloading?
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# a bit cleaner than accessing keys in different ways.
module Stripe
class << self
# Returns the value of Stripe.publishable_key and Stripe.endpoint_secret.
# Attribute values can also be set by doing Stripe.publishable_key = <your_new_value>
attr_accessor :publishable_key, :endpoint_secret
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ en:
products_no_permission: you do not have permission to manage products for this enterprise
inventory_no_permission: you do not have permission to create inventory for this producer
none_saved: did not save any products successfully
line: Line
line_number: "Line %{number}:"
index:
select_file: Select a spreadsheet to upload
spreadsheet: Spreadsheet
Expand Down
Loading