godmin 1.3.1 → 2.2.0
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 +84 -2
- data/Gemfile +1 -2
- data/README.md +119 -10
- 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/_table.html.erb +3 -0
- data/app/views/godmin/resource/columns/_actions.html.erb +4 -4
- 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 +2 -1
- 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/paginator.rb +12 -4
- 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 +8 -0
- data/test/dummy/app/controllers/comments_controller.rb +3 -0
- data/test/dummy/app/models/another_admin_user.rb +7 -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 +6 -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/20170207081043_create_another_admin_user.rb +10 -0
- data/test/dummy/db/migrate/20210519215502_create_magazines.rb +9 -0
- data/test/dummy/db/schema.rb +38 -16
- 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 +8 -0
- data/test/integration/authorization_test.rb +13 -0
- data/test/integration/nested_resources_test.rb +47 -0
- data/test/test_helper.rb +1 -4
- data/test/{lib/godmin → unit}/engine_wrapper_test.rb +1 -1
- data/test/{lib/godmin → unit}/helpers/filters_test.rb +0 -0
- data/test/{lib/godmin → unit}/paginator_test.rb +11 -0
- data/test/{lib/godmin → unit}/resolver_test.rb +0 -0
- data/test/{lib/godmin → unit}/resources/resource_service/batch_actions_test.rb +1 -1
- data/test/{lib/godmin → unit}/resources/resource_service/filters_test.rb +1 -1
- data/test/{lib/godmin → unit}/resources/resource_service/ordering_test.rb +1 -1
- 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 +175 -108
- 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: 11671dfd7c0219abf4626b93f1f7273ee5769486e48a43b82889fe43601f3370
|
4
|
+
data.tar.gz: 0bb8078a5792d05b7fbf4543fd20d924432571e22dc87e00beafc6309a4cae08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f02e2821b7bae9cd0611a97292f6cb8159e9bcaac1f871e7077ddf0f1ad553be98804e4385c434de5326ca12138310032fa52e459db0b9c6572eeac381dbc51
|
7
|
+
data.tar.gz: 166aef398cffb04a6b38560b177f991cdaf5e9cec4be9bf8d2025188d3b83a7c8763502b183ca891bb32b5e2ce7a4a8bc3ba90b7e464164b3be90400bd6b22b6
|
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,63 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 2.2.0 - 2021-05-20
|
4
|
+
|
5
|
+
Other
|
6
|
+
- Build and test against Ruby 3.0
|
7
|
+
|
8
|
+
Bug fixes
|
9
|
+
- Regression: within an Engine, always look for Pundit policies in the engine (https://github.com/varvet/godmin/pull/259)
|
10
|
+
|
11
|
+
### 2.1.0 - 2021-05-10
|
12
|
+
|
13
|
+
Bug fixes
|
14
|
+
- Use symbol in path for compatibility with the latest Rails security patches (https://github.com/varvet/godmin/pull/256)
|
15
|
+
|
16
|
+
Other
|
17
|
+
- Build and test against Ruby 2.6 and 2.7
|
18
|
+
- Stop building and testing against unsupported rubies (2.5 and older). These may still work and PRs may still be accepted.
|
19
|
+
|
20
|
+
### 2.0.0 - 2019-12-06
|
21
|
+
|
22
|
+
Features
|
23
|
+
- Allow skipping authorization per action (https://github.com/varvet/godmin/pull/231)
|
24
|
+
|
25
|
+
Bug fixes
|
26
|
+
- Support namespaced models when generating resources (https://github.com/varvet/godmin/issues/181)
|
27
|
+
|
28
|
+
Other
|
29
|
+
- Drop support for Rails 4 (https://github.com/varvet/godmin/pull/239)
|
30
|
+
- Better policy lookups for namespaced models (https://github.com/varvet/godmin/pull/180)
|
31
|
+
- Use Pundit for authorization (https://github.com/varvet/godmin/pull/180)
|
32
|
+
- Rails 6 support (https://github.com/varvet/godmin/pull/248) and (https://github.com/varvet/godmin/pull/250)
|
33
|
+
|
34
|
+
In order to upgrade
|
35
|
+
- Upgrade to at least Rails 5 and Ruby 2.2.2
|
36
|
+
- If using an admin engine, create a namespaced model for every resource, inheriting from the main app model
|
37
|
+
- Replace any `authenticate_admin_user` with `authenticate`
|
38
|
+
- Replace any `skip_before_action :authenticate_admin_user` with `prepend_before_action :disable_authentication`
|
39
|
+
- Replace any `rescue_from NotAuthorizedError` with `rescue_from Pundit::NotAuthorizedError`
|
40
|
+
|
41
|
+
### 1.5.0 - 2017-02-17
|
42
|
+
|
43
|
+
Features
|
44
|
+
- Support for nested resources (https://github.com/varvet/godmin/pull/189)
|
45
|
+
|
46
|
+
### 1.4.0 - 2017-02-15
|
47
|
+
|
48
|
+
Features
|
49
|
+
- Support group queries in scopes and filters (https://github.com/varvet/godmin/pull/208)
|
50
|
+
- Change color of remove buttons, so they're not grabbing all the attention (https://github.com/varvet/godmin/pull/212)
|
51
|
+
|
52
|
+
Bug fixes
|
53
|
+
- Fix permitted params in sessions controller to work with models other than `AdminUser` (https://github.com/varvet/godmin/pull/210)
|
54
|
+
|
55
|
+
Other
|
56
|
+
- Remove authentication alert (https://github.com/varvet/godmin/pull/207)
|
57
|
+
- Add table caption for tests (https://github.com/varvet/godmin/pull/187)
|
58
|
+
|
3
59
|
### 1.3.1 - 2016-09-27
|
60
|
+
|
4
61
|
Bug fixes
|
5
62
|
- Fix FileSystemResolver issue (https://github.com/varvet/godmin/pull/202)
|
6
63
|
|
@@ -8,6 +65,7 @@ Other
|
|
8
65
|
- Update template for Rails 5 (https://github.com/varvet/godmin/commit/95e0a7917dd9767d77c3bfc876ebbf0a6036f347)
|
9
66
|
|
10
67
|
### 1.3.0 - 2016-07-11
|
68
|
+
|
11
69
|
Features
|
12
70
|
- Increased batch action checkbox click area (https://github.com/varvet/godmin/pull/183)
|
13
71
|
- Adds titles to action links (https://github.com/varvet/godmin/pull/185)
|
@@ -23,6 +81,7 @@ Other
|
|
23
81
|
- Adds caching partial overrides to increase table rendering speed (https://github.com/varvet/godmin/pull/184)
|
24
82
|
|
25
83
|
### 1.2.0 - 2016-02-02
|
84
|
+
|
26
85
|
Features
|
27
86
|
- Adds support for custom ordering of columns (https://github.com/varvet/godmin/pull/168)
|
28
87
|
- Adds passing of options to association form helper (https://github.com/varvet/godmin/pull/172)
|
@@ -32,6 +91,7 @@ Bug fixes
|
|
32
91
|
- Fixes an issue with the template resolver and Rails 4.2.5.1 (https://github.com/varvet/godmin/pull/175)
|
33
92
|
|
34
93
|
### 1.1.0 - 2015-12-08
|
94
|
+
|
35
95
|
Features
|
36
96
|
- Adds locale for pt-BR (Brazilian Portuguese) (https://github.com/varvet/godmin/pull/141)
|
37
97
|
- New sandbox template with with more examples (https://github.com/varvet/godmin/pull/135)
|
@@ -44,22 +104,27 @@ Bug fixes
|
|
44
104
|
- Fixes a namespace issue with the authentication generator (https://github.com/varvet/godmin/pull/150)
|
45
105
|
|
46
106
|
### 1.0.0 - 2015-11-13
|
107
|
+
|
47
108
|
Release of 1.0.0 :tada:
|
48
109
|
|
49
110
|
### 0.12.4 - 2015-10-21
|
111
|
+
|
50
112
|
Bug fixes
|
51
113
|
- Fixes a bug which made it impossible to override the datetimepicker locale (https://github.com/varvet/godmin/issues/132)
|
52
114
|
|
53
115
|
### 0.12.3 - 2015-09-18
|
116
|
+
|
54
117
|
Bug fixes
|
55
118
|
- Adds support for plural engines (https://github.com/varvet/godmin/pull/128)
|
56
119
|
- Remove turbolinks from application.js if present (https://github.com/varvet/godmin/issues/129)
|
57
120
|
|
58
121
|
### 0.12.2 - 2015-09-07
|
122
|
+
|
59
123
|
Bug fixes
|
60
124
|
- Fixes broken sign in page
|
61
125
|
|
62
126
|
### 0.12.1 - 2015-09-07
|
127
|
+
|
63
128
|
Bug fixes
|
64
129
|
- Fixes issue where column ordering on index table didn't work (https://github.com/varvet/godmin/issues/124)
|
65
130
|
|
@@ -67,17 +132,18 @@ Other
|
|
67
132
|
- Adds integration tests
|
68
133
|
- Removes the namespace config in `initializers/godmin.rb`
|
69
134
|
|
70
|
-
In order to upgrade
|
135
|
+
In order to upgrade
|
71
136
|
- Remove the `initializers/godmin.rb` file
|
72
137
|
|
73
138
|
### 0.12.0 - 2015-06-30
|
139
|
+
|
74
140
|
Features
|
75
141
|
- Adds new navigation helpers for building a custom navbar (https://github.com/varvet/godmin/issues/54)
|
76
142
|
|
77
143
|
Other
|
78
144
|
- Removes the godmin router method
|
79
145
|
|
80
|
-
In order to upgrade
|
146
|
+
In order to upgrade
|
81
147
|
- Remove the `godmin do` block from the `config/routes.rb` file
|
82
148
|
- Specify a root route if there is none already
|
83
149
|
- Create a `shared/_navigation.html.erb` partial if there is none already
|
@@ -86,10 +152,12 @@ Bug fixes
|
|
86
152
|
- Fixes issue with authentication generator not modifying the application controller
|
87
153
|
|
88
154
|
### 0.11.2 - 2015-06-22
|
155
|
+
|
89
156
|
Bug fixes
|
90
157
|
- Fixes broken collection select helper
|
91
158
|
|
92
159
|
### 0.11.1 - 2015-05-20
|
160
|
+
|
93
161
|
Features
|
94
162
|
- Adds `destroy_resource` method to `ResourceService`
|
95
163
|
- Adds query param to authorize
|
@@ -103,6 +171,7 @@ Bug fixes
|
|
103
171
|
- Fixes a regression where filter labels were not translated
|
104
172
|
|
105
173
|
### 0.11.0 - 2015-04-13
|
174
|
+
|
106
175
|
Other
|
107
176
|
- Split resources into controllers and service objects (https://github.com/varvet/godmin/pull/79)
|
108
177
|
- Renames the following modules:
|
@@ -111,18 +180,22 @@ Other
|
|
111
180
|
- Godmin::Sessions -> Godmin::SessionsController
|
112
181
|
|
113
182
|
### 0.10.3 - 2015-02-18
|
183
|
+
|
114
184
|
Bug fixes
|
115
185
|
- Adds the possibility to pass options to the `date_field` and `datetime_field` form helpers
|
116
186
|
|
117
187
|
### 0.10.2 - 2015-02-16
|
188
|
+
|
118
189
|
Bug fixes
|
119
190
|
- Fixes standard resource params for multi-word models
|
120
191
|
|
121
192
|
### 0.10.1 - 2015-02-13
|
193
|
+
|
122
194
|
Bug fixes
|
123
195
|
- Fixes multi-select selectize issue (https://github.com/varvet/godmin/issues/71)
|
124
196
|
|
125
197
|
### 0.10.0 - 2015-02-11
|
198
|
+
|
126
199
|
Features
|
127
200
|
- Shows the number of items in each scope in the scope tab (https://github.com/varvet/godmin/issues/16)
|
128
201
|
- Two new overridable methods for resources: `build_resource` and `find_resource`
|
@@ -139,21 +212,25 @@ Other
|
|
139
212
|
- Restructured the locale files a bit
|
140
213
|
|
141
214
|
### 0.9.9 - 2015-01-23
|
215
|
+
|
142
216
|
Features
|
143
217
|
- Bump bootstrap to 3.3.3
|
144
218
|
- Extracted button actions partial
|
145
219
|
|
146
220
|
### 0.9.8 - 2015-01-12
|
221
|
+
|
147
222
|
Bug fixes
|
148
223
|
- Created resources are now properly scoped by `resources_relation`
|
149
224
|
- Fixes broken signin form
|
150
225
|
|
151
226
|
### 0.9.7 - 2015-01-07
|
227
|
+
|
152
228
|
Features
|
153
229
|
- Support for Rails 4.2
|
154
230
|
- New form system (https://github.com/varvet/godmin/pull/50)
|
155
231
|
|
156
232
|
### 0.9.6 - 2014-12-18
|
233
|
+
|
157
234
|
Features
|
158
235
|
- Bundled [datetimepicker](https://github.com/Eonasdan/bootstrap-datetimepicker/)
|
159
236
|
- Exposed JavaScript API
|
@@ -163,18 +240,22 @@ Notes
|
|
163
240
|
- You can no longer use the `select-tag` class to initialize a select box
|
164
241
|
|
165
242
|
### 0.9.5 - 2014-12-15
|
243
|
+
|
166
244
|
Bug fixes
|
167
245
|
- Fixes Godmin::FormBuilder issue
|
168
246
|
|
169
247
|
### 0.9.4 - 2014-12-15
|
248
|
+
|
170
249
|
Features
|
171
250
|
- Added Godmin::FormBuilder
|
172
251
|
|
173
252
|
### 0.9.3 - 2014-12-10
|
253
|
+
|
174
254
|
Bug fixes
|
175
255
|
- Pagination offset fix
|
176
256
|
|
177
257
|
### 0.9.2 - 2014-12-09
|
258
|
+
|
178
259
|
Features
|
179
260
|
- Replaces select2 with [selectize](http://brianreavis.github.io/selectize.js/)
|
180
261
|
- Adds flash messages (https://github.com/varvet/godmin/issues/26)
|
@@ -187,6 +268,7 @@ Bug fixes
|
|
187
268
|
- Fixes default permitted params to work with multiword models.
|
188
269
|
|
189
270
|
### 0.9.1 - 2014-11-18
|
271
|
+
|
190
272
|
Bug fixes
|
191
273
|
- Removed rails executable from /bin folder.
|
192
274
|
|
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)
|
@@ -47,7 +48,7 @@ Godmin supports two common admin scenarios:
|
|
47
48
|
|
48
49
|
If you want to set up an example app that you can play around with, run the following:
|
49
50
|
```sh
|
50
|
-
rails new sandbox -m https://raw.githubusercontent.com/varvet/godmin/master/template.rb
|
51
|
+
rails new sandbox --skip-spring -m https://raw.githubusercontent.com/varvet/godmin/master/template.rb
|
51
52
|
```
|
52
53
|
|
53
54
|
### Standalone installation
|
@@ -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`.
|
@@ -637,6 +671,14 @@ class AdminUser < ActiveRecord::Base
|
|
637
671
|
end
|
638
672
|
```
|
639
673
|
|
674
|
+
By default the user model is called `AdminUser`. If you'd like to change this, you can pass an argument to the authentication generator:
|
675
|
+
|
676
|
+
```
|
677
|
+
$ bin/rails generate godmin:authentication SuperUser
|
678
|
+
or for an engine:
|
679
|
+
$ admin/bin/rails generate godmin:authentication SuperUser
|
680
|
+
```
|
681
|
+
|
640
682
|
By default the model is generated with an `email` field as the login column. This can changed in the migration prior to migrating if, for instance, a `username` column is more appropriate.
|
641
683
|
|
642
684
|
The following route is generated:
|
@@ -708,9 +750,19 @@ end
|
|
708
750
|
|
709
751
|
The admin section is now authenticated using Devise.
|
710
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
|
+
|
711
763
|
## Authorization
|
712
764
|
|
713
|
-
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).
|
714
766
|
|
715
767
|
Add the authorization module to the application controller:
|
716
768
|
|
@@ -770,8 +822,8 @@ end
|
|
770
822
|
That is, everyone can list and view articles, only editors can create them, and only unpublished articles can be updated and destroyed.
|
771
823
|
|
772
824
|
### Handle unauthorized access
|
773
|
-
|
774
|
-
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`:
|
775
827
|
|
776
828
|
```ruby
|
777
829
|
class ApplicationController < ActionController::Base
|
@@ -780,13 +832,14 @@ class ApplicationController < ActionController::Base
|
|
780
832
|
include Godmin::Authorization
|
781
833
|
|
782
834
|
# Renders 404 page and returns status code 404.
|
783
|
-
rescue_from NotAuthorizedError do
|
835
|
+
rescue_from Pundit::NotAuthorizedError do
|
784
836
|
render file: "#{Rails.root}/public/404.html", status: 404, layout: false
|
785
837
|
end
|
786
838
|
end
|
787
839
|
```
|
788
840
|
|
789
841
|
### Override policy object
|
842
|
+
|
790
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.
|
791
844
|
|
792
845
|
```ruby
|
@@ -798,6 +851,7 @@ end
|
|
798
851
|
```
|
799
852
|
|
800
853
|
### Batch action authorization
|
854
|
+
|
801
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.
|
802
856
|
|
803
857
|
```ruby
|
@@ -808,6 +862,61 @@ class ArticlePolicy < Godmin::Authorization::Policy
|
|
808
862
|
end
|
809
863
|
```
|
810
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
|
+
|
811
920
|
## Localization
|
812
921
|
|
813
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).
|