devise_masquerade 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e7178dc0f54d070a2f4e839f320f65c5506b215a902cc2180b8e357d1a9f62d
4
- data.tar.gz: 5466190dbaae779ca45abaa8e65f526e1b99805a493019c8dc67572d387b8022
3
+ metadata.gz: b21015ee6b3b1561bcf507063f84e0eea7f0bd4db78bee58c2122b287628cc56
4
+ data.tar.gz: 6817e192073914e507c1ba3cf7b9bef3178e733b3b83314ff80914f827e612d6
5
5
  SHA512:
6
- metadata.gz: f2b85a5241c5aef644ca6139f89807631b6e93ebcbc2fc77f0b88f74e43bd411a056bb49c3340ae63322e22cf13a5ca4185208d7c8c778e124d04fa37bb19cbd
7
- data.tar.gz: 374dacc212988505fca5cfea9188a7fcdce44d174b54b3cd980363b37c377bb92713ab8467858eefa62d23568783e09929bcdace08efa344bf5610f382e32f31
6
+ metadata.gz: db0d98e2513d372a40896dfd4453359e5d04a3865300c0c96407582e1a6601d52528dced610830bb95b527ea416ea60b212d8de1a286a1b56706d6c4dbb41451
7
+ data.tar.gz: 70fdb0e0e55321832ce09c00613ca5c26faff9f2dc7587523b09d61cbcdcfc66fbf3e3368a898cc39564057cae97a1b96ad668c53812e8b5bfbc5e28749eafe2
data/Gemfile.lock CHANGED
@@ -52,7 +52,7 @@ GIT
52
52
  PATH
53
53
  remote: .
54
54
  specs:
55
- devise_masquerade (2.0.1)
55
+ devise_masquerade (2.0.2)
56
56
  devise (>= 4.7.0)
57
57
  globalid (>= 0.3.6)
58
58
  railties (>= 5.2.0)
@@ -98,24 +98,6 @@ class Devise::MasqueradesController < DeviseController
98
98
 
99
99
  private
100
100
 
101
- def masqueraded_resource_class
102
- @masqueraded_resource_class ||= begin
103
- unless params[:masqueraded_resource_class].blank?
104
- params[:masqueraded_resource_class].constantize
105
- else
106
- unless session[session_key_masqueraded_resource_class].blank?
107
- session[session_key_masquerading_resource_class].constantize
108
- else
109
- if Devise.masqueraded_resource_class_name.present?
110
- Devise.masqueraded_resource_class_name.constantize
111
- else
112
- Devise.masqueraded_resource_class || resource_class
113
- end
114
- end
115
- end
116
- end
117
- end
118
-
119
101
  def masqueraded_resource_name
120
102
  Devise.masqueraded_resource_name || masqueraded_resource_class.model_name.param_key
121
103
  end
@@ -193,18 +175,6 @@ class Devise::MasqueradesController < DeviseController
193
175
  "devise_masquerade_#{masqueraded_resource_name}_#{masqueradable_resource.to_param}_#{guid}".to_sym
194
176
  end
195
177
 
196
- def session_key_masqueraded_resource_class
197
- "devise_masquerade_masqueraded_resource_class"
198
- end
199
-
200
- def session_key_masquerading_resource_class
201
- "devise_masquerade_masquerading_resource_class"
202
- end
203
-
204
- def session_key_masquerading_resource_guid
205
- "devise_masquerade_masquerading_resource_guid"
206
- end
207
-
208
178
  def masquerading_current_user
209
179
  send("current_#{masquerading_resource_name}")
210
180
  end
@@ -11,6 +11,7 @@ Feature: Use back button for returning to the owner of the masquerade action.
11
11
  When I am on the users page
12
12
  And I login as one user
13
13
  Then I should be login as this user
14
+ And I should be masqueraded by owner user
14
15
 
15
16
  When I press back masquerade button
16
17
  Then I should be login as owner user
@@ -23,6 +24,7 @@ Feature: Use back button for returning to the owner of the masquerade action.
23
24
  When I am on the users page
24
25
  And I login as one user
25
26
  Then I should be login as this user
27
+ And I should be masqueraded by owner user
26
28
 
27
29
  When I press back masquerade button
