spree_multi_vendor 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/v1/vendors_controller.rb +61 -0
- data/app/helpers/spree_multi_vendor/spree/api/api_helpers_decorator.rb +17 -0
- data/app/models/spree/vendor_ability.rb +2 -1
- data/app/models/spree_multi_vendor/configuration.rb +1 -1
- data/app/models/spree_multi_vendor/spree/order_decorator.rb +1 -1
- data/app/views/spree/api/v1/vendors/index.rabl +3 -0
- data/app/views/spree/api/v1/vendors/show.rabl +2 -0
- data/config/routes.rb +3 -0
- data/lib/spree_multi_vendor/factories.rb +1 -1
- data/lib/spree_multi_vendor/version.rb +1 -1
- data/spec/requests/spree/api/v1/vendors_spec.rb +210 -0
- data/spec/requests/spree/api/v2/storefront/products_spec.rb +2 -0
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c44adfbeea75e7b5d36a5282b3f73e82a50914e2afdcb3e5d5100f0f1fb7e2f
|
4
|
+
data.tar.gz: e0fc1a00cc1c075944a888257004841199da7a62f85065dc087b0546a9eadf16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6862e52f1a430fcbe23b6fef685c2c12d30245ce0199d993caae87c7a71dd9278ed73c29d611d325266c9dab107922a5921783f57bf8789c752f81b1f58c78e9
|
7
|
+
data.tar.gz: 310a440feb55b56bc73ec09656f6167a7cbdc2fce296e5793379611ebc066749dc7853721140dc0963498f6dc7eb3116e259f5ca64eeb4c33320158870f3cc02
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class VendorsController < Spree::Api::BaseController
|
5
|
+
def index
|
6
|
+
@vendors = if params[:ids].present?
|
7
|
+
scope.where(id: params[:ids].split(','))
|
8
|
+
else
|
9
|
+
scope.load.ransack(
|
10
|
+
params[:q]
|
11
|
+
).result
|
12
|
+
end
|
13
|
+
respond_with(@vendors)
|
14
|
+
end
|
15
|
+
|
16
|
+
def show
|
17
|
+
@vendor = scope.find(params[:id])
|
18
|
+
authorize! :show, @vendor
|
19
|
+
respond_with(@vendor)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
authorize! :create, Spree::Vendor
|
24
|
+
@vendor = Spree::Vendor.new(vendor_params)
|
25
|
+
if @vendor.save
|
26
|
+
render :show, status: 201
|
27
|
+
else
|
28
|
+
invalid_resource!(@vendor)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
@vendor = scope.find(params[:id])
|
34
|
+
authorize! :update, @vendor
|
35
|
+
if @vendor.update(vendor_params)
|
36
|
+
render :show
|
37
|
+
else
|
38
|
+
invalid_resource!(@vendor)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy
|
43
|
+
@vendor = scope.find(params[:id])
|
44
|
+
authorize! :destroy, @vendor
|
45
|
+
@vendor.destroy
|
46
|
+
render plain: nil, status: 204
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def scope
|
52
|
+
Spree::Vendor.accessible_by(current_ability)
|
53
|
+
end
|
54
|
+
|
55
|
+
def vendor_params
|
56
|
+
params.require(:vendor).permit(Spree::PermittedAttributes.vendor_attributes)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SpreeMultiVendor
|
2
|
+
module Spree
|
3
|
+
module Api
|
4
|
+
module ApiHelpersDecorator
|
5
|
+
def self.prepended(base)
|
6
|
+
base::ATTRIBUTES.push(:vendor_attributes)
|
7
|
+
|
8
|
+
base.mattr_reader *base::ATTRIBUTES
|
9
|
+
end
|
10
|
+
|
11
|
+
@@vendor_attributes = [:id, :name, :slug, :state, :about_us, :contact_us]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
::Spree::Api::ApiHelpers.prepend(SpreeMultiVendor::Spree::Api::ApiHelpersDecorator)
|
@@ -135,7 +135,8 @@ class Spree::VendorAbility
|
|
135
135
|
end
|
136
136
|
|
137
137
|
def apply_vendor_permissions
|
138
|
-
can
|
138
|
+
can :manage, Spree::Vendor, id: @vendor_ids
|
139
|
+
cannot :create, Spree::Vendor
|
139
140
|
end
|
140
141
|
|
141
142
|
def apply_vendor_settings_permissions
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module SpreeMultiVendor
|
2
|
-
class Configuration < Spree::Preferences::Configuration
|
2
|
+
class Configuration < ::Spree::Preferences::Configuration
|
3
3
|
DEFAULT_VENDORIZED_MODELS ||= %w[product variant stock_location shipping_method].freeze
|
4
4
|
|
5
5
|
# Some example preferences are shown below, for more information visit:
|
@@ -66,7 +66,7 @@ module SpreeMultiVendor::Spree::OrderDecorator
|
|
66
66
|
end
|
67
67
|
|
68
68
|
# money methods
|
69
|
-
METHOD_NAMES
|
69
|
+
METHOD_NAMES ||= %w[
|
70
70
|
total ship_total subtotal included_tax_total additional_tax_total promo_total
|
71
71
|
pre_tax_item_amount pre_tax_ship_amount pre_tax_total commission
|
72
72
|
].freeze
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe 'API V1 Vendors Spec', type: :request do
|
5
|
+
let(:params) { {} }
|
6
|
+
let(:selected_vendor) { vendor }
|
7
|
+
|
8
|
+
let!(:vendor) { create(:vendor, state: :active) }
|
9
|
+
let!(:another_vendor) { create(:vendor, state: :active) }
|
10
|
+
|
11
|
+
before { stub_authentication! }
|
12
|
+
|
13
|
+
describe 'vendors#index' do
|
14
|
+
before { get '/api/v1/vendors', params: params }
|
15
|
+
|
16
|
+
context 'as a regular user' do
|
17
|
+
it 'gets an empty list' do
|
18
|
+
expect(response.status).to eq(200)
|
19
|
+
expect(json_response.size).to eq(0)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'as an admin' do
|
24
|
+
sign_in_as_admin!
|
25
|
+
|
26
|
+
it 'gets a list of all vendors' do
|
27
|
+
expect(response.status).to eq(200)
|
28
|
+
expect(json_response.size).to eq(2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'as a vendor' do
|
33
|
+
let!(:current_api_user) do
|
34
|
+
user = create(:user, vendors: [vendor])
|
35
|
+
user
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'gets a list of assigned vendors' do
|
39
|
+
expect(response.status).to eq(200)
|
40
|
+
expect(json_response.size).to eq(1)
|
41
|
+
expect(json_response[0]['id']).to eq(vendor.id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'vendors#show' do
|
47
|
+
before { get "/api/v1/vendors/#{selected_vendor.id}" }
|
48
|
+
|
49
|
+
context 'as a regular user' do
|
50
|
+
it 'cannot view a vendor' do
|
51
|
+
expect(response.status).to eq(404)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'as an admin' do
|
56
|
+
sign_in_as_admin!
|
57
|
+
it 'can view a vendor' do
|
58
|
+
expect(response.status).to eq(200)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'as a vendor' do
|
63
|
+
let!(:current_api_user) do
|
64
|
+
user = create(:user, vendors: [vendor])
|
65
|
+
user
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'can view a assigned vendor' do
|
69
|
+
it do
|
70
|
+
expect(response.status).to eq(200)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'cannot view an another vendor' do
|
75
|
+
let(:selected_vendor) { another_vendor }
|
76
|
+
|
77
|
+
it do
|
78
|
+
expect(response.status).to eq(404)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'vendors#create' do
|
85
|
+
let(:params) do
|
86
|
+
{
|
87
|
+
vendor: {
|
88
|
+
name: 'name'
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
before { post '/api/v1/vendors', params: params }
|
94
|
+
|
95
|
+
context 'as regular user' do
|
96
|
+
it 'cannot create a new vendor' do
|
97
|
+
expect(response.status).to eq(401)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'as an admin' do
|
102
|
+
sign_in_as_admin!
|
103
|
+
|
104
|
+
it 'can create a new vendor' do
|
105
|
+
expect(response.status).to eq(201)
|
106
|
+
expect(json_response['name']).to eq(params[:vendor][:name])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'as a vendor' do
|
111
|
+
let!(:current_api_user) do
|
112
|
+
user = create(:user, vendors: [vendor], email: FFaker::Internet.email)
|
113
|
+
user
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'cannot create a new vendor' do
|
117
|
+
expect(response.status).to eq(401)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'vendors#update' do
|
123
|
+
let(:params) do
|
124
|
+
{
|
125
|
+
vendor: {
|
126
|
+
name: 'updated name'
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
before { put "/api/v1/vendors/#{selected_vendor.id}", params: params }
|
132
|
+
|
133
|
+
context 'as regular user' do
|
134
|
+
it 'cannot update vendor' do
|
135
|
+
expect(response.status).to eq(404)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'as an admin' do
|
140
|
+
sign_in_as_admin!
|
141
|
+
|
142
|
+
it 'can update vendor' do
|
143
|
+
expect(response.status).to eq(200)
|
144
|
+
expect(json_response['name']).to eq(params[:vendor][:name])
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'as a vendor' do
|
149
|
+
let!(:current_api_user) do
|
150
|
+
user = create(:user, vendors: [vendor])
|
151
|
+
user
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'can update as assigned vendor' do
|
155
|
+
it do
|
156
|
+
expect(response.status).to eq(200)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'cannot update an another vendor' do
|
161
|
+
let(:selected_vendor) { another_vendor }
|
162
|
+
|
163
|
+
it do
|
164
|
+
expect(response.status).to eq(404)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'vendors#destroy' do
|
171
|
+
before { delete "/api/v1/vendors/#{selected_vendor.id}" }
|
172
|
+
|
173
|
+
context 'as regular user' do
|
174
|
+
it 'cannot delete vendor' do
|
175
|
+
expect(response.status).to eq(404)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'as an admin' do
|
180
|
+
sign_in_as_admin!
|
181
|
+
|
182
|
+
it 'can delete vendor' do
|
183
|
+
expect(response.status).to eq(204)
|
184
|
+
expect(vendor.reload.deleted_at).to_not eq(nil)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'as a vendor' do
|
189
|
+
let!(:current_api_user) do
|
190
|
+
user = create(:user, vendors: [vendor])
|
191
|
+
user
|
192
|
+
end
|
193
|
+
|
194
|
+
describe 'can delete an assigned vendor' do
|
195
|
+
it do
|
196
|
+
expect(response.status).to eq(204)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe 'cannot delete an another vendor' do
|
201
|
+
let(:selected_vendor) { another_vendor }
|
202
|
+
|
203
|
+
it do
|
204
|
+
expect(response.status).to eq(404)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -26,6 +26,8 @@ describe 'API V2 Storefront Products Spec', type: :request do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'with specified vendor ids' do
|
29
|
+
before { vendor.products << create(:product) }
|
30
|
+
before { vendor_2.products << create(:product) }
|
29
31
|
before { get "/api/v2/storefront/products?filter[vendor_ids]=#{vendor.id}&include=vendor" }
|
30
32
|
|
31
33
|
it_behaves_like 'returns 200 HTTP status'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_multi_vendor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spark Solutions
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- Rakefile
|
143
143
|
- app/controllers/spree/admin/vendor_settings_controller.rb
|
144
144
|
- app/controllers/spree/admin/vendors_controller.rb
|
145
|
+
- app/controllers/spree/api/v1/vendors_controller.rb
|
145
146
|
- app/controllers/spree/api/v2/storefront/vendors_controller.rb
|
146
147
|
- app/controllers/spree_multi_vendor/spree/admin/base_controller_decorator.rb
|
147
148
|
- app/controllers/spree_multi_vendor/spree/admin/products_controller_decorator.rb
|
@@ -152,6 +153,7 @@ files:
|
|
152
153
|
- app/controllers/spree_multi_vendor/spree/admin/variants_controller_decorator.rb
|
153
154
|
- app/finders/spree_multi_vendor/products_finder_decorator.rb
|
154
155
|
- app/helpers/spree/admin/vendor_helper.rb
|
156
|
+
- app/helpers/spree_multi_vendor/spree/api/api_helpers_decorator.rb
|
155
157
|
- app/mailers/spree/vendor_mailer.rb
|
156
158
|
- app/models/concerns/spree/vendor_concern.rb
|
157
159
|
- app/models/spree/order_commission.rb
|
@@ -190,6 +192,8 @@ files:
|
|
190
192
|
- app/views/spree/admin/vendors/edit.html.erb
|
191
193
|
- app/views/spree/admin/vendors/index.html.erb
|
192
194
|
- app/views/spree/admin/vendors/new.html.erb
|
195
|
+
- app/views/spree/api/v1/vendors/index.rabl
|
196
|
+
- app/views/spree/api/v1/vendors/show.rabl
|
193
197
|
- app/views/spree/vendor_mailer/vendor_notification_email.html.erb
|
194
198
|
- app/views/spree/vendor_mailer/vendor_notification_email.text.erb
|
195
199
|
- bin/rails
|
@@ -241,6 +245,7 @@ files:
|
|
241
245
|
- spec/models/spree/vendor_order_totals_spec.rb
|
242
246
|
- spec/models/spree/vendor_spec.rb
|
243
247
|
- spec/models/spree/vendor_user_spec.rb
|
248
|
+
- spec/requests/spree/api/v1/vendors_spec.rb
|
244
249
|
- spec/requests/spree/api/v2/storefront/cart_spec.rb
|
245
250
|
- spec/requests/spree/api/v2/storefront/products_spec.rb
|
246
251
|
- spec/requests/spree/api/v2/storefront/vendors_spec.rb
|
@@ -256,9 +261,9 @@ licenses:
|
|
256
261
|
- BSD-3-Clause
|
257
262
|
metadata:
|
258
263
|
bug_tracker_uri: https://github.com/spree-contrib/spree_multi_vendor/issues
|
259
|
-
changelog_uri: https://github.com/spree-contrib/spree_multi_vendor/releases/tag/v2.0
|
264
|
+
changelog_uri: https://github.com/spree-contrib/spree_multi_vendor/releases/tag/v2.1.0
|
260
265
|
documentation_uri: https://guides.spreecommerce.org/
|
261
|
-
source_code_uri: https://github.com/spree-contrib/spree_multi_vendor/tree/v2.0
|
266
|
+
source_code_uri: https://github.com/spree-contrib/spree_multi_vendor/tree/v2.1.0
|
262
267
|
post_install_message:
|
263
268
|
rdoc_options: []
|
264
269
|
require_paths:
|
@@ -275,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
275
280
|
version: '0'
|
276
281
|
requirements:
|
277
282
|
- none
|
278
|
-
rubygems_version: 3.
|
283
|
+
rubygems_version: 3.0.3
|
279
284
|
signing_key:
|
280
285
|
specification_version: 4
|
281
286
|
summary: Spree Commerce multi vendor marketplace extension
|
@@ -299,6 +304,7 @@ test_files:
|
|
299
304
|
- spec/models/spree/vendor_order_totals_spec.rb
|
300
305
|
- spec/models/spree/vendor_spec.rb
|
301
306
|
- spec/models/spree/vendor_user_spec.rb
|
307
|
+
- spec/requests/spree/api/v1/vendors_spec.rb
|
302
308
|
- spec/requests/spree/api/v2/storefront/cart_spec.rb
|
303
309
|
- spec/requests/spree/api/v2/storefront/products_spec.rb
|
304
310
|
- spec/requests/spree/api/v2/storefront/vendors_spec.rb
|