workarea-core 3.5.18 → 3.5.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84d99f1dbf010e7d67b9dbc7785720bbed5cd17c22528dfe57e194dfbb660892
4
- data.tar.gz: c5453a27cf96335ae9d35fe857ccc770a0412117579b37dc1cb84e9221cd6efe
3
+ metadata.gz: a59bf88202898e6d59be0edbdb90c7000fe606fa3ab522aee27079288708e262
4
+ data.tar.gz: 76cb3fbfaf8847f50b296cb1790bc6997f9b79f304af9131854442ba779c465d
5
5
  SHA512:
6
- metadata.gz: 4605fd9a72741e6cac8ab7a32d2408ba1b8f2bfb79ac875875461ab59fe660ffd5254e3b0eb69d5534222217de0ec2fc3d60351bee5e7575d93d2393fb8d9221
7
- data.tar.gz: e2946da1f9618bc92f65ceca4281c426747f4c75d162b33e68a6fe629008507c43e07dcde39e12f871b2f0011225f40bfd5d9ecdc8d7f563586b90900f43c447
6
+ metadata.gz: 88354b9cb2e04bca758bfa1f1d089a979684a1e18bdb37c54d523ed622e47c7131f2cf4c41d4baa71d1bb712a888c7fb6b40d1c34cc6b972d4dde8c5c8fbe892
7
+ data.tar.gz: d6008ffbfc3f803061e92a43d1b598b3179c51ed2205175b63213fe66525a25c71ee2d53e5b87761d0c70f703c325654dc58499a5e8aa3a07100642388039f02
@@ -1,7 +1,6 @@
1
1
  module Workarea
2
2
  module CurrentTracking
3
3
  extend ActiveSupport::Concern
4
- include HttpCaching
5
4
 
6
5
  included do
7
6
  before_action :ensure_current_metrics
@@ -27,7 +26,10 @@ module Workarea
27
26
  if email.blank?
28
27
  cookies.delete(:email)
29
28
  elsif email != cookies.signed[:email]
30
- Metrics::User.find_or_initialize_by(id: email).merge!(current_visit&.metrics)
29
+ unless impersonating?
30
+ Metrics::User.find_or_initialize_by(id: email).merge!(current_visit&.metrics)
31
+ end
32
+
31
33
  cookies.permanent.signed[:email] = email
32
34
  end
33
35
 
@@ -15,10 +15,11 @@ module Workarea
15
15
  session[:user_id] = user.id.to_s
16
16
 
17
17
  user.mark_impersonated_by!(current_user)
18
- @current_user = user
18
+ update_tracking!(email: user.email)
19
19
  end
20
20
 
21
21
  def stop_impersonation
22
+ update_tracking!(email: current_admin.email)
22
23
  session[:user_id] = current_admin.id.to_s
23
24
  session.delete(:admin_id)
24
25
  end
@@ -33,17 +33,17 @@ module Workarea
33
33
  # To allow for custom policies defining their own methods here
34
34
  Workarea.config.fulfillment_policies.each do |class_name|
35
35
  define_method "#{class_name.demodulize.underscore}?" do
36
- fulfillment == class_name.demodulize.underscore
36
+ fulfilled_by?(class_name.demodulize.underscore)
37
37
  end
38
38
  end
39
39
 
40
40
  # These methods exist for findability
41
41
  def shipping?
42
- fulfillment == 'shipping'
42
+ fulfilled_by?('shipping')
43
43
  end
44
44
 
45
45
  def download?
46
- fulfillment == 'download'
46
+ fulfilled_by?('download')
47
47
  end
48
48
 
49
49
  # Whether this order has any items that need to be fulfilled by a particular
@@ -53,7 +53,7 @@ module Workarea
53
53
  # @return [Boolean]
54
54
  #
55
55
  def fulfilled_by?(*types)
56
- types.any? { |t| send("#{t}?") }
56
+ types.map(&:to_s).include?(fulfillment)
57
57
  end
58
58
 
59
59
  # Whether this item is a digital (not-shipped) type of item.
@@ -11,7 +11,11 @@ module Workarea
11
11
  end
12
12
 
13
13
  def jump_to_text
14
- "#{model.id} (#{model.available} available)"
14
+ I18n.t(
15
+ 'workarea.inventory_sku.jump_to_text',
16
+ id: model.id,
17
+ count: model.available_to_sell
18
+ )
15
19
  end
16
20
 
17
21
  def jump_to_position
@@ -37,15 +37,22 @@ module Workarea
37
37
  end
38
38
 
39
39
  def self.by_price(price)
40
- cache.select do |method|
41
- (method.subtotal_min.nil? || method.subtotal_min <= price) &&
42
- (method.subtotal_max.nil? || method.subtotal_max >= price)
40
+ cache.select do |service|
41
+ (service.subtotal_min.nil? || service.subtotal_min <= price) &&
42
+ (service.subtotal_max.nil? || service.subtotal_max >= price)
43
43
  end
44
44
  end
45
45
 
46
46
  def self.find_tax_code(carrier, name)
