spree_cm_commissioner 1.17.0 → 1.18.0

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: 9270cf6464159655e0c794de5c2cfd928bb6a696707676f4166a5062d80810d1
4
- data.tar.gz: e5039d47fd725c87a214187184f9610fd7be488b1d0e5b75925ec382088d0fc0
3
+ metadata.gz: 2c10fd2782b1a1ac7ecab5d27e02a49212f8e816f8f2325fadbcd717fe9882e9
4
+ data.tar.gz: 3b1b296e3403e5dd040063c19a3ac4952afafb617af17cd2ca924ea8df25de23
5
5
  SHA512:
6
- metadata.gz: 22b9ab443f30d5214daa18cb51b487c7bbce4764af5a4c27afe3d65b20102c11536a75122167b58bd9b12030b0e9cd737e89f6b3424a2894a746d07917baa154
7
- data.tar.gz: 4bc00907e7fe3afe5d7266fcb0b40cde518d3b9c9f9bd343ef7b0e80caaa958e76f127028d87292a53e7204fc50b7d4e9e56e48a1c81d7500bcd53bc4275e9ab
6
+ metadata.gz: 1f31cf8a9073664246d505c0494b2da2dc6565ec14c57fae06f34320039a478af4d8a1e0ee5eb1e68c42a5de37baf393bee0e791f7d9dfb8fd2b66356f143566
7
+ data.tar.gz: e29ba3d6d3e2d8343209260edd69117fe67c14ea1c20c13891b6cd9930f044467daa7b2fffaff51ab27db42e98eb7f43a85254e33a4644927e3eb61a1e9d742f
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GIT
34
34
  PATH
35
35
  remote: .
36
36
  specs:
37
- spree_cm_commissioner (1.17.0)
37
+ spree_cm_commissioner (1.18.0)
38
38
  activerecord-multi-tenant
39
39
  activerecord_json_validator (~> 2.1, >= 2.1.3)
40
40
  aws-sdk-cloudfront
@@ -572,10 +572,6 @@ GEM
572
572
  nokogiri (1.15.4)
573
573
  mini_portile2 (~> 2.8.2)
574
574
  racc (~> 1.4)
575
- nokogiri (1.15.4-x86_64-darwin)
576
- racc (~> 1.4)
577
- nokogiri (1.15.4-x86_64-linux)
578
- racc (~> 1.4)
579
575
  noticed (1.6.3)
580
576
  http (>= 4.0.0)
581
577
  rails (>= 5.2.0)
@@ -38,7 +38,24 @@ module Spree
38
38
  def update
39
39
  spree_authorize! :update, spree_current_order, order_token
40
40
 
41
- if resource.update(guest_params)
41
+ if guest_params[:guest_dynamic_fields_attributes]
42
+ resource.guest_dynamic_fields.destroy_all
43
+
44
+ guest_params[:guest_dynamic_fields_attributes].each do |attr|
45
+ field = resource.guest_dynamic_fields.build(attr.except(:id))
46
+
47
+ if field.dynamic_field.requires_dynamic_field_options?
48
+ option = field.dynamic_field.dynamic_field_options.find_by(id: field.value)
49
+ field.dynamic_field_option = option if option
50
+ end
51
+
52
+ field.save!
53
+ end
54
+ end
55
+
56
+ resource.assign_attributes(guest_params.except(:guest_dynamic_fields_attributes))
57
+
58
+ if resource.save
42
59
  render_serialized_payload { serialize_resource(resource) }
43
60
  else
44
61
  render_error_payload(resource, 400)
@@ -76,7 +93,7 @@ module Spree
76
93
  :upload_later,
77
94
  :country_code,
78
95
  :contact,
79
- guest_dynamic_fields_attributes: %i[id dynamic_field_id value _destroy]
96
+ guest_dynamic_fields_attributes: %i[id dynamic_field_id dynamic_field_option_id value _destroy]
80
97
  )
81
98
  end
82
99
  end
@@ -37,7 +37,7 @@ module SpreeCmCommissioner
37
37
  bit_fields = SpreeCmCommissioner::KycBitwise::BIT_FIELDS.keys
38
38
 
39
39
  if permitted_resource_params[:use_product_kyc] == '1'
40
- permitted_resource_params[:kyc] = @product.kyc
40
+ permitted_resource_params[:kyc] = nil
41
41
  else
42
42
  @kyc_result = calculate_kyc_value(params[:variant])
43
43
  permitted_resource_params[:kyc] = @kyc_result
@@ -6,15 +6,27 @@ module SpreeCmCommissioner
6
6
  has_many :guest_dynamic_fields, class_name: 'SpreeCmCommissioner::GuestDynamicField', dependent: :destroy
7
7
  has_many :product_dynamic_fields, class_name: 'SpreeCmCommissioner::ProductDynamicField', dependent: :destroy
