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

[CIty OFN Voucher]Fix VINE settings page #13015

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
03cbf57
12968: update condition to match variant with unit scale
chahmedejaz Nov 15, 2024
6d6aa96
12968: fix product import update
chahmedejaz Nov 19, 2024
d2c295e
12968: fix existing specs
chahmedejaz Nov 25, 2024
524469c
12919: add unit scale prompt
chahmedejaz Nov 10, 2024
fdaaf8c
Show alert if map cannot load
murjax Nov 1, 2024
ea1002f
8230 - Map spec update
murjax Nov 6, 2024
e897dc7
Anonymise customer first and last names
dacook Sep 16, 2024
af87172
Update all locales with the latest Transifex translations
filipefurtad0 Nov 29, 2024
6bdc870
Remove failing map spec
mkllnk Nov 29, 2024
0aa1e03
Use Alpine Image for Docker
Oct 11, 2024
7e5156a
Remove bundle exec from docker commands
Oct 11, 2024
7499c87
Add Redis Test URL for Spree Preferences
Oct 11, 2024
5e0b8e2
Add Helpful Docker Commands
Oct 23, 2024
149a497
Refactor Alpine Dockerfile
macanudo527 Nov 2, 2024
909884a
Revise docker scripts to use optional dockfiles
macanudo527 Nov 9, 2024
7fec5d1
Optimize Dockerfile
macanudo527 Nov 8, 2024
44e08c6
Revert "Remove bundle exec from docker commands"
macanudo527 Nov 8, 2024
592dca8
Add Dockerfile back in
macanudo527 Nov 8, 2024
1e24718
Revise Docker README
macanudo527 Nov 9, 2024
d2760ef
Simplify Docker Build
macanudo527 Nov 9, 2024
d5828eb
Rewrite Powershell Scripts for Alternative Dockerfile
macanudo527 Nov 9, 2024
bbc8f1e
Add Windows Docker Commands to README
macanudo527 Nov 9, 2024
0d20db5
Sync Docker Container to the Host
Nov 14, 2024
ac921b0
Revise README
Nov 14, 2024
5c7aeb9
Enable Bugsnag testing in any Rails env with ENV var
mkllnk Nov 20, 2024
dba1a07
Revert "Notify bugsnag on 404 errors"
mkllnk Nov 14, 2024
45a9233
Add simpler Bugsnag wrapper
mkllnk Nov 14, 2024
ce8340a
Add live test for Bugsnag
mkllnk Nov 19, 2024
5121d40
Replace Bugsnag calls with Alert.raise
mkllnk Nov 20, 2024
452d90e
Replace obsolete ErrorLogger
mkllnk Nov 20, 2024
41f1e82
Replace broken order data
mkllnk Nov 20, 2024
8d5d90b
Use shorter Alert syntax
mkllnk Nov 21, 2024
d7592a7
Remove unnecessary error creation
mkllnk Nov 21, 2024
a534fc8
Deactivate some specs on CI
mkllnk Nov 21, 2024
0bdb82d
Fix missed Alert call with order object
mkllnk Dec 3, 2024
c920e5e
VineApiService, add voucher_validation
rioug Oct 8, 2024
bb3496f
Add VineVoucherValidatorService and spec
rioug Oct 16, 2024
32536e1
Handle adding a VINE voucher to an order
rioug Oct 16, 2024
e37d60d
VineApiService, add voucher_redemptions
rioug Oct 21, 2024
148e4b4
Add Voucher#vine?
rioug Oct 21, 2024
2ccd568
Add VineVoucherRedeemerService
rioug Oct 21, 2024
bc5738d
CheckoutController, add VINE voucher redemption
rioug Oct 22, 2024
fe0f45f
Reddeem VINE voucher when firing "capture_and_complete_order"o
rioug Oct 28, 2024
8db0237
Refactor Vine related services
rioug Oct 28, 2024
c99ab33
Per review, rename not_vine scope to local
rioug Nov 4, 2024
b5e375d
Move Vine voucher to Vouchers::Vine
rioug Nov 6, 2024
404f9e8
Split description and link to VINE
rioug Dec 3, 2024
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ RUN ./script/install-bundler
RUN yarn install

