dscf-marketplace 0.7.2 → 0.7.3
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 42792144bb56d00c7a6767aa3f8e2b4a0704fbbd815de3647bb942a764b34bb7
|
|
4
|
+
data.tar.gz: cb649cc916dedf3729a38b12e08714242647f34fd98971741decc3344fe8a776
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ed6fa17b79144e124102e838d34322d4b1735a77f2c9b9015c55f939669c6a6f16d059550394464e66402ceb9002ae33e8213c8da7af84e084c0dc15b9e9d83
|
|
7
|
+
data.tar.gz: babc3f0ccf9eef0f5be066fa59b0e77046ba03dae121c243ea8a946b3e49c3bfdea146c944486fe5bb1994d08a8e72e88cdcd8d362c2da4e802ba866c6db018c
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Dscf
|
|
2
|
+
module Marketplace
|
|
3
|
+
module DemoPermissionBypass
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
before_action :demo_bypass_permissions!
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def bypass_permissions_for_demo?
|
|
11
|
+
true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def pundit_user
|
|
15
|
+
user = current_user
|
|
16
|
+
return nil unless user
|
|
17
|
+
|
|
18
|
+
bypass_permissions_on_user!(user)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def authorize_review_action!
|
|
22
|
+
skip_authorization if respond_to?(:skip_authorization, true)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def demo_bypass_permissions!
|
|
28
|
+
skip_authorization if respond_to?(:skip_authorization, true)
|
|
29
|
+
skip_policy_scope if respond_to?(:skip_policy_scope, true)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def bypass_permissions_on_user!(user)
|
|
33
|
+
return user if user.instance_variable_defined?(:@_banking_demo_permission_bypass)
|
|
34
|
+
|
|
35
|
+
user.define_singleton_method(:has_permission?) { |_permission_code| true }
|
|
36
|
+
user.define_singleton_method(:can?) { |permission_code| has_permission?(permission_code) }
|
|
37
|
+
user.define_singleton_method(:super_admin?) { true }
|
|
38
|
+
user.instance_variable_set(:@_banking_demo_permission_bypass, true)
|
|
39
|
+
|
|
40
|
+
user
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
module Dscf
|
|
2
2
|
module Marketplace
|
|
3
|
-
class ApplicationController <
|
|
3
|
+
class ApplicationController < ActionController::API
|
|
4
|
+
include Dscf::Core::Authenticatable
|
|
5
|
+
include Dscf::Core::JsonResponse
|
|
6
|
+
before_action :authenticate_user
|
|
7
|
+
before_action :demo_bypass_permissions!
|
|
8
|
+
|
|
9
|
+
# TEMPORARY DEMO BYPASS:
|
|
10
|
+
# Bypass marketplace authorization checks for authenticated users only.
|
|
11
|
+
# Remove after the demo.
|
|
12
|
+
def bypass_permissions_for_demo?
|
|
13
|
+
true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def pundit_user
|
|
17
|
+
user = current_user
|
|
18
|
+
return nil unless user
|
|
19
|
+
|
|
20
|
+
bypass_permissions_on_user!(user)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def demo_bypass_permissions!
|
|
26
|
+
skip_authorization if respond_to?(:skip_authorization, true)
|
|
27
|
+
skip_policy_scope if respond_to?(:skip_policy_scope, true)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def bypass_permissions_on_user!(user)
|
|
31
|
+
return user if user.instance_variable_defined?(:@_banking_demo_permission_bypass)
|
|
32
|
+
|
|
33
|
+
user.define_singleton_method(:has_permission?) { |_permission_code| true }
|
|
34
|
+
user.define_singleton_method(:can?) { |permission_code| has_permission?(permission_code) }
|
|
35
|
+
user.define_singleton_method(:super_admin?) { true }
|
|
36
|
+
user.instance_variable_set(:@_banking_demo_permission_bypass, true)
|
|
37
|
+
|
|
38
|
+
user
|
|
39
|
+
end
|
|
4
40
|
end
|
|
5
41
|
end
|
|
6
42
|
end
|
|
@@ -3,6 +3,24 @@ module Dscf
|
|
|
3
3
|
class OrdersController < ApplicationController
|
|
4
4
|
include Dscf::Core::Common
|
|
5
5
|
|
|
6
|
+
def create
|
|
7
|
+
authorize @clazz.new, :create?
|
|
8
|
+
|
|
9
|
+
return create_direct_listing_order if direct_listing_request?
|
|
10
|
+
|
|
11
|
+
obj = @clazz.new(model_params)
|
|
12
|
+
if obj.save
|
|
13
|
+
obj = @clazz.includes(eager_loaded_associations).find(obj.id) if eager_loaded_associations.present?
|
|
14
|
+
includes = default_serializer_includes[:create] || []
|
|
15
|
+
options = {include: includes} if includes.present?
|
|
16
|
+
render_success(data: obj, serializer_options: options, status: :created)
|
|
17
|
+
else
|
|
18
|
+
render_error(errors: obj.errors.full_messages.join(", "), status: :unprocessable_entity)
|
|
19
|
+
end
|
|
20
|
+
rescue => e
|
|
21
|
+
render_error(error: e.message)
|
|
22
|
+
end
|
|
23
|
+
|
|
6
24
|
def filter
|
|
7
25
|
authorize @clazz.new, :filter?
|
|
8
26
|
orders = @clazz.all
|
|
@@ -48,7 +66,7 @@ module Dscf
|
|
|
48
66
|
@obj = find_record
|
|
49
67
|
authorize @obj, :complete?
|
|
50
68
|
if @obj.can_be_completed? && @obj.update(status: :completed)
|
|
51
|
-
@obj.order_items.update_all(status: OrderItem.statuses[:
|
|
69
|
+
@obj.order_items.update_all(status: OrderItem.statuses[:fulfilled])
|
|
52
70
|
render_success("orders.success.completed", data: @obj)
|
|
53
71
|
else
|
|
54
72
|
render_error("orders.errors.complete_failed")
|
|
@@ -70,6 +88,67 @@ module Dscf
|
|
|
70
88
|
|
|
71
89
|
private
|
|
72
90
|
|
|
91
|
+
def create_direct_listing_order
|
|
92
|
+
listing = Dscf::Marketplace::Listing.active.find_by(id: model_params[:listing_id])
|
|
93
|
+
return render_error(errors: "Listing is not available", status: :unprocessable_entity) unless listing
|
|
94
|
+
|
|
95
|
+
quantity = direct_listing_quantity
|
|
96
|
+
return render_error(errors: "Quantity must be greater than 0", status: :unprocessable_entity) unless quantity.positive?
|
|
97
|
+
|
|
98
|
+
if quantity > listing.quantity
|
|
99
|
+
return render_error(errors: "Requested quantity exceeds available listing quantity", status: :unprocessable_entity)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
order = nil
|
|
103
|
+
ActiveRecord::Base.transaction do
|
|
104
|
+
listing.lock!
|
|
105
|
+
|
|
106
|
+
if quantity > listing.quantity
|
|
107
|
+
listing.errors.add(:base, "Requested quantity exceeds available listing quantity")
|
|
108
|
+
raise ActiveRecord::RecordInvalid.new(listing)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
order = @clazz.new(model_params.except(:order_items_attributes))
|
|
112
|
+
order.order_type = :direct_listing
|
|
113
|
+
order.status = :pending
|
|
114
|
+
order.listing = listing
|
|
115
|
+
order.ordered_to = listing.business
|
|
116
|
+
|
|
117
|
+
product = listing.supplier_product.product
|
|
118
|
+
order.order_items.build(
|
|
119
|
+
listing: listing,
|
|
120
|
+
product: product,
|
|
121
|
+
unit: product.unit,
|
|
122
|
+
quantity: quantity,
|
|
123
|
+
unit_price: listing.price,
|
|
124
|
+
status: :pending
|
|
125
|
+
)
|
|
126
|
+
order.save!
|
|
127
|
+
|
|
128
|
+
new_quantity = listing.quantity - quantity
|
|
129
|
+
listing.update!(quantity: new_quantity, status: (new_quantity.zero? ? :sold_out : listing.status))
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
order = @clazz.includes(eager_loaded_associations).find(order.id) if eager_loaded_associations.present?
|
|
133
|
+
includes = default_serializer_includes[:create] || []
|
|
134
|
+
options = {include: includes} if includes.present?
|
|
135
|
+
render_success(data: order, serializer_options: options, status: :created)
|
|
136
|
+
rescue ActiveRecord::RecordInvalid => e
|
|
137
|
+
errors = e.record&.errors&.full_messages&.presence || [e.message]
|
|
138
|
+
render_error(errors: errors.join(", "), status: :unprocessable_entity)
|
|
139
|
+
rescue => e
|
|
140
|
+
render_error(error: e.message)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def direct_listing_request?
|
|
144
|
+
%w[direct_listing 1].include?(model_params[:order_type].to_s)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def direct_listing_quantity
|
|
148
|
+
item = model_params[:order_items_attributes]&.first
|
|
149
|
+
(item&.[](:quantity) || item&.[]("quantity")).to_i
|
|
150
|
+
end
|
|
151
|
+
|
|
73
152
|
def model_params
|
|
74
153
|
params.require(:order).permit(
|
|
75
154
|
:quotation_id, :listing_id, :user_id, :ordered_by_id, :ordered_to_id, :delivery_order_id, :dropoff_address_id,
|
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
|
+
version: 0.7.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Asrat
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-04-17 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rails
|
|
@@ -416,6 +416,7 @@ extra_rdoc_files: []
|
|
|
416
416
|
files:
|
|
417
417
|
- MIT-LICENSE
|
|
418
418
|
- Rakefile
|
|
419
|
+
- app/controllers/concerns/dscf/marketplace/demo_permission_bypass.rb
|
|
419
420
|
- app/controllers/dscf/marketplace/application_controller.rb
|
|
420
421
|
- app/controllers/dscf/marketplace/categories_controller.rb
|
|
421
422
|
- app/controllers/dscf/marketplace/delivery_order_items_controller.rb
|