godmin 1.3.0 → 2.1.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 +7 -15
- data/Appraisals +4 -4
- data/CHANGELOG.md +83 -2
- data/Gemfile +1 -2
- data/README.md +74 -9
- data/Rakefile +2 -10
- 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/_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 +6 -20
- 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 +23 -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 +42 -7
- data/test/dummy/admin/app/controllers/admin/authorized_articles_controller.rb +15 -0
- data/test/dummy/admin/app/models/admin/article.rb +4 -0
- data/test/dummy/admin/app/policies/admin/article_policy.rb +7 -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/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/schema.rb +26 -11
- data/test/fakes/article.rb +1 -1
- data/test/fakes/article_service.rb +3 -7
- data/test/generators/resource_generator_test.rb +77 -0
- data/test/integration/authentication_test.rb +8 -0
- data/test/integration/authorization_test.rb +5 -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 +167 -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: 9a084849cf4dd5f729b2f5ca0dabdcec727ef1172eb1cb19baf9de27ca822950
|
4
|
+
data.tar.gz: 8b655c6dad3b1a1fc95d88b08cf2f25e848b646266fd63808dffad77b47f767e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0fec37368ae0548a3e3adb1b662f214aff97756f916d11da1907acbc7caa43304b920844f9a1f8ebb500a35d7f261c060fd8e605e5cb841e7fdafb9da8a744b
|
7
|
+
data.tar.gz: d6a218a707bafe5ac68611b13c74e6975c13702562d5a804514faad4af0100544b5bf722e252077af89653f2702deb932e36f1c5131855b2604af86247b069fe
|
data/.codeclimate.yml
CHANGED
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,21 +1,13 @@
|
|
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
|
10
7
|
gemfile:
|
11
|
-
- gemfiles/rails_4.gemfile
|
12
8
|
- gemfiles/rails_5.gemfile
|
13
|
-
|
14
|
-
matrix:
|
15
|
-
exclude:
|
16
|
-
- rvm: 2.1.0
|
17
|
-
gemfile: gemfiles/rails_5.gemfile
|
18
|
-
|
9
|
+
- gemfiles/rails_6.gemfile
|
19
10
|
addons:
|
20
11
|
code_climate:
|
21
|
-
repo_token:
|
12
|
+
repo_token:
|
13
|
+
secure: WBszVdtEvWM2KugFre9BpwkCduY6hjrmK7xo1GLiru4NMqr4ZoRXruQ5ijhZE79YqduR6zudKr72g9yG4R+4CK7ghYu4x5JB76IW8gFWpI9teTWrF4hdSbJgwxSH5JNkqWF4f6ic4Xr1Vgc43agzt+1KmA9imoGs2Q0EbAY3H2M=
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,63 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 2.1.0 - 2021-05-10
|
4
|
+
|
5
|
+
Bug fixes
|
6
|
+
- Use symbol in path for compatibility with the latest Rails security patches (https://github.com/varvet/godmin/pull/256)
|
7
|
+
|
8
|
+
Other
|
9
|
+
- Build and test against Ruby 2.6 and 2.7
|
10
|
+
- Stop building and testing against unsupported rubies (2.5 and older). These may still work and PRs may still be accepted.
|
11
|
+
|
12
|
+
### 2.0.0 - 2019-12-06
|
13
|
+
|
14
|
+
Features
|
15
|
+
- Allow skipping authorization per action (https://github.com/varvet/godmin/pull/231)
|
16
|
+
|
17
|
+
Bug fixes
|
18
|
+
- Support namespaced models when generating resources (https://github.com/varvet/godmin/issues/181)
|
19
|
+
|
20
|
+
Other
|
21
|
+
- Drop support for Rails 4 (https://github.com/varvet/godmin/pull/239)
|
22
|
+
- Better policy lookups for namespaced models (https://github.com/varvet/godmin/pull/180)
|
23
|
+
- Use Pundit for authorization (https://github.com/varvet/godmin/pull/180)
|
24
|
+
- Rails 6 support (https://github.com/varvet/godmin/pull/248) and (https://github.com/varvet/godmin/pull/250)
|
25
|
+
|
26
|
+
In order to upgrade
|
27
|
+
- Upgrade to at least Rails 5 and Ruby 2.2.2
|
28
|
+
- If using an admin engine, create a namespaced model for every resource, inheriting from the main app model
|
29
|
+
- Replace any `authenticate_admin_user` with `authenticate`
|
30
|
+
- Replace any `skip_before_action :authenticate_admin_user` with `prepend_before_action :disable_authentication`
|
31
|
+
- Replace any `rescue_from NotAuthorizedError` with `rescue_from Pundit::NotAuthorizedError`
|
32
|
+
|
33
|
+
### 1.5.0 - 2017-02-17
|
34
|
+
|
35
|
+
Features
|
36
|
+
- Support for nested resources (https://github.com/varvet/godmin/pull/189)
|
37
|
+
|
38
|
+
### 1.4.0 - 2017-02-15
|
39
|
+
|
40
|
+
Features
|
41
|
+
- Support group queries in scopes and filters (https://github.com/varvet/godmin/pull/208)
|
42
|
+
- Change color of remove buttons, so they're not grabbing all the attention (https://github.com/varvet/godmin/pull/212)
|
43
|
+
|
44
|
+
Bug fixes
|
45
|
+
- Fix permitted params in sessions controller to work with models other than `AdminUser` (https://github.com/varvet/godmin/pull/210)
|
46
|
+
|
47
|
+
Other
|
48
|
+
- Remove authentication alert (https://github.com/varvet/godmin/pull/207)
|
49
|
+
- Add table caption for tests (https://github.com/varvet/godmin/pull/187)
|
50
|
+
|
51
|
+
### 1.3.1 - 2016-09-27
|
52
|
+
|
53
|
+
Bug fixes
|
54
|
+
- Fix FileSystemResolver issue (https://github.com/varvet/godmin/pull/202)
|
55
|
+
|
56
|
+
Other
|
57
|
+
- Update template for Rails 5 (https://github.com/varvet/godmin/commit/95e0a7917dd9767d77c3bfc876ebbf0a6036f347)
|
58
|
+
|
3
59
|
### 1.3.0 - 2016-07-11
|
60
|
+
|
4
61
|
Features
|
5
62
|
- Increased batch action checkbox click area (https://github.com/varvet/godmin/pull/183)
|
6
63
|
- Adds titles to action links (https://github.com/varvet/godmin/pull/185)
|
@@ -16,6 +73,7 @@ Other
|
|
16
73
|
- Adds caching partial overrides to increase table rendering speed (https://github.com/varvet/godmin/pull/184)
|
17
74
|
|
18
75
|
### 1.2.0 - 2016-02-02
|
76
|
+
|
19
77
|
Features
|
20
78
|
- Adds support for custom ordering of columns (https://github.com/varvet/godmin/pull/168)
|
21
79
|
- Adds passing of options to association form helper (https://github.com/varvet/godmin/pull/172)
|
@@ -25,6 +83,7 @@ Bug fixes
|
|
25
83
|
- Fixes an issue with the template resolver and Rails 4.2.5.1 (https://github.com/varvet/godmin/pull/175)
|
26
84
|
|
27
85
|
### 1.1.0 - 2015-12-08
|
86
|
+
|
28
87
|
Features
|
29
88
|
- Adds locale for pt-BR (Brazilian Portuguese) (https://github.com/varvet/godmin/pull/141)
|
30
89
|
- New sandbox template with with more examples (https://github.com/varvet/godmin/pull/135)
|
@@ -37,22 +96,27 @@ Bug fixes
|
|
37
96
|
- Fixes a namespace issue with the authentication generator (https://github.com/varvet/godmin/pull/150)
|
38
97
|
|
39
98
|
### 1.0.0 - 2015-11-13
|
99
|
+
|
40
100
|
Release of 1.0.0 :tada:
|
41
101
|
|
42
102
|
### 0.12.4 - 2015-10-21
|
103
|
+
|
43
104
|
Bug fixes
|
44
105
|
- Fixes a bug which made it impossible to override the datetimepicker locale (https://github.com/varvet/godmin/issues/132)
|
45
106
|
|
46
107
|
### 0.12.3 - 2015-09-18
|
108
|
+
|
47
109
|
Bug fixes
|
48
110
|
- Adds support for plural engines (https://github.com/varvet/godmin/pull/128)
|
49
111
|
- Remove turbolinks from application.js if present (https://github.com/varvet/godmin/issues/129)
|
50
112
|
|
51
113
|
### 0.12.2 - 2015-09-07
|
114
|
+
|
52
115
|
Bug fixes
|
53
116
|
- Fixes broken sign in page
|
54
117
|
|
55
118
|
### 0.12.1 - 2015-09-07
|
119
|
+
|
56
120
|
Bug fixes
|
57
121
|
- Fixes issue where column ordering on index table didn't work (https://github.com/varvet/godmin/issues/124)
|
58
122
|
|
@@ -60,17 +124,18 @@ Other
|
|
60
124
|
- Adds integration tests
|
61
125
|
- Removes the namespace config in `initializers/godmin.rb`
|
62
126
|
|
63
|
-
In order to upgrade
|
127
|
+
In order to upgrade
|
64
128
|
- Remove the `initializers/godmin.rb` file
|
65
129
|
|
66
130
|
### 0.12.0 - 2015-06-30
|
131
|
+
|
67
132
|
Features
|
68
133
|
- Adds new navigation helpers for building a custom navbar (https://github.com/varvet/godmin/issues/54)
|
69
134
|
|
70
135
|
Other
|
71
136
|
- Removes the godmin router method
|
72
137
|
|
73
|
-
In order to upgrade
|
138
|
+
In order to upgrade
|
74
139
|
- Remove the `godmin do` block from the `config/routes.rb` file
|
75
140
|
- Specify a root route if there is none already
|
76
141
|
- Create a `shared/_navigation.html.erb` partial if there is none already
|
@@ -79,10 +144,12 @@ Bug fixes
|
|
79
144
|
- Fixes issue with authentication generator not modifying the application controller
|
80
145
|
|
81
146
|
### 0.11.2 - 2015-06-22
|
147
|
+
|
82
148
|
Bug fixes
|
83
149
|
- Fixes broken collection select helper
|
84
150
|
|
85
151
|
### 0.11.1 - 2015-05-20
|
152
|
+
|
86
153
|
Features
|
87
154
|
- Adds `destroy_resource` method to `ResourceService`
|
88
155
|
- Adds query param to authorize
|
@@ -96,6 +163,7 @@ Bug fixes
|
|
96
163
|
- Fixes a regression where filter labels were not translated
|
97
164
|
|
98
165
|
### 0.11.0 - 2015-04-13
|
166
|
+
|
99
167
|
Other
|
100
168
|
- Split resources into controllers and service objects (https://github.com/varvet/godmin/pull/79)
|
101
169
|
- Renames the following modules:
|
@@ -104,18 +172,22 @@ Other
|
|
104
172
|
- Godmin::Sessions -> Godmin::SessionsController
|
105
173
|
|
106
174
|
### 0.10.3 - 2015-02-18
|
175
|
+
|
107
176
|
Bug fixes
|
108
177
|
- Adds the possibility to pass options to the `date_field` and `datetime_field` form helpers
|
109
178
|
|
110
179
|
### 0.10.2 - 2015-02-16
|
180
|
+
|
111
181
|
Bug fixes
|
112
182
|
- Fixes standard resource params for multi-word models
|
113
183
|
|
114
184
|
### 0.10.1 - 2015-02-13
|
185
|
+
|
115
186
|
Bug fixes
|
116
187
|
- Fixes multi-select selectize issue (https://github.com/varvet/godmin/issues/71)
|
117
188
|
|
118
189
|
### 0.10.0 - 2015-02-11
|
190
|
+
|
119
191
|
Features
|
120
192
|
- Shows the number of items in each scope in the scope tab (https://github.com/varvet/godmin/issues/16)
|
121
193
|
- Two new overridable methods for resources: `build_resource` and `find_resource`
|
@@ -132,21 +204,25 @@ Other
|
|
132
204
|
- Restructured the locale files a bit
|
133
205
|
|
134
206
|
### 0.9.9 - 2015-01-23
|
207
|
+
|
135
208
|
Features
|
136
209
|
- Bump bootstrap to 3.3.3
|
137
210
|
- Extracted button actions partial
|
138
211
|
|
139
212
|
### 0.9.8 - 2015-01-12
|
213
|
+
|
140
214
|
Bug fixes
|
141
215
|
- Created resources are now properly scoped by `resources_relation`
|
142
216
|
- Fixes broken signin form
|
143
217
|
|
144
218
|
### 0.9.7 - 2015-01-07
|
219
|
+
|
145
220
|
Features
|
146
221
|
- Support for Rails 4.2
|
147
222
|
- New form system (https://github.com/varvet/godmin/pull/50)
|
148
223
|
|
149
224
|
### 0.9.6 - 2014-12-18
|
225
|
+
|
150
226
|
Features
|
151
227
|
- Bundled [datetimepicker](https://github.com/Eonasdan/bootstrap-datetimepicker/)
|
152
228
|
- Exposed JavaScript API
|
@@ -156,18 +232,22 @@ Notes
|
|
156
232
|
- You can no longer use the `select-tag` class to initialize a select box
|
157
233
|
|
158
234
|
### 0.9.5 - 2014-12-15
|
235
|
+
|
159
236
|
Bug fixes
|
160
237
|
- Fixes Godmin::FormBuilder issue
|
161
238
|
|
162
239
|
### 0.9.4 - 2014-12-15
|
240
|
+
|
163
241
|
Features
|
164
242
|
- Added Godmin::FormBuilder
|
165
243
|
|
166
244
|
### 0.9.3 - 2014-12-10
|
245
|
+
|
167
246
|
Bug fixes
|
168
247
|
- Pagination offset fix
|
169
248
|
|
170
249
|
### 0.9.2 - 2014-12-09
|
250
|
+
|
171
251
|
Features
|
172
252
|
- Replaces select2 with [selectize](http://brianreavis.github.io/selectize.js/)
|
173
253
|
- Adds flash messages (https://github.com/varvet/godmin/issues/26)
|
@@ -180,6 +260,7 @@ Bug fixes
|
|
180
260
|
- Fixes default permitted params to work with multiword models.
|
181
261
|
|
182
262
|
### 0.9.1 - 2014-11-18
|
263
|
+
|
183
264
|
Bug fixes
|
184
265
|
- Removed rails executable from /bin folder.
|
185
266
|
|
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
@@ -3,9 +3,10 @@
|
|
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
5
|
[![Code Climate](https://img.shields.io/codeclimate/github/varvet/godmin.svg)](https://codeclimate.com/github/varvet/godmin)
|
6
|
-
[![Test Coverage](https://codeclimate.com/github/varvet/godmin/badges/coverage.svg)](https://codeclimate.com/github/varvet/godmin/coverage)
|
7
6
|
|
8
|
-
|
7
|
+
**If you are looking for the current stable version, which is Rails 4+ compatible, see the [v1.5](https://github.com/varvet/godmin/tree/v1.5) branch**
|
8
|
+
|
9
|
+
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
10
|
|
10
11
|
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
12
|
|
@@ -25,6 +26,7 @@ Godmin differs from tools like [ActiveAdmin](http://activeadmin.info/) and [Rail
|
|
25
26
|
- [Redirecting](#redirecting)
|
26
27
|
- [Pagination](#pagination)
|
27
28
|
- [Exporting](#exporting)
|
29
|
+
- [Nested resources](#nested-resources)
|
28
30
|
- [Views](#views)
|
29
31
|
- [Forms](#forms)
|
30
32
|
- [Navigation](#navigation)
|
@@ -47,7 +49,7 @@ Godmin supports two common admin scenarios:
|
|
47
49
|
|
48
50
|
If you want to set up an example app that you can play around with, run the following:
|
49
51
|
```sh
|
50
|
-
rails new sandbox -m https://raw.githubusercontent.com/varvet/godmin/master/template.rb
|
52
|
+
rails new sandbox --skip-spring -m https://raw.githubusercontent.com/varvet/godmin/master/template.rb
|
51
53
|
```
|
52
54
|
|
53
55
|
### Standalone installation
|
@@ -143,6 +145,15 @@ It inserts a `navbar_item` in the `app/views/shared/_navigation.html.erb` partia
|
|
143
145
|
<%= navbar_item Article %>
|
144
146
|
```
|
145
147
|
|
148
|
+
If Godmin was installed inside an engine, it creates a model class:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
module Admin
|
152
|
+
class Article < ::Article
|
153
|
+
end
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
146
157
|
It creates a controller:
|
147
158
|
|
148
159
|
```ruby
|
@@ -511,7 +522,7 @@ If you wish to change the number of resources per page, you can override the `pe
|
|
511
522
|
|
512
523
|
```ruby
|
513
524
|
class ArticlesService
|
514
|
-
include Godmin::Resources::
|
525
|
+
include Godmin::Resources::ResourceService
|
515
526
|
|
516
527
|
def per_page
|
517
528
|
50
|
@@ -525,12 +536,36 @@ The `attrs_for_export` method in the service object makes it possible to mark at
|
|
525
536
|
|
526
537
|
```ruby
|
527
538
|
class ArticlesService
|
528
|
-
include Godmin::Resources::
|
539
|
+
include Godmin::Resources::ResourceService
|
529
540
|
|
530
541
|
attrs_for_export :id, :title, :created_at, :updated_at
|
531
542
|
end
|
532
543
|
```
|
533
544
|
|
545
|
+
### Nested resources
|
546
|
+
|
547
|
+
Nested resources can be implemented by nesting your routes:
|
548
|
+
|
549
|
+
```ruby
|
550
|
+
resources :blogs do
|
551
|
+
resources :blog_posts
|
552
|
+
end
|
553
|
+
```
|
554
|
+
|
555
|
+
This will set up scoping of the nested resource as well as correct links in the breadcrumb.
|
556
|
+
|
557
|
+
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:
|
558
|
+
|
559
|
+
```ruby
|
560
|
+
class BlogService
|
561
|
+
include Godmin::Resources::ResourceService
|
562
|
+
|
563
|
+
has_many :blog_posts
|
564
|
+
end
|
565
|
+
```
|
566
|
+
|
567
|
+
Otherwise, simply add links as you see fit using partial overrides.
|
568
|
+
|
534
569
|
## Views
|
535
570
|
|
536
571
|
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 +672,14 @@ class AdminUser < ActiveRecord::Base
|
|
637
672
|
end
|
638
673
|
```
|
639
674
|
|
675
|
+
By default the user model is called `AdminUser`. If you'd like to change this, you can pass an argument to the authentication generator:
|
676
|
+
|
677
|
+
```
|
678
|
+
$ bin/rails generate godmin:authentication SuperUser
|
679
|
+
or for an engine:
|
680
|
+
$ admin/bin/rails generate godmin:authentication SuperUser
|
681
|
+
```
|
682
|
+
|
640
683
|
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
684
|
|
642
685
|
The following route is generated:
|
@@ -708,9 +751,19 @@ end
|
|
708
751
|
|
709
752
|
The admin section is now authenticated using Devise.
|
710
753
|
|
754
|
+
### Disable authentication
|
755
|
+
|
756
|
+
If you want to disable authentication for a single controller or controller action, use the following `before_action`:
|
757
|
+
|
758
|
+
```ruby
|
759
|
+
class ArticlesController < ApplicationController
|
760
|
+
prepend_before_action :disable_authentication
|
761
|
+
end
|
762
|
+
```
|
763
|
+
|
711
764
|
## Authorization
|
712
765
|
|
713
|
-
In order to enable authorization, authentication must first be enabled. See the previous section. The Godmin authorization system
|
766
|
+
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
767
|
|
715
768
|
Add the authorization module to the application controller:
|
716
769
|
|
@@ -770,8 +823,8 @@ end
|
|
770
823
|
That is, everyone can list and view articles, only editors can create them, and only unpublished articles can be updated and destroyed.
|
771
824
|
|
772
825
|
### Handle unauthorized access
|
773
|
-
|
774
|
-
If you want to change this behaviour you can rescue the error yourself in the appropriate `ApplicationController`:
|
826
|
+
|
827
|
+
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
828
|
|
776
829
|
```ruby
|
777
830
|
class ApplicationController < ActionController::Base
|
@@ -780,13 +833,14 @@ class ApplicationController < ActionController::Base
|
|
780
833
|
include Godmin::Authorization
|
781
834
|
|
782
835
|
# Renders 404 page and returns status code 404.
|
783
|
-
rescue_from NotAuthorizedError do
|
836
|
+
rescue_from Pundit::NotAuthorizedError do
|
784
837
|
render file: "#{Rails.root}/public/404.html", status: 404, layout: false
|
785
838
|
end
|
786
839
|
end
|
787
840
|
```
|
788
841
|
|
789
842
|
### Override policy object
|
843
|
+
|
790
844
|
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
845
|
|
792
846
|
```ruby
|
@@ -798,6 +852,7 @@ end
|
|
798
852
|
```
|
799
853
|
|
800
854
|
### Batch action authorization
|
855
|
+
|
801
856
|
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
857
|
|
803
858
|
```ruby
|
@@ -808,6 +863,16 @@ class ArticlePolicy < Godmin::Authorization::Policy
|
|
808
863
|
end
|
809
864
|
```
|
810
865
|
|
866
|
+
### Disable authorization
|
867
|
+
|
868
|
+
If you want to disable authorization for a single controller or controller action, use the following `before_action`:
|
869
|
+
|
870
|
+
```ruby
|
871
|
+
class ArticlesController < ApplicationController
|
872
|
+
prepend_before_action :disable_authorization
|
873
|
+
end
|
874
|
+
```
|
875
|
+
|
811
876
|
## Localization
|
812
877
|
|
813
878
|
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).
|