# Run bundler install in parallel with the amount of available CPUs
RUN bundle install --jobs="$(nproc)"
RUN bundle install --jobs="$(nproc)"
32 changes: 32 additions & 0 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ruby:3.1.4-alpine3.19 AS base
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
TZ=Europe/London \
RAILS_ROOT=/usr/src/app
RUN apk --no-cache upgrade && \
apk add --no-cache tzdata postgresql-client imagemagick imagemagick-jpeg && \
apk add --no-cache --virtual wkhtmltopdf

WORKDIR $RAILS_ROOT

# Development dependencies
FROM base AS development-base
RUN apk add --no-cache --virtual .build-deps \
build-base postgresql-dev git nodejs yarn && \
apk add --no-cache --virtual .dev-utils \
bash curl less vim chromium-chromedriver zlib-dev openssl-dev \
readline-dev yaml-dev sqlite-dev libxml2-dev libxslt-dev libffi-dev vips-dev && \
curl -o /usr/local/bin/wait-for-it https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && \
chmod +x /usr/local/bin/wait-for-it

# Install yarn dependencies separately for caching
FROM development-base AS yarn-dependencies
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Install Ruby gems
FROM development-base
COPY . $RAILS_ROOT
COPY Gemfile Gemfile.lock ./
RUN bundle install --jobs "$(nproc)"
COPY --from=yarn-dependencies $RAILS_ROOT/node_modules ./node_modules
11 changes: 7 additions & 4 deletions app/assets/javascripts/darkswarm/directives/map_search.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ angular.module('Darkswarm').directive 'mapSearch', ($timeout, Search) ->
$timeout =>
map = ctrl.getMap()

searchBox = scope.createSearchBox map
scope.bindSearchResponse map, searchBox
scope.biasResults map, searchBox
scope.performUrlSearch map
if !map
alert(t('gmap_load_failure'))
else
searchBox = scope.createSearchBox map
scope.bindSearchResponse map, searchBox
scope.biasResults map, searchBox
scope.performUrlSearch map

scope.createSearchBox = (map) ->
map.controls[google.maps.ControlPosition.TOP_LEFT].push scope.input
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/connected_apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def handle_error(message)

def log_and_notify_exception(exception)
Rails.logger.error exception.inspect
Bugsnag.notify(exception)
Alert.raise(exception)
end

def vine_params_empty?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v0/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def set_content_type
end

def error_during_processing(exception)
Bugsnag.notify(exception)
Alert.raise(exception)

render(json: { exception: exception.message },
status: :unprocessable_entity) && return
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def api_key
end

def error_during_processing(exception)
Bugsnag.notify(exception)
Alert.raise(exception)

if Rails.env.development? || Rails.env.test?
render status: :unprocessable_entity,
Expand Down
8 changes: 2 additions & 6 deletions app/controllers/concerns/order_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def order_invalid_for_checkout?
end

def order_invalid!
Bugsnag.notify("Notice: invalid order loaded during checkout") do |payload|
payload.add_metadata :order, :order, @order
end
Alert.raise_with_record("Notice: invalid order loaded during checkout", @order)

flash[:error] = t('checkout.order_not_loaded')
redirect_to main_app.shop_path
Expand Down Expand Up @@ -92,9 +90,7 @@ def processing_failed
end

def notify_failure(error = RuntimeError.new(order_processing_error))
Bugsnag.notify(error) do |payload|
payload.add_metadata :order, @order
end
Alert.raise_with_record(error, @order)
flash[:error] = order_processing_error if flash.blank?
end

Expand Down
4 changes: 1 addition & 3 deletions app/controllers/concerns/order_stock_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def handle_insufficient_stock
def check_order_cycle_expiry
return unless current_order_cycle&.closed?

Bugsnag.notify("Notice: order cycle closed during checkout completion") do |payload|
payload.add_metadata :order, :order, current_order
end
Alert.raise_with_record("Notice: order cycle closed during checkout completion", current_order)
current_order.empty!
current_order.set_order_cycle! nil

Expand Down
5 changes: 0 additions & 5 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ class ErrorsController < ApplicationController
layout "errors"

def not_found
Bugsnag.notify("404") do |event|
event.severity = "info"

event.add_metadata(:request, :env, request.env)
end
render status: :not_found, formats: :html
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def fire
end
rescue StandardError => e
logger.error e.message
Bugsnag.notify(e)
Alert.raise(e)
flash[:error] = e.message
ensure
redirect_to request.referer
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def set_stock_levels(product, on_hand, on_demand)
end

