devise_masquerade 0.5.3 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/brakeman-analysis.yml +44 -0
  4. data/.github/workflows/rubocop-analysis.yml +39 -0
  5. data/.gitignore +1 -2
  6. data/.ruby-version +1 -1
  7. data/.travis.yml +3 -4
  8. data/Gemfile +16 -10
  9. data/Gemfile.lock +307 -0
  10. data/Makefile +6 -1
  11. data/README.md +93 -8
  12. data/app/controllers/devise/masquerades_controller.rb +85 -71
  13. data/devise_masquerade.gemspec +13 -12
  14. data/features/back.feature +0 -1
  15. data/features/multiple_masquerading_models.feature +17 -0
  16. data/features/step_definitions/auth_steps.rb +1 -0
  17. data/features/step_definitions/back_steps.rb +18 -3
  18. data/features/step_definitions/url_helpers_steps.rb +11 -0
  19. data/features/support/env.rb +23 -4
  20. data/features/url_helpers.feature +14 -0
  21. data/lib/devise_masquerade/controllers/helpers.rb +40 -15
  22. data/lib/devise_masquerade/controllers/url_helpers.rb +18 -4
  23. data/lib/devise_masquerade/models/masqueradable.rb +13 -0
  24. data/lib/devise_masquerade/models.rb +9 -0
  25. data/lib/devise_masquerade/rails.rb +14 -4
  26. data/lib/devise_masquerade/routes.rb +11 -8
  27. data/lib/devise_masquerade/version.rb +1 -1
  28. data/lib/devise_masquerade.rb +7 -11
  29. data/spec/controllers/admin/dashboard_controller_spec.rb +3 -4
  30. data/spec/controllers/dashboard_controller_spec.rb +3 -5
  31. data/spec/controllers/devise/masquerades_controller_spec.rb +63 -35
  32. data/spec/controllers/masquerades_tests_controller_spec.rb +41 -0
  33. data/spec/dummy/app/controllers/admin/dashboard_controller.rb +1 -2
  34. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  35. data/spec/dummy/app/controllers/dashboard_controller.rb +5 -2
  36. data/spec/dummy/app/controllers/masquerades_tests_controller.rb +7 -0
  37. data/spec/dummy/app/controllers/students_controller.rb +8 -0
  38. data/spec/dummy/app/models/admin/user.rb +0 -7
  39. data/spec/dummy/app/models/student.rb +3 -0
  40. data/spec/dummy/app/models/user.rb +1 -10
  41. data/spec/dummy/app/views/admin/dashboard/index.html.erb +0 -2
  42. data/spec/dummy/app/views/dashboard/extra_params.html.erb +7 -0
  43. data/spec/dummy/app/views/dashboard/index.html.erb +0 -2
  44. data/spec/dummy/app/views/layouts/application.html.erb +7 -1
  45. data/spec/dummy/app/views/students/_student.html.erb +6 -0
  46. data/spec/dummy/app/views/students/index.html.erb +1 -0
  47. data/spec/dummy/app/views/users/_user.html.erb +1 -1
  48. data/spec/dummy/config/application.rb +2 -0
  49. data/spec/dummy/config/environment.rb +1 -0
  50. data/spec/dummy/config/routes.rb +9 -5
  51. data/spec/dummy/db/.gitignore +1 -0
  52. data/spec/dummy/db/migrate/20121119085620_devise_create_users.rb +1 -1
  53. data/spec/dummy/db/migrate/20140418160449_create_admin_users.rb +1 -1
  54. data/spec/dummy/db/migrate/20191022100000_create_students.rb +14 -0
  55. data/spec/dummy/db/schema.rb +37 -31
  56. data/spec/models/user_spec.rb +3 -30
  57. data/spec/orm/active_record.rb +5 -2
  58. data/spec/spec_helper.rb +3 -3
  59. data/spec/support/factories.rb +13 -9
  60. metadata +57 -19
  61. data/lib/devise_masquerade/model.rb +0 -41
  62. data/spec/controllers/masquerades_controller_spec.rb +0 -42
  63. data/spec/dummy/app/controllers/masquerades_controller.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bf92dd8ac9972b55c63ff7b7b45527dc6dbedecc
