dscf-marketplace 0.7.4 → 0.7.5

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: 6868f5b7cbade52d287939591c2011a7140b76eda6f3223ba7f66a3a51fb3d08
4
- data.tar.gz: dd56581029c76743ec281f4de717f00410a38d780b68ad57a13a11cd36e8ddd2
3
+ metadata.gz: e66e6a4fac1c4edcfd47fee2305ae1f1003e0f5b67d1de4ed92437efab52c51d
4
+ data.tar.gz: 938e70e67ec267163bdb2414da889a90ecb5d46c4c72c016af6b26bac160a4cb
5
5
  SHA512:
6
- metadata.gz: 1d7737babebba09f37154720fea2502464ad2c71cac4007114a40d3d22529efc664091d8f96a26086140bdd66696cfffa0bf7b1d828b6764f833e1497327940e
7
- data.tar.gz: a2f2b76706da91f693a76cbe47e6b913b97819777f81ef3dacd354a83e59d8106dfcca11402af054493c1dcda586edca8b998858adbcfaeb11297aea302ffff2
6
+ metadata.gz: 74555ff90a3951e9ba75d3fc451da200458a4b15c6eb4cd227f48dee569fe14e70174c292e7e7f1454200a6765431f3b3e66cd2862e4885dc474e0a1eddfc6eb
7
+ data.tar.gz: 999a3fa20ea0ee8db77b9d39c48efcffb9f5f9d19c73d1fd7555c7a9b0b9a77c9cf76ee363564e5acfabf1ed3cfbfe5b84f6bda1525fdb018903429495f3a21f
@@ -16,12 +16,64 @@ module Dscf
16
16
  render_success("supplier_products.success.index", data: products, serializer_options: options)
17
17
  end
18
18
 
19
+ # Override create so supplier submissions default to inactive (require approval)
20
+ def create
21
+ authorize @clazz.new, :create?
22
+
23
+ obj = @clazz.new(model_params)
24
+ # Ensure newly created supplier products are inactive until approved by platform admin
25
+ obj.status = :inactive
26
+
27
+ ActiveRecord::Base.transaction do
28
+ if obj.save
29
+ @obj = obj
30
+ after_save_hook(obj) if respond_to?(:after_save_hook, true)
31
+
32
+ obj = @clazz.includes(eager_loaded_associations).find(obj.id) if eager_loaded_associations.present?
33
+ @obj = obj
34
+
35
+ includes = serializer_includes_for_action(:create)
36
+ options = {}
37
+ options[:include] = includes if includes.present?
38
+
39
+ render_success(data: obj, serializer_options: options, status: :created)
40
+ else
41
+ render_error(errors: obj.errors.full_messages[0], status: :unprocessable_entity)
42
+ end
43
+ end
44
+ end
45
+
46
+ # Admin action to approve a supplier product (makes it active)
47
+ def approve
48
+ set_object
49
+ authorize @obj, :approve?
50
+
51
+ if @obj.update(status: :active)
52
+ render_success("supplier_products.success.approve", data: @obj)
53
+ else
54
+ render_error("supplier_products.errors.approve", errors: @obj.errors.full_messages, status: :unprocessable_entity)
55
+ end
56
+ end
57
+
58
+ # Admin action to reject a supplier product (makes it inactive)
59
+ def reject
60
+ set_object
61
+ authorize @obj, :approve?
62
+
63
+ if @obj.update(status: :inactive)
64
+ render_success("supplier_products.success.reject", data: @obj)
65
+ else
66
+ render_error("supplier_products.errors.reject", errors: @obj.errors.full_messages, status: :unprocessable_entity)
67
+ end
68
+ end
69
+
19
70
  private
20
71
 
21
72
  def model_params
22
73
  params.require(:supplier_product).permit(
23
74
  :business_id, :product_id, :supplier_price, :available_quantity,
24
- :minimum_order_quantity, :status
75
+ :minimum_order_quantity, :status,
76
+ :supplier_name, :supplier_address, :supplier_contact_phone
25
77
  )
