effective_resources 2.4.6 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/effective/impersonation_controller/destroy.rb +25 -0
- data/app/controllers/concerns/effective/impersonation_controller/impersonate.rb +29 -0
- data/app/helpers/effective_resources_private_helper.rb +14 -6
- data/app/models/effective/resources/controller.rb +36 -34
- data/app/models/effective/resources/i18n.rb +23 -0
- data/config/locales/effective_resources.en.yml +10 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 856d2a15f81a4ecff7c02f01a0e6444e5d81999af6f357428b86a6479bd126fb
|
4
|
+
data.tar.gz: 72a6da8d12e0b5ce4465028fe5269ca2ef22cfb3f4f70655783cf8db1ecd97b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a18cacf16dd2d0c54f14b4995f73708b9136baf1701d75d3d0cc5c186b782bee8bee3fc49a54658da1794b9faac59dc6544f8a53a9eddbe033c25af6360e0bd
|
7
|
+
data.tar.gz: fea55cc3cc15071d6bf80a34b4bbb1ab975d5f173434f4589277a9ed1885166f205b0c2c710c1c73ffc169c5a624daa6f1ada46f16aa0941e4b3cb6a145d7634
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Effective
|
2
|
+
module ImpersonationController
|
3
|
+
module Destroy
|
4
|
+
|
5
|
+
def destroy
|
6
|
+
@user = current_user.class.find(session[:impersonation_user_id])
|
7
|
+
redirect_path = after_destroy_impersonate_path_for(@user)
|
8
|
+
|
9
|
+
# Reset impersonation
|
10
|
+
session[:impersonation_user_id] = nil
|
11
|
+
session[:impersonation_original_path] = nil
|
12
|
+
|
13
|
+
expire_data_after_sign_in!
|
14
|
+
warden.session_serializer.store(@user, Devise::Mapping.find_scope!(@user))
|
15
|
+
|
16
|
+
redirect_to(redirect_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def after_destroy_impersonate_path_for(user)
|
20
|
+
session[:impersonation_original_path].presence || '/admin/users'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Effective
|
2
|
+
module ImpersonationController
|
3
|
+
module Impersonate
|
4
|
+
|
5
|
+
def impersonate
|
6
|
+
@user = current_user.class.find(params[:id])
|
7
|
+
redirect_path = after_impersonate_path_for(@user)
|
8
|
+
|
9
|
+
authorize! :impersonate, @user
|
10
|
+
|
11
|
+
# Impersonate
|
12
|
+
session[:impersonation_user_id] = current_user.id
|
13
|
+
session[:impersonation_original_path] = request.referer.presence || '/admin/users'
|
14
|
+
|
15
|
+
expire_data_after_sign_in!
|
16
|
+
warden.session_serializer.store(@user, Devise::Mapping.find_scope!(@user))
|
17
|
+
|
18
|
+
@user.touch
|
19
|
+
|
20
|
+
redirect_to(redirect_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def after_impersonate_path_for(user)
|
24
|
+
try(:dashboard_path) || try(:root_path) || '/'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module EffectiveResourcesPrivateHelper
|
4
4
|
REPLACE_PAGE_ACTIONS = {'update' => :edit, 'create' => :new}
|
5
5
|
BLACKLIST = [:default, :only, :except, :if, :unless, :redirect, :success, :danger, :klass]
|
6
|
+
REPLACE_RESOURCE_METHODS = Regexp.new('@resource\.\w+')
|
6
7
|
|
7
8
|
def permitted_resource_actions(resource, actions)
|
8
9
|
page_action = REPLACE_PAGE_ACTIONS[params[:action]] || params[:action].try(:to_sym) || :save
|
@@ -20,7 +21,7 @@ module EffectiveResourcesPrivateHelper
|
|
20
21
|
next unless permitted
|
21
22
|
|
22
23
|
opts = args.except(:default, :only, :except, :if, :unless, :redirect, :success, :danger, :klass)
|
23
|
-
resource_to_s = resource.to_s.presence || resource
|
24
|
+
resource_to_s = resource.to_s.presence || EffectiveResources.et(resource)
|
24
25
|
|
25
26
|
# Transform data: { ... } hash into 'data-' keys
|
26
27
|
if opts.key?(:data)
|
@@ -35,9 +36,16 @@ module EffectiveResourcesPrivateHelper
|
|
35
36
|
opts[:href] = opts.delete(:url)
|
36
37
|
end
|
37
38
|
|
38
|
-
#
|
39
|
+
# Replaces @resource.emails_send_to and @resource in data-confirm
|
39
40
|
if opts.key?('data-confirm') && opts['data-confirm'].to_s.include?('@resource')
|
40
|
-
|
41
|
+
confirm = opts['data-confirm']
|
42
|
+
|
43
|
+
confirm.gsub!(REPLACE_RESOURCE_METHODS) do |value|
|
44
|
+
method = value.to_s.split('.').last
|
45
|
+
resource.public_send(method)
|
46
|
+
end
|
47
|
+
|
48
|
+
opts['data-confirm'] = confirm.gsub('@resource', resource_to_s)
|
41
49
|
end
|
42
50
|
|
43
51
|
# Assign class
|
@@ -56,10 +64,10 @@ module EffectiveResourcesPrivateHelper
|
|
56
64
|
# Assign title
|
57
65
|
opts[:title] ||= case opts[:action]
|
58
66
|
when :save then commit
|
59
|
-
when :edit then "
|
67
|
+
when :edit then "#{et("effective_resources.actions.edit")} #{resource_to_s}"
|
60
68
|
when :show then "#{resource_to_s}"
|
61
|
-
when :destroy then "
|
62
|
-
when :index then "
|
69
|
+
when :destroy then "#{et("effective_resources.actions.destroy")} #{resource_to_s}"
|
70
|
+
when :index then "#{et("effective_resources.actions.index")} #{ets(resource)}"
|
63
71
|
else "#{opts[:action].to_s.titleize} #{resource_to_s}"
|
64
72
|
end
|
65
73
|
|
@@ -25,44 +25,45 @@ module Effective
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def buttons
|
28
|
+
human_index = EffectiveResources.et("effective_resources.actions.index")
|
29
|
+
human_new = EffectiveResources.et("effective_resources.actions.new")
|
30
|
+
|
28
31
|
{}.tap do |buttons|
|
29
32
|
member_get_actions.each do |action| # default true means it will be overwritten by dsl methods
|
30
|
-
buttons[action
|
33
|
+
buttons[human_action_name(action)] = { action: action, default: true }
|
31
34
|
end
|
32
35
|
|
33
36
|
(member_post_actions - crud_actions).each do |action| # default true means it will be overwritten by dsl methods
|
34
|
-
|
37
|
+
name = human_action_name(action)
|
38
|
+
confirm = human_action_confirm(action)
|
35
39
|
|
36
|
-
buttons[
|
40
|
+
buttons[name] = case action
|
37
41
|
when :archive
|
38
|
-
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' =>
|
42
|
+
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => confirm }
|
39
43
|
when :unarchive
|
40
|
-
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' =>
|
44
|
+
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => confirm }
|
41
45
|
else
|
42
|
-
{ action: action, default: true, 'data-method' => :post, 'data-confirm' =>
|
46
|
+
{ action: action, default: true, 'data-method' => :post, 'data-confirm' => confirm }
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
50
|
member_delete_actions.each do |action|
|
47
|
-
|
51
|
+
name = human_action_name(action)
|
52
|
+
confirm = human_action_confirm(action)
|
48
53
|
|
49
|
-
|
50
|
-
buttons['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
|
51
|
-
else
|
52
|
-
buttons[action_name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action_name} @resource?" }
|
53
|
-
end
|
54
|
+
buttons[name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => confirm }
|
54
55
|
end
|
55
56
|
|
56
57
|
if collection_get_actions.find { |a| a == :index }
|
57
|
-
buttons["
|
58
|
+
buttons["#{human_index} #{human_plural_name}"] = { action: :index, default: true }
|
58
59
|
end
|
59
60
|
|
60
61
|
if collection_get_actions.find { |a| a == :new }
|
61
|
-
buttons["
|
62
|
+
buttons["#{human_new} #{human_name}"] = { action: :new, default: true }
|
62
63
|
end
|
63
64
|
|
64
65
|
(collection_get_actions - crud_actions).each do |action|
|
65
|
-
buttons[action
|
66
|
+
buttons[human_action_name(action)] = { action: action, default: true }
|
66
67
|
end
|
67
68
|
end
|
68
69
|
end
|
@@ -73,37 +74,35 @@ module Effective
|
|
73
74
|
{}.tap do |actions|
|
74
75
|
member_get_actions.reverse_each do |action|
|
75
76
|
next unless crud_actions.include?(action)
|
76
|
-
actions[action
|
77
|
+
actions[human_action_name(action)] = { action: action, default: true }
|
77
78
|
end
|
78
79
|
|
79
80
|
member_get_actions.each do |action|
|
80
81
|
next if crud_actions.include?(action)
|
81
|
-
actions[action
|
82
|
+
actions[human_action_name(action)] = { action: action, default: true }
|
82
83
|
end
|
83
84
|
|
84
85
|
member_post_actions.each do |action|
|
85
86
|
next if crud_actions.include?(action)
|
86
87
|
|
87
|
-
|
88
|
+
name = human_action_name(action)
|
89
|
+
confirm = human_action_confirm(action)
|
88
90
|
|
89
|
-
actions[
|
91
|
+
actions[name] = case action
|
90
92
|
when :archive
|
91
|
-
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' =>
|
93
|
+
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => confirm }
|
92
94
|
when :unarchive
|
93
|
-
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' =>
|
95
|
+
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => confirm }
|
94
96
|
else
|
95
|
-
{ action: action, default: true, 'data-method' => :post, 'data-confirm' =>
|
97
|
+
{ action: action, default: true, 'data-method' => :post, 'data-confirm' => confirm }
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
99
101
|
member_delete_actions.each do |action|
|
100
|
-
|
102
|
+
name = human_action_name(action)
|
103
|
+
confirm = human_action_confirm(action)
|
101
104
|
|
102
|
-
|
103
|
-
actions['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
|
104
|
-
else
|
105
|
-
actions[action_name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action_name} @resource?" }
|
106
|
-
end
|
105
|
+
actions[name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => confirm }
|
107
106
|
end
|
108
107
|
end
|
109
108
|
end
|
@@ -111,26 +110,29 @@ module Effective
|
|
111
110
|
# Used by datatables
|
112
111
|
def fallback_resource_actions
|
113
112
|
{
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
human_action_name(:show) => { action: :show, default: true },
|
114
|
+
human_action_name(:edit) => { action: :edit, default: true },
|
115
|
+
human_action_name(:destroy) => { action: :destroy, default: true, 'data-method' => :delete, 'data-confirm' => human_action_confirm(:destroy) }
|
117
116
|
}
|
118
117
|
end
|
119
118
|
|
120
119
|
# This is the fallback for render_resource_actions when no actions are specified, but a class is given
|
121
120
|
# Used by Datatables new
|
122
121
|
def resource_klass_actions
|
122
|
+
human_index = EffectiveResources.et("effective_resources.actions.index")
|
123
|
+
human_new = EffectiveResources.et("effective_resources.actions.new")
|
124
|
+
|
123
125
|
{}.tap do |buttons|
|
124
126
|
if collection_get_actions.find { |a| a == :index }
|
125
|
-
buttons["
|
127
|
+
buttons["#{human_index} #{human_plural_name}"] = { action: :index, default: true }
|
126
128
|
end
|
127
129
|
|
128
130
|
if collection_get_actions.find { |a| a == :new }
|
129
|
-
buttons["
|
131
|
+
buttons["#{human_new} #{human_name}"] = { action: :new, default: true }
|
130
132
|
end
|
131
133
|
|
132
134
|
(collection_get_actions - crud_actions).each do |action|
|
133
|
-
buttons[action
|
135
|
+
buttons[human_action_name(action)] = { action: action, default: true }
|
134
136
|
end
|
135
137
|
end
|
136
138
|
end
|
@@ -4,6 +4,29 @@ module Effective
|
|
4
4
|
module Resources
|
5
5
|
module I18n
|
6
6
|
|
7
|
+
def human_action_name(action)
|
8
|
+
if klass.respond_to?(:model_name)
|
9
|
+
value = ::I18n.t("activerecord.actions.#{klass.model_name.i18n_key}.#{action}")
|
10
|
+
return value unless value.start_with?('translation missing:')
|
11
|
+
end
|
12
|
+
|
13
|
+
if(crud_actions.include?(action))
|
14
|
+
# Raises exception if not present
|
15
|
+
return EffectiveResources.et("effective_resources.actions.#{action}")
|
16
|
+
end
|
17
|
+
|
18
|
+
action.to_s.titleize
|
19
|
+
end
|
20
|
+
|
21
|
+
def human_action_confirm(action)
|
22
|
+
if klass.respond_to?(:model_name)
|
23
|
+
value = ::I18n.t("activerecord.actions.#{klass.model_name.i18n_key}.#{action}_confirm")
|
24
|
+
return value unless value.start_with?('translation missing:')
|
25
|
+
end
|
26
|
+
|
27
|
+
"Really #{human_action_name(action)} @resource?"
|
28
|
+
end
|
29
|
+
|
7
30
|
def human_name
|
8
31
|
if klass.respond_to?(:model_name)
|
9
32
|
klass.model_name.human
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -143,6 +143,8 @@ files:
|
|
143
143
|
- app/controllers/concerns/effective/crud_controller/save.rb
|
144
144
|
- app/controllers/concerns/effective/crud_controller/submits.rb
|
145
145
|
- app/controllers/concerns/effective/flash_messages.rb
|
146
|
+
- app/controllers/concerns/effective/impersonation_controller/destroy.rb
|
147
|
+
- app/controllers/concerns/effective/impersonation_controller/impersonate.rb
|
146
148
|
- app/controllers/concerns/effective/select2_ajax_controller.rb
|
147
149
|
- app/controllers/concerns/effective/wizard_controller.rb
|
148
150
|
- app/controllers/concerns/effective/wizard_controller/actions.rb
|
@@ -210,6 +212,7 @@ files:
|
|
210
212
|
- app/views/effective/resource/_actions_glyphicons.html.haml
|
211
213
|
- app/views/layouts/effective_mailer_layout.html.haml
|
212
214
|
- config/effective_resources.rb
|
215
|
+
- config/locales/effective_resources.en.yml
|
213
216
|
- config/routes.rb
|
214
217
|
- lib/effective_resources.rb
|
215
218
|
- lib/effective_resources/effective_gem.rb
|