4
- data.tar.gz: c844f06c0b9124705dff331aea2bae877b342587
2
+ SHA256:
3
+ metadata.gz: 7e8cd4d05e6a1c75e17d26588532e261c01e95689d87d491757132d3242faed7
4
+ data.tar.gz: a9e581005ebf3f238f39aa83d276cef37716bbc1669462f2a4e80f745e29c70a
5
5
  SHA512:
6
- metadata.gz: bbc8724e293c172038bd0ef62bcff064b9f206bf65f410f99cf49826a8d99d863c9098d87e1b0d1330a63bfe45ba626fa63fba3e627472e31bd0fd779b6b8a0b
7
- data.tar.gz: 002b0d76daac1a263bf64d8d7512059475612e2df0e37e52a29b2a297760a2df62c33c54712289e262edeaebee1664a0d8fab1c4030f263538495284fb2ce776
6
+ metadata.gz: 27aee8dd6cfd3f270a466bc30c4a4b545c7b4e944c3794567ed6c220b86598ff2e5361cb00a7cb7a49d20fccc6532cbd97cd0e301459c5b980bbe2e6052847d8
7
+ data.tar.gz: 4df45047b964dd10855dbf563f907bedd5e497130cfab4e5b7d65168d5ca91d47265ea562aea1345563fe15b17f7e944b867dfae3420f4e9cbd030287952bc8f
@@ -0,0 +1 @@
1
+ patreon: oivoodoo
@@ -0,0 +1,44 @@
1
+ # This workflow integrates Brakeman with GitHub's Code Scanning feature
2
+ # Brakeman is a static analysis security vulnerability scanner for Ruby on Rails applications
3
+
4
+ name: Brakeman Scan
5
+
6
+ # This section configures the trigger for the workflow. Feel free to customize depending on your convention
7
+ on:
8
+ push:
9
+ branches: [ "master", "main" ]
10
+ pull_request:
11
+ branches: [ "master", "main" ]
12
+
13
+ jobs:
14
+ brakeman-scan:
15
+ name: Brakeman Scan
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ # Checkout the repository to the GitHub Actions runner
19
+ - name: Checkout
20
+ uses: actions/checkout@v2
21
+
22
+ # Customize the ruby version depending on your needs
23
+ - name: Setup Ruby
24
+ uses: actions/setup-ruby@v1
25
+ with:
26
+ ruby-version: '2.7'
27
+
28
+ - name: Setup Brakeman
29
+ env:
30
+ BRAKEMAN_VERSION: '4.10' # SARIF support is provided in Brakeman version 4.10+
31
+ run: |
32
+ gem install brakeman --version $BRAKEMAN_VERSION
33
+
34
+ # Execute Brakeman CLI and generate a SARIF output with the security issues identified during the analysis
35
+ - name: Scan
36
+ continue-on-error: true
37
+ run: |
38
+ brakeman -f sarif -o output.sarif.json .
39
+
40
+ # Upload the SARIF file generated in the previous step
41
+ - name: Upload SARIF
42
+ uses: github/codeql-action/upload-sarif@v1
43
+ with:
44
+ sarif_file: output.sarif.json
@@ -0,0 +1,39 @@
1
+ name: "Rubocop"
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ rubocop:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+
11
+ steps:
12
+ - name: Checkout repository
13
+ uses: actions/checkout@v2
14
+
15
+ # If running on a self-hosted runner, check it meets the requirements
16
+ # listed at https://github.com/ruby/setup-ruby#using-self-hosted-runners
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 2.6
21
+
22
+ # This step is not necessary if you add the gem to your Gemfile
23
+ - name: Install Code Scanning integration
24
+ run: bundle add code-scanning-rubocop --version 0.3.0 --skip-install
25
+
26
+ - name: Install dependencies
27
+ run: bundle install
28
+
29
+ - name: Rubocop run
30
+ run: |
31
+ bash -c "
32
+ bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
33
+ [[ $? -ne 2 ]]
34
+ "
35
+
36
+ - name: Upload Sarif output
37
+ uses: github/codeql-action/upload-sarif@v1
38
+ with:
39
+ sarif_file: rubocop.sarif
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -19,4 +18,4 @@ spec/dummy/db/*.sqlite3
19
18
  tmp
20
19
  tags
21
20
  .vimrc
22
-
21
+ vendor/
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.7.2
data/.travis.yml CHANGED
@@ -1,12 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.5
4
- - 2.3.1
5
- - 2.3.3
3
+ - 2.5.1
4
+ - 2.6.0
5
+ - 2.7.2
6
6
  gemfile:
7
7
  - Gemfile
8
8
  script: time ./script/travis.sh
9
- cache: bundler
10
9
  sudo: false
11
10
  addons:
12
11
  apt:
data/Gemfile CHANGED
@@ -4,10 +4,10 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'activerecord', '~> 3.0'
8
- gem 'actionmailer', '~> 3.0'
9
- gem "bson_ext", "~> 1.3"
10
- gem 'sqlite3'
7
+ gem 'activerecord', '>= 5.2'
8
+ gem 'actionmailer', '>= 5.2'
9
+ gem 'bson_ext', '~> 1.3'
10
+ gem 'sqlite3', '~> 1.4'
11
11
 
12
12
  gem 'test-unit'
13
13
 
@@ -15,21 +15,27 @@ group :test do
15
15
  gem 'pry-byebug'
16
16
 
17
17
  gem 'guard'
18
- gem 'guard-rspec'
18
+ gem 'guard-rspec', '~> 4.7'
19
19
  gem 'guard-bundler'
20
20
  gem 'guard-cucumber'
21
21
 
22
- gem 'rspec-rails'
23
- gem 'rspec'
24
- gem 'rspec-mocks'
22
+ gem 'rspec', github: 'rspec/rspec'
23
+ gem 'rspec-core', github: 'rspec/rspec-core'
24
+ gem 'rspec-expectations', github: 'rspec/rspec-expectations'
25
+ gem 'rspec-mocks', github: 'rspec/rspec-mocks'
26
+ gem 'rspec-rails', github: 'rspec/rspec-rails'
27
+ gem 'rspec-support', github: 'rspec/rspec-support'
25
28
 
26
29
  gem 'shoulda'
27
30
  gem 'rb-fsevent'
28
- gem 'factory_girl_rails'
31
+ gem 'factory_bot_rails'
29
32
  gem 'database_cleaner', '< 1.1.0'
30
33
  gem 'cucumber'
31
34
  gem 'cucumber-rails'
32
35
  gem 'capybara'
33
- gem 'capybara-webkit'
36
+ gem 'selenium-webdriver'
37
+ gem 'chromedriver-helper'
34
38
  gem 'launchy'
39
+
40
+ gem "nokogiri", ">= 1.10.8"
35
41
  end
data/Gemfile.lock ADDED
@@ -0,0 +1,307 @@
1
+ GIT
2
+ remote: https://github.com/rspec/rspec-core.git
3
+ revision: b7067c5da4fde57cbbff739b168008482e61db44
4
+ specs:
5
+ rspec-core (3.10.0.pre)
6
+ rspec-support (= 3.10.0.pre)
7
+
8
+ GIT
9
+ remote: https://github.com/rspec/rspec-expectations.git
10
+ revision: 99f9bcaff2a6f3d82f4e350e829eca6ab015694f
11
+ specs:
12
+ rspec-expectations (3.10.0.pre)
13
+ diff-lcs (>= 1.2.0, < 2.0)
14
+ rspec-support (= 3.10.0.pre)
15
+
16
+ GIT
17
+ remote: https://github.com/rspec/rspec-mocks.git
18
+ revision: 5b897e8f74f3059aef43f1ed5f91719f2267a04e
19
+ specs:
20
+ rspec-mocks (3.10.0.pre)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (= 3.10.0.pre)
23
+
24
+ GIT
25
+ remote: https://github.com/rspec/rspec-rails.git
26
+ revision: 9b7ab39c027a8cb25e2ebe9e0e985756025b0549
27
+ specs:
28
+ rspec-rails (4.0.0.pre)
29
+ actionpack (>= 4.2)
30
+ activesupport (>= 4.2)
31
+ railties (>= 4.2)
32
+ rspec-core (= 3.10.0.pre)
33
+ rspec-expectations (= 3.10.0.pre)
34
+ rspec-mocks (= 3.10.0.pre)
35
+ rspec-support (= 3.10.0.pre)
36
+
37
+ GIT
38
+ remote: https://github.com/rspec/rspec-support.git
39
+ revision: 673133cdd13b17077b3d88ece8d7380821f8d7dc
40
+ specs:
41
+ rspec-support (3.10.0.pre)
42
+
43
+ GIT
44
+ remote: https://github.com/rspec/rspec.git
45
+ revision: e1c2c6bd78c849d7956431331f32ba5092951dab
46
+ specs:
47
+ rspec (3.10.0.pre)
48
+ rspec-core (= 3.10.0.pre)
49
+ rspec-expectations (= 3.10.0.pre)
50
+ rspec-mocks (= 3.10.0.pre)
51
+
52
+ PATH
53
+ remote: .
54
+ specs:
55
+ devise_masquerade (1.3.1)
56
+ devise (>= 4.7.0)
57
+ globalid (>= 0.3.6)
58
+ railties (>= 5.2.0)
59
+
60
+ GEM
61
+ remote: https://rubygems.org/
62
+ specs:
63
+ actionmailer (6.0.0)
64
+ actionpack (= 6.0.0)
65
+ actionview (= 6.0.0)
66
+ activejob (= 6.0.0)
67
+ mail (~> 2.5, >= 2.5.4)
68
+ rails-dom-testing (~> 2.0)
69
+ actionpack (6.0.0)
70
+ actionview (= 6.0.0)
71
+ activesupport (= 6.0.0)
72
+ rack (~> 2.0)
73
+ rack-test (>= 0.6.3)
74
+ rails-dom-testing (~> 2.0)
75
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
76
+ actionview (6.0.0)
77
+ activesupport (= 6.0.0)
78
+ builder (~> 3.1)
79
+ erubi (~> 1.4)
80
+ rails-dom-testing (~> 2.0)
81
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
82
+ activejob (6.0.0)
83
+ activesupport (= 6.0.0)
84
+ globalid (>= 0.3.6)
85
+ activemodel (6.0.0)
86
+ activesupport (= 6.0.0)
87
+ activerecord (6.0.0)
88
+ activemodel (= 6.0.0)
89
+ activesupport (= 6.0.0)
90
+ activesupport (6.0.0)
91
+ concurrent-ruby (~> 1.0, >= 1.0.2)
92
+ i18n (>= 0.7, < 2)
93
+ minitest (~> 5.1)
94
+ tzinfo (~> 1.1)
95
+ zeitwerk (~> 2.1, >= 2.1.8)
96
+ addressable (2.7.0)
97
+ public_suffix (>= 2.0.2, < 5.0)
98
+ archive-zip (0.12.0)
99
+ io-like (~> 0.3.0)
100
+ backports (3.15.0)
101
+ bcrypt (3.1.16)
102
+ bson (1.12.5)
103
+ bson_ext (1.12.5)
104
+ bson (~> 1.12.5)
105
+ builder (3.2.3)
106
+ byebug (11.0.1)
107
+ capybara (3.29.0)
108
+ addressable
109
+ mini_mime (>= 0.1.3)
110
+ nokogiri (~> 1.8)
111
+ rack (>= 1.6.0)
112
+ rack-test (>= 0.6.3)
113
+ regexp_parser (~> 1.5)
114
+ xpath (~> 3.2)
115
+ childprocess (3.0.0)
116
+ chromedriver-helper (2.1.1)
117
+ archive-zip (~> 0.10)
118
+ nokogiri (~> 1.8)
119
+ coderay (1.1.2)
120
+ concurrent-ruby (1.1.5)
121
+ crass (1.0.5)
122
+ cucumber (3.1.2)
123
+ builder (>= 2.1.2)
124
+ cucumber-core (~> 3.2.0)
125
+ cucumber-expressions (~> 6.0.1)
126
+ cucumber-wire (~> 0.0.1)
127
+ diff-lcs (~> 1.3)
128
+ gherkin (~> 5.1.0)
129
+ multi_json (>= 1.7.5, < 2.0)
130
+ multi_test (>= 0.1.2)
131
+ cucumber-core (3.2.1)
132
+ backports (>= 3.8.0)
133
+ cucumber-tag_expressions (~> 1.1.0)
134
+ gherkin (~> 5.0)
135
+ cucumber-expressions (6.0.1)
136
+ cucumber-rails (1.8.0)
137
+ capybara (>= 2.12, < 4)
138
+ cucumber (>= 3.0.2, < 4)
139
+ mime-types (>= 2.0, < 4)
140
+ nokogiri (~> 1.8)
141
+ railties (>= 4.2, < 7)
142
+ cucumber-tag_expressions (1.1.1)
143
+ cucumber-wire (0.0.1)
144
+ database_cleaner (1.0.1)
145
+ devise (4.7.3)
146
+ bcrypt (~> 3.0)
147
+ orm_adapter (~> 0.1)
148
+ railties (>= 4.1.0)
149
+ responders
150
+ warden (~> 1.2.3)
151
+ diff-lcs (1.3)
152
+ erubi (1.9.0)
153
+ factory_bot (5.1.1)
154
+ activesupport (>= 4.2.0)
155
+ factory_bot_rails (5.1.1)
156
+ factory_bot (~> 5.1.0)
157
+ railties (>= 4.2.0)
158
+ ffi (1.11.1)
159
+ formatador (0.2.5)
160
+ gherkin (5.1.0)
161
+ globalid (0.4.2)
162
+ activesupport (>= 4.2.0)
163
+ guard (2.15.1)
164
+ formatador (>= 0.2.4)
165
+ listen (>= 2.7, < 4.0)
166
+ lumberjack (>= 1.0.12, < 2.0)
167
+ nenv (~> 0.1)
168
+ notiffany (~> 0.0)
169
+ pry (>= 0.9.12)
170
+ shellany (~> 0.0)
171
+ thor (>= 0.18.1)
172
+ guard-bundler (2.2.1)
173
+ bundler (>= 1.3.0, < 3)
174
+ guard (~> 2.2)
175
+ guard-compat (~> 1.1)
176
+ guard-compat (1.2.1)
177
+ guard-cucumber (1.5.4)
178
+ cucumber (>= 1.3.0)
179
+ guard-compat (~> 1.0)
180
+ nenv (~> 0.1)
181
+ guard-rspec (4.7.3)
182
+ guard (~> 2.1)
183
+ guard-compat (~> 1.1)
184
+ rspec (>= 2.99.0, < 4.0)
185
+ i18n (1.7.0)
186
+ concurrent-ruby (~> 1.0)
187
+ io-like (0.3.0)
188
+ launchy (2.4.3)
189
+ addressable (~> 2.3)
190
+ listen (3.2.0)
191
+ rb-fsevent (~> 0.10, >= 0.10.3)
192
+ rb-inotify (~> 0.9, >= 0.9.10)
193
+ loofah (2.3.1)
194
+ crass (~> 1.0.2)
195
+ nokogiri (>= 1.5.9)
196
+ lumberjack (1.0.13)
197
+ mail (2.7.1)
198
+ mini_mime (>= 0.1.1)
199
+ method_source (0.9.2)
200
+ mime-types (3.3)
201
+ mime-types-data (~> 3.2015)
202
+ mime-types-data (3.2019.1009)
203
+ mini_mime (1.0.2)
204
+ mini_portile2 (2.5.0)
205
+ minitest (5.12.2)
206
+ multi_json (1.14.1)
207
+ multi_test (0.1.2)
208
+ nenv (0.3.0)
209
+ nokogiri (1.11.1)
210
+ mini_portile2 (~> 2.5.0)
211
+ racc (~> 1.4)
212
+ notiffany (0.1.3)
213
+ nenv (~> 0.1)
214
+ shellany (~> 0.0)
215
+ orm_adapter (0.5.0)
216
+ power_assert (1.1.5)
217
+ pry (0.12.2)
218
+ coderay (~> 1.1.0)
219
+ method_source (~> 0.9.0)
220
+ pry-byebug (3.7.0)
221
+ byebug (~> 11.0)
222
+ pry (~> 0.10)
223
+ public_suffix (4.0.1)
224
+ racc (1.5.2)
225
+ rack (2.2.3)
226
+ rack-test (1.1.0)
227
+ rack (>= 1.0, < 3)
228
+ rails-dom-testing (2.0.3)
229
+ activesupport (>= 4.2.0)
230
+ nokogiri (>= 1.6)
231
+ rails-html-sanitizer (1.3.0)
232
+ loofah (~> 2.3)
233
+ railties (6.0.0)
234
+ actionpack (= 6.0.0)
235
+ activesupport (= 6.0.0)
236
+ method_source
237
+ rake (>= 0.8.7)
238
+ thor (>= 0.20.3, < 2.0)
239
+ rake (13.0.0)
240
+ rb-fsevent (0.10.3)
241
+ rb-inotify (0.10.0)
242
+ ffi (~> 1.0)
243
+ regexp_parser (1.6.0)
244
+ responders (3.0.1)
245
+ actionpack (>= 5.0)
246
+ railties (>= 5.0)
247
+ rubyzip (2.0.0)
248
+ selenium-webdriver (3.142.6)
249
+ childprocess (>= 0.5, < 4.0)
250
+ rubyzip (>= 1.2.2)
251
+ shellany (0.0.1)
252
+ shoulda (3.6.0)
253
+ shoulda-context (~> 1.0, >= 1.0.1)
254
+ shoulda-matchers (~> 3.0)
255
+ shoulda-context (1.2.2)
256
+ shoulda-matchers (3.1.3)
257
+ activesupport (>= 4.0.0)
258
+ sqlite3 (1.4.1)
259
+ test-unit (3.3.4)
260
+ power_assert
261
+ thor (0.20.3)
262
+ thread_safe (0.3.6)
263
+ tzinfo (1.2.5)
264
+ thread_safe (~> 0.1)
265
+ warden (1.2.9)
266
+ rack (>= 2.0.9)
267
+ xpath (3.2.0)
268
+ nokogiri (~> 1.8)
269
+ zeitwerk (2.2.0)
270
+
271
+ PLATFORMS
272
+ ruby
273
+
274
+ DEPENDENCIES
275
+ actionmailer (>= 5.2)
276
+ activerecord (>= 5.2)
277
+ bson_ext (~> 1.3)
278
+ bundler (>= 2.0.0)
279
+ capybara
280
+ chromedriver-helper
281
+ cucumber
282
+ cucumber-rails
283
+ database_cleaner (< 1.1.0)
284
+ devise_masquerade!
285
+ factory_bot_rails
286
+ guard
287
+ guard-bundler
288
+ guard-cucumber
289
+ guard-rspec (~> 4.7)
290
+ launchy
291
+ nokogiri (>= 1.10.8)
292
+ pry
293
+ pry-byebug
294
+ rb-fsevent
295
+ rspec!
296
+ rspec-core!
297
+ rspec-expectations!
298
+ rspec-mocks!
299
+ rspec-rails!
300
+ rspec-support!
301
+ selenium-webdriver
302
+ shoulda
303
+ sqlite3 (~> 1.4)
304
+ test-unit
305
+
306
+ BUNDLED WITH
307
+ 2.1.4
data/Makefile CHANGED
@@ -1,6 +1,11 @@
1
+ release:
2
+ bundle exec rake release
3
+ .PHONY: release
4
+
1
5
  setup:
2
6
  cd spec/dummy && \
3
- RAILS_ENV=test rake db:setup
7
+ bundle exec rails db:environment:set RAILS_ENV=test && \
8
+ RAILS_ENV=test bundle exec rails db:setup
4
9
  .PHONY: setup
5
10
 
6
11
  rspec:
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Devise Masquerade
2
2
  [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/oivoodoo/devise_masquerade?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3
+ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Foivoodoo%2Fdevise_masquerade.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Foivoodoo%2Fdevise_masquerade?ref=badge_shield)
3
4
 
4
5
  [![Build Status](https://secure.travis-ci.org/oivoodoo/devise_masquerade.png?branch=master)](https://travis-ci.org/oivoodoo/devise_masquerade)
5
6
 
@@ -32,13 +33,29 @@ In the view you can use url helper for defining link:
32
33
 
33
34
  = link_to "Login As", masquerade_path(user)
34
35
 
36
+ `masquerade_path` would create specific `/masquerade` path with query params `masquerade`(key) and `masqueraded_resource_class` to know
37
+ which model to choose to search and sign in by masquerade key.
38
+
35
39
  In the model you'll need to add the parameter :masqueradable to the existing comma separated values in the devise method:
36
40
 
41
+ ```ruby
37
42
  devise :invitable, :confirmable, :database_authenticatable, :registerable, :masqueradable
43
+ ```
38
44
 
39
- Add into your application_controller.rb:
45
+ Add into your `application_controller.rb` if you want to have custom way on sign in by using masquerade token otherwise you can still
46
+ use only `masquerade_path` in your view to generate temporary token and link to make `Login As`:
40
47
 
48
+ ```ruby
41
49
  before_action :masquerade_user!
50
+ ```
51
+
52
+ or
53
+
54
+ ```ruby
55
+ before_action :masquerade!
56
+ ```
57
+
58
+ `masquerade!` is generic way in case if you want to support multiple models on masquerade.
42
59
 
43
60
  Instead of user you can use your resource name admin, student or another names.
44
61
 
@@ -51,6 +68,7 @@ helpers:
51
68
 
52
69
  ## Custom controller for adding cancan for authorization
53
70
 
71
+ ```ruby
54
72
  class Admin::MasqueradesController < Devise::MasqueradesController
55
73
  def show
56
74
  super
@@ -67,9 +85,33 @@ helpers:
67
85
  # <has access to something?> (true/false)
68
86
  # end
69
87
  end
88
+ ```
89
+
90
+ ## Alternatively using Pundit
91
+
92
+ Controller:
93
+
94
+ ```ruby
95
+ class Admin::MasqueradesController < Devise::MasqueradesController
96
+ protected
97
+
98
+ def masquerade_authorize!
99
+ authorize(User, :masquerade?) unless params[:action] == 'back'
100
+ end
101
+ end
102
+ ```
103
+
104
+ In your view:
105
+
106
+ ```erb
107
+ <% if policy(@user).masquerade? %>
108
+ <%= link_to "Login as", masquerade_path(@user) %>
109
+ <% end %>
110
+ ```
70
111
 
71
112
  ## Custom url redirect after masquerade:
72
113
 
114
+ ```ruby
73
115
  class Admin::MasqueradesController < Devise::MasqueradesController
74
116
  protected
75
117
 
@@ -77,20 +119,56 @@ helpers:
77
119
  "/custom_url"
78
120
  end
79
121
  end
122
+ ```
123
+
124
+ ## Custom url redirect after finishing masquerade:
125
+
126
+ ```ruby
127
+ class Admin::MasqueradesController < Devise::MasqueradesController
128
+ protected
129
+
130
+ def after_back_masquerade_path_for(resource)
131
+ "/custom_url"
132
+ end
133
+ end
134
+ ```
135
+
136
+ ## Overriding the finder
137
+
138
+ For example, if you use FriendlyId:
139
+
140
+ ```ruby
141
+ class Admin::MasqueradesController < Devise::MasqueradesController
142
+ protected
143
+
144
+ def find_resource
145
+ masqueraded_resource_class.friendly.find(params[:id])
146
+ end
147
+ end
148
+ ```
80
149
 
81
150
  #### Dont forget to update your Devise routes to point at your Custom Authorization Controller
82
151
  in `routes.rb`:
83
152
 
153
+ ```ruby
84
154
  devise_for :users, controllers: { masquerades: "admin/masquerades" }
85
-
155
+ ```
86
156
 
87
157
  ## You can redefine few options:
88
158
 
159
+ ```ruby
89
160
  Devise.masquerade_param = 'masquerade'
90
161
  Devise.masquerade_expires_in = 10.seconds
91
162
  Devise.masquerade_key_size = 16 # size of the generate by SecureRandom.urlsafe_base64
92
163
  Devise.masquerade_bypass_warden_callback = false
93
164
  Devise.masquerade_routes_back = false # if true, route back to the page the user was on via redirect_back
165
+ Devise.masquerading_resource_class = User
166
+ # optional, default: masquerading_resource_class.model_name.param_key
167
+ Devise.masquerading_resource_name = :user
168
+ Devise.masqueraded_resource_class = AdminUser
169
+ # optional, default: masqueraded_resource_class.model_name.param_key
170
+ Devise.masqueraded_resource_name = :admin_user
171
+ ```
94
172
 
95
173
  ## Demo project
96
174
 
@@ -101,14 +179,17 @@ in `routes.rb`:
101
179
  And check http://localhost:3000/, use for login user1@example.com and
102
180
  'password'
103
181
 
104
- ## Test project
182
+ ## Troubleshooting
105
183
 
106
- cd spec/dummy
107
- RAILS_ENV=test rake db:setup
108
- cd -
109
- rspec
110
- cucumber
184
+ Are you working in development mode and wondering why masquerade attempts result in a [Receiving "You are already signed in" flash[:error]](https://github.com/oivoodoo/devise_masquerade/issues/58) message? `Filter chain halted as :require_no_authentication rendered or redirected` showing up in your logfile? Chances are that you need to enable caching:
185
+
186
+ rails dev:cache
111
187
 
188
+ This is a one-time operation, so you can set it and forget it. Should you ever need to disable caching in development, you can re-run the command as required.
189
+
190
+ ## Test project
191
+
192
+ make test
112
193
 
113
194
  ## Contributing
114
195
 
@@ -117,3 +198,7 @@ And check http://localhost:3000/, use for login user1@example.com and
117
198
  3. Commit your changes (`git commit -am 'Add some feature'`)
118
199
  4. Push to the branch (`git push origin my-new-feature`)
119
200
  5. Create new Pull Request
201
+
202
+
203
+ ## License
204
+ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Foivoodoo%2Fdevise_masquerade.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Foivoodoo%2Fdevise_masquerade?ref=badge_large)