godmin 1.4.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +0 -2
- data/.gitignore +1 -0
- data/.travis.yml +9 -10
- data/Appraisals +4 -4
- data/CHANGELOG.md +77 -2
- data/Gemfile +1 -2
- data/README.md +110 -9
- data/Rakefile +2 -2
- data/app/views/godmin/resource/_breadcrumb.html.erb +12 -24
- data/app/views/godmin/resource/_breadcrumb_actions.html.erb +41 -0
- data/app/views/godmin/resource/_button_actions.html.erb +1 -1
- data/app/views/godmin/resource/_pagination.html.erb +4 -4
- data/app/views/godmin/resource/columns/_actions.html.erb +3 -3
- data/app/views/godmin/resource/show.html.erb +1 -1
- data/config/locales/en.yml +2 -0
- data/config/locales/pt-BR.yml +2 -0
- data/config/locales/sv.yml +2 -0
- data/gemfiles/rails_5.gemfile +3 -4
- data/gemfiles/rails_6.gemfile +8 -0
- data/godmin.gemspec +18 -16
- data/lib/generators/godmin/resource/resource_generator.rb +7 -1
- data/lib/generators/godmin/resource/templates/resource_model.rb +4 -0
- data/lib/godmin/application_controller.rb +10 -11
- data/lib/godmin/authentication.rb +11 -11
- data/lib/godmin/authentication/sessions_controller.rb +1 -0
- data/lib/godmin/authorization.rb +34 -14
- data/lib/godmin/engine_wrapper.rb +10 -1
- data/lib/godmin/generators/base.rb +4 -4
- data/lib/godmin/generators/named_base.rb +4 -4
- data/lib/godmin/helpers/application.rb +3 -3
- data/lib/godmin/helpers/batch_actions.rb +1 -1
- data/lib/godmin/helpers/forms.rb +5 -1
- data/lib/godmin/resolver.rb +20 -5
- data/lib/godmin/resources/resource_controller.rb +24 -5
- data/lib/godmin/resources/resource_controller/batch_actions.rb +1 -1
- data/lib/godmin/resources/resource_service.rb +8 -7
- data/lib/godmin/resources/resource_service/associations.rb +23 -0
- data/lib/godmin/version.rb +1 -1
- data/template.rb +17 -3
- data/test/dummy/admin/app/controllers/admin/authorized_articles_controller.rb +29 -0
- data/test/dummy/admin/app/models/admin/article.rb +4 -0
- data/test/dummy/admin/app/models/admin/magazine.rb +4 -0
- data/test/dummy/admin/app/policies/admin/article_policy.rb +11 -0
- data/test/dummy/admin/app/policies/admin/magazine_policy.rb +4 -0
- data/test/dummy/admin/app/views/admin/shared/_navigation.html.erb +5 -0
- data/test/dummy/admin/config/routes.rb +1 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/controllers/another_admin_sessions_controller.rb +0 -2
- data/test/dummy/app/controllers/comments_controller.rb +3 -0
- data/test/dummy/app/models/article.rb +1 -0
- data/test/dummy/app/models/comment.rb +7 -0
- data/test/dummy/app/models/magazine.rb +2 -0
- data/test/dummy/app/services/article_service.rb +2 -0
- data/test/dummy/app/services/comment_service.rb +7 -0
- data/test/dummy/bin/rails +1 -1
- data/test/dummy/config/application.rb +2 -14
- data/test/dummy/config/locales/en.yml +9 -0
- data/test/dummy/config/routes.rb +3 -1
- data/test/dummy/db/migrate/20150717121532_create_articles.rb +1 -1
- data/test/dummy/db/migrate/20150907133753_create_admin_users.rb +1 -1
- data/test/dummy/db/migrate/20160713134238_create_comment.rb +9 -0
- data/test/dummy/db/migrate/20210519215502_create_magazines.rb +9 -0
- data/test/dummy/db/schema.rb +35 -20
- data/test/fakes/article.rb +1 -1
- data/test/fakes/article_service.rb +3 -7
- data/test/generators/resource_generator_test.rb +78 -0
- data/test/integration/authentication_test.rb +3 -2
- data/test/integration/authorization_test.rb +13 -0
- data/test/integration/nested_resources_test.rb +47 -0
- data/test/test_helper.rb +1 -7
- data/test/{lib/godmin → unit}/engine_wrapper_test.rb +0 -0
- data/test/{lib/godmin → unit}/helpers/filters_test.rb +0 -0
- data/test/{lib/godmin → unit}/paginator_test.rb +0 -0
- data/test/{lib/godmin → unit}/resolver_test.rb +0 -0
- data/test/{lib/godmin → unit}/resources/resource_service/batch_actions_test.rb +0 -0
- data/test/{lib/godmin → unit}/resources/resource_service/filters_test.rb +0 -0
- data/test/{lib/godmin → unit}/resources/resource_service/ordering_test.rb +0 -0
- data/test/{lib/godmin → unit}/resources/resource_service/pagination_test.rb +0 -0
- data/test/{lib/godmin → unit}/resources/resource_service/scopes_test.rb +0 -0
- data/test/{lib/godmin → unit}/resources/resource_service_test.rb +0 -0
- metadata +169 -107
- data/gemfiles/rails_4.gemfile +0 -9
- data/lib/godmin/authorization/policy_finder.rb +0 -31
- data/lib/tasks/godmin_tasks.rake +0 -4
- data/test/lib/godmin/policy_finder_test.rb +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d659e1782cb8fbbe56b7f2b02e6d35accf718a9b86b04d26072343bc7b7d0946
|
4
|
+
data.tar.gz: eed902f06dd62ed82872c938bed84e3197140aae626551794248554b2c3a7a3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40496213be9caea389d129d5ee649ba2283a553e6c5a9c8f7b819f14934a38e9a2fcf257c947bd5bbc498d08edb0a229d32ad65c9332e8cd88552ed83803afeb
|
7
|
+
data.tar.gz: e89991517c1dd57de145f369c23b47fda087d343932da47e2776874b1b13eb0da33594868f2adc9130c7e4d73c25d03d1484607d6d76711d5a6315bfbb0e655d
|
data/.codeclimate.yml
CHANGED
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
-
bundler_args: --without debug
|
1
|
+
bundler_args: "--without debug"
|
2
2
|
cache: bundler
|
3
|
-
script:
|
4
|
-
sudo: false
|
5
|
-
|
3
|
+
script: bundle exec rake test
|
6
4
|
rvm:
|
7
|
-
- 2.
|
8
|
-
- 2.3
|
9
|
-
|
5
|
+
- 2.6.7
|
6
|
+
- 2.7.3
|
7
|
+
- 3.0.1
|
10
8
|
gemfile:
|
11
|
-
- gemfiles/rails_4.gemfile
|
12
9
|
- gemfiles/rails_5.gemfile
|
10
|
+
- gemfiles/rails_6.gemfile
|
13
11
|
|
14
12
|
matrix:
|
15
13
|
exclude:
|
16
|
-
- rvm:
|
14
|
+
- rvm: 3.0.1
|
17
15
|
gemfile: gemfiles/rails_5.gemfile
|
18
16
|
|
19
17
|
addons:
|
20
18
|
code_climate:
|
21
|
-
repo_token:
|
19
|
+
repo_token:
|
20
|
+
secure: WBszVdtEvWM2KugFre9BpwkCduY6hjrmK7xo1GLiru4NMqr4ZoRXruQ5ijhZE79YqduR6zudKr72g9yG4R+4CK7ghYu4x5JB76IW8gFWpI9teTWrF4hdSbJgwxSH5JNkqWF4f6ic4Xr1Vgc43agzt+1KmA9imoGs2Q0EbAY3H2M=
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,55 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 2.2.1 - 2021-05-20
|
4
|
+
|
5
|
+
Fix
|
6
|
+
- Use Pundit >= 2.0.0 so that namespaces are handled correctly (https://github.com/varvet/godmin/pull/260)
|
7
|
+
|
8
|
+
### 2.2.0 - 2021-05-20
|
9
|
+
|
10
|
+
Other
|
11
|
+
- Build and test against Ruby 3.0
|
12
|
+
|
13
|
+
Bug fixes
|
14
|
+
- Regression: within an Engine, always look for Pundit policies in the engine (https://github.com/varvet/godmin/pull/259)
|
15
|
+
|
16
|
+
### 2.1.0 - 2021-05-10
|
17
|
+
|
18
|
+
Bug fixes
|
19
|
+
- Use symbol in path for compatibility with the latest Rails security patches (https://github.com/varvet/godmin/pull/256)
|
20
|
+
|
21
|
+
Other
|
22
|
+
- Build and test against Ruby 2.6 and 2.7
|
23
|
+
- Stop building and testing against unsupported rubies (2.5 and older). These may still work and PRs may still be accepted.
|
24
|
+
|
25
|
+
### 2.0.0 - 2019-12-06
|
26
|
+
|
27
|
+
Features
|
28
|
+
- Allow skipping authorization per action (https://github.com/varvet/godmin/pull/231)
|
29
|
+
|
30
|
+
Bug fixes
|
31
|
+
- Support namespaced models when generating resources (https://github.com/varvet/godmin/issues/181)
|
32
|
+
|
33
|
+
Other
|
34
|
+
- Drop support for Rails 4 (https://github.com/varvet/godmin/pull/239)
|
35
|
+
- Better policy lookups for namespaced models (https://github.com/varvet/godmin/pull/180)
|
36
|
+
- Use Pundit for authorization (https://github.com/varvet/godmin/pull/180)
|
37
|
+
- Rails 6 support (https://github.com/varvet/godmin/pull/248) and (https://github.com/varvet/godmin/pull/250)
|
38
|
+
|
39
|
+
In order to upgrade
|
40
|
+
- Upgrade to at least Rails 5 and Ruby 2.2.2
|
41
|
+
- If using an admin engine, create a namespaced model for every resource, inheriting from the main app model
|
42
|
+
- Replace any `authenticate_admin_user` with `authenticate`
|
43
|
+
- Replace any `skip_before_action :authenticate_admin_user` with `prepend_before_action :disable_authentication`
|
44
|
+
- Replace any `rescue_from NotAuthorizedError` with `rescue_from Pundit::NotAuthorizedError`
|
45
|
+
|
46
|
+
### 1.5.0 - 2017-02-17
|
47
|
+
|
48
|
+
Features
|
49
|
+
- Support for nested resources (https://github.com/varvet/godmin/pull/189)
|
50
|
+
|
3
51
|
### 1.4.0 - 2017-02-15
|
52
|
+
|
4
53
|
Features
|
5
54
|
- Support group queries in scopes and filters (https://github.com/varvet/godmin/pull/208)
|
6
55
|
- Change color of remove buttons, so they're not grabbing all the attention (https://github.com/varvet/godmin/pull/212)
|
@@ -13,6 +62,7 @@ Other
|
|
13
62
|
- Add table caption for tests (https://github.com/varvet/godmin/pull/187)
|
14
63
|
|
15
64
|
### 1.3.1 - 2016-09-27
|
65
|
+
|
16
66
|
Bug fixes
|
17
67
|
- Fix FileSystemResolver issue (https://github.com/varvet/godmin/pull/202)
|
18
68
|
|
@@ -20,6 +70,7 @@ Other
|
|
20
70
|
- Update template for Rails 5 (https://github.com/varvet/godmin/commit/95e0a7917dd9767d77c3bfc876ebbf0a6036f347)
|
21
71
|
|
22
72
|
### 1.3.0 - 2016-07-11
|
73
|
+
|
23
74
|
Features
|
24
75
|
- Increased batch action checkbox click area (https://github.com/varvet/godmin/pull/183)
|
25
76
|
- Adds titles to action links (https://github.com/varvet/godmin/pull/185)
|
@@ -35,6 +86,7 @@ Other
|
|
35
86
|
- Adds caching partial overrides to increase table rendering speed (https://github.com/varvet/godmin/pull/184)
|
36
87
|
|
37
88
|
### 1.2.0 - 2016-02-02
|
89
|
+
|
38
90
|
Features
|
39
91
|
- Adds support for custom ordering of columns (https://github.com/varvet/godmin/pull/168)
|
40
92
|
- Adds passing of options to association form helper (https://github.com/varvet/godmin/pull/172)
|
@@ -44,6 +96,7 @@ Bug fixes
|
|
44
96
|
- Fixes an issue with the template resolver and Rails 4.2.5.1 (https://github.com/varvet/godmin/pull/175)
|
45
97
|
|
46
98
|
### 1.1.0 - 2015-12-08
|
99
|
+
|
47
100
|
Features
|
48
101
|
- Adds locale for pt-BR (Brazilian Portuguese) (https://github.com/varvet/godmin/pull/141)
|
49
102
|
- New sandbox template with with more examples (https://github.com/varvet/godmin/pull/135)
|
@@ -56,22 +109,27 @@ Bug fixes
|
|
56
109
|
- Fixes a namespace issue with the authentication generator (https://github.com/varvet/godmin/pull/150)
|
57
110
|
|
58
111
|
### 1.0.0 - 2015-11-13
|
112
|
+
|
59
113
|
Release of 1.0.0 :tada:
|
60
114
|
|
61
115
|
### 0.12.4 - 2015-10-21
|
116
|
+
|
62
117
|
Bug fixes
|
63
118
|
- Fixes a bug which made it impossible to override the datetimepicker locale (https://github.com/varvet/godmin/issues/132)
|
64
119
|
|
65
120
|
### 0.12.3 - 2015-09-18
|
121
|
+
|
66
122
|
Bug fixes
|
67
123
|
- Adds support for plural engines (https://github.com/varvet/godmin/pull/128)
|
68
124
|
- Remove turbolinks from application.js if present (https://github.com/varvet/godmin/issues/129)
|
69
125
|
|
70
126
|
### 0.12.2 - 2015-09-07
|
127
|
+
|
71
128
|
Bug fixes
|
72
129
|
- Fixes broken sign in page
|
73
130
|
|
74
131
|
### 0.12.1 - 2015-09-07
|
132
|
+
|
75
133
|
Bug fixes
|
76
134
|
- Fixes issue where column ordering on index table didn't work (https://github.com/varvet/godmin/issues/124)
|
77
135
|
|
@@ -79,17 +137,18 @@ Other
|
|
79
137
|
- Adds integration tests
|
80
138
|
- Removes the namespace config in `initializers/godmin.rb`
|
81
139
|
|
82
|
-
In order to upgrade
|
140
|
+
In order to upgrade
|
83
141
|
- Remove the `initializers/godmin.rb` file
|
84
142
|
|
85
143
|
### 0.12.0 - 2015-06-30
|
144
|
+
|
86
145
|
Features
|
87
146
|
- Adds new navigation helpers for building a custom navbar (https://github.com/varvet/godmin/issues/54)
|
88
147
|
|
89
148
|
Other
|
90
149
|
- Removes the godmin router method
|
91
150
|
|
92
|
-
In order to upgrade
|
151
|
+
In order to upgrade
|
93
152
|
- Remove the `godmin do` block from the `config/routes.rb` file
|
94
153
|
- Specify a root route if there is none already
|
95
154
|
- Create a `shared/_navigation.html.erb` partial if there is none already
|
@@ -98,10 +157,12 @@ Bug fixes
|
|
98
157
|
- Fixes issue with authentication generator not modifying the application controller
|
99
158
|
|
100
159
|
### 0.11.2 - 2015-06-22
|
160
|
+
|
101
161
|
Bug fixes
|
102
162
|
- Fixes broken collection select helper
|
103
163
|
|
104
164
|
### 0.11.1 - 2015-05-20
|
165
|
+
|
105
166
|
Features
|
106
167
|
- Adds `destroy_resource` method to `ResourceService`
|
107
168
|
- Adds query param to authorize
|
@@ -115,6 +176,7 @@ Bug fixes
|
|
115
176
|
- Fixes a regression where filter labels were not translated
|
116
177
|
|
117
178
|
### 0.11.0 - 2015-04-13
|
179
|
+
|
118
180
|
Other
|
119
181
|
- Split resources into controllers and service objects (https://github.com/varvet/godmin/pull/79)
|
120
182
|
- Renames the following modules:
|
@@ -123,18 +185,22 @@ Other
|
|
123
185
|
- Godmin::Sessions -> Godmin::SessionsController
|
124
186
|
|
125
187
|
### 0.10.3 - 2015-02-18
|
188
|
+
|
126
189
|
Bug fixes
|
127
190
|
- Adds the possibility to pass options to the `date_field` and `datetime_field` form helpers
|
128
191
|
|
129
192
|
### 0.10.2 - 2015-02-16
|
193
|
+
|
130
194
|
Bug fixes
|
131
195
|
- Fixes standard resource params for multi-word models
|
132
196
|
|
133
197
|
### 0.10.1 - 2015-02-13
|
198
|
+
|
134
199
|
Bug fixes
|
135
200
|
- Fixes multi-select selectize issue (https://github.com/varvet/godmin/issues/71)
|
136
201
|
|
137
202
|
### 0.10.0 - 2015-02-11
|
203
|
+
|
138
204
|
Features
|
139
205
|
- Shows the number of items in each scope in the scope tab (https://github.com/varvet/godmin/issues/16)
|
140
206
|
- Two new overridable methods for resources: `build_resource` and `find_resource`
|
@@ -151,21 +217,25 @@ Other
|
|
151
217
|
- Restructured the locale files a bit
|
152
218
|
|
153
219
|
### 0.9.9 - 2015-01-23
|
220
|
+
|
154
221
|
Features
|
155
222
|
- Bump bootstrap to 3.3.3
|
156
223
|
- Extracted button actions partial
|
157
224
|
|
158
225
|
### 0.9.8 - 2015-01-12
|
226
|
+
|
159
227
|
Bug fixes
|
160
228
|
- Created resources are now properly scoped by `resources_relation`
|
161
229
|
- Fixes broken signin form
|
162
230
|
|
163
231
|
### 0.9.7 - 2015-01-07
|
232
|
+
|
164
233
|
Features
|
165
234
|
- Support for Rails 4.2
|
166
235
|
- New form system (https://github.com/varvet/godmin/pull/50)
|
167
236
|
|
168
237
|
### 0.9.6 - 2014-12-18
|
238
|
+
|
169
239
|
Features
|
170
240
|
- Bundled [datetimepicker](https://github.com/Eonasdan/bootstrap-datetimepicker/)
|
171
241
|
- Exposed JavaScript API
|
@@ -175,18 +245,22 @@ Notes
|
|
175
245
|
- You can no longer use the `select-tag` class to initialize a select box
|
176
246
|
|
177
247
|
### 0.9.5 - 2014-12-15
|
248
|
+
|
178
249
|
Bug fixes
|
179
250
|
- Fixes Godmin::FormBuilder issue
|
180
251
|
|
181
252
|
### 0.9.4 - 2014-12-15
|
253
|
+
|
182
254
|
Features
|
183
255
|
- Added Godmin::FormBuilder
|
184
256
|
|
185
257
|
### 0.9.3 - 2014-12-10
|
258
|
+
|
186
259
|
Bug fixes
|
187
260
|
- Pagination offset fix
|
188
261
|
|
189
262
|
### 0.9.2 - 2014-12-09
|
263
|
+
|
190
264
|
Features
|
191
265
|
- Replaces select2 with [selectize](http://brianreavis.github.io/selectize.js/)
|
192
266
|
- Adds flash messages (https://github.com/varvet/godmin/issues/26)
|
@@ -199,6 +273,7 @@ Bug fixes
|
|
199
273
|
- Fixes default permitted params to work with multiword models.
|
200
274
|
|
201
275
|
### 0.9.1 - 2014-11-18
|
276
|
+
|
202
277
|
Bug fixes
|
203
278
|
- Removed rails executable from /bin folder.
|
204
279
|
|
data/Gemfile
CHANGED
@@ -12,5 +12,4 @@ gemspec
|
|
12
12
|
|
13
13
|
# The dummy app loads whatever is specified in this gemfile, therefore
|
14
14
|
# we add the admin engine used by the dummy app here
|
15
|
-
gem "admin", path: "test/dummy/admin", group: [
|
16
|
-
gem "codeclimate-test-reporter", group: :test, require: nil
|
15
|
+
gem "admin", path: "test/dummy/admin", group: %i[test development]
|
data/README.md
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](http://img.shields.io/gem/v/godmin.svg)](https://rubygems.org/gems/godmin)
|
4
4
|
[![Build Status](https://img.shields.io/travis/varvet/godmin/master.svg)](https://travis-ci.org/varvet/godmin)
|
5
|
-
[![Code Climate](https://
|
6
|
-
[![Test Coverage](https://codeclimate.com/
|
5
|
+
[![Code Climate](https://api.codeclimate.com/v1/badges/d8e5c7c54c1dba073689/maintainability)](https://codeclimate.com/github/varvet/godmin)
|
6
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/d8e5c7c54c1dba073689/test_coverage)](https://codeclimate.com/github/varvet/godmin)
|
7
7
|
|
8
|
-
Godmin is an admin framework for Rails
|
8
|
+
Godmin is an admin framework for Rails 5+. Use it to build dedicated admin sections for your apps, or stand alone admin apps such as internal tools. It has support for common features such as scoping, filtering and performing batch actions on your models. Check out the [demo app](http://godmin-sandbox.herokuapp.com) and its [source code](https://github.com/varvet/godmin-sandbox) to get a feel for how it works.
|
9
9
|
|
10
10
|
Godmin differs from tools like [ActiveAdmin](http://activeadmin.info/) and [RailsAdmin](https://github.com/sferik/rails_admin) in how admin sections are created. Rather than being DSL-based, Godmin is a set of opt-in modules and helpers that can be applied to regular Rails apps and engines. An admin section built with Godmin is just that, a regular Rails app or Rails engine, with regular routes, controllers and views. That means there is less to learn, because you already know most of it, and fewer constraints on what you can do. After all, administrators are users too, and what better way to provide them with a tailor made experience than building them a Rails app?
|
11
11
|
|
@@ -25,6 +25,7 @@ Godmin differs from tools like [ActiveAdmin](http://activeadmin.info/) and [Rail
|
|
25
25
|
- [Redirecting](#redirecting)
|
26
26
|
- [Pagination](#pagination)
|
27
27
|
- [Exporting](#exporting)
|
28
|
+
- [Nested resources](#nested-resources)
|
28
29
|
- [Views](#views)
|
29
30
|
- [Forms](#forms)
|
30
31
|
- [Navigation](#navigation)
|
@@ -143,6 +144,15 @@ It inserts a `navbar_item` in the `app/views/shared/_navigation.html.erb` partia
|
|
143
144
|
<%= navbar_item Article %>
|
144
145
|
```
|
145
146
|
|
147
|
+
If Godmin was installed inside an engine, it creates a model class:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
module Admin
|
151
|
+
class Article < ::Article
|
152
|
+
end
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
146
156
|
It creates a controller:
|
147
157
|
|
148
158
|
```ruby
|
@@ -511,7 +521,7 @@ If you wish to change the number of resources per page, you can override the `pe
|
|
511
521
|
|
512
522
|
```ruby
|
513
523
|
class ArticlesService
|
514
|
-
include Godmin::Resources::
|
524
|
+
include Godmin::Resources::ResourceService
|
515
525
|
|
516
526
|
def per_page
|
517
527
|
50
|
@@ -525,12 +535,36 @@ The `attrs_for_export` method in the service object makes it possible to mark at
|
|
525
535
|
|
526
536
|
```ruby
|
527
537
|
class ArticlesService
|
528
|
-
include Godmin::Resources::
|
538
|
+
include Godmin::Resources::ResourceService
|
529
539
|
|
530
540
|
attrs_for_export :id, :title, :created_at, :updated_at
|
531
541
|
end
|
532
542
|
```
|
533
543
|
|
544
|
+
### Nested resources
|
545
|
+
|
546
|
+
Nested resources can be implemented by nesting your routes:
|
547
|
+
|
548
|
+
```ruby
|
549
|
+
resources :blogs do
|
550
|
+
resources :blog_posts
|
551
|
+
end
|
552
|
+
```
|
553
|
+
|
554
|
+
This will set up scoping of the nested resource as well as correct links in the breadcrumb.
|
555
|
+
|
556
|
+
If you want to add a link to the nested resource from the parent's show and edit pages, you can add the following to the service object:
|
557
|
+
|
558
|
+
```ruby
|
559
|
+
class BlogService
|
560
|
+
include Godmin::Resources::ResourceService
|
561
|
+
|
562
|
+
has_many :blog_posts
|
563
|
+
end
|
564
|
+
```
|
565
|
+
|
566
|
+
Otherwise, simply add links as you see fit using partial overrides.
|
567
|
+
|
534
568
|
## Views
|
535
569
|
|
536
570
|
It's easy to override view templates and partials in Godmin, both globally and per resource. All you have to do is place a file with an identical name in your `app/views` directory. For instance, to override the `godmin/resource/index.html.erb` template for all resources, place a file under `app/views/resource/index.html.erb`. If you only wish to override it for articles, place it instead under `app/views/articles/index.html.erb`.
|
@@ -716,9 +750,19 @@ end
|
|
716
750
|
|
717
751
|
The admin section is now authenticated using Devise.
|
718
752
|
|
753
|
+
### Disable authentication
|
754
|
+
|
755
|
+
If you want to disable authentication for a single controller or controller action, use the following `before_action`:
|
756
|
+
|
757
|
+
```ruby
|
758
|
+
class ArticlesController < ApplicationController
|
759
|
+
prepend_before_action :disable_authentication
|
760
|
+
end
|
761
|
+
```
|
762
|
+
|
719
763
|
## Authorization
|
720
764
|
|
721
|
-
In order to enable authorization, authentication must first be enabled. See the previous section. The Godmin authorization system
|
765
|
+
In order to enable authorization, authentication must first be enabled. See the previous section. The Godmin authorization system uses [Pundit](https://github.com/elabs/pundit).
|
722
766
|
|
723
767
|
Add the authorization module to the application controller:
|
724
768
|
|
@@ -778,8 +822,8 @@ end
|
|
778
822
|
That is, everyone can list and view articles, only editors can create them, and only unpublished articles can be updated and destroyed.
|
779
823
|
|
780
824
|
### Handle unauthorized access
|
781
|
-
|
782
|
-
If you want to change this behaviour you can rescue the error yourself in the appropriate `ApplicationController`:
|
825
|
+
|
826
|
+
When a user is not authorized to access a resource, a `Pundit::NotAuthorizedError` is raised. By default this error is rescued by Godmin and turned into a status code `403 Forbidden` response. If you want to change this behaviour you can rescue the error yourself in the appropriate `ApplicationController`:
|
783
827
|
|
784
828
|
```ruby
|
785
829
|
class ApplicationController < ActionController::Base
|
@@ -788,13 +832,14 @@ class ApplicationController < ActionController::Base
|
|
788
832
|
include Godmin::Authorization
|
789
833
|
|
790
834
|
# Renders 404 page and returns status code 404.
|
791
|
-
rescue_from NotAuthorizedError do
|
835
|
+
rescue_from Pundit::NotAuthorizedError do
|
792
836
|
render file: "#{Rails.root}/public/404.html", status: 404, layout: false
|
793
837
|
end
|
794
838
|
end
|
795
839
|
```
|
796
840
|
|
797
841
|
### Override policy object
|
842
|
+
|
798
843
|
If you wish to specify what policy to use manually, override the following method in your model. It does not have to be an ActiveRecord object, but any object will do.
|
799
844
|
|
800
845
|
```ruby
|
@@ -806,6 +851,7 @@ end
|
|
806
851
|
```
|
807
852
|
|
808
853
|
### Batch action authorization
|
854
|
+
|
809
855
|
Batch actions must be authorized in your policy if you are using Godmin's built in authorization functionality. The policy method is called with the relation containing all records to be processed.
|
810
856
|
|
811
857
|
```ruby
|
@@ -816,6 +862,61 @@ class ArticlePolicy < Godmin::Authorization::Policy
|
|
816
862
|
end
|
817
863
|
```
|
818
864
|
|
865
|
+
### Disable authorization
|
866
|
+
|
867
|
+
If you want to disable authorization for a single controller or controller action, use the following `before_action`:
|
868
|
+
|
869
|
+
```ruby
|
870
|
+
class ArticlesController < ApplicationController
|
871
|
+
prepend_before_action :disable_authorization
|
872
|
+
end
|
873
|
+
```
|
874
|
+
|
875
|
+
### Authorization in Engines
|
876
|
+
|
877
|
+
When Godmin is installed as an engine, it expects policies to be defined
|
878
|
+
within the engine: eg. `Admin::ArticlePolicy` defined in
|
879
|
+
`admin/app/policies/article_policy.rb`.
|
880
|
+
|
881
|
+
If your admin application is itself broken up into several engines, then
|
882
|
+
either
|
883
|
+
|
884
|
+
1. the policies for those engines need to live in the main engine, or
|
885
|
+
2. those engines need to be namespaced under the namespace of the main engine.
|
886
|
+
|
887
|
+
Here is one example of a directory structure for approach 2:
|
888
|
+
|
889
|
+
```
|
890
|
+
admin
|
891
|
+
├── app
|
892
|
+
│ └── policies
|
893
|
+
│ └── admin
|
894
|
+
│ └── article_policy.rb
|
895
|
+
└── engines
|
896
|
+
└── content
|
897
|
+
└── policies
|
898
|
+
└── admin
|
899
|
+
└── content
|
900
|
+
└── text_block_policy.rb
|
901
|
+
app
|
902
|
+
└── models
|
903
|
+
└── article.rb
|
904
|
+
engines
|
905
|
+
└── content
|
906
|
+
└── models
|
907
|
+
└── content
|
908
|
+
└── text_block.rb
|
909
|
+
```
|
910
|
+
```ruby
|
911
|
+
# admin/engines/content/policies/admin/content/text_block_policy.rb
|
912
|
+
module Admin
|
913
|
+
module Content
|
914
|
+
class TextBlockPolicy < ::Admin::ApplicationPolicy
|
915
|
+
end
|
916
|
+
end
|
917
|
+
end
|
918
|
+
```
|
919
|
+
|
819
920
|
## Localization
|
820
921
|
|
821
922
|
Godmin supports localization out of the box. For a list of translatable strings, [look here](https://github.com/varvet/godmin/blob/master/config/locales/en.yml).
|