spree_multi_vendor 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2249038a9dae7dde5d3c7b0eb3833921f4bdd0144ab76fa5c7277e53ee4aadce
4
- data.tar.gz: 555815de55c3298001c60c753b69974e1d524db73257a130a661279b4ec3e594
3
+ metadata.gz: f74e64bbf275693c1232604c1e33a99fd6d0ea32ee1ef5ce1f13d6cf9e3e3b47
4
+ data.tar.gz: 99b385ac825a76281dd754d0b5b0911805614c18a6189713c47373a2d0b9acdd
5
5
  SHA512:
6
- metadata.gz: 6db7385cd15712b90faf63172eb6f2a05bebd0941f12ddd0faa55c53ce44ddca10c1527fb46ecbcd1524d9662e44359bdafb8eb26044012445d9b157552090ba
7
- data.tar.gz: 48a0f9438bf8f7df0fc303760be106f23632b40e903f9cea0afc786ab523c181f52677817b0c633b800457a409569a331b9fc8aebfc997f71e53a955d990ff15
6
+ metadata.gz: 228371ed8973f3012e6160d7d580f17311c18c9062b82e2c090b6392a608091a5dd5217d48cfb310c2201d8bc2130a5d0c60b11f114b2238da3f8af55390910d
7
+ data.tar.gz: 0c6dde13714bab1a18c0ad130ed5b5c42ae773c9b53f8a9d3b1058df74b2682e0ccd552df9d3caf0d8eff9307c2d1e0e83055bf190e93a1de23db75c609f0546
@@ -36,8 +36,21 @@ class Spree::VendorAbility
36
36
 
37
37
  def apply_order_permissions
38
38
  cannot :create, Spree::Order
39
- can [:admin, :index, :edit, :update, :cart], Spree::Order do |order|
40
- (order.vendor_ids & @vendor_ids).any?
39
+
40
+ order_scope = if ::Spree::Order.reflect_on_association(:vendor)
41
+ { vendor_id: @vendor_ids }
42
+ elsif ::Spree::LineItem.reflect_on_association(:vendor)
43
+ { line_items: { vendor_id: @vendor_ids } }
44
+ elsif ::Spree::Product.reflect_on_association(:vendor)
45
+ { line_items: { product: { vendor_id: @vendor_ids } } }
46
+ elsif ::Spree::Variant.reflect_on_association(:vendor)
47
+ { line_items: { variant: { vendor_id: @vendor_ids } } }
48
+ end
49
+
50
+ if order_scope.present?
51
+ can %i[admin index edit update cart], Spree::Order, order_scope.merge(state: 'complete')
52
+ else
53
+ cannot_display_model(Spree::Order)
41
54
  end
42
55
  end
43
56
 
@@ -51,9 +64,8 @@ class Spree::VendorAbility
51
64
  end
52
65
 
53
66
  def apply_option_type_permissions
54
- cannot_display_model(Spree::OptionType)
55
- can :manage, Spree::OptionType, vendor_id: @vendor_ids
56
- can :create, Spree::OptionType
67
+ can :display, Spree::OptionType
68
+ can :display, Spree::OptionValue
57
69
  end
58
70
 
59
71
  def apply_price_permissions
@@ -61,8 +73,6 @@ class Spree::VendorAbility
61
73
  end
62
74
 
63
75
  def apply_product_option_type_permissions
64
- can :display, Spree::OptionType
65
- can :display, Spree::OptionValue
66
76
  can :manage, Spree::ProductOptionType, product: { vendor_id: @vendor_ids }
67
77
  can :create, Spree::ProductOptionType
68
78
  can :manage, Spree::OptionValueVariant, variant: { vendor_id: @vendor_ids }
@@ -71,6 +81,9 @@ class Spree::VendorAbility
71
81
 
72
82
  def apply_product_permissions
73
83
  cannot_display_model(Spree::Product)
84
+
85
+ return unless Spree::Product.reflect_on_association(:vendor)
86
+
74
87
  can :manage, Spree::Product, vendor_id: @vendor_ids
75
88
  can :create, Spree::Product
76
89
  end
@@ -78,7 +91,7 @@ class Spree::VendorAbility
78
91
  def apply_properties_permissions
