dscf-core 0.3.14 → 0.3.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04dc0626657988f601694e4e423b72fbc82996d6960178bc52024aa1de41bfe8
4
- data.tar.gz: 9270c931ab649cf64b2265e0680ea36cdea14c85cb7d73439e66035a4336bae1
3
+ metadata.gz: 8d0212cd56d88328433f2976b536c39cdbbe16a240b2ab3ede3a9ed25e07818b
4
+ data.tar.gz: 16d3d5cfb125698800e11250de6c53d03747962acaa4a63899fb326ae482be62
5
5
  SHA512:
6
- metadata.gz: 369e0eb673118c48fafb0c41ab308a926cda01ba05348047db3907fa988ca569185c9f5c899f9a5d560ed728271b2bc273baed41abe2a62695eca5171d52ef88
7
- data.tar.gz: fa2cc032c4fb2ce73478517a353896dd03dc36717a05839b8fde475308d41215d0b396cde8aa935a1fed48ffe9b5b437909c067a5548434d048fed3ce808fbd0
6
+ metadata.gz: 95fc979d818ab2875ab6426f224eb06bcd39e4faea8fbf94896ba5236ae82d9d584ee1fb71955c25c9231b02b6f7c31b61f3cf82eacbb78aaa325a1a68efa114
7
+ data.tar.gz: 824300b9d0ed578d6b600bf150c0bf10992c227c5a20071e4162230f50e263998555d86f9156598ce5402484421712bce41baef28baf510e08c57089b0cfa833
@@ -41,6 +41,8 @@ module Dscf
41
41
 
42
42
  def signup
43
43
  skip_authorization
44
+ return signup_retailer if params[:retailer].present?
45
+
44
46
  user = User.new(user_params)
45
47
 
46
48
  return render_error("auth.errors.missing_email_or_phone") unless user.email.present? || user.phone.present?
@@ -58,8 +60,6 @@ module Dscf
58
60
 
59
61
  # Optionally create marketplace records when onboarding via mobile app
60
62
  create_agent_from_signup!(user) if params[:agent].present?
61
- create_retailer_from_signup!(user) if params[:retailer].present?
62
-
63
63
  user_with_includes = User.includes(roles: :permissions, user_profile: {}).find(user.id)
64
64
  render_success(
65
65
  "auth.success.signup",
@@ -129,7 +129,7 @@ module Dscf
129
129
  :password,
130
130
  :password_confirmation,
131
131
  :temp_password,
132
- user_profile_attributes: %i[first_name last_name date_of_birth address]
132
+ user_profile_attributes: %i[first_name last_name gender date_of_birth]
133
133
  )
134
134
  end
135
135
 
@@ -150,53 +150,46 @@ module Dscf
150
150
  )
151
151
  end
152
152
 
153
- # Creates a Retailer record when included in signup request (mobile onboarding)
154
- def create_retailer_from_signup!(user)
155
- return unless defined?(Dscf::Marketplace::Retailer)
156
-
157
- # `authenticate_user` is skipped for this action so self-service
158
- # signup stays public, but `current_user` still resolves whatever
159
- # Bearer token was sent — an agent onboarding a retailer on their
160
- # behalf attaches their own token, so we derive the onboarding
161
- # agent from it rather than trusting a client-supplied agent_id
162
- # (there is none in this params shape today, but this keeps the
163
- # same trust model as the rest of the agent-assisted flows).
164
- # Guard on current_user first: find_by(user_id: nil) matches any
165
- # Agent row with a null user_id, silently attributing anonymous
166
- # self-signups to a random agent (confirmed live in dscf_marketplace's
167
- # equivalent bug — same fix applied here).
168
- onboarding_agent = if current_user && defined?(Dscf::Marketplace::Agent)
169
- Dscf::Marketplace::Agent.find_by(user_id: current_user.id)
153
+ def signup_retailer
154
+ unless defined?(Dscf::Marketplace::Retailer::Registration)
155
+ return render_error(errors: ["Retailer registration is unavailable"], status: :unprocessable_entity)
170
156
  end
