wallaby-core 0.2.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -1
- data/app/controllers/wallaby/resources_controller.rb +15 -375
- data/app/security/ability.rb +1 -1
- data/config/locales/wallaby.en.yml +92 -128
- data/config/locales/wallaby_class.en.yml +2 -23
- data/lib/adaptors/wallaby/custom/default_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_decorator.rb +8 -7
- data/lib/adaptors/wallaby/custom/model_finder.rb +3 -2
- data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_service_provider.rb +1 -40
- data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +30 -24
- data/lib/authorizers/wallaby/default_authorization_provider.rb +6 -13
- data/lib/authorizers/wallaby/model_authorizer.rb +43 -67
- data/lib/authorizers/wallaby/pundit_authorization_provider.rb +21 -30
- data/lib/concerns/wallaby/application_concern.rb +110 -0
- data/lib/concerns/wallaby/authentication_concern.rb +162 -0
- data/lib/concerns/wallaby/authorizable.rb +8 -8
- data/lib/concerns/wallaby/baseable.rb +91 -10
- data/lib/concerns/wallaby/decoratable.rb +3 -3
- data/lib/concerns/wallaby/engineable.rb +1 -1
- data/lib/concerns/wallaby/fieldable.rb +4 -4
- data/lib/concerns/wallaby/paginatable.rb +3 -3
- data/lib/concerns/wallaby/resourcable.rb +4 -35
- data/lib/concerns/wallaby/resources_concern.rb +434 -0
- data/lib/concerns/wallaby/servicable.rb +4 -4
- data/lib/decorators/wallaby/resource_decorator.rb +53 -80
- data/lib/errors/wallaby/class_not_found.rb +6 -0
- data/lib/errors/wallaby/model_not_found.rb +3 -1
- data/lib/errors/wallaby/resource_not_found.rb +1 -1
- data/lib/helpers/wallaby/application_helper.rb +6 -0
- data/lib/helpers/wallaby/form_helper.rb +2 -3
- data/lib/helpers/wallaby/index_helper.rb +2 -2
- data/lib/helpers/wallaby/links_helper.rb +5 -5
- data/lib/helpers/wallaby/resources_helper.rb +3 -0
- data/lib/helpers/wallaby/secure_helper.rb +3 -3
- data/lib/helpers/wallaby/styling_helper.rb +17 -3
- data/lib/interfaces/wallaby/mode.rb +5 -5
- data/lib/interfaces/wallaby/model_authorization_provider.rb +15 -13
- data/lib/interfaces/wallaby/model_decorator.rb +15 -3
- data/lib/paginators/wallaby/model_paginator.rb +14 -45
- data/lib/routes/wallaby/resources_router.rb +1 -1
- data/lib/servicers/wallaby/model_servicer.rb +32 -62
- data/lib/services/wallaby/map/mode_mapper.rb +14 -14
- data/lib/services/wallaby/map/model_class_collector.rb +2 -2
- data/lib/services/wallaby/map/model_class_mapper.rb +7 -26
- data/lib/services/wallaby/type_renderer.rb +2 -12
- data/lib/utils/wallaby/locale.rb +53 -0
- data/lib/utils/wallaby/model_utils.rb +4 -3
- data/lib/utils/wallaby/module_utils.rb +1 -1
- data/lib/utils/wallaby/utils.rb +23 -9
- data/lib/wallaby/class_array.rb +75 -0
- data/lib/wallaby/class_hash.rb +94 -0
- data/lib/wallaby/classifier.rb +29 -0
- data/lib/wallaby/configuration/mapping.rb +33 -21
- data/lib/wallaby/configuration/metadata.rb +1 -1
- data/lib/wallaby/configuration/models.rb +5 -9
- data/lib/wallaby/configuration/security.rb +6 -3
- data/lib/wallaby/configuration/sorting.rb +1 -1
- data/lib/wallaby/configuration.rb +31 -2
- data/lib/wallaby/core/version.rb +1 -1
- data/lib/wallaby/core.rb +18 -6
- data/lib/wallaby/engine.rb +9 -20
- data/lib/wallaby/logger.rb +35 -0
- data/lib/wallaby/map.rb +20 -17
- data/lib/wallaby/preloader.rb +77 -0
- metadata +16 -9
- data/app/controllers/wallaby/application_controller.rb +0 -84
- data/app/controllers/wallaby/secure_controller.rb +0 -81
- data/lib/utils/wallaby/preload_utils.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 549512f63ab75eb29715ca2842daba07744482836896ddbf8d58ee873eeda983
|
4
|
+
data.tar.gz: 7997ba9973a504145d363673a5ea222013358673601cb0304bdf6d22a74b927e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eaff56ae4c69091a6de82f5ae4e067b65490aec8b76a54ff602b6714957e4ccf90b6ddec573032868941d5868bccde3c000ee038cb19dfe8d0cfc5fa12cf08e
|
7
|
+
data.tar.gz: 55c273983a048eb454248efe777b2abb9fb72e4a969792b3d33483b5b4944740ca1555e98fb41b25c558188420cb5a27fbd9c3aa5094786ee623fc6b81a3522f
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/f16f8d87553424c1aacc/test_coverage)](https://codeclimate.com/github/wallaby-rails/wallaby-core/test_coverage)
|
8
8
|
[![Inch CI](https://inch-ci.org/github/wallaby-rails/wallaby-core.svg?branch=master)](https://inch-ci.org/github/wallaby-rails/wallaby-core)
|
9
9
|
|
10
|
-
Wallaby::Core
|
10
|
+
**Wallaby::Core** holds all the core interfaces that [Wallaby](https://github.com/wallaby-rails/wallaby) gem is built upon.
|
11
11
|
|
12
12
|
## Install
|
13
13
|
|
@@ -28,6 +28,47 @@ bundle install
|
|
28
28
|
- [API Reference](https://www.rubydoc.info/gems/wallaby-core)
|
29
29
|
- [Change Logs](https://github.com/wallaby-rails/wallaby-core/blob/master/CHANGELOG.md)
|
30
30
|
|
31
|
+
## Build, test and update document
|
32
|
+
|
33
|
+
To set up local development environment:
|
34
|
+
|
35
|
+
- git clone this repo
|
36
|
+
- install Ruby (2.4 ~ 3.0)
|
37
|
+
- install gems
|
38
|
+
|
39
|
+
```shell
|
40
|
+
bundle install
|
41
|
+
```
|
42
|
+
|
43
|
+
- install both MySQL and PostgreSQL
|
44
|
+
- create databases
|
45
|
+
|
46
|
+
```shell
|
47
|
+
bundle exec rake db:create
|
48
|
+
```
|
49
|
+
|
50
|
+
- start developing
|
51
|
+
|
52
|
+
Make sure to pass the following checks and tests before putting up a PR:
|
53
|
+
|
54
|
+
- rubocop analysis and format check
|
55
|
+
|
56
|
+
```shell
|
57
|
+
bundle exec rubocop -a
|
58
|
+
```
|
59
|
+
|
60
|
+
- rspec test suites and 100% test coverage
|
61
|
+
|
62
|
+
```shell
|
63
|
+
RAILS_ENV=test bundle exec rake --trace spec
|
64
|
+
```
|
65
|
+
|
66
|
+
- update the comments and build the yardoc
|
67
|
+
|
68
|
+
```shell
|
69
|
+
yardoc
|
70
|
+
```
|
71
|
+
|
31
72
|
## Want to contribute?
|
32
73
|
|
33
74
|
Raise an [issue](https://github.com/wallaby-rails/wallaby-core/issues/new), discuss and resolve!
|
@@ -1,382 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Wallaby
|
4
|
+
ResourcesController = Class.new configuration.base_controller
|
5
|
+
|
4
6
|
# Resources controller, superclass for all customization controllers.
|
5
|
-
# It contains CRUD template action methods
|
7
|
+
# It contains CRUD template action methods
|
8
|
+
# ({Wallaby::ResourcesConcern#index #index} / {Wallaby::ResourcesConcern#new #new}
|
9
|
+
# / {Wallaby::ResourcesConcern#create #create} / {Wallaby::ResourcesConcern#edit #edit}
|
10
|
+
# / {Wallaby::ResourcesConcern#update #update} / {Wallaby::ResourcesConcern#destroy #destroy})
|
6
11
|
# that allow subclasses to override.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
include
|
16
|
-
prepend Prefixable
|
17
|
-
|
18
|
-
include Authorizable
|
19
|
-
include Decoratable
|
20
|
-
include Defaultable
|
21
|
-
include Paginatable
|
22
|
-
include Resourcable
|
23
|
-
include Servicable
|
24
|
-
|
25
|
-
self.responder = ResourcesResponder
|
26
|
-
respond_to :html
|
27
|
-
respond_to :json
|
28
|
-
respond_to :csv, only: :index
|
29
|
-
helper ResourcesHelper
|
30
|
-
before_action :authenticate_user!
|
31
|
-
|
32
|
-
# @note This is a template method that can be overridden by subclasses.
|
33
|
-
# This is an action for landing page display. It does nothing more than rendering `home` template.
|
34
|
-
#
|
35
|
-
# It can be replaced completely in subclasses as below:
|
36
|
-
#
|
37
|
-
# ```
|
38
|
-
# def home
|
39
|
-
# generate_dashboard_report
|
40
|
-
# end
|
41
|
-
# ```
|
42
|
-
def home
|
43
|
-
# do nothing
|
44
|
-
end
|
45
|
-
|
46
|
-
# @note This is a template method that can be overridden by subclasses.
|
47
|
-
# This is a resourceful action to list records that user can access.
|
48
|
-
#
|
49
|
-
# It can be customized as below in subclasses:
|
50
|
-
#
|
51
|
-
# `WARN: Please keep in mind that Wallaby User Interface requires **index**
|
52
|
-
# action to respond to **csv** and **json** format as well.`
|
53
|
-
#
|
54
|
-
# ```
|
55
|
-
# def index
|
56
|
-
# # do something before the origin action
|
57
|
-
# options = {} # NOTE: see `options` parameter for more details
|
58
|
-
# index!(options) do |format| # NOTE: this is better than using `super`
|
59
|
-
# # NOTE: this block is for `respond_with` which works similar to `respond_to`
|
60
|
-
# # customize response behaviour, or do something before the request is rendered
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
# ```
|
64
|
-
#
|
65
|
-
# Otherwise, it can be replaced completely in subclasses:
|
66
|
-
#
|
67
|
-
# `WARN: Please keep in mind that Wallaby User Interface requires **index**
|
68
|
-
# action to respond to **csv** and **json** format as well.`
|
69
|
-
#
|
70
|
-
# ```
|
71
|
-
# def index
|
72
|
-
# # NOTE: `@collection` will be used by the view, please ensure it is assigned, for example:
|
73
|
-
# @collection = Product.all
|
74
|
-
# respond_with @collection
|
75
|
-
# end
|
76
|
-
# ```
|
77
|
-
# @param options [Hash] (since 5.2.0) options for
|
78
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
79
|
-
# respond_with}
|
80
|
-
# @yield [format] block for
|
81
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
82
|
-
# respond_with}
|
83
|
-
# to customize response behaviour.
|
84
|
-
# @raise [Wallaby::Forbidden] if user has no access
|
85
|
-
def index(options = {}, &block)
|
86
|
-
current_authorizer.authorize :index, current_model_class
|
87
|
-
respond_with collection, options, &block
|
88
|
-
end
|
89
|
-
|
90
|
-
alias index! index
|
91
|
-
|
92
|
-
# @note This is a template method that can be overridden by subclasses.
|
93
|
-
# This is a resourceful action to show the form to create record that user is allowed to.
|
94
|
-
#
|
95
|
-
# It can be customized as below in subclasses:
|
96
|
-
#
|
97
|
-
# ```
|
98
|
-
# def new
|
99
|
-
# # do something before the origin action
|
100
|
-
# options = {} # NOTE: see `options` parameter for more details
|
101
|
-
# new!(options) do |format| # NOTE: this is better than using `super`
|
102
|
-
# # NOTE: this block is for `respond_with` which works similar to `respond_to`
|
103
|
-
# # customize response behaviour, or do something before the request is rendered
|
104
|
-
# end
|
105
|
-
# end
|
106
|
-
# ```
|
107
|
-
#
|
108
|
-
# Otherwise, it can be replaced completely in subclasses:
|
109
|
-
#
|
110
|
-
# ```
|
111
|
-
# def new
|
112
|
-
# # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
|
113
|
-
# @resource = Product.new new_arrival: true
|
114
|
-
# end
|
115
|
-
# ```
|
116
|
-
# @param options [Hash] (since 5.2.0) options for
|
117
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
118
|
-
# respond_with}
|
119
|
-
# @yield [format] block for
|
120
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
121
|
-
# respond_with}
|
122
|
-
# to customize response behaviour.
|
123
|
-
# @raise [Wallaby::Forbidden] if user has no access
|
124
|
-
def new(options = {}, &block)
|
125
|
-
current_authorizer.authorize :new, resource
|
126
|
-
respond_with resource, options, &block
|
127
|
-
end
|
128
|
-
|
129
|
-
alias new! new
|
130
|
-
|
131
|
-
# @note This is a template method that can be overridden by subclasses.
|
132
|
-
# This is a resourceful action to create a record that user is allowed to.
|
133
|
-
#
|
134
|
-
# If record is created successfully, user will be navigated to the record show page.
|
135
|
-
# Otherwise, the form will be shown again with error messages.
|
136
|
-
#
|
137
|
-
# It can be customized as below in subclasses:
|
138
|
-
#
|
139
|
-
# ```
|
140
|
-
# def create
|
141
|
-
# # do something before the origin action
|
142
|
-
# options = {} # NOTE: see `options` parameter for more details
|
143
|
-
# create!(options) do |format| # NOTE: this is better than using `super`
|
144
|
-
# # NOTE: this block is for `respond_with` which works similar to `respond_to`
|
145
|
-
# # customize response behaviour, or do something before the request is rendered
|
146
|
-
# end
|
147
|
-
# end
|
148
|
-
# ```
|
149
|
-
#
|
150
|
-
# Otherwise, it can be replaced completely in subclasses:
|
151
|
-
#
|
152
|
-
# ```
|
153
|
-
# def create
|
154
|
-
# # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
|
155
|
-
# @resource = Product.new resource_params.merge(new_arrival: true)
|
156
|
-
# if @resource.save
|
157
|
-
# redirect_to helper.index_path(current_model_class)
|
158
|
-
# else
|
159
|
-
# render :new
|
160
|
-
# end
|
161
|
-
# end
|
162
|
-
# ```
|
163
|
-
# @param options [Hash] (since 5.2.0) options for
|
164
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
165
|
-
# respond_with}. In addition, options `:params` is supported, see below
|
166
|
-
# @option options [ActionController::Parameters, Hash] :params
|
167
|
-
# permitted parameters for servicer to create the record. _(defaults to: {#resource_params})_
|
168
|
-
# @yield [format] block for
|
169
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
170
|
-
# respond_with}
|
171
|
-
# to customize response behaviour.
|
172
|
-
# @raise [Wallaby::Forbidden] if user has no access
|
173
|
-
def create(options = {}, &block)
|
174
|
-
set_defaults_for :create, options
|
175
|
-
current_authorizer.authorize :create, resource
|
176
|
-
current_servicer.create resource, options.delete(:params)
|
177
|
-
respond_with resource, options, &block
|
178
|
-
end
|
179
|
-
|
180
|
-
alias create! create
|
181
|
-
|
182
|
-
# @note This is a template method that can be overridden by subclasses.
|
183
|
-
# This is a resourceful action to display the record details that user is allowed to.
|
184
|
-
#
|
185
|
-
# It can be customized as below in subclasses:
|
186
|
-
#
|
187
|
-
# ```
|
188
|
-
# def show
|
189
|
-
# # do something before the origin action
|
190
|
-
# options = {} # NOTE: see `options` parameter for more details
|
191
|
-
# show!(options) do |format| # NOTE: this is better than using `super`
|
192
|
-
# # NOTE: this block is for `respond_with` which works similar to `respond_to`
|
193
|
-
# # customize response behaviour, or do something before the request is rendered
|
194
|
-
# end
|
195
|
-
# end
|
196
|
-
# ```
|
197
|
-
#
|
198
|
-
# Otherwise, it can be replaced completely in subclasses:
|
199
|
-
#
|
200
|
-
# ```
|
201
|
-
# def show
|
202
|
-
# # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
|
203
|
-
# @resource = Product.find_by_slug params[:id]
|
204
|
-
# end
|
205
|
-
# ```
|
206
|
-
# @param options [Hash] (since 5.2.0) options for
|
207
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
208
|
-
# respond_with}
|
209
|
-
# @yield [format] block for
|
210
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
211
|
-
# respond_with}
|
212
|
-
# to customize response behaviour.
|
213
|
-
# @raise [Wallaby::Forbidden] if user has no access
|
214
|
-
def show(options = {}, &block)
|
215
|
-
current_authorizer.authorize :show, resource
|
216
|
-
respond_with resource, options, &block
|
217
|
-
end
|
218
|
-
|
219
|
-
alias show! show
|
220
|
-
|
221
|
-
# @note This is a template method that can be overridden by subclasses.
|
222
|
-
# This is a resourceful action to show the form to edit record that user is allowed to.
|
223
|
-
#
|
224
|
-
# It can be customized as below in subclasses:
|
225
|
-
#
|
226
|
-
# ```
|
227
|
-
# def edit
|
228
|
-
# # do something before the origin action
|
229
|
-
# options = {} # NOTE: see `options` parameter for more details
|
230
|
-
# edit!(options) do |format| # NOTE: this is better than using `super`
|
231
|
-
# # NOTE: this block is for `respond_with` which works similar to `respond_to`
|
232
|
-
# # customize response behaviour, or do something before the request is rendered
|
233
|
-
# end
|
234
|
-
# end
|
235
|
-
# ```
|
236
|
-
#
|
237
|
-
# Otherwise, it can be replaced completely in subclasses:
|
238
|
-
#
|
239
|
-
# ```
|
240
|
-
# def edit
|
241
|
-
# # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
|
242
|
-
# @resource = Product.find_by_slug params[:id]
|
243
|
-
# end
|
244
|
-
# ```
|
245
|
-
# @param options [Hash] (since 5.2.0) options for
|
246
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
247
|
-
# respond_with}
|
248
|
-
# @yield [format] block for
|
249
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
250
|
-
# respond_with}
|
251
|
-
# to customize response behaviour.
|
252
|
-
# @raise [Wallaby::Forbidden] if user has no access
|
253
|
-
def edit(options = {}, &block)
|
254
|
-
current_authorizer.authorize :edit, resource
|
255
|
-
respond_with resource, options, &block
|
256
|
-
end
|
257
|
-
|
258
|
-
alias edit! edit
|
259
|
-
|
260
|
-
# @note This is a template method that can be overridden by subclasses.
|
261
|
-
# This is a resourceful action to update the record that user is allowed to.
|
262
|
-
#
|
263
|
-
# If record is updated successfully, user will be navigated to the record show page.
|
264
|
-
# Otherwise, the form will be shown again with error messages.
|
265
|
-
#
|
266
|
-
# It can be customized as below in subclasses:
|
267
|
-
#
|
268
|
-
# ```
|
269
|
-
# def update
|
270
|
-
# # do something before the origin action
|
271
|
-
# options = {} # NOTE: see `options` parameter for more details
|
272
|
-
# update!(options) do |format| # NOTE: this is better than using `super`
|
273
|
-
# # NOTE: this block is for `respond_with` which works similar to `respond_to`
|
274
|
-
# # customize response behaviour, or do something before the request is rendered
|
275
|
-
# end
|
276
|
-
# end
|
277
|
-
# ```
|
278
|
-
#
|
279
|
-
# Otherwise, it can be replaced completely in subclasses:
|
280
|
-
#
|
281
|
-
# ```
|
282
|
-
# def update
|
283
|
-
# # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
|
284
|
-
# @resource = Product.find_by_slug params[:id]
|
285
|
-
# @resource.assign_attributes resource_params.merge(new_arrival: true)
|
286
|
-
# if @resource.save
|
287
|
-
# redirect_to helper.index_path(current_model_class)
|
288
|
-
# else
|
289
|
-
# render :new
|
290
|
-
# end
|
291
|
-
# end
|
292
|
-
# ```
|
293
|
-
# @param options [Hash] (since 5.2.0) options for
|
294
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
295
|
-
# respond_with}. In addition, options `:params` is supported, see below
|
296
|
-
# @option options [ActionController::Parameters, Hash] :params
|
297
|
-
# permitted parameters for servicer to update the record. _(defaults to: {#resource_params})_
|
298
|
-
# @yield [format] block for
|
299
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
300
|
-
# respond_with}
|
301
|
-
# to customize response behaviour.
|
302
|
-
# @raise [Wallaby::Forbidden] if user has no access
|
303
|
-
def update(options = {}, &block)
|
304
|
-
set_defaults_for :update, options
|
305
|
-
current_authorizer.authorize :update, resource
|
306
|
-
current_servicer.update resource, options.delete(:params)
|
307
|
-
respond_with resource, options, &block
|
308
|
-
end
|
309
|
-
|
310
|
-
alias update! update
|
311
|
-
|
312
|
-
# @note This is a template method that can be overridden by subclasses.
|
313
|
-
# This is a resourceful action to delete the record that user is allowed to.
|
314
|
-
#
|
315
|
-
# It can be customized as below in subclasses:
|
316
|
-
#
|
317
|
-
# ```
|
318
|
-
# def destroy
|
319
|
-
# # do something before the origin action
|
320
|
-
# options = {} # NOTE: see `options` parameter for more details
|
321
|
-
# destroy!(options) do |format| # NOTE: this is better than using `super`
|
322
|
-
# # NOTE: this block is for `respond_with` which works similar to `respond_to`
|
323
|
-
# # customize response behaviour, or do something before the request is rendered
|
324
|
-
# end
|
325
|
-
# end
|
326
|
-
# ```
|
327
|
-
#
|
328
|
-
# Otherwise, it can be replaced completely in subclasses:
|
329
|
-
#
|
330
|
-
# ```
|
331
|
-
# def destroy
|
332
|
-
# # NOTE: `@resource` will be used by the view, please ensure it is assigned, for example:
|
333
|
-
# @resource = Product.find_by_slug params[:id]
|
334
|
-
# @resource.destroy
|
335
|
-
# redirect_to helper.index_path(current_model_class)
|
336
|
-
# end
|
337
|
-
# ```
|
338
|
-
# @param options [Hash] (since 5.2.0) options for
|
339
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
340
|
-
# respond_with}. In addition, options `:params` is supported, see below
|
341
|
-
# @option options [ActionController::Parameters, Hash] :params
|
342
|
-
# permitted parameters for servicer to destroy the record. _(defaults to: {#resource_params})_
|
343
|
-
# @yield [format] block for
|
344
|
-
# {https://www.rubydoc.info/gems/responders/ActionController/RespondWith#respond_with-instance_method
|
345
|
-
# respond_with}
|
346
|
-
# to customize response behaviour.
|
347
|
-
# @raise [Wallaby::Forbidden] if user has no access
|
348
|
-
def destroy(options = {}, &block)
|
349
|
-
set_defaults_for :destroy, options
|
350
|
-
current_authorizer.authorize :destroy, resource
|
351
|
-
current_servicer.destroy resource, options.delete(:params)
|
352
|
-
respond_with resource, options, &block
|
353
|
-
end
|
354
|
-
|
355
|
-
alias destroy! destroy
|
356
|
-
|
357
|
-
# @note This is a template method that can be overridden by subclasses.
|
358
|
-
# To whitelist the params for {#create} and {#update} actions.
|
359
|
-
#
|
360
|
-
# If Wallaby cannot generate the correct strong parameters, it can be replaced, for example:
|
361
|
-
#
|
362
|
-
# ```
|
363
|
-
# def resource_params
|
364
|
-
# params.fetch(:product, {}).permit(:name, :sku)
|
365
|
-
# end
|
366
|
-
# ```
|
367
|
-
# @return [ActionController::Parameters] whitelisted params
|
368
|
-
def resource_params
|
369
|
-
@resource_params ||= current_servicer.permit params, action_name
|
370
|
-
end
|
371
|
-
|
372
|
-
# @!method collection(options = {}, &block)
|
373
|
-
# (see Wallaby::Resourcable#collection)
|
374
|
-
# @see Wallaby::Resourcable#collection
|
375
|
-
alias collection! collection
|
376
|
-
|
377
|
-
# @!method resource(options = {}, &block)
|
378
|
-
# (see Wallaby::Resourcable#resource)
|
379
|
-
# @see Wallaby::Resourcable#resource
|
380
|
-
alias resource! resource
|
12
|
+
#
|
13
|
+
# For better practice, please create an application controller class (see example)
|
14
|
+
# to better control the functions shared between different resource controllers.
|
15
|
+
# @example Create an application class for Admin Interface usage
|
16
|
+
# class Admin::ApplicationController < Wallaby::ResourcesController
|
17
|
+
# base_class!
|
18
|
+
# end
|
19
|
+
class ResourcesController
|
20
|
+
include ResourcesConcern
|
381
21
|
end
|
382
22
|
end
|
data/app/security/ability.rb
CHANGED