79
92
  can :display, Spree::Property
80
93
  end
81
-
94
+
82
95
  def apply_product_properties_permissions
83
96
  can :manage, Spree::ProductProperty, product: { vendor_id: @vendor_ids }
84
97
  can :create, Spree::ProductProperty
@@ -116,6 +129,7 @@ class Spree::VendorAbility
116
129
  end
117
130
 
118
131
  def apply_variant_permissions
132
+ cannot_display_model(Spree::Variant)
119
133
  can :manage, Spree::Variant, vendor_id: @vendor_ids
120
134
  can :create, Spree::Variant
121
135
  end
@@ -1,5 +1,5 @@
1
1
  module SpreeMultiVendor
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
 
4
4
  module_function
5
5
 
@@ -3,23 +3,72 @@ require 'spec_helper'
3
3
  RSpec.feature 'Admin Orders', :js do
4
4
  let(:vendor) { create(:active_vendor, name: 'Vendor') }
5
5
  let(:vendor_2) { create(:active_vendor, name: 'Other vendor') }
6
- let(:order) do
7
- create(:order,
8
- line_items: [
9
- create(:line_item, product: product),
10
- create(:line_item, product: product_2)
11
- ])
12
- end
6
+ let(:order) { create(:order, ship_address: create(:address), bill_address: create(:address)) }
7
+ let(:order_2) { create(:order) }
13
8
  let!(:user) { create(:user, vendors: [vendor]) }
14
9
  let(:product) { create(:product_in_stock, vendor: vendor) }
15
10
  let(:product_2) { create(:product_in_stock, vendor: vendor_2) }
16
11
 
12
+ before do
13
+ create(:line_item, order: order, product: product)
14
+ create(:line_item, order: order, product: product_2)
15
+ order.create_proposed_shipments
16
+ order.update(state: :complete, completed_at: Time.current)
17
+ login_as(user, scope: :spree_user)
18
+ end
19
+
20
+ shared_examples 'shows order data' do
21
+ it { expect(page).to have_text(order.number) }
22
+ it { expect(page).to have_content(order.display_vendor_total(vendor).to_html) }
23
+ end
24
+
25
+ context 'index' do
26
+ background do
27
+ visit spree.admin_orders_path
28
+ end
29
+
30
+ it_behaves_like 'shows order data'
31
+
32
+ it 'does not show non-vendor orders' do
33
+ expect(page).not_to have_text(order_2.number)
34
+ end
35
+ end
36
+
37
+ context 'cart' do
38
+ background do
39
+ visit spree.cart_admin_order_path(id: order.number)
40
+ end
41
+
42
+ it_behaves_like 'shows order data'
43
+ end
44
+
45
+ context 'customer info' do
46
+ background do
47
+ visit spree.admin_order_customer_path(order_id: order.number)
48
+ end
49
+
50
+ it_behaves_like 'shows order data'
51
+
52
+ it 'shows customer information' do
53
+ expect(page).to have_text(order.ship_address.full_name)
54
+ expect(page).to have_text(order.ship_address.address1)
55
+ expect(page).to have_text(order.ship_address.city)
56
+
57
+ expect(page).to have_text(order.bill_address.full_name)
58
+ expect(page).to have_text(order.bill_address.address1)
59
+ expect(page).to have_text(order.bill_address.city)
60
+
61
+ expect(page).not_to have_selector('input[type=text]')
62
+ end
63
+ end
64
+
17
65
  context 'edit' do
18
66
  background do
19
- login_as(user, scope: :spree_user)
20
67
  visit spree.edit_admin_order_path(id: order.number)
21
68
  end
22
69
 
70
+ it_behaves_like 'shows order data'
71
+
23
72
  scenario 'vendor can add his product' do
24
73
  select2_open label: 'Name or SKU'
25
74
  select2_search product.name, from: 'Name or SKU'
@@ -29,8 +78,8 @@ RSpec.feature 'Admin Orders', :js do
29
78
 
30
79
  scenario 'vendor cannot add other vendors product' do
31
80
  select2_open label: 'Name or SKU'