def notify_bugsnag(error, product, variant)
Bugsnag.notify(error) do |report|
Alert.raise(error) do |report|
report.add_metadata(:product,
{ product: product.attributes, variant: variant.attributes })
report.add_metadata(:product, :product_error, product.errors.first) unless product.valid?
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/user_registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'open_food_network/error_logger'
require "spree/core/controller_helpers/auth"
require "spree/core/controller_helpers/common"
require "spree/core/controller_helpers/order"
Expand Down Expand Up @@ -37,7 +36,7 @@ def create
end
end
rescue StandardError => e
OpenFoodNetwork::ErrorLogger.notify(e)
Alert.raise(e)
render_error(message: I18n.t('unknown_error', scope: I18N_SCOPE))
end

Expand Down
4 changes: 1 addition & 3 deletions app/jobs/backorder_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def self.check_stock(order)
rescue StandardError => e
# Errors here shouldn't affect the checkout. So let's report them
# separately:
Bugsnag.notify(e) do |payload|
payload.add_metadata(:order, :order, order)
end
Alert.raise_with_record(e, order)
end

def perform(order)
Expand Down
6 changes: 1 addition & 5 deletions app/jobs/report_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ def perform(report_class:, user:, params:, format:, blob:, channel: nil)

broadcast_result(channel, format, blob) if channel
rescue StandardError => e
Bugsnag.notify(e) do |payload|
payload.add_metadata :report, {
report_class:, user:, params:, format:
}
end
Alert.raise(e, { report: { report_class:, user:, params:, format: } })

broadcast_error(channel)
end
Expand Down
8 changes: 2 additions & 6 deletions app/jobs/stock_sync_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def self.sync_linked_catalogs(order)
rescue StandardError => e
# Errors here shouldn't affect the shopping. So let's report them
# separately:
Bugsnag.notify(e) do |payload|
payload.add_metadata(:order, :order, order)
end
Alert.raise_with_record(e, order)
end

def self.sync_linked_catalogs_now(order)
Expand All @@ -29,9 +27,7 @@ def self.sync_linked_catalogs_now(order)
rescue StandardError => e
# Errors here shouldn't affect the shopping. So let's report them
# separately:
Bugsnag.notify(e) do |payload|
payload.add_metadata(:order, :order, order)
end
Alert.raise_with_record(e, order)
end

def self.catalog_ids(order)
Expand Down
8 changes: 2 additions & 6 deletions app/jobs/subscription_confirm_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def confirm_order!(order)
if order.errors.any?
send_failed_payment_email(order)
else
Bugsnag.notify(e) do |payload|
payload.add_metadata :order, :order, order
end
Alert.raise_with_record(e, order)
send_failed_payment_email(order, e.message)
end
end
Expand Down Expand Up @@ -108,8 +106,6 @@ def send_failed_payment_email(order, error_message = nil)
record_and_log_error(:failed_payment, order, error_message)
SubscriptionMailer.failed_payment_email(order).deliver_now
rescue StandardError => e
Bugsnag.notify(e) do |payload|
payload.add_metadata :subscription_data, { order:, error_message: }
end
Alert.raise(e, { subscription_data: { order:, error_message: } })
end
end
2 changes: 1 addition & 1 deletion app/models/calculator/default_tax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def compute_order(order)
# In theory it should never be called any more after this has been deployed.
# If the message below doesn't show up in Bugsnag, we can safely delete this method and all
# the related methods below it.
Bugsnag.notify("Calculator::DefaultTax was called with legacy tax calculations")
Alert.raise("Calculator::DefaultTax was called with legacy tax calculations")

calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(order.distributor,
order.order_cycle)
Expand Down
2 changes: 1 addition & 1 deletion app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def image_url_for(image, name)

image_variant_url_for(image.variant(name))
rescue StandardError => e
Bugsnag.notify "Enterprise ##{id} #{image.try(:name)} error: #{e.message}"
Alert.raise "Enterprise ##{id} #{image.try(:name)} error: #{e.message}"
Rails.logger.error(e.message)

nil
Expand Down
4 changes: 2 additions & 2 deletions app/models/product_import/entry_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def primary_producer_error(entry)
end

