devise_masquerade 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise_masquerade might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +16 -7
- data/README.md +11 -0
- data/app/controllers/devise/masquerades_controller.rb +19 -3
- data/devise_masquerade.gemspec +0 -1
- data/features/back.feature +0 -1
- data/features/multiple_masquerading_models.feature +17 -0
- data/features/step_definitions/auth_steps.rb +1 -0
- data/features/step_definitions/back_steps.rb +18 -3
- data/lib/devise_masquerade/controllers/helpers.rb +24 -3
- data/lib/devise_masquerade/controllers/url_helpers.rb +6 -2
- data/lib/devise_masquerade/rails.rb +5 -7
- data/lib/devise_masquerade/version.rb +1 -1
- data/lib/devise_masquerade.rb +4 -4
- data/spec/controllers/admin/dashboard_controller_spec.rb +5 -4
- data/spec/controllers/dashboard_controller_spec.rb +4 -4
- data/spec/controllers/devise/masquerades_controller_spec.rb +21 -4
- data/spec/controllers/{masquerades_controller_spec.rb → masquerades_tests_controller_spec.rb} +4 -4
- data/spec/dummy/app/controllers/admin/dashboard_controller.rb +0 -1
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/dashboard_controller.rb +0 -1
- data/spec/dummy/app/controllers/masquerades_tests_controller.rb +7 -0
- data/spec/dummy/app/controllers/students_controller.rb +8 -0
- data/spec/dummy/app/models/student.rb +3 -0
- data/spec/dummy/app/views/admin/dashboard/index.html.erb +0 -2
- data/spec/dummy/app/views/dashboard/index.html.erb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +7 -1
- data/spec/dummy/app/views/students/_student.html.erb +6 -0
- data/spec/dummy/app/views/students/index.html.erb +1 -0
- data/spec/dummy/app/views/users/_user.html.erb +1 -1
- data/spec/dummy/config/routes.rb +6 -4
- data/spec/dummy/db/migrate/20191022100000_create_students.rb +14 -0
- data/spec/dummy/db/schema.rb +10 -1
- data/spec/support/factories.rb +8 -4
- metadata +18 -20
- data/spec/dummy/app/controllers/masquerades_controller.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69a694e1d79273ade4a016a4dfd62ce952373a9d3ae7d0a9c75172d270213f21
|
4
|
+
data.tar.gz: 6037a5b54a20e17270926a4ba3c75f9cd0b42126afea5ddb5b85463f291fac9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b252044c3e04dfc33c642e3ac01b6bc534f1edf08a7a45114987f0ad88fcb12fea0fdc4d40571b349e5b7ea8377a4ed7e2b1be77a0d71efa5fd9a8e8d6eee42d
|
7
|
+
data.tar.gz: 00ddb118dc090eba4faf55c97b7bdc8adede4aaeccc2e8f8ebddc4170afeebdae77f26f15a00393987872e7d2fe099cbdeea276657c1cc9ef12ee8bf167c15a3
|
data/Gemfile
CHANGED
@@ -15,11 +15,11 @@ 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'
|
22
|
+
gem 'rspec', github: 'rspec/rspec'
|
23
23
|
gem 'rspec-core', github: 'rspec/rspec-core'
|
24
24
|
gem 'rspec-expectations', github: 'rspec/rspec-expectations'
|
25
25
|
gem 'rspec-mocks', github: 'rspec/rspec-mocks'
|
data/Gemfile.lock
CHANGED
@@ -40,13 +40,21 @@ GIT
|
|
40
40
|
specs:
|
41
41
|
rspec-support (3.10.0.pre)
|
42
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
|
+
|
43
52
|
PATH
|
44
53
|
remote: .
|
45
54
|
specs:
|
46
|
-
devise_masquerade (1.
|
55
|
+
devise_masquerade (1.1.0)
|
47
56
|
devise (>= 4.7.0)
|
48
57
|
railties (>= 5.2.0)
|
49
|
-
zeitwerk (>= 2.2.0)
|
50
58
|
|
51
59
|
GEM
|
52
60
|
remote: https://rubygems.org/
|
@@ -169,8 +177,10 @@ GEM
|
|
169
177
|
cucumber (>= 1.3.0)
|
170
178
|
guard-compat (~> 1.0)
|
171
179
|
nenv (~> 0.1)
|
172
|
-
guard-rspec (
|
173
|
-
guard (
|
180
|
+
guard-rspec (4.7.3)
|
181
|
+
guard (~> 2.1)
|
182
|
+
guard-compat (~> 1.1)
|
183
|
+
rspec (>= 2.99.0, < 4.0)
|
174
184
|
i18n (1.7.0)
|
175
185
|
concurrent-ruby (~> 1.0)
|
176
186
|
io-like (0.3.0)
|
@@ -231,7 +241,6 @@ GEM
|
|
231
241
|
responders (3.0.0)
|
232
242
|
actionpack (>= 5.0)
|
233
243
|
railties (>= 5.0)
|
234
|
-
rspec (1.3.2)
|
235
244
|
rubyzip (2.0.0)
|
236
245
|
selenium-webdriver (3.142.6)
|
237
246
|
childprocess (>= 0.5, < 4.0)
|
@@ -274,12 +283,12 @@ DEPENDENCIES
|
|
274
283
|
guard
|
275
284
|
guard-bundler
|
276
285
|
guard-cucumber
|
277
|
-
guard-rspec
|
286
|
+
guard-rspec (~> 4.7)
|
278
287
|
launchy
|
279
288
|
pry
|
280
289
|
pry-byebug
|
281
290
|
rb-fsevent
|
282
|
-
rspec
|
291
|
+
rspec!
|
283
292
|
rspec-core!
|
284
293
|
rspec-expectations!
|
285
294
|
rspec-mocks!
|
data/README.md
CHANGED
@@ -33,6 +33,9 @@ In the view you can use url helper for defining link:
|
|
33
33
|
|
34
34
|
= link_to "Login As", masquerade_path(user)
|
35
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
|
+
|
36
39
|
In the model you'll need to add the parameter :masqueradable to the existing comma separated values in the devise method:
|
37
40
|
|
38
41
|
```ruby
|
@@ -45,6 +48,14 @@ Add into your application_controller.rb:
|
|
45
48
|
before_action :masquerade_user!
|
46
49
|
```
|
47
50
|
|
51
|
+
or
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
before_action :masquerade!
|
55
|
+
```
|
56
|
+
|
57
|
+
`masquerade!` is generic way in case if you want to support multiple models on masquerade.
|
58
|
+
|
48
59
|
Instead of user you can use your resource name admin, student or another names.
|
49
60
|
|
50
61
|
If you want to back to the owner of masquerade action user you could use
|
@@ -65,7 +65,13 @@ class Devise::MasqueradesController < DeviseController
|
|
65
65
|
private
|
66
66
|
|
67
67
|
def masqueraded_resource_class
|
68
|
-
|
68
|
+
@masqueraded_resource_class ||= begin
|
69
|
+
unless params[:masqueraded_resource_class].blank?
|
70
|
+
params[:masqueraded_resource_class].constantize
|
71
|
+
else
|
72
|
+
Devise.masqueraded_resource_class || resource_class
|
73
|
+
end
|
74
|
+
end
|
69
75
|
end
|
70
76
|
|
71
77
|
def masqueraded_resource_name
|
@@ -73,7 +79,13 @@ class Devise::MasqueradesController < DeviseController
|
|
73
79
|
end
|
74
80
|
|
75
81
|
def masquerading_resource_class
|
76
|
-
|
82
|
+
@masquerading_resource_class ||= begin
|
83
|
+
unless params[:masquerading_resource_class].blank?
|
84
|
+
params[:masquerading_resource_class].constantize
|
85
|
+
else
|
86
|
+
Devise.masquerading_resource_class || resource_class
|
87
|
+
end
|
88
|
+
end
|
77
89
|
end
|
78
90
|
|
79
91
|
def masquerading_resource_name
|
@@ -97,7 +109,11 @@ class Devise::MasqueradesController < DeviseController
|
|
97
109
|
end
|
98
110
|
|
99
111
|
def after_masquerade_param_for(resource)
|
100
|
-
|
112
|
+
[
|
113
|
+
"#{Devise.masquerade_param}=#{resource.masquerade_key}",
|
114
|
+
"masquerading_resource_class=#{masquerading_resource_class}",
|
115
|
+
"masqueraded_resource_class=#{masqueraded_resource_class}",
|
116
|
+
].join('&')
|
101
117
|
end
|
102
118
|
|
103
119
|
def after_back_masquerade_path_for(resource)
|
data/devise_masquerade.gemspec
CHANGED
data/features/back.feature
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
Feature: Use various models for masquerading
|
2
|
+
In order to use various models for masquerading
|
3
|
+
As an masquerade user
|
4
|
+
I want to be able to press press masquerade as link for different models
|
5
|
+
|
6
|
+
Scenario: Use masquerade button on student and user models
|
7
|
+
Given I logged in
|
8
|
+
And I have a user for masquerade
|
9
|
+
And I have a student for masquerade
|
10
|
+
|
11
|
+
When I am on the users page
|
12
|
+
And I login as one user
|
13
|
+
Then I should be login as this user
|
14
|
+
|
15
|
+
When I am on the students page
|
16
|
+
And I login as one student
|
17
|
+
Then I should be login as this student
|
@@ -1,5 +1,5 @@
|
|
1
1
|
Given /^I have a user for masquerade$/ do
|
2
|
-
@
|
2
|
+
@user_mask = create(:user)
|
3
3
|
end
|
4
4
|
|
5
5
|
When /^I am on the users page$/ do
|
@@ -7,11 +7,11 @@ When /^I am on the users page$/ do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
When /^I login as one user$/ do
|
10
|
-
|
10
|
+
find('.login_as').click
|
11
11
|
end
|
12
12
|
|
13
13
|
Then /^I should be login as this user$/ do
|
14
|
-
find('.current_user').should have_content(@
|
14
|
+
find('.current_user').should have_content(@user_mask.email)
|
15
15
|
end
|
16
16
|
|
17
17
|
When /^I press back masquerade button$/ do
|
@@ -22,3 +22,18 @@ Then /^I should be login as owner user$/ do
|
|
22
22
|
find('.current_user').should have_content(@user.email)
|
23
23
|
end
|
24
24
|
|
25
|
+
Given /^I have a student for masquerade$/ do
|
26
|
+
@student_mask = create(:student)
|
27
|
+
end
|
28
|
+
|
29
|
+
When /^I am on the students page$/ do
|
30
|
+
visit '/students'
|
31
|
+
end
|
32
|
+
|
33
|
+
When /^I login as one student$/ do
|
34
|
+
find('.login_as').click
|
35
|
+
end
|
36
|
+
|
37
|
+
Then /^I should be login as this student$/ do
|
38
|
+
find('.current_student').should have_content(@student_mask.email)
|
39
|
+
end
|
@@ -6,13 +6,34 @@ module DeviseMasquerade
|
|
6
6
|
class_name = mapping.class_name
|
7
7
|
|
8
8
|
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
9
|
+
def masquerade!
|
10
|
+
return if params["#{Devise.masquerade_param}"].blank?
|
11
|
+
|
12
|
+
klass = unless params[:masqueraded_resource_class].blank?
|
13
|
+
params[:masqueraded_resource_class].constantize
|
14
|
+
else
|
15
|
+
if Devise.masqueraded_resource_class
|
16
|
+
Devise.masqueraded_resource_class
|
17
|
+
elsif defined?(User)
|
18
|
+
User
|
19
|
+
end
|
20
|
+
end
|
21
|
+
return unless klass
|
22
|
+
|
23
|
+
resource = klass.find_by_masquerade_key(params["#{Devise.masquerade_param}"])
|
24
|
+
|
25
|
+
if resource
|
26
|
+
masquerade_sign_in(resource)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
9
30
|
def masquerade_#{name}!
|
10
31
|
return if params["#{Devise.masquerade_param}"].blank?
|
11
32
|
|
12
|
-
|
33
|
+
resource = ::#{class_name}.find_by_masquerade_key(params["#{Devise.masquerade_param}"])
|
13
34
|
|
14
|
-
if
|
15
|
-
masquerade_sign_in(
|
35
|
+
if resource
|
36
|
+
masquerade_sign_in(resource)
|
16
37
|
end
|
17
38
|
end
|
18
39
|
|
@@ -4,12 +4,16 @@ module DeviseMasquerade
|
|
4
4
|
module UrlHelpers
|
5
5
|
def masquerade_path(resource, *args)
|
6
6
|
scope = Devise::Mapping.find_scope!(resource)
|
7
|
-
|
7
|
+
opts = args.first || {}
|
8
|
+
opts.merge!(masqueraded_resource_class: resource.class.name)
|
9
|
+
send("#{scope}_masquerade_path", resource, opts, *args)
|
8
10
|
end
|
9
11
|
|
10
12
|
def back_masquerade_path(resource, *args)
|
11
13
|
scope = Devise::Mapping.find_scope!(resource)
|
12
|
-
|
14
|
+
opts = args.first || {}
|
15
|
+
opts.merge!(masqueraded_resource_class: resource.class.name)
|
16
|
+
send("back_#{scope}_masquerade_index_path", opts, *args)
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
@@ -1,17 +1,15 @@
|
|
1
|
-
|
2
|
-
require 'devise_masquerade/models'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module DeviseMasquerade
|
5
4
|
module Rails
|
6
5
|
|
7
6
|
class Engine < ::Rails::Engine
|
8
|
-
|
9
|
-
|
10
|
-
include DeviseMasquerade::Controllers::UrlHelpers
|
7
|
+
initializer "devise.url_helpers" do
|
8
|
+
Devise.include_helpers(DeviseMasquerade::Controllers)
|
11
9
|
end
|
12
10
|
|
13
|
-
ActiveSupport.on_load(:
|
14
|
-
include DeviseMasquerade::Controllers::
|
11
|
+
ActiveSupport.on_load(:action_controller) do
|
12
|
+
include DeviseMasquerade::Controllers::Helpers
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
data/lib/devise_masquerade.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'zeitwerk'
|
2
|
-
loader = Zeitwerk::Loader.for_gem
|
3
|
-
loader.setup # ready!
|
4
|
-
|
5
1
|
require 'devise'
|
2
|
+
require 'devise_masquerade/version'
|
3
|
+
require 'devise_masquerade/routes'
|
4
|
+
require 'devise_masquerade/controllers/helpers'
|
5
|
+
require 'devise_masquerade/controllers/url_helpers'
|
6
6
|
require 'devise_masquerade/rails'
|
7
7
|
|
8
8
|
module Devise
|
@@ -5,14 +5,15 @@ describe Admin::DashboardController, type: :controller do
|
|
5
5
|
before { admin_logged_in }
|
6
6
|
|
7
7
|
context 'and admin masquerade by user' do
|
8
|
-
let!(:
|
8
|
+
let!(:mask) { create(:admin_user) }
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
12
|
-
|
11
|
+
mask.masquerade!
|
12
|
+
|
13
|
+
get :index, params: { masquerade: mask.masquerade_key, masqueraded_resource_class: 'Admin::User' }
|
13
14
|
end
|
14
15
|
|
15
|
-
it { expect(current_admin_user.reload).to eq(
|
16
|
+
it { expect(current_admin_user.reload).to eq(mask) }
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -5,15 +5,15 @@ describe DashboardController, type: :controller do
|
|
5
5
|
before { logged_in }
|
6
6
|
|
7
7
|
context 'and admin masquerade by user' do
|
8
|
-
let!(:
|
8
|
+
let!(:mask) { create(:user) }
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
11
|
+
mask.masquerade!
|
12
12
|
|
13
|
-
get :index, params: { masquerade:
|
13
|
+
get :index, params: { masquerade: mask.masquerade_key }
|
14
14
|
end
|
15
15
|
|
16
|
-
it { expect(current_user.reload).to eq(
|
16
|
+
it { expect(current_user.reload).to eq(mask) }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -7,6 +7,23 @@ describe Devise::MasqueradesController, type: :controller do
|
|
7
7
|
context 'when logged in' do
|
8
8
|
before { logged_in }
|
9
9
|
|
10
|
+
context 'with masqueradable_class param' do
|
11
|
+
let(:mask) { create(:student) }
|
12
|
+
|
13
|
+
before do
|
14
|
+
expect(SecureRandom).to receive(:urlsafe_base64) { "secure_key" }
|
15
|
+
get :show, params: { id: mask.to_param, masqueraded_resource_class: mask.class.name }
|
16
|
+
end
|
17
|
+
|
18
|
+
it { expect(session.keys).to include('devise_masquerade_student') }
|
19
|
+
|
20
|
+
it 'should have warden keys defined' do
|
21
|
+
expect(session["warden.user.student.key"].first.first).to eq(mask.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
it { should redirect_to("/?masquerade=secure_key&masquerading_resource_class=User&masqueraded_resource_class=Student") }
|
25
|
+
end
|
26
|
+
|
10
27
|
describe '#masquerade user' do
|
11
28
|
let(:mask) { create(:user) }
|
12
29
|
|
@@ -17,7 +34,7 @@ describe Devise::MasqueradesController, type: :controller do
|
|
17
34
|
|
18
35
|
it { expect(session.keys).to include('devise_masquerade_user') }
|
19
36
|
it { expect(session["warden.user.user.key"].first.first).to eq(mask.id) }
|
20
|
-
it { should redirect_to("/?masquerade=secure_key") }
|
37
|
+
it { should redirect_to("/?masquerade=secure_key&masquerading_resource_class=User&masqueraded_resource_class=User") }
|
21
38
|
|
22
39
|
context 'and back' do
|
23
40
|
before { get :back }
|
@@ -53,17 +70,17 @@ describe Devise::MasqueradesController, type: :controller do
|
|
53
70
|
|
54
71
|
before { get :show, params: { id: mask.to_param } }
|
55
72
|
|
56
|
-
it { should redirect_to("/dashboard?color=red&masquerade=secure_key") }
|
73
|
+
it { should redirect_to("/dashboard?color=red&masquerade=secure_key&masquerading_resource_class=User&masqueraded_resource_class=User") }
|
57
74
|
end # context
|
58
75
|
end # context
|
59
76
|
|
60
|
-
context '
|
77
|
+
context 'and back' do
|
61
78
|
before { get :back }
|
62
79
|
|
63
80
|
it { should redirect_to(masquerade_page) }
|
64
81
|
end # context
|
65
82
|
|
66
|
-
context '
|
83
|
+
context 'and back fallback if http_referer not present' do
|
67
84
|
before do
|
68
85
|
@request.env['HTTP_REFERER'] = 'previous_location'
|
69
86
|
get :back
|
data/spec/controllers/{masquerades_controller_spec.rb → masquerades_tests_controller_spec.rb}
RENAMED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe MasqueradesTestsController, type: :controller do
|
4
4
|
before { @request.env['devise.mapping'] = Devise.mappings[:user] }
|
5
5
|
|
6
6
|
context 'no access for masquerade' do
|
7
7
|
before do
|
8
8
|
session.clear
|
9
|
-
allow_any_instance_of(
|
9
|
+
allow_any_instance_of(MasqueradesTestsController).to receive(:masquerade_authorized?) { false }
|
10
10
|
end
|
11
11
|
|
12
12
|
before { logged_in }
|
13
13
|
|
14
14
|
let(:mask) { create(:user) }
|
15
15
|
|
16
|
-
before { get :show, params: { :
|
16
|
+
before { get :show, params: { id: mask.to_param } }
|
17
17
|
|
18
18
|
it { expect(response.status).to eq(403) }
|
19
19
|
it { expect(session.keys).not_to include('devise_masquerade_user') }
|
@@ -23,7 +23,7 @@ describe MasqueradesController, type: :controller do
|
|
23
23
|
context 'access for masquerade' do
|
24
24
|
before do
|
25
25
|
session.clear
|
26
|
-
allow_any_instance_of(
|
26
|
+
allow_any_instance_of(MasqueradesTestsController).to receive(:masquerade_authorized?) { true }
|
27
27
|
end
|
28
28
|
|
29
29
|
before { logged_in }
|
@@ -8,7 +8,13 @@
|
|
8
8
|
</head>
|
9
9
|
<body>
|
10
10
|
<% if signed_in? %>
|
11
|
-
|
11
|
+
<% if user_signed_in? %>
|
12
|
+
<h1 class='current_user'><%= current_user.email %></h1>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<% if student_signed_in? %>
|
16
|
+
<h1 class='current_student'><%= current_student.email %></h1>
|
17
|
+
<% end %>
|
12
18
|
|
13
19
|
<% if user_masquerade? %>
|
14
20
|
<%= link_to "Back masquerade", back_masquerade_path(current_user) %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render @students %>
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
2
|
devise_for :users, controllers: { masquerades: "users/masquerades" }
|
3
|
-
devise_for :admin_users, :
|
3
|
+
devise_for :admin_users, class_name: Admin::User.name
|
4
|
+
devise_for :students, class_name: Student.name
|
4
5
|
|
5
|
-
root :
|
6
|
+
root to: 'dashboard#index'
|
6
7
|
|
7
|
-
resources :
|
8
|
+
resources :masquerades_tests
|
9
|
+
resources :students, only: :index
|
8
10
|
|
9
11
|
namespace :admin do
|
10
|
-
root :
|
12
|
+
root to: 'dashboard#index'
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateStudents < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table(:students) do |t|
|
4
|
+
t.string :email, null: false, default: ''
|
5
|
+
t.string :encrypted_password, null: false, default: ''
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :students, :email, unique: true
|
11
|
+
add_index :students, :reset_password_token, unique: true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2019_10_22_100000) do
|
14
14
|
|
15
15
|
create_table "admin_users", force: :cascade do |t|
|
16
16
|
t.string "email", default: "", null: false
|
@@ -29,6 +29,15 @@ ActiveRecord::Schema.define(version: 2014_04_18_160449) do
|
|
29
29
|
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
|
30
30
|
end
|
31
31
|
|
32
|
+
create_table "students", force: :cascade do |t|
|
33
|
+
t.string "email", default: "", null: false
|
34
|
+
t.string "encrypted_password", default: "", null: false
|
35
|
+
t.datetime "created_at", null: false
|
36
|
+
t.datetime "updated_at", null: false
|
37
|
+
t.index "\"reset_password_token\"", name: "index_students_on_reset_password_token", unique: true
|
38
|
+
t.index ["email"], name: "index_students_on_email", unique: true
|
39
|
+
end
|
40
|
+
|
32
41
|
create_table "users", force: :cascade do |t|
|
33
42
|
t.string "email", default: "", null: false
|
34
43
|
t.string "encrypted_password", default: "", null: false
|
data/spec/support/factories.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
FactoryBot.define do
|
2
|
-
sequence(:email) { |i| "john#{i}@example.com" }
|
3
|
-
|
4
2
|
factory :user do
|
5
|
-
email
|
3
|
+
sequence(:email) { |i| "user#{i}@example.com" }
|
6
4
|
password { 'password' }
|
7
5
|
password_confirmation { 'password' }
|
8
6
|
end
|
9
7
|
|
10
8
|
factory :admin_user, :class => 'Admin::User' do
|
11
|
-
email
|
9
|
+
sequence(:email) { |i| "admin#{i}@example.com" }
|
10
|
+
password { 'password' }
|
11
|
+
password_confirmation { 'password' }
|
12
|
+
end
|
13
|
+
|
14
|
+
factory :student do
|
15
|
+
sequence(:email) { |i| "student#{i}@example.com" }
|
12
16
|
password { 'password' }
|
13
17
|
password_confirmation { 'password' }
|
14
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_masquerade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Korsak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 4.7.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: zeitwerk
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.2.0
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.2.0
|
69
55
|
description: devise masquerade library
|
70
56
|
email:
|
71
57
|
- alex.korsak@gmail.com
|
@@ -89,6 +75,7 @@ files:
|
|
89
75
|
- config/environment.rb
|
90
76
|
- devise_masquerade.gemspec
|
91
77
|
- features/back.feature
|
78
|
+
- features/multiple_masquerading_models.feature
|
92
79
|
- features/step_definitions/auth_steps.rb
|
93
80
|
- features/step_definitions/back_steps.rb
|
94
81
|
- features/support/env.rb
|
@@ -104,20 +91,24 @@ files:
|
|
104
91
|
- spec/controllers/admin/dashboard_controller_spec.rb
|
105
92
|
- spec/controllers/dashboard_controller_spec.rb
|
106
93
|
- spec/controllers/devise/masquerades_controller_spec.rb
|
107
|
-
- spec/controllers/
|
94
|
+
- spec/controllers/masquerades_tests_controller_spec.rb
|
108
95
|
- spec/dummy/Rakefile
|
109
96
|
- spec/dummy/app/controllers/admin/dashboard_controller.rb
|
110
97
|
- spec/dummy/app/controllers/application_controller.rb
|
111
98
|
- spec/dummy/app/controllers/dashboard_controller.rb
|
112
|
-
- spec/dummy/app/controllers/
|
99
|
+
- spec/dummy/app/controllers/masquerades_tests_controller.rb
|
100
|
+
- spec/dummy/app/controllers/students_controller.rb
|
113
101
|
- spec/dummy/app/controllers/users/masquerades_controller.rb
|
114
102
|
- spec/dummy/app/helpers/application_helper.rb
|
115
103
|
- spec/dummy/app/models/admin.rb
|
116
104
|
- spec/dummy/app/models/admin/user.rb
|
105
|
+
- spec/dummy/app/models/student.rb
|
117
106
|
- spec/dummy/app/models/user.rb
|
118
107
|
- spec/dummy/app/views/admin/dashboard/index.html.erb
|
119
108
|
- spec/dummy/app/views/dashboard/index.html.erb
|
120
109
|
- spec/dummy/app/views/layouts/application.html.erb
|
110
|
+
- spec/dummy/app/views/students/_student.html.erb
|
111
|
+
- spec/dummy/app/views/students/index.html.erb
|
121
112
|
- spec/dummy/app/views/users/_user.html.erb
|
122
113
|
- spec/dummy/config.ru
|
123
114
|
- spec/dummy/config/application.rb
|
@@ -139,6 +130,7 @@ files:
|
|
139
130
|
- spec/dummy/db/.gitignore
|
140
131
|
- spec/dummy/db/migrate/20121119085620_devise_create_users.rb
|
141
132
|
- spec/dummy/db/migrate/20140418160449_create_admin_users.rb
|
133
|
+
- spec/dummy/db/migrate/20191022100000_create_students.rb
|
142
134
|
- spec/dummy/db/schema.rb
|
143
135
|
- spec/dummy/db/seeds.rb
|
144
136
|
- spec/dummy/public/.empty
|
@@ -173,26 +165,31 @@ specification_version: 4
|
|
173
165
|
summary: use for login as functionallity on your admin users pages
|
174
166
|
test_files:
|
175
167
|
- features/back.feature
|
168
|
+
- features/multiple_masquerading_models.feature
|
176
169
|
- features/step_definitions/auth_steps.rb
|
177
170
|
- features/step_definitions/back_steps.rb
|
178
171
|
- features/support/env.rb
|
179
172
|
- spec/controllers/admin/dashboard_controller_spec.rb
|
180
173
|
- spec/controllers/dashboard_controller_spec.rb
|
181
174
|
- spec/controllers/devise/masquerades_controller_spec.rb
|
182
|
-
- spec/controllers/
|
175
|
+
- spec/controllers/masquerades_tests_controller_spec.rb
|
183
176
|
- spec/dummy/Rakefile
|
184
177
|
- spec/dummy/app/controllers/admin/dashboard_controller.rb
|
185
178
|
- spec/dummy/app/controllers/application_controller.rb
|
186
179
|
- spec/dummy/app/controllers/dashboard_controller.rb
|
187
|
-
- spec/dummy/app/controllers/
|
180
|
+
- spec/dummy/app/controllers/masquerades_tests_controller.rb
|
181
|
+
- spec/dummy/app/controllers/students_controller.rb
|
188
182
|
- spec/dummy/app/controllers/users/masquerades_controller.rb
|
189
183
|
- spec/dummy/app/helpers/application_helper.rb
|
190
184
|
- spec/dummy/app/models/admin.rb
|
191
185
|
- spec/dummy/app/models/admin/user.rb
|
186
|
+
- spec/dummy/app/models/student.rb
|
192
187
|
- spec/dummy/app/models/user.rb
|
193
188
|
- spec/dummy/app/views/admin/dashboard/index.html.erb
|
194
189
|
- spec/dummy/app/views/dashboard/index.html.erb
|
195
190
|
- spec/dummy/app/views/layouts/application.html.erb
|
191
|
+
- spec/dummy/app/views/students/_student.html.erb
|
192
|
+
- spec/dummy/app/views/students/index.html.erb
|
196
193
|
- spec/dummy/app/views/users/_user.html.erb
|
197
194
|
- spec/dummy/config.ru
|
198
195
|
- spec/dummy/config/application.rb
|
@@ -214,6 +211,7 @@ test_files:
|
|
214
211
|
- spec/dummy/db/.gitignore
|
215
212
|
- spec/dummy/db/migrate/20121119085620_devise_create_users.rb
|
216
213
|
- spec/dummy/db/migrate/20140418160449_create_admin_users.rb
|
214
|
+
- spec/dummy/db/migrate/20191022100000_create_students.rb
|
217
215
|
- spec/dummy/db/schema.rb
|
218
216
|
- spec/dummy/db/seeds.rb
|
219
217
|
- spec/dummy/public/.empty
|