32
- select2_search product.name, from: 'Name or SKU'
33
- expect(page).not_to have_text(product.name)
81
+ select2_search product_2.name, from: 'Name or SKU'
82
+ expect(page).not_to have_text(product_2.name)
34
83
  end
35
84
  end
36
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_multi_vendor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spark Solutions
@@ -144,15 +144,12 @@ files:
144
144
  - app/controllers/spree/admin/vendors_controller.rb
145
145
  - app/controllers/spree/api/v2/storefront/vendors_controller.rb
146
146
  - app/controllers/spree_multi_vendor/spree/admin/base_controller_decorator.rb
147
- - app/controllers/spree_multi_vendor/spree/admin/option_types_controller_decorator.rb
148
147
  - app/controllers/spree_multi_vendor/spree/admin/products_controller_decorator.rb
149
- - app/controllers/spree_multi_vendor/spree/admin/properties_controller_decorator.rb
150
148
  - app/controllers/spree_multi_vendor/spree/admin/resource_controller_decorator.rb
151
149
  - app/controllers/spree_multi_vendor/spree/admin/shipping_methods_controller_decorator.rb
152
150
  - app/controllers/spree_multi_vendor/spree/admin/stock_locations_controller_decorator.rb
153
151
  - app/controllers/spree_multi_vendor/spree/admin/users_controller_decorator.rb
154
152
  - app/controllers/spree_multi_vendor/spree/admin/variants_controller_decorator.rb
155
- - app/controllers/spree_multi_vendor/spree/api/v1/variants_controller_decorator.rb
156
153
  - app/finders/spree_multi_vendor/products_finder_decorator.rb
157
154
  - app/helpers/spree/admin/vendor_helper.rb
158
155
  - app/mailers/spree/vendor_mailer.rb
@@ -259,9 +256,9 @@ licenses:
259
256
  - BSD-3-Clause
260
257
  metadata:
261
258
  bug_tracker_uri: https://github.com/spree-contrib/spree_multi_vendor/issues
262
- changelog_uri: https://github.com/spree-contrib/spree_multi_vendor/releases/tag/v2.0.1
259
+ changelog_uri: https://github.com/spree-contrib/spree_multi_vendor/releases/tag/v2.0.2
263
260
  documentation_uri: https://guides.spreecommerce.org/
264
- source_code_uri: https://github.com/spree-contrib/spree_multi_vendor/tree/v2.0.1
261
+ source_code_uri: https://github.com/spree-contrib/spree_multi_vendor/tree/v2.0.2
265
262
  post_install_message:
266
263
  rdoc_options: []
267
264
  require_paths:
@@ -1,7 +0,0 @@
1
- module SpreeMultiVendor::Spree::Admin::OptionTypesControllerDecorator
2
- def self.prepended(base)
3
- base.before_action :set_vendor_id, only: [:create, :update]
4
- end
5
- end
6
-
7
- Spree::Admin::OptionTypesController.prepend SpreeMultiVendor::Spree::Admin::OptionTypesControllerDecorator
@@ -1,7 +0,0 @@
1
- module SpreeMultiVendor::Spree::Admin::PropertiesControllerDecorator
2
- def self.prepended(base)
3
- base.before_action :set_vendor_id, only: [:create, :update]
4
- end
5
- end
6
-
7
- Spree::Admin::PropertiesController.prepend SpreeMultiVendor::Spree::Admin::PropertiesControllerDecorator
@@ -1,22 +0,0 @@
1
- module SpreeMultiVendor::Spree::Api::V1::VariantsControllerDecorator
2
- private
3
-
4
- def scope
5
- variants = if @product
6
- @product.variants_including_master
7
- else
8
- Spree::Variant
9
- end
10
-
11
- if current_ability.can?(:manage, Spree::Variant) && params[:show_deleted]
12
- variants = variants.with_deleted
13
- end
14
-
15
- variants = variants.for_vendor_user(current_spree_user) unless @current_user_roles.include?('admin')
16
- variants = variants.eligible if Spree.version.to_f >= 3.7
17
-
18
- variants.accessible_by(current_ability, :read)
19
- end
20
- end
21
-
22
- Spree::Api::V1::VariantsController.prepend SpreeMultiVendor::Spree::Api::V1::VariantsControllerDecorator