28
30
  Then I should be login as owner user
@@ -13,6 +13,7 @@ Feature: Use back button for returning to the owner despite on expiration time.
13
13
  When I am on the users page
14
14
  And I login as one user
15
15
  Then I should be login as this user
16
+ And I should be masqueraded by owner user
16
17
  And I waited for 2 seconds
17
18
 
18
19
  When I press back masquerade button
@@ -28,6 +29,7 @@ Feature: Use back button for returning to the owner despite on expiration time.
28
29
  When I am on the users page
29
30
  And I login as one user
30
31
  Then I should be login as this user
32
+ And I should be masqueraded by owner user
31
33
  And I waited for 2 seconds
32
34
 
33
35
  When I press back masquerade button
@@ -14,6 +14,10 @@ Then /^I should be login as this user$/ do
14
14
  find('.current_user').should have_content(@user_mask.email)
15
15
  end
16
16
 
17
+ Then /^I should be masqueraded by owner user$/ do
18
+ find('.owner_user').should have_content(@user.email)
19
+ end
20
+
17
21
  When /^I press back masquerade button$/ do
18
22
  click_on "Back masquerade"
19
23
  end
@@ -53,13 +53,15 @@ module DeviseMasquerade
53
53
  def #{name}_masquerade_owner
54
54
  return unless send(:#{name}_masquerade?)
55
55
 
56
- sgid = if Devise.masquerade_storage_method_session?
57
- session[#{name}_helper_session_key]
56
+ if Devise.masquerade_storage_method_session?
57
+ resource_id = session[#{name}_helper_session_key]
58
+
59
+ masqueraded_resource_class.find(resource_id)
58
60
  else
59
- ::Rails.cache.read(#{name}_helper_session_key)
60
- end
61
+ sgid = ::Rails.cache.read(#{name}_helper_session_key)
61
62
 
62
- GlobalID::Locator.locate_signed(sgid, for: 'masquerade')
63
+ GlobalID::Locator.locate_signed(sgid, for: 'masquerade')
64
+ end
63
65
  end
64
66
 
65
67
  private
@@ -83,12 +85,48 @@ module DeviseMasquerade
83
85
  sign_in(resource)
84
86
  end
85
87
  end
88
+
89
+ def masqueraded_resource_class
90
+ @masqueraded_resource_class ||= begin
91
+ unless params[:masqueraded_resource_class].blank?
92
+ params[:masqueraded_resource_class].constantize
93
+ else
94
+ unless session[session_key_masqueraded_resource_class].blank?
95
+ session[session_key_masquerading_resource_class].constantize
96
+ else
97
+ if Devise.masqueraded_resource_class_name.present?
98
+ Devise.masqueraded_resource_class_name.constantize
99
+ else
100
+ Devise.masqueraded_resource_class || resource_class
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ def session_key_masqueraded_resource_class
108
+ "devise_masquerade_masqueraded_resource_class"
109
+ end
110
+
111
+ def session_key_masquerading_resource_class
112
+ "devise_masquerade_masquerading_resource_class"
113
+ end
114
+
115
+ def session_key_masquerading_resource_guid
116
+ "devise_masquerade_masquerading_resource_guid"
117
+ end
118
+
86
119
  METHODS
87
120
 
88
121
  ActiveSupport.on_load(:action_controller) do
89
122
  if respond_to?(:helper_method)
90
123
  helper_method "#{name}_masquerade?"
91
124
  helper_method "#{name}_masquerade_owner"
125
+
126
+ helper_method :masqueraded_resource_class
127
+ helper_method :session_key_masqueraded_resource_class
128
+ helper_method :session_key_masquerading_resource_class
129
+ helper_method :session_key_masquerading_resource_guid
92
130
  end
93
131
  end
94
132
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseMasquerade
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
@@ -17,6 +17,8 @@
17
17
  <% end %>
18
18
 
19
19
  <% if user_masquerade? %>
20
+ <h1 class='owner_user'><%= user_masquerade_owner.email %></h1>
21
+
20
22
  <%= link_to "Back masquerade", back_masquerade_path(User.new) %>
21
23
  <% end %>
22
24
  <% 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: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandr Korsak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2022-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler