moderate_parameters 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7da243c4e3c3402126ab024168790ca875ce97288d783432ce7d7105aa0082a8
|
4
|
+
data.tar.gz: 981432f67a8d7a5e17e774dc171cc239ff2379059e164cd4e24f40b446e51a70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f87a7a589852fccbc9dce81f5d4e041aeda5bbedbdadccd8a17599e5266a25cdc98b48047cf80886360c5f3e596b2b07aa705a2bd86f2ff575e929fac271740e
|
7
|
+
data.tar.gz: c0f48cd8721c99870af9229902bb26e7a3b805109afce9ea2fde53cce48266c546ccf267396db2780e1c34093556e63939db90fe0b399367e113394467b87af4
|
data/Gemfile.lock
CHANGED
@@ -2,34 +2,90 @@
|
|
2
2
|
|
3
3
|
module ModerateParameters
|
4
4
|
module Breadcrumbs
|
5
|
-
def [](key)
|
6
|
-
internal_param_logging(key, '
|
5
|
+
def []=(key, _value)
|
6
|
+
internal_param_logging(key, key?(key) ? 'overwritten' : 'added', caller_locations)
|
7
7
|
super
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def merge!(other_hash)
|
11
|
+
internal_method_logging('merge!', other_hash.keys, caller_locations)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def reverse_merge!(other_hash)
|
16
|
+
internal_method_logging('reverse_merge!', other_hash.keys, caller_locations)
|
12
17
|
super
|
13
18
|
end
|
14
19
|
|
15
20
|
def extract!(*keys)
|
16
|
-
internal_method_logging('extract!', keys, caller_locations)
|
21
|
+
internal_method_logging('extract!', keys, caller_locations)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def slice!(*keys)
|
26
|
+
internal_method_logging('slice!', keys, caller_locations)
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(*keys, &block)
|
31
|
+
internal_method_logging('delete', keys, caller_locations)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def reject!(&block)
|
36
|
+
internal_block_logging('reject!', caller_locations)
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
# Alias for #reject!
|
41
|
+
def delete_if(&block)
|
42
|
+
internal_block_logging('delete_if', caller_locations)
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def select!(&block)
|
47
|
+
internal_block_logging('select!', caller_locations)
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
# Alias for #select!
|
52
|
+
def keep_if(&block)
|
53
|
+
internal_block_logging('keep_if', caller_locations)
|
17
54
|
super
|
18
55
|
end
|
19
56
|
|
20
57
|
private
|
21
58
|
|
59
|
+
def needs_logged?
|
60
|
+
ModerateParameters.breadcrumbs_enabled &&
|
61
|
+
instance_variable_get(:@moderate_params_object_id) &&
|
62
|
+
!permitted?
|
63
|
+
end
|
64
|
+
|
22
65
|
def internal_param_logging(key, action, stack_array)
|
66
|
+
return unless needs_logged?
|
67
|
+
|
23
68
|
ActiveSupport::Notifications.instrument('moderate_parameters') do |payload|
|
24
69
|
payload[:caller_locations] = stack_array
|
25
70
|
payload[:message] = "#{key} is being #{action} on: #{stack_array.join("\n")}"
|
26
71
|
end
|
27
72
|
end
|
28
73
|
|
29
|
-
def internal_method_logging(method,
|
74
|
+
def internal_method_logging(method, args, stack_array)
|
75
|
+
return unless needs_logged?
|
76
|
+
|
77
|
+
ActiveSupport::Notifications.instrument('moderate_parameters') do |payload|
|
78
|
+
payload[:caller_locations] = stack_array
|
79
|
+
payload[:message] = "#{method} is being called with #{args} on: #{stack_array.join("\n")}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def internal_block_logging(method, stack_array)
|
84
|
+
return unless needs_logged?
|
85
|
+
|
30
86
|
ActiveSupport::Notifications.instrument('moderate_parameters') do |payload|
|
31
87
|
payload[:caller_locations] = stack_array
|
32
|
-
payload[:message] = "#{method} is being called with
|
88
|
+
payload[:message] = "#{method} is being called with a block on: #{stack_array.join("\n")}"
|
33
89
|
end
|
34
90
|
end
|
35
91
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
ActiveSupport::Notifications.subscribe('moderate_parameters') do |_, _, _, _, payload|
|
4
|
-
(ModerateParameters.logger || ActiveSupport::Logger.new('/dev/null')).info
|
4
|
+
(ModerateParameters.logger || ActiveSupport::Logger.new('/dev/null')).info(
|
5
|
+
"#{payload[:controller]}##{payload[:action]} #{payload[:message]}"
|
6
|
+
)
|
5
7
|
end
|
@@ -2,7 +2,17 @@
|
|
2
2
|
|
3
3
|
module ModerateParameters
|
4
4
|
module Parameters
|
5
|
+
MP_OBJECT_ID = :@moderate_params_object_id
|
6
|
+
MP_PARENT_KEY = :@moderate_params_parent_key
|
7
|
+
|
5
8
|
def moderate(controller_name, action, *filters)
|
9
|
+
log_duplicate_moderate_warning(
|
10
|
+
caller_locations,
|
11
|
+
instance_variable_get(MP_PARENT_KEY),
|
12
|
+
controller_name,
|
13
|
+
action
|
14
|
+
) if instance_variable_get(MP_OBJECT_ID)
|
15
|
+
|
6
16
|
params = self.class.new
|
7
17
|
|
8
18
|
filters.each do |filter|
|
@@ -19,7 +29,15 @@ module ModerateParameters
|
|
19
29
|
end
|
20
30
|
|
21
31
|
incoming_params_logging(params, controller_name, action)
|
22
|
-
dup
|
32
|
+
duplicate_params = dup
|
33
|
+
instance_variable_set(MP_OBJECT_ID, duplicate_params.object_id)
|
34
|
+
duplicate_params.permit!
|
35
|
+
end
|
36
|
+
|
37
|
+
def require(key)
|
38
|
+
return super if key.is_a?(Array) || self[key].blank?
|
39
|
+
self[key].instance_variable_set(MP_PARENT_KEY, key)
|
40
|
+
super
|
23
41
|
end
|
24
42
|
|
25
43
|
private
|
@@ -38,6 +56,12 @@ module ModerateParameters
|
|
38
56
|
end
|
39
57
|
end
|
40
58
|
|
59
|
+
def log_duplicate_moderate_warning(stack_array, parent_key, controller_name, action)
|
60
|
+
write_to_log(message: ".moderate has already been called on params.require(:#{parent_key}): #{stack_array.join("\n")}",
|
61
|
+
action: action,
|
62
|
+
controller: controller_name)
|
63
|
+
end
|
64
|
+
|
41
65
|
def non_scalar_value_filter(params, key, controller_name, action)
|
42
66
|
if has_key?(key) && !permitted_scalar?(self[key])
|
43
67
|
params[key] = self[key].class.new
|
@@ -50,7 +74,7 @@ module ModerateParameters
|
|
50
74
|
def array_of_permitted_scalars?(value)
|
51
75
|
if value.is_a?(Array) && value.all? { |element| permitted_scalar?(element) }
|
52
76
|
return true unless block_given?
|
53
|
-
|
77
|
+
|
54
78
|
yield value
|
55
79
|
end
|
56
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moderate_parameters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Boe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|