devise_masquerade 2.0.0 → 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: 99dc9de6d6af53393db0f0f0a8c8b80191bf203bad2ba604eb50dce7708aa314
4
- data.tar.gz: a8a89851d08443baaf4e7106bec7267d7a0c8209f01da40431874672ff56d1c9
3
+ metadata.gz: b21015ee6b3b1561bcf507063f84e0eea7f0bd4db78bee58c2122b287628cc56
4
+ data.tar.gz: 6817e192073914e507c1ba3cf7b9bef3178e733b3b83314ff80914f827e612d6
5
5
  SHA512:
6
- metadata.gz: 13133209d039b4f64ff124fc88935198e4cde0ee181abd6ce973b9d31f2618d6ed2512a27adf9c3f5d32be4fff16084f15135a6f95b97ff96b0a430ba4f9819a
7
- data.tar.gz: 0b4455f0adfd73ea7a49794349d686010c47157e4e30a836ea9a811f05005f8533af55a1945401f2595845ccd82cc2a84f4b6aa392ef0dcc3bea5b423f9ef35a
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.0)
55
+ devise_masquerade (2.0.2)
56
56
  devise (>= 4.7.0)
57
57
  globalid (>= 0.3.6)
58
58
  railties (>= 5.2.0)
@@ -77,13 +77,15 @@ class Devise::MasqueradesController < DeviseController
77
77
  def find_owner_resource(masqueradable_resource)
78
78
  skey = session_key(masqueradable_resource, masquerading_guid)
79
79
 
80
- data = if Devise.masquerade_storage_method_session?
81
- session[skey]
80
+ if Devise.masquerade_storage_method_session?
81
+ resource_id = session[skey]
82
+
83
+ masqueraded_resource_class.find(resource_id)
82
84
  else
83
- Rails.cache.read(skey)
84
- end
85
+ data = Rails.cache.read(skey)
85
86
 
86
- GlobalID::Locator.locate_signed(data, for: 'masquerade')
87
+ GlobalID::Locator.locate_signed(data, for: 'masquerade')
88
+ end
87
89
  end
88
90
 
89
91
  def go_back(user, path:)
@@ -96,24 +98,6 @@ class Devise::MasqueradesController < DeviseController
96
98
 
97
99
  private
98
100
 
99
- def masqueraded_resource_class
100
- @masqueraded_resource_class ||= begin
101
- unless params[:masqueraded_resource_class].blank?
102
- params[:masqueraded_resource_class].constantize
103
- else
104
- unless session[session_key_masqueraded_resource_class].blank?
105
- session[session_key_masquerading_resource_class].constantize
106
- else
107
- if Devise.masqueraded_resource_class_name.present?
108
- Devise.masqueraded_resource_class_name.constantize
109
- else
110
- Devise.masqueraded_resource_class || resource_class
111
- end
112
- end
113
- end
114
- end
115
- end
116
-
117
101
  def masqueraded_resource_name
118
102
  Devise.masqueraded_resource_name || masqueraded_resource_class.model_name.param_key
119
103
  end
@@ -161,13 +145,13 @@ class Devise::MasqueradesController < DeviseController
161
145
 
162
146
  skey = session_key(masqueradable_resource, guid)
163
147
 
164
- resource_gid = send("current_#{masquerading_resource_name}").to_sgid(for: 'masquerade')
148
+ resource_obj = send("current_#{masquerading_resource_name}")
165
149
 
166
150
  if Devise.masquerade_storage_method_session?
167
- session[skey] = resource_gid
151
+ session[skey] = resource_obj.to_param
168
152
  else
169
153
  # skip sharing owner id via session
170
- Rails.cache.write(skey, resource_gid)
154
+ Rails.cache.write(skey, resource_obj.to_sgid(for: 'masquerade'))
171
155
 
172
156
  session[skey] = true
173
157
  end
@@ -191,18 +175,6 @@ class Devise::MasqueradesController < DeviseController
191
175
  "devise_masquerade_#{masqueraded_resource_name}_#{masqueradable_resource.to_param}_#{guid}".to_sym
192
176
  end
193
177
 
194
- def session_key_masqueraded_resource_class
195
- "devise_masquerade_masqueraded_resource_class"
196
- end
197
-
198
- def session_key_masquerading_resource_class
199
- "devise_masquerade_masquerading_resource_class"
200
- end
201
-
202
- def session_key_masquerading_resource_guid
203
- "devise_masquerade_masquerading_resource_guid"
204
- end
205
-
206
178
  def masquerading_current_user
207
179
  send("current_#{masquerading_resource_name}")
208
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.0'.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.0
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-10 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