def unit_fields_validation(entry)
unit_types = ['g', 'oz', 'lb', 'kg', 't', 'ml', 'l', 'kl', '']
unit_types = ['mg', 'g', 'kg', 'oz', 'lb', 't', 'ml', 'cl', 'dl', 'l', 'kl', 'gal', '']

if entry.units.blank?
mark_as_invalid(entry, attribute: 'units',
Expand Down Expand Up @@ -297,7 +297,7 @@ def inventory_validation(entry)
unscaled_units = entry.unscaled_units.to_f || 0
entry.unit_value = unscaled_units * unit_scale unless unit_scale.nil?

if entry.match_inventory_variant?(existing_variant)
if entry.match_variant?(existing_variant)
variant_override = create_inventory_item(entry, existing_variant)
return validate_inventory_item(entry, variant_override)
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/product_import/spreadsheet_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ def invalid_attributes
end

def match_variant?(variant)
match_display_name?(variant) && variant.unit_value.to_d == unscaled_units.to_d
end

def match_inventory_variant?(variant)
match_display_name?(variant) && variant.unit_value.to_d == unit_value.to_d
end

Expand Down
6 changes: 5 additions & 1 deletion app/models/product_import/unit_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ def convert_custom_unit_fields

def unit_scales
{
'mg' => { scale: 0.001, unit: 'weight' },
'g' => { scale: 1, unit: 'weight' },
'kg' => { scale: 1000, unit: 'weight' },
'oz' => { scale: 28.35, unit: 'weight' },
'lb' => { scale: 453.6, unit: 'weight' },
't' => { scale: 1_000_000, unit: 'weight' },
'ml' => { scale: 0.001, unit: 'volume' },
'cl' => { scale: 0.01, unit: 'volume' },
'dl' => { scale: 0.1, unit: 'volume' },
'l' => { scale: 1, unit: 'volume' },
'kl' => { scale: 1000, unit: 'volume' }
'kl' => { scale: 1000, unit: 'volume' },
'gal' => { scale: 4.54609, unit: 'volume' },
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def url(size)

image_variant_url_for(variant(size))
rescue StandardError => e
Bugsnag.notify "Product ##{viewable_id} Image ##{id} error: #{e.message}"
Alert.raise "Product ##{viewable_id} Image ##{id} error: #{e.message}"
Rails.logger.error(e.message)

self.class.default_image_url(size)
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def save_or_rescue_shipment(shipment)
# 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(e) do |report|
Alert.raise(e) do |report|
report.add_metadata(:order, attributes)
report.add_metadata(:shipment, shipment.attributes)
report.add_metadata(:shipment_in_db, Spree::Shipment.find_by(id: shipment.id).attributes)
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/tax_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def compute_amount(item)
calculator.compute(item)
else
# Tax refund should not be possible with the way our production server are configured
Bugsnag.notify(
Alert.raise(
"Notice: Tax refund should not be possible, please check the default zone and " \
"the tax rate zone configuration"
) do |payload|
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def destruction
end

def ensure_unit_value
Bugsnag.notify("Trying to set unit_value to NaN") if unit_value&.nan?
Alert.raise("Trying to set unit_value to NaN") if unit_value&.nan?
return unless (variant_unit == "items" && unit_value.nil?) || unit_value&.nan?

self.unit_value = 1.0
Expand Down
2 changes: 1 addition & 1 deletion app/models/stripe_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def deauthorize_and_destroy

destroy && Stripe::OAuth.deauthorize(stripe_user_id:)
rescue Stripe::OAuth::OAuthError => e
Bugsnag.notify(
Alert.raise(
e,
stripe_account: stripe_user_id,
enterprise_id:
Expand Down
8 changes: 4 additions & 4 deletions app/models/variant_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def use_producer_stock_settings?

def move_stock!(quantity)
unless stock_overridden?
Bugsnag.notify RuntimeError.new "Attempting to move stock of a VariantOverride " \
"without a count_on_hand specified."
Alert.raise "Attempting to move stock of a VariantOverride " \
"without a count_on_hand specified."
return
end

Expand All @@ -73,8 +73,8 @@ def reset_stock!
self.attributes = { on_demand: false, count_on_hand: default_stock }
save
else
Bugsnag.notify RuntimeError.new "Attempting to reset stock level for a variant " \
"with no default stock level."
Alert.raise "Attempting to reset stock level for a variant " \
"with no default stock level."
end
end
self
Expand Down
Loading
Loading