8
8
 
9
- enum data_type: { string: 0, integer: 1, boolean: 2, checkbox: 3, radio: 4 }
9
+ enum data_type: { text: 0, number: 1, boolean: 2, checkbox: 3, radio: 4, selection: 5, textarea: 6 }
10
10
 
11
11
  accepts_nested_attributes_for :dynamic_field_options, allow_destroy: true, reject_if: :all_blank
12
12
 
13
13
  validates :label, presence: true
14
14
  validates :data_type, presence: true
15
+ validates :configurations, presence: true, allow_blank: false
15
16
 
16
- def selection?
17
- checkbox? || radio?
17
+ def requires_dynamic_field_options?
18
+ checkbox? || radio? || selection?
19
+ end
20
+
21
+ def multiple_select
22
+ return nil unless selection?
23
+
24
+ configurations['multiple_select'] == true
25
+ end
26
+
27
+ def multiple_select=(value)
28
+ self.configurations ||= {}
29
+ self.configurations['multiple_select'] = ActiveModel::Type::Boolean.new.cast(value)
18
30
  end
19
31
  end
20
32
  end
@@ -1,8 +1,12 @@
1
1
  module SpreeCmCommissioner
2
2
  class DynamicFieldOption < SpreeCmCommissioner::Base
3
3
  belongs_to :dynamic_field, class_name: 'SpreeCmCommissioner::DynamicField', optional: false
4
+ has_many :guest_dynamic_fields, class_name: 'SpreeCmCommissioner::GuestDynamicField', dependent: :restrict_with_error
5
+
6
+ enum status: { active: 0, draft: 1, archived: 2 }
4
7
 
5
8
  validates :value, presence: true, uniqueness: { scope: :dynamic_field_id }
9
+ validates :status, presence: true
6
10
  validate :parent_field_must_be_selection_type
7
11
 
8
12
  private
@@ -10,7 +14,7 @@ module SpreeCmCommissioner
10
14
  def parent_field_must_be_selection_type
11
15
  return unless dynamic_field
12
16
 
13
- return if dynamic_field.selection?
17
+ return if dynamic_field.requires_dynamic_field_options?
14
18
 
15
19
  errors.add(:dynamic_field, 'must be a selection type field')
16
20
  end
@@ -2,9 +2,11 @@ module SpreeCmCommissioner
2
2
  class GuestDynamicField < SpreeCmCommissioner::Base
3
3
  belongs_to :guest, class_name: 'SpreeCmCommissioner::Guest', optional: false
4
4
  belongs_to :dynamic_field, class_name: 'SpreeCmCommissioner::DynamicField', optional: false
5
+ belongs_to :dynamic_field_option, class_name: 'SpreeCmCommissioner::DynamicFieldOption', optional: true
5
6
 
6
7
  validates :value, presence: true
7
8
  validate :validate_value_format, if: -> { value.present? && dynamic_field.present? }
9
+ validate :validate_option_reference, if: -> { dynamic_field_option.present? }
8
10
 
9
11
  private
10
12
 
@@ -12,14 +14,30 @@ module SpreeCmCommissioner
12
14
  return if dynamic_field.blank?
13
15
 
14
16
  case dynamic_field.data_type.to_s
15
- when 'integer'
17
+ when 'number'
16
18
  errors.add(:value, 'must be a number') unless value.to_s.match?(/\A\d+\z/)
17
19
  when 'boolean'
18
- errors.add(:value, 'must be true or false') unless %w[true false 1 0].include?(value.to_s.downcase)
19
- when 'checkbox', 'radio'
20
+ errors.add(:value, 'must be true or false') unless %w[true false].include?(value.to_s.downcase)
21
+ when 'checkbox', 'radio', 'selection'
22
+ validate_option_value
23
+ end
24
+ end
25
+
26
+ def validate_option_value
27
+ if dynamic_field_option.present?
28
+ self.value ||= dynamic_field_option.value
29
+ else
20
30
  valid_options = dynamic_field.dynamic_field_options.pluck(:id).map(&:to_s)
21
31
  errors.add(:value, 'is not a valid option') unless valid_options.include?(value)
22
32
  end
23
33
  end
34
+
35
+ def validate_option_reference
36
+ return if dynamic_field.blank? || dynamic_field_option.blank?
37
+
38
+ return if dynamic_field_option.dynamic_field_id == dynamic_field_id
39
+
40
+ errors.add(:dynamic_field_option, 'must belong to the same dynamic field')
41
+ end
24
42
  end
25
43
  end
@@ -1,5 +1,7 @@
1
1
  module SpreeCmCommissioner
2
2
  class InviteTeam < SpreeCmCommissioner::Base
3
+ validates :email, presence: true, uniqueness: { scope: :vendor_id, message: I18n.t('invite.already_invited') }
4
+
3
5
  belongs_to :user, class_name: 'Spree::User', optional: true
4
6
  belongs_to :inviter, class_name: 'Spree::User'
5
7
  belongs_to :vendor, class_name: 'Spree::Vendor'
@@ -2,13 +2,13 @@
2
2
 
3
3
  <p>Guest Information Fields</p>
4
4
  <div class="form-check mb-3">
5
- <%= f.check_box :use_product_kyc, id: "toggleGuestInfo", class: 'form-check-input mr-2', checked: (@variant.kyc == @product.kyc) %>
5
+ <%= f.check_box :use_product_kyc, id: "toggleGuestInfo", class: 'form-check-input mr-2', checked: @variant.kyc.nil? %>
6
6
  <label for="toggleGuestInfo" class="form-check-label">
7
7
  Use Product Guest Information
8
8
  </label>
9
9
  </div>
10
10
 
11
- <div id="guestInfoForm" <% if @variant.kyc == @product.kyc %>style="display: none;"<% end %>">
11
+ <div id="guestInfoForm" <% if @variant.kyc.nil? %>style="display: none;"<% end %>">
12
12
  <small class="form-text text-muted mb-4">
13
13
  <%= raw I18n.t('kyc.variant_note') %>
14
14
  </small>
@@ -2,9 +2,7 @@ module SpreeCmCommissioner
2
2
  module V2
3
3
  module Storefront
4
4
  class DynamicFieldOptionSerializer < BaseSerializer
5
- set_type :dynamic_field_option
6
-
7
- attributes :id, :value, :dynamic_field_id, :created_at, :updated_at
5
+ attributes :id, :value, :dynamic_field_id, :status, :created_at, :updated_at
8
6
  end
9
7
  end
10
8
  end
@@ -2,9 +2,7 @@ module SpreeCmCommissioner
2
2
  module V2
3
3
  module Storefront
4
4
  class DynamicFieldSerializer < BaseSerializer
5
- set_type :dynamic_field
6
-
7
- attributes :id, :label, :data_type, :vendor_id, :created_at, :updated_at
5
+ attributes :id, :label, :data_type, :vendor_id, :multiple_select, :created_at, :updated_at
8
6
 
9
7
  has_many :dynamic_field_options, serializer: SpreeCmCommissioner::V2::Storefront::DynamicFieldOptionSerializer
10
8
  end
@@ -4,9 +4,10 @@ module SpreeCmCommissioner
4
4
  class GuestDynamicFieldSerializer < BaseSerializer
5
5
  set_type :guest_dynamic_field
6
6
 
7
- attributes :id, :value, :guest_id, :dynamic_field_id, :created_at, :updated_at
7
+ attributes :id, :value, :guest_id, :dynamic_field_id, :dynamic_field_option_id, :created_at, :updated_at
8
8
 
9
9
  belongs_to :dynamic_field, serializer: SpreeCmCommissioner::V2::Storefront::DynamicFieldSerializer
10
+ belongs_to :dynamic_field_option, serializer: SpreeCmCommissioner::V2::Storefront::DynamicFieldOptionSerializer
10
11
  end
11
12
  end
12
13
  end
@@ -0,0 +1,6 @@
1
+ class AddConfigurationsToCmDynamicField < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :cm_dynamic_fields, :configurations, :jsonb, default: {}, null: false, if_not_exists: true
4
+ add_index :cm_dynamic_fields, :configurations, if_not_exists: true
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddDynamicFieldOptionToGuestDynamicField < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_reference :cm_guest_dynamic_fields, :dynamic_field_option, index: true, foreign_key: { to_table: :cm_dynamic_field_options }, if_not_exists: true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddStatusToDynamicFieldOption < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :cm_dynamic_field_options, :status, :integer, default: 0, if_not_exists: true
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module SpreeCmCommissioner
2
- VERSION = '1.17.0'.freeze
2
+ VERSION = '1.18.0'.freeze
3
3
 
4
4
  module_function
5
5
 
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: 1.17.0
4
+ version: 1.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-03 00:00:00.000000000 Z
11
+ date: 2025-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree
@@ -2517,6 +2517,9 @@ files:
2517
2517
  - db/migrate/20250611023548_add_country_code_to_guests.rb
2518
2518
  - db/migrate/20250612035937_add_intel_phone_number_to_guests.rb
2519
2519
  - db/migrate/20250616084219_add_description_to_cm_vendor_place.rb
2520
+ - db/migrate/20250701093203_add_configurations_to_cm_dynamic_field.rb
2521
+ - db/migrate/20250702091305_add_dynamic_field_option_to_guest_dynamic_field.rb
2522
+ - db/migrate/20250702091935_add_status_to_dynamic_field_option.rb
2520
2523
  - docker-compose.yml
2521
2524
  - docs/option_types/attr_types.md
2522
2525
  - docs/private_key.pem