171
157
 
172
- retailer = Dscf::Marketplace::Retailer.create!(
173
- name: retailer_signup_params[:name],
174
- phone: retailer_signup_params[:phone],
175
- tin_number: retailer_signup_params[:tin_number],
176
- location: retailer_signup_params[:location],
177
- user: user,
178
- agent: onboarding_agent,
179
- onboarded_at: (Time.current if onboarding_agent)
180
- )
158
+ registration = Dscf::Marketplace::Retailer::Registration.new(
159
+ user_attributes: user_params,
160
+ retailer_attributes: retailer_signup_params,
161
+ address_attributes: address_signup_params,
162
+ actor: current_user,
163
+ obsolete_profile_address: obsolete_profile_address?
164
+ ).create!
181
165
 
182
- if retailer.location.present? && defined?(Dscf::Core::Address)
183
- lat_str, lng_str = retailer.location.split(",")
184
- lat = lat_str.to_f
185
- lng = lng_str.to_f
186
-
187
- if lat != 0.0 && lng != 0.0
188
- Dscf::Core::Address.create!(
189
- user: user,
190
- address_type: :shipping,
191
- country: "Ethiopia",
192
- city: "Addis Ababa",
193
- latitude: lat,
194
- longitude: lng
195
- )
196
- end
197
- end
198
- rescue => e
199
- logger.warn "Failed to auto-create address from retailer onboarding location: #{e.message}"
166
+ user_with_includes = User.includes(roles: :permissions, user_profile: {}).find(registration.user.id)
167
+ render_success(
168
+ "auth.success.signup",
169
+ data: {
170
+ user: user_with_includes,
171
+ retailer: registration.retailer,
172
+ address: registration.address
173
+ },
174
+ status: :created,
175
+ serializer_options: {
176
+ user: {
177
+ serializer: Dscf::Core::UserAuthSerializer,
178
+ include: [:user_profile, roles: [:permissions]]
179
+ },
180
+ retailer: {
181
+ serializer: Dscf::Marketplace::RetailerSerializer
182
+ },
183
+ address: {
184
+ serializer: Dscf::Core::AddressSerializer
185
+ }
186
+ }
187
+ )
188
+ rescue Dscf::Marketplace::Retailer::Registration::InvalidInput => e
189
+ render_error("auth.errors.signup_failed", errors: e.errors, status: :unprocessable_entity)
190
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
191
+ errors = e.respond_to?(:record) && e.record ? e.record.errors.full_messages : [e.message]
192
+ render_error("auth.errors.signup_failed", errors: errors, status: :unprocessable_entity)
200
193
  end
201
194
 
202
195
  def agent_signup_params
@@ -204,7 +197,21 @@ module Dscf
204
197
  end
205
198
 
206
199
  def retailer_signup_params
207
- params.fetch(:retailer, {}).permit(:name, :phone, :tin_number, :location)
200
+ params.fetch(:retailer, {}).permit(
201
+ :name, :phone, :tin_number, :location, :branch_count,
202
+ preferred_category_ids: []
203
+ )
204
+ end
205
+
206
+ def address_signup_params
207
+ params.fetch(:address, {}).permit(
208
+ :country, :city, :sub_city, :woreda, :kebele,
209
+ :house_numbers, :po_box, :latitude, :longitude
210
+ )
211
+ end
212
+
213
+ def obsolete_profile_address?
214
+ params.dig(:user, :user_profile_attributes)&.key?(:address)
208
215
  end
209
216
  end
210
217
  end
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Core
3
- VERSION = "0.3.14".freeze
3
+ VERSION = "0.3.15".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2026-07-30 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -589,7 +589,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
589
589
  - !ruby/object:Gem::Version
590
590
  version: '0'
591
591
  requirements: []
592
- rubygems_version: 3.6.9
592
+ rubygems_version: 3.6.2
593
593
  specification_version: 4
594
594
  summary: An Engine for Supply Chain Financing
595
595
  test_files: []