26
78
  end
27
79
 
@@ -20,7 +20,7 @@ module Dscf::Marketplace
20
20
  scope :by_product, ->(product_id) { where(product_id: product_id) }
21
21
 
22
22
  def self.ransackable_attributes(_auth_object = nil)
23
- %w[id business_id product_id supplier_price available_quantity minimum_order_quantity status created_at updated_at]
23
+ %w[id business_id product_id supplier_price available_quantity minimum_order_quantity status created_at updated_at supplier_name supplier_address supplier_contact_phone]
24
24
  end
25
25
 
26
26
  def self.ransackable_associations(_auth_object = nil)
@@ -4,6 +4,13 @@ module Dscf
4
4
  def my_products?
5
5
  user.has_permission?("supplier_products.my_products")
6
6
  end
7
+
8
+ def approve?
9
+ return true if user.super_admin?
10
+
11
+ # Only allow users who belong to a system business to approve supplier products
12
+ user.businesses.where(is_system: true).exists?
13
+ end
7
14
  end
8
15
  end
9
16
  end
@@ -4,7 +4,8 @@ module Dscf
4
4
  attributes :id, :business_id, :product_id, :supplier_price, :available_quantity,
5
5
  :minimum_order_quantity, :status, :created_at, :updated_at,
6
6
  :in_stock?, :price_per_unit, :display_name, :name, :description,
7
- :thumbnail_url, :images_urls
7
+ :thumbnail_url, :images_urls,
8
+ :supplier_name, :supplier_address, :supplier_contact_phone
8
9
 
9
10
  belongs_to :business
10
11
  belongs_to :product
@@ -77,12 +77,16 @@ en:
77
77
  supplier_products:
78
78
  success:
79
79
  index: "Supplier products retrieved successfully"
80
+ approve: "Supplier product approved successfully"
81
+ reject: "Supplier product rejected successfully"
80
82
  show: "Supplier product details retrieved successfully"
81
83
  create: "Supplier product created successfully"
82
84
  update: "Supplier product updated successfully"
83
85
  destroy: "Supplier product deleted successfully"
84
86
  errors:
85
87
  index: "Failed to retrieve supplier products"
88
+ approve: "Failed to approve supplier product"
89
+ reject: "Failed to reject supplier product"
86
90
  show: "Failed to retrieve supplier product details"
87
91
  create: "Failed to create supplier product"
88
92
  update: "Failed to update supplier product"
data/config/routes.rb CHANGED
@@ -25,6 +25,10 @@ Dscf::Marketplace::Engine.routes.draw do
25
25
  collection do
26
26
  get "my_products"
27
27
  end
28
+ member do
29
+ post "approve"
30
+ post "reject"
31
+ end
28
32
  end
29
33
 
30
34
  resources :listings do
@@ -0,0 +1,7 @@
1
+ class AddSupplierContactFieldsToSupplierProducts < ActiveRecord::Migration[8.0]
2
+ def change
3
+ add_column :dscf_marketplace_supplier_products, :supplier_name, :string
4
+ add_column :dscf_marketplace_supplier_products, :supplier_address, :text
5
+ add_column :dscf_marketplace_supplier_products, :supplier_contact_phone, :string
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Marketplace
3
- VERSION = "0.7.4".freeze
3
+ VERSION = "0.7.5".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-marketplace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-04-24 00:00:00.000000000 Z
10
+ date: 2026-05-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -532,6 +532,7 @@ files:
532
532
  - db/migrate/20251130144500_add_delivery_stop_to_delivery_order_items.rb
533
533
  - db/migrate/20260310120000_add_active_and_description_to_dscf_core_roles.rb
534
534
  - db/migrate/20260310122000_add_missing_fields_to_dscf_core_user_roles.rb
535
+ - db/migrate/20260501000002_add_supplier_contact_fields_to_supplier_products.rb
535
536
  - db/seeds.rb
536
537
  - lib/dscf/marketplace.rb
537
538
  - lib/dscf/marketplace/engine.rb