47
- method = find_by(carrier: carrier, name: name) rescue nil
48
- method.try(:tax_code)
47
+ service = find_by(carrier: carrier, name: name) rescue nil
48
+ service.present? ? service.tax_code : default_tax_code(carrier, name)
49
+ end
50
+
51
+ def self.default_tax_code(carrier, name)
52
+ default = Workarea.config.default_shipping_service_tax_code
53
+ return default unless default.respond_to?(:call)
54
+
55
+ default.call(carrier, name)
49
56
  end
50
57
 
51
58
  def find_rate(price = 0.to_m)
@@ -76,6 +76,17 @@ Workarea::Configuration.define_fields do
76
76
  zip: '19106'
77
77
  },
78
78
  description: 'Origin location for calculating shipping costs'
79
+
80
+ # This can be overwritten within the app to use a proc for more complex
81
+ # scenarios.
82
+ field 'Default Shipping Service Tax Code',
83
+ type: String,
84
+ allow_blank: true,
85
+ description: %(
86
+ Tax code assigned to shipping options when an existing service does
87
+ not exist. This is useful for third-party gateways to assign tax codes
88
+ to dynamically generated options.
89
+ ).squish
79
90
  end
80
91
 
81
92
  fieldset 'Payment', namespaced: false do
@@ -102,6 +102,7 @@ en:
102
102
  name: "Fulfillment SKU %{id}"
103
103
  inventory_sku:
104
104
  name: "Inventory %{id}"
105
+ jump_to_text: "%{id} (%{count} sellable)"
105
106
  inquiry:
106
107
  subjects: {}
107
108
  order:
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 5
5
- PATCH = 18
5
+ PATCH = 19
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
8
8
 
@@ -6,7 +6,6 @@ module Workarea
6
6
  attr_writer :override_segments
7
7
 
8
8
  delegate :postal_code, :city, :subdivision, :region, :country, to: :geolocation
9
- delegate :admin?, to: :metrics
10
9
 
11
10
  def initialize(env)
12
11
  @env = env
@@ -25,6 +24,14 @@ module Workarea
25
24
  session[:user_id].present?
26
25
  end
27
26
 
27
+ def impersonating?
28
+ session[:admin_id].present?
29
+ end
30
+
31
+ def admin?
32
+ (logged_in? && impersonating?) || metrics.admin?
33
+ end
34
+
28
35
  def request
29
36
  @request ||= ActionDispatch::Request.new(env)
30
37
  end
@@ -3,8 +3,9 @@ require 'test_helper'
3
3
  module Workarea
4
4
  class AuthenticationTest < IntegrationTest
5
5
  class AuthenticationController < Workarea::ApplicationController
6
- include Authentication
7
6
  include HttpCaching
7
+ include Authentication
8
+ include Impersonation
8
9
  include Storefront::CurrentCheckout
9
10
 
10
11
  before_action :cache_page, only: :cached
@@ -55,6 +55,15 @@ module Workarea
55
55
  )
56
56
  assert(item.on_sale?)
57
57
  end
58
+
59
+ def test_fulfilled_by?
60
+ item.fulfillment = 'shipping'
61
+ assert(item.fulfilled_by?(:shipping))
62
+ assert(item.fulfilled_by?(:shipping, :download))
63
+ refute(item.fulfilled_by?(:download))
64
+ assert(item.shipping?)
65
+ refute(item.download?)
66
+ end
58
67
  end
59
68
  end
60
69
  end
@@ -35,6 +35,32 @@ module Workarea
35
35
  assert_equal(3.to_m, shipping_service.find_rate(7.to_m).price)
36
36
  assert_equal(2.to_m, shipping_service.find_rate(10.to_m).price)
37
37
  end
38
+
39
+ def test_find_tax_code
40
+ create_shipping_service(name: 'Ground', carrier: 'UPS', tax_code: '001')
41
+ create_shipping_service(name: 'Express', carrier: 'UPS', tax_code: nil)
42
+ Workarea.config.default_shipping_service_tax_code = nil
43
+
44
+ assert_equal('001', Service.find_tax_code('UPS', 'Ground'))
45
+ assert_nil(Service.find_tax_code('UPS', 'Express'))
46
+ assert_nil(Service.find_tax_code('FedEx', 'Express'))
47
+
48
+ Workarea.config.default_shipping_service_tax_code = '101'
49
+
50
+ assert_equal('001', Service.find_tax_code('UPS', 'Ground'))
51
+ assert_nil(Service.find_tax_code('UPS', 'Express'))
52
+ assert_equal('101', Service.find_tax_code('FedEx', 'Express'))
53
+ assert_equal('101', Service.find_tax_code('FedEx', 'Express'))
54
+
55
+ Workarea.config.default_shipping_service_tax_code = -> (carrier, name) do
56
+ carrier == 'FedEx' ? '101' : '001'
57
+ end
58
+
59
+ assert_equal('001', Service.find_tax_code('UPS', 'Ground'))
60
+ assert_nil(Service.find_tax_code('UPS', 'Express'))
61
+ assert_equal('101', Service.find_tax_code('FedEx', 'Express'))
62
+ assert_equal('001', Service.find_tax_code('DHL', 'Overnight'))
63
+ end
38
64
  end
39
65
  end
40
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.18
4
+ version: 3.5.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Crouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-01 00:00:00.000000000 Z
11
+ date: 2020-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler