workarea-core 3.5.21 → 3.5.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/workarea/current_tracking.rb +3 -1
- data/app/models/workarea/metrics/user.rb +18 -8
- data/app/models/workarea/release.rb +8 -0
- data/app/models/workarea/search/storefront.rb +1 -5
- data/app/models/workarea/search/storefront/product.rb +1 -14
- data/app/queries/workarea/product_releases.rb +1 -11
- data/app/workers/workarea/update_email.rb +33 -0
- data/lib/workarea/changelog.rake +1 -1
- data/lib/workarea/version.rb +1 -1
- data/test/models/workarea/metrics/user_test.rb +55 -52
- data/test/workers/workarea/update_email_test.rb +39 -0
- metadata +4 -4
- data/app/workers/workarea/update_payment_profile_email.rb +0 -22
- data/test/workers/workarea/update_payment_profile_email_test.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48dfcf76f720a117fd8f3a16cdbef856816837692dc53f731b38729c5d37b9ef
|
4
|
+
data.tar.gz: a1ffa660f618f5d1b428ce4db9c6d768f0a12c3490ea45f02d699fa4b5ff441f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 509b598d21369c93345837d160e2a95d271c4c0d06276192f050a2997badec0b1542a012be9c1ed10d7bb176816372825abc08370d8fb67b3cd961a96ecb6246
|
7
|
+
data.tar.gz: 0cf582e5e981a1524f7b1cb2229f542c2d99f8b152802386aa68a42a09de7c84602ee8c07659011ecc3a1bec1ca6ddcfdb85c2e7aa8ecdcf6333c42808b81027
|
@@ -27,7 +27,9 @@ module Workarea
|
|
27
27
|
cookies.delete(:email)
|
28
28
|
elsif email != cookies.signed[:email]
|
29
29
|
unless impersonating?
|
30
|
-
Metrics::User
|
30
|
+
Metrics::User
|
31
|
+
.find_or_initialize_by(id: email)
|
32
|
+
.merge_views!(current_visit&.metrics)
|
31
33
|
end
|
32
34
|
|
33
35
|
cookies.permanent.signed[:email] = email
|
@@ -110,6 +110,8 @@ module Workarea
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def merge!(other)
|
113
|
+
return if other.blank?
|
114
|
+
|
113
115
|
# To recalculate average_order_value
|
114
116
|
self.orders += other.orders
|
115
117
|
self.revenue += other.revenue
|
@@ -132,14 +134,8 @@ module Workarea
|
|
132
134
|
update['$max'] = { last_order_at: other.last_order_at.utc } if other.last_order_at.present?
|
133
135
|
|
134
136
|
self.class.collection.update_one({ _id: id }, update, upsert: true)
|
137
|
+
other.delete
|
135
138
|
|
136
|
-
self.class.save_affinity(
|
137
|
-
id: id,
|
138
|
-
action: 'viewed',
|
139
|
-
product_ids: other.viewed.product_ids,
|
140
|
-
category_ids: other.viewed.category_ids,
|
141
|
-
search_ids: other.viewed.search_ids
|
142
|
-
)
|
143
139
|
self.class.save_affinity(
|
144
140
|
id: id,
|
145
141
|
action: 'purchased',
|
@@ -148,7 +144,21 @@ module Workarea
|
|
148
144
|
search_ids: other.purchased.search_ids
|
149
145
|
)
|
150
146
|
|
151
|
-
|
147
|
+
merge_views!(other)
|
148
|
+
end
|
149
|
+
|
150
|
+
def merge_views!(other)
|
151
|
+
return if other.blank?
|
152
|
+
|
153
|
+
self.class.save_affinity(
|
154
|
+
id: id,
|
155
|
+
action: 'viewed',
|
156
|
+
product_ids: other.viewed.product_ids,
|
157
|
+
category_ids: other.viewed.category_ids,
|
158
|
+
search_ids: other.viewed.search_ids
|
159
|
+
)
|
160
|
+
|
161
|
+
reload rescue self # save_affinity might not have actually persisted anything
|
152
162
|
end
|
153
163
|
end
|
154
164
|
end
|
@@ -129,6 +129,14 @@ module Workarea
|
|
129
129
|
scoped.sort_by { |r| [r.publish_at, r.created_at] }
|
130
130
|
end
|
131
131
|
|
132
|
+
def self.schedule_affected_by_changesets(changesets)
|
133
|
+
changesets
|
134
|
+
.uniq(&:release)
|
135
|
+
.reject { |cs| cs.release.blank? }
|
136
|
+
.flat_map { |cs| [cs.release] + cs.release.scheduled_after }
|
137
|
+
.uniq
|
138
|
+
end
|
139
|
+
|
132
140
|
def as_current
|
133
141
|
self.class.with_current(self) { yield }
|
134
142
|
end
|
@@ -83,11 +83,7 @@ module Workarea
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def releases
|
86
|
-
changesets
|
87
|
-
.uniq(&:release)
|
88
|
-
.reject { |cs| cs.release.blank? }
|
89
|
-
.flat_map { |cs| [cs.release] + cs.release.scheduled_after }
|
90
|
-
.uniq
|
86
|
+
Release.schedule_affected_by_changesets(changesets)
|
91
87
|
end
|
92
88
|
|
93
89
|
def as_document
|
@@ -122,21 +122,8 @@ module Workarea
|
|
122
122
|
ProductPrimaryImageUrl.new(model).path
|
123
123
|
end
|
124
124
|
|
125
|
-
# All {Releasable}s that could affect the product's Elasticsearch document
|
126
|
-
# should add their changesets to this method.
|
127
|
-
#
|
128
|
-
# @example Add to the changesets affecting a product in a decorator
|
129
|
-
# def changesets
|
130
|
-
# super.merge(SomeReleasable.for_product(product.id).changesets_with_children)
|
131
|
-
# end
|
132
|
-
#
|
133
|
-
# @return [Mongoid::Criteria]
|
134
|
-
#
|
135
125
|
def changesets
|
136
|
-
|
137
|
-
pricing.each { |ps| criteria.merge!(ps.changesets_with_children) }
|
138
|
-
criteria.merge!(FeaturedProducts.changesets(model.id))
|
139
|
-
criteria.includes(:release)
|
126
|
+
ProductReleases.new(model).changesets
|
140
127
|
end
|
141
128
|
|
142
129
|
private
|
@@ -1,10 +1,4 @@
|
|
1
1
|
module Workarea
|
2
|
-
#
|
3
|
-
# TODO remove in v3.6
|
4
|
-
#
|
5
|
-
# This is no longer used, this logic was moved into the search models to allow
|
6
|
-
# it to be used for any model (not just products).
|
7
|
-
#
|
8
2
|
class ProductReleases
|
9
3
|
attr_reader :product
|
10
4
|
|
@@ -13,11 +7,7 @@ module Workarea
|
|
13
7
|
end
|
14
8
|
|
15
9
|
def releases
|
16
|
-
changesets
|
17
|
-
.uniq(&:release)
|
18
|
-
.reject { |cs| cs.release.blank? }
|
19
|
-
.flat_map { |cs| [cs.release] + cs.release.scheduled_after }
|
20
|
-
.uniq
|
10
|
+
Release.schedule_affected_by_changesets(changesets)
|
21
11
|
end
|
22
12
|
|
23
13
|
# All {Releasable}s that could affect the product's Elasticsearch document
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Workarea
|
2
|
+
class UpdateEmail
|
3
|
+
include Sidekiq::Worker
|
4
|
+
include Sidekiq::CallbacksWorker
|
5
|
+
|
6
|
+
sidekiq_options(
|
7
|
+
enqueue_on: { User => :update, with: -> { [id, changes] } }
|
8
|
+
)
|
9
|
+
|
10
|
+
def perform(id, changes)
|
11
|
+
return unless changes['email'].present? && changes['email'].first.present?
|
12
|
+
|
13
|
+
old_email, new_email = changes['email']
|
14
|
+
update_payment_profile(id, old_email, new_email)
|
15
|
+
update_metrics(old_email, new_email)
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_payment_profile(id, old_email, new_email)
|
19
|
+
user = User.find(id)
|
20
|
+
user.email = old_email # set old email so we lookup by old email value
|
21
|
+
|
22
|
+
Payment::Profile.update_email(PaymentReference.new(user), new_email)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_metrics(old_email, new_email)
|
26
|
+
old_metrics = Metrics::User.find(old_email) rescue nil
|
27
|
+
return if old_metrics.blank?
|
28
|
+
|
29
|
+
new_metrics = Metrics::User.find_or_initialize_by(id: new_email)
|
30
|
+
new_metrics.merge!(old_metrics)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/workarea/changelog.rake
CHANGED
data/lib/workarea/version.rb
CHANGED
@@ -134,7 +134,7 @@ module Workarea
|
|
134
134
|
def test_merging_metrics
|
135
135
|
freeze_time
|
136
136
|
|
137
|
-
|
137
|
+
first = User.create!(
|
138
138
|
first_order_at: 2.weeks.ago,
|
139
139
|
last_order_at: 1.day.ago,
|
140
140
|
orders: 2,
|
@@ -147,41 +147,43 @@ module Workarea
|
|
147
147
|
purchased: { product_ids: ['qoo'], category_ids: ['quo'], search_ids: ['qux'] }
|
148
148
|
)
|
149
149
|
|
150
|
-
|
151
|
-
|
152
|
-
assert_equal(
|
153
|
-
assert_equal(
|
154
|
-
assert_equal(
|
155
|
-
assert_equal(
|
156
|
-
assert_equal(
|
157
|
-
assert_equal(
|
158
|
-
assert_equal(
|
159
|
-
assert_equal(
|
160
|
-
assert_equal(
|
161
|
-
assert_equal(['
|
162
|
-
assert_equal(['
|
163
|
-
assert_equal(['
|
164
|
-
assert_equal(['
|
165
|
-
assert_equal(['
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
assert_equal(1
|
171
|
-
assert_equal(2,
|
172
|
-
assert_equal(
|
173
|
-
assert_equal(
|
174
|
-
assert_equal(
|
175
|
-
assert_equal(
|
176
|
-
assert_equal(
|
177
|
-
assert_equal(
|
178
|
-
assert_equal(
|
179
|
-
assert_equal(['
|
180
|
-
assert_equal(['
|
181
|
-
assert_equal(['
|
182
|
-
assert_equal(['
|
183
|
-
|
184
|
-
|
150
|
+
first.merge!(User.new)
|
151
|
+
first.reload
|
152
|
+
assert_equal(1, Metrics::User.count)
|
153
|
+
assert_equal(2.weeks.ago, first.first_order_at)
|
154
|
+
assert_equal(1.day.ago, first.last_order_at)
|
155
|
+
assert_equal(2, first.orders)
|
156
|
+
assert_equal(100, first.revenue)
|
157
|
+
assert_equal(-10, first.discounts)
|
158
|
+
assert_equal(50, first.average_order_value)
|
159
|
+
assert_equal(1, first.cancellations)
|
160
|
+
assert_equal(-20, first.refund)
|
161
|
+
assert_equal(['foo'], first.viewed.product_ids)
|
162
|
+
assert_equal(['bar'], first.viewed.category_ids)
|
163
|
+
assert_equal(['baz'], first.viewed.search_ids)
|
164
|
+
assert_equal(['qoo'], first.purchased.product_ids)
|
165
|
+
assert_equal(['quo'], first.purchased.category_ids)
|
166
|
+
assert_equal(['qux'], first.purchased.search_ids)
|
167
|
+
|
168
|
+
second = User.create!(id: 'foo').tap { |u| u.merge!(first) }
|
169
|
+
second.reload
|
170
|
+
assert_equal(1, Metrics::User.count)
|
171
|
+
assert_equal(2.weeks.ago, second.first_order_at)
|
172
|
+
assert_equal(1.day.ago, second.last_order_at)
|
173
|
+
assert_equal(2, second.orders)
|
174
|
+
assert_equal(100, second.revenue)
|
175
|
+
assert_equal(-10, second.discounts)
|
176
|
+
assert_equal(50, second.average_order_value)
|
177
|
+
assert_equal(1, second.cancellations)
|
178
|
+
assert_equal(-20, second.refund)
|
179
|
+
assert_equal(['foo'], second.viewed.product_ids)
|
180
|
+
assert_equal(['bar'], second.viewed.category_ids)
|
181
|
+
assert_equal(['baz'], second.viewed.search_ids)
|
182
|
+
assert_equal(['qoo'], second.purchased.product_ids)
|
183
|
+
assert_equal(['quo'], second.purchased.category_ids)
|
184
|
+
assert_equal(['qux'], second.purchased.search_ids)
|
185
|
+
|
186
|
+
third = User.create!(
|
185
187
|
first_order_at: 3.weeks.ago,
|
186
188
|
last_order_at: 3.weeks.ago,
|
187
189
|
orders: 2,
|
@@ -191,22 +193,23 @@ module Workarea
|
|
191
193
|
purchased: { product_ids: ['four'], category_ids: ['five'], search_ids: ['six'] }
|
192
194
|
)
|
193
195
|
|
194
|
-
|
195
|
-
|
196
|
-
assert_equal(
|
197
|
-
assert_equal(
|
198
|
-
assert_equal(
|
199
|
-
assert_equal(
|
200
|
-
assert_equal(
|
201
|
-
assert_equal(
|
202
|
-
assert_equal(
|
203
|
-
assert_equal(
|
204
|
-
assert_equal(
|
205
|
-
assert_equal(%w(
|
206
|
-
assert_equal(%w(
|
207
|
-
assert_equal(%w(
|
208
|
-
assert_equal(%w(
|
209
|
-
assert_equal(%w(
|
196
|
+
third.merge!(second)
|
197
|
+
third.reload
|
198
|
+
assert_equal(1, Metrics::User.count)
|
199
|
+
assert_equal(3.weeks.ago, third.first_order_at)
|
200
|
+
assert_equal(1.day.ago, third.last_order_at)
|
201
|
+
assert_equal(4, third.orders)
|
202
|
+
assert_equal(220, third.revenue)
|
203
|
+
assert_equal(-10, third.discounts)
|
204
|
+
assert_equal(55, third.average_order_value)
|
205
|
+
assert_equal(1, third.cancellations)
|
206
|
+
assert_equal(-20, third.refund)
|
207
|
+
assert_equal(%w(one foo), third.viewed.product_ids)
|
208
|
+
assert_equal(%w(two bar), third.viewed.category_ids)
|
209
|
+
assert_equal(%w(three baz), third.viewed.search_ids)
|
210
|
+
assert_equal(%w(four qoo), third.purchased.product_ids)
|
211
|
+
assert_equal(%w(five quo), third.purchased.category_ids)
|
212
|
+
assert_equal(%w(six qux), third.purchased.search_ids)
|
210
213
|
end
|
211
214
|
end
|
212
215
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class UpdateEmailTest < TestCase
|
5
|
+
def test_updating_payment_profile
|
6
|
+
user = create_user(email: 'user@workarea.com')
|
7
|
+
profile = Payment::Profile.lookup(PaymentReference.new(user))
|
8
|
+
|
9
|
+
UpdateEmail.new.perform(user.id.to_s, 'email' => [nil, 'user@workarea.com'])
|
10
|
+
assert_equal(profile.reload.email, 'user@workarea.com')
|
11
|
+
|
12
|
+
UpdateEmail.new.perform(
|
13
|
+
user.id.to_s,
|
14
|
+
'email' => ['user@workarea.com', 'test@workarea.com']
|
15
|
+
)
|
16
|
+
assert_equal(profile.reload.email, 'test@workarea.com')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_updating_metrics
|
20
|
+
user = create_user(email: 'user@workarea.com')
|
21
|
+
old_metrics = Metrics::User.find_or_initialize_by(id: 'user@workarea.com')
|
22
|
+
old_metrics.update!(orders: 3)
|
23
|
+
|
24
|
+
UpdateEmail.new.perform(user.id.to_s, 'email' => [nil, 'user@workarea.com'])
|
25
|
+
assert_equal(1, Metrics::User.count)
|
26
|
+
assert_equal(3, old_metrics.reload.orders)
|
27
|
+
|
28
|
+
new_metrics = Metrics::User.create!(id: 'test@workarea.com', orders: 1)
|
29
|
+
|
30
|
+
UpdateEmail.new.perform(
|
31
|
+
user.id.to_s,
|
32
|
+
'email' => ['user@workarea.com', 'test@workarea.com']
|
33
|
+
)
|
34
|
+
assert_equal(1, Metrics::User.count)
|
35
|
+
assert_raises(Mongoid::Errors::DocumentNotFound) { old_metrics.reload }
|
36
|
+
assert_equal(4, new_metrics.reload.orders)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.
|
4
|
+
version: 3.5.22
|
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-
|
11
|
+
date: 2020-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -1795,7 +1795,7 @@ files:
|
|
1795
1795
|
- app/workers/workarea/status_reporter.rb
|
1796
1796
|
- app/workers/workarea/synchronize_user_metrics.rb
|
1797
1797
|
- app/workers/workarea/update_elasticsearch_settings.rb
|
1798
|
-
- app/workers/workarea/
|
1798
|
+
- app/workers/workarea/update_email.rb
|
1799
1799
|
- app/workers/workarea/verify_scheduled_releases.rb
|
1800
1800
|
- bin/rails
|
1801
1801
|
- config/i18n-js.yml
|
@@ -2499,7 +2499,7 @@ files:
|
|
2499
2499
|
- test/workers/workarea/send_refund_email_test.rb
|
2500
2500
|
- test/workers/workarea/status_reporter_test.rb
|
2501
2501
|
- test/workers/workarea/synchronize_user_metrics_test.rb
|
2502
|
-
- test/workers/workarea/
|
2502
|
+
- test/workers/workarea/update_email_test.rb
|
2503
2503
|
- test/workers/workarea/verify_scheduled_releases_test.rb
|
2504
2504
|
- vendor/active_shipping/.gitignore
|
2505
2505
|
- vendor/active_shipping/.travis.yml
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Workarea
|
2
|
-
class UpdatePaymentProfileEmail
|
3
|
-
include Sidekiq::Worker
|
4
|
-
include Sidekiq::CallbacksWorker
|
5
|
-
|
6
|
-
sidekiq_options(
|
7
|
-
enqueue_on: { User => :update, with: -> { [id, changes] } }
|
8
|
-
)
|
9
|
-
|
10
|
-
def perform(id, changes)
|
11
|
-
if changes['email'].present? && changes['email'].first.present?
|
12
|
-
old_email = changes['email'].first
|
13
|
-
new_email = changes['email'].last
|
14
|
-
|
15
|
-
user = User.find(id)
|
16
|
-
user.email = old_email # set old email so we lookup by old email value
|
17
|
-
|
18
|
-
Payment::Profile.update_email(PaymentReference.new(user), new_email)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Workarea
|
4
|
-
class UpdatePaymentProfileEmailTest < Workarea::TestCase
|
5
|
-
setup do
|
6
|
-
@user = create_user(email: 'user@workarea.com')
|
7
|
-
@profile = Payment::Profile.lookup(PaymentReference.new(@user))
|
8
|
-
@worker = UpdatePaymentProfileEmail.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_updating_payment_profile_email_address
|
12
|
-
@worker.perform(
|
13
|
-
@user.id.to_s,
|
14
|
-
'email' => ['user@workarea.com', 'test@workarea.com']
|
15
|
-
)
|
16
|
-
|
17
|
-
@profile.reload
|
18
|
-
assert_equal(@profile.email, 'test@workarea.com')
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_skipping_update_if_email_change_is_nil
|
22
|
-
@worker.perform(@user.id.to_s, 'email' => [nil, 'user@workarea.com'])
|
23
|
-
@profile.reload
|
24
|
-
assert_equal(@profile.email, 'user@workarea.com')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|