spree_cm_commissioner 2.3.0.pre.pre17 → 2.3.0.pre.pre18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/spree/api/v2/storefront/line_items_controller.rb +1 -0
- data/app/interactors/spree_cm_commissioner/user_registration_with_id_token.rb +72 -36
- data/app/models/spree_cm_commissioner/line_item_decorator.rb +5 -0
- data/app/serializers/spree/v2/storefront/line_item_serializer_decorator.rb +2 -0
- data/lib/spree_cm_commissioner/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31d13343c99ba15786dc8ea2706e64fd79ada05ce505f06fea9dfdffd24f1313
|
|
4
|
+
data.tar.gz: 2638b1befd6df8abbc2ed8bcabfd447bb15bb2006336e2ff894662c58c07e933
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 487aa62c3894d83cd38036169a677ab79633f9792654e4d87e59c61fdbbe6a6bb60cd303f69727e093fc37fcf41c361ad43fbb2f60e79f84e5cd6e830aa05ed2
|
|
7
|
+
data.tar.gz: 608a5d18e523889840e11a31f2686d357636de604fb360abb0c5074c1f3eda129c33012e779f5dc5ce025aed2842eb605cb051014217fccf4fa36361b8315fb5
|
data/Gemfile.lock
CHANGED
|
@@ -2,26 +2,54 @@ module SpreeCmCommissioner
|
|
|
2
2
|
class UserRegistrationWithIdToken < BaseInteractor
|
|
3
3
|
# :id_token
|
|
4
4
|
def call
|
|
5
|
+
firebase_context = validate_firebase_token!
|
|
6
|
+
return if firebase_context.nil?
|
|
7
|
+
|
|
8
|
+
ActiveRecord::Base.transaction do
|
|
9
|
+
find_or_register_user!(firebase_context.provider[:name], firebase_context.provider[:email])
|
|
10
|
+
link_user_account!(firebase_context.provider)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def validate_firebase_token!
|
|
5
17
|
firebase_context = SpreeCmCommissioner::FirebaseIdTokenProvider.call(id_token: context.id_token)
|
|
18
|
+
return firebase_context if firebase_context.success?
|
|
6
19
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
context.fail!(message: firebase_context.message)
|
|
21
|
+
nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def find_or_register_user!(name, email)
|
|
25
|
+
if email.present?
|
|
26
|
+
register_user_with_email!(name, email)
|
|
12
27
|
else
|
|
13
|
-
|
|
28
|
+
register_user_without_email!(name)
|
|
14
29
|
end
|
|
15
30
|
end
|
|
16
31
|
|
|
17
|
-
def
|
|
18
|
-
user = Spree.user_class.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
def register_user_with_email!(name, email)
|
|
33
|
+
user = Spree.user_class.find_by(email: email, tenant_id: context.tenant_id)
|
|
34
|
+
return context.user = ensure_user_confirmed!(user) if user.present?
|
|
35
|
+
|
|
36
|
+
begin
|
|
37
|
+
context.user = Spree.user_class.find_or_create_by!(email: email, tenant_id: context.tenant_id) do |u|
|
|
38
|
+
assign_user_attributes(u, name)
|
|
39
|
+
end
|
|
40
|
+
# Handle potential race condition: Another request might have created the user
|
|
41
|
+
# between our find_by and find_or_create_by calls. If we get a RecordNotUnique,
|
|
42
|
+
# it means the user was created by another process, so we find and return it.
|
|
43
|
+
rescue ActiveRecord::RecordNotUnique
|
|
44
|
+
user = Spree.user_class.find_by!(email: email, tenant_id: context.tenant_id)
|
|
45
|
+
context.user = ensure_user_confirmed!(user)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def register_user_without_email!(name)
|
|
50
|
+
user = Spree.user_class.new(email: nil, tenant_id: context.tenant_id)
|
|
51
|
+
assign_user_attributes(user, name)
|
|
52
|
+
|
|
25
53
|
if user.save(validate: false)
|
|
26
54
|
context.user = user
|
|
27
55
|
else
|
|
@@ -29,39 +57,32 @@ module SpreeCmCommissioner
|
|
|
29
57
|
end
|
|
30
58
|
end
|
|
31
59
|
|
|
60
|
+
def assign_user_attributes(user, name)
|
|
61
|
+
user.password = SecureRandom.base64(16)
|
|
62
|
+
user.confirmed_at = Time.zone.now
|
|
63
|
+
user.assign_attributes(name_attributes(name))
|
|
64
|
+
end
|
|
65
|
+
|
|
32
66
|
def name_attributes(name)
|
|
33
67
|
full_name = name&.strip
|
|
34
68
|
return {} if full_name.blank?
|
|
35
69
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
last_name =
|
|
39
|
-
|
|
40
|
-
attributes = {}
|
|
41
|
-
attributes[:first_name] = first_name if first_name.present?
|
|
42
|
-
attributes[:last_name] = last_name if last_name.present?
|
|
70
|
+
parts = full_name.split
|
|
71
|
+
attributes = { first_name: parts[0] }
|
|
72
|
+
attributes[:last_name] = parts[1..].join(' ') if parts.size > 1
|
|
43
73
|
|
|
44
74
|
attributes
|
|
45
75
|
end
|
|
46
76
|
|
|
47
|
-
# provider object
|
|
48
|
-
|
|
49
|
-
# {
|
|
50
|
-
# identity_type: identity_type,
|
|
51
|
-
# sub: sub
|
|
52
|
-
# }
|
|
53
|
-
|
|
54
77
|
def link_user_account!(provider)
|
|
55
78
|
identity_type = SpreeCmCommissioner::UserIdentityProvider.identity_types[provider[:identity_type]]
|
|
79
|
+
user_identity_provider = find_or_initialize_identity_provider(identity_type)
|
|
56
80
|
|
|
57
|
-
user_identity_provider
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
user_identity_provider.sub = provider[:sub]
|
|
63
|
-
user_identity_provider.email = provider[:email]
|
|
64
|
-
user_identity_provider.name = provider[:name]
|
|
81
|
+
user_identity_provider.assign_attributes(
|
|
82
|
+
sub: provider[:sub],
|
|
83
|
+
email: provider[:email],
|
|
84
|
+
name: provider[:name]
|
|
85
|
+
)
|
|
65
86
|
|
|
66
87
|
if user_identity_provider.save
|
|
67
88
|
context.user_identity_provider = user_identity_provider
|
|
@@ -69,5 +90,20 @@ module SpreeCmCommissioner
|
|
|
69
90
|
context.fail!(message: user_identity_provider.errors.full_messages)
|
|
70
91
|
end
|
|
71
92
|
end
|
|
93
|
+
|
|
94
|
+
def find_or_initialize_identity_provider(identity_type)
|
|
95
|
+
SpreeCmCommissioner::UserIdentityProvider.where(
|
|
96
|
+
user_id: context.user,
|
|
97
|
+
identity_type: identity_type
|
|
98
|
+
).first_or_initialize
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Ensure user is confirmed when linking with identity provider.
|
|
102
|
+
# Users created via OAuth should be auto-confirmed since they've proven
|
|
103
|
+
# their identity through the OAuth provider.
|
|
104
|
+
def ensure_user_confirmed!(user)
|
|
105
|
+
user.update(confirmed_at: Time.zone.now) if user.confirmed_at.nil?
|
|
106
|
+
user
|
|
107
|
+
end
|
|
72
108
|
end
|
|
73
109
|
end
|
|
@@ -22,6 +22,11 @@ module SpreeCmCommissioner
|
|
|
22
22
|
base.has_many :pending_guests, pending_guests_query, class_name: 'SpreeCmCommissioner::Guest', dependent: :destroy
|
|
23
23
|
base.has_many :product_completion_steps, class_name: 'SpreeCmCommissioner::ProductCompletionStep', through: :product
|
|
24
24
|
|
|
25
|
+
base.has_many :saved_guests,
|
|
26
|
+
through: :guests,
|
|
27
|
+
source: :saved_guest,
|
|
28
|
+
class_name: 'SpreeCmCommissioner::SavedGuest'
|
|
29
|
+
|
|
25
30
|
base.before_validation -> { self.product_type = variant.product_type || product.product_type }, if: -> { product_type.nil? }
|
|
26
31
|
|
|
27
32
|
base.before_save :update_vendor_id
|
|
@@ -25,6 +25,8 @@ module Spree
|
|
|
25
25
|
|
|
26
26
|
base.has_many :guests, serializer: SpreeCmCommissioner::V2::Storefront::GuestSerializer
|
|
27
27
|
|
|
28
|
+
base.has_many :saved_guests, serializer: SpreeCmCommissioner::V2::Storefront::SavedGuestSerializer
|
|
29
|
+
|
|
28
30
|
base.has_many :pending_guests, serializer: SpreeCmCommissioner::V2::Storefront::GuestSerializer
|
|
29
31
|
|
|
30
32
|
base.has_one :product, serializer: Spree::V2::Storefront::ProductSerializer
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spree_cm_commissioner
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.3.0.pre.
|
|
4
|
+
version: 2.3.0.pre.pre18
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- You
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: spree
|