active_scaffold 4.4.7 → 4.4.9
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 +4 -4
- data/CHANGELOG.rdoc +18 -0
- data/README.md +101 -0
- data/app/views/active_scaffold_overrides/_add_existing_form.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -1
- data/app/views/active_scaffold_overrides/_field_search.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +13 -11
- data/app/views/active_scaffold_overrides/_list.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_new_record.js.erb +3 -3
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_search.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_show.html.erb +1 -1
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
- data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
- data/app/views/active_scaffold_overrides/destroy.js.erb +5 -5
- data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
- data/lib/active_scaffold/actions/core.rb +115 -14
- data/lib/active_scaffold/actions/field_search.rb +8 -1
- data/lib/active_scaffold/actions/nested.rb +3 -1
- data/lib/active_scaffold/actions/subform.rb +56 -9
- data/lib/active_scaffold/actions/update.rb +2 -2
- data/lib/active_scaffold/api_association_serializer.rb +27 -0
- data/lib/active_scaffold/config/core.rb +25 -0
- data/lib/active_scaffold/extensions/action_view_rendering.rb +4 -9
- data/lib/active_scaffold/finder.rb +12 -4
- data/lib/active_scaffold/helpers/action_link_helpers.rb +19 -7
- data/lib/active_scaffold/helpers/association_helpers.rb +1 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +65 -2
- data/lib/active_scaffold/helpers/form_column_helpers.rb +3 -2
- data/lib/active_scaffold/helpers/form_ui_helpers.rb +1 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +3 -3
- data/lib/active_scaffold/helpers/list_column_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/pagination_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/search_column_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/tabs_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
- data/lib/active_scaffold/parameter_filter_warning.rb +24 -0
- data/lib/active_scaffold/parameter_signing.rb +34 -0
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/active_scaffold.rb +2 -0
- metadata +4 -1
|
@@ -21,28 +21,75 @@ module ActiveScaffold::Actions
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def do_edit_associated
|
|
24
|
+
verify_tab_selection_parameters
|
|
24
25
|
@scope = params[:scope]
|
|
25
26
|
@parent_record = params[:id].nil? ? new_parent_record : find_if_allowed(params[:id], :update)
|
|
26
27
|
@column = active_scaffold_config.columns[params[:child_association]]
|
|
27
28
|
|
|
28
29
|
@record = (find_associated_record if params[:associated_id]) ||
|
|
29
|
-
build_associated(@column.association, @parent_record)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
build_associated(@column.association, @parent_record)
|
|
31
|
+
if params[:tabbed_by] && params[:value]
|
|
32
|
+
@tab_id = params.delete(:value)
|
|
33
|
+
assign_tabbed_by(@record, @column, params.delete(:tabbed_by), @tab_id, params.delete(:value_type))
|
|
34
|
+
end
|
|
35
|
+
@record
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def verify_tab_selection_parameters
|
|
39
|
+
return unless params.key?(:tabbed_by) || params.key?(:value_type) || params.key?(:tab_signature)
|
|
40
|
+
|
|
41
|
+
payload = ActiveScaffold::ParameterSigning.tab_selection_payload(params, controller: controller_path)
|
|
42
|
+
unless params[:tabbed_by].is_a?(String) && params[:value].is_a?(String) &&
|
|
43
|
+
ActiveScaffold::ParameterSigning.valid_signature?(payload, params[:tab_signature], purpose: :tab_selection)
|
|
44
|
+
raise ::ActionController::BadRequest, 'Invalid tab selection signature'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
params.delete(:tab_signature)
|
|
35
48
|
end
|
|
36
49
|
|
|
37
50
|
def assign_tabbed_by(record, parent_column, tabbed_by, value, value_type)
|
|
38
51
|
if (association = tabbed_by_association(parent_column, tabbed_by))
|
|
39
|
-
klass =
|
|
52
|
+
klass =
|
|
53
|
+
if association.polymorphic?
|
|
54
|
+
raise ::ActionController::BadRequest if value_type.blank?
|
|
55
|
+
|
|
56
|
+
value_type.constantize
|
|
57
|
+
else
|
|
58
|
+
association.klass
|
|
59
|
+
end
|
|
40
60
|
end
|
|
41
|
-
|
|
61
|
+
value =
|
|
62
|
+
if klass
|
|
63
|
+
klass.find(value)
|
|
64
|
+
else
|
|
65
|
+
field = ActiveScaffold::OrmChecks.columns_hash(record.class)[tabbed_by.to_s]
|
|
66
|
+
ActiveScaffold::Core.column_type_cast(value, field, record.class)
|
|
67
|
+
end
|
|
68
|
+
assign_tabbed_value(record, association, tabbed_by, value)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def assign_tabbed_value(record, association, tabbed_by, value)
|
|
72
|
+
return if record.public_send(tabbed_by) == value
|
|
73
|
+
|
|
74
|
+
if record.persisted?
|
|
75
|
+
unless record.authorized_for?(crud_type: :update, column: tabbed_by.to_sym)
|
|
76
|
+
raise ActiveScaffold::RecordNotAllowed, 'Not authorized to change the tab grouping'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
if association && association.macro != :belongs_to
|
|
80
|
+
# Association setters could save records immediately. Only stage
|
|
81
|
+
# their form values until the parent form is submitted.
|
|
82
|
+
record.association(association.name).target = association.collection? ? Array(value) : value
|
|
83
|
+
return
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
record.public_send :"#{tabbed_by}=", value
|
|
42
88
|
end
|
|
43
89
|
|
|
44
90
|
def find_associated_record
|
|
45
|
-
@column.association.klass
|
|
91
|
+
scope = associated_record_scope(@column.association.klass, column: @column)
|
|
92
|
+
find_if_allowed(params[:associated_id], :read, scope).tap do |record|
|
|
46
93
|
save_record_to_association(record, @column.association.reverse_association, @parent_record, @column.association)
|
|
47
94
|
end
|
|
48
95
|
end
|
|
@@ -23,6 +23,7 @@ module ActiveScaffold::Actions
|
|
|
23
23
|
|
|
24
24
|
# for inline (inlist) editing
|
|
25
25
|
def update_column
|
|
26
|
+
@column = inplace_edit_column(params[:column])
|
|
26
27
|
do_update_column
|
|
27
28
|
@column_span_id = params.delete(:editor_id) || params.delete(:editorId)
|
|
28
29
|
end
|
|
@@ -153,10 +154,9 @@ module ActiveScaffold::Actions
|
|
|
153
154
|
def do_update_column
|
|
154
155
|
# delete from params so update :table won't break urls, also they shouldn't be used in sort links too
|
|
155
156
|
value = params.delete(:value)
|
|
156
|
-
|
|
157
|
+
params.delete(:column)
|
|
157
158
|
params.delete(:original_html)
|
|
158
159
|
params.delete(:original_value)
|
|
159
|
-
@column = active_scaffold_config.columns[column]
|
|
160
160
|
|
|
161
161
|
value_record = record_for_update_column
|
|
162
162
|
value = value_for_update_column(value, @column, value_record)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveScaffold
|
|
4
|
+
class ApiAssociationSerializer
|
|
5
|
+
def initialize(options = nil)
|
|
6
|
+
@options = options
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def serialize(value, column)
|
|
10
|
+
if column.association.collection?
|
|
11
|
+
value.filter_map { |record| serialize_record(record, column) }
|
|
12
|
+
else
|
|
13
|
+
serialize_record(value, column)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def serialize_record(record, column)
|
|
20
|
+
return unless record
|
|
21
|
+
return if record.respond_to?(:authorized_for?) && !record.authorized_for?(crud_type: :read)
|
|
22
|
+
|
|
23
|
+
options = @options ? @options.call(column, record) : {only: [record.class.primary_key], methods: [:to_label]}
|
|
24
|
+
record.serializable_hash(options)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -43,6 +43,22 @@ module ActiveScaffold::Config
|
|
|
43
43
|
cattr_accessor :store_user_settings, instance_accessor: false
|
|
44
44
|
@@store_user_settings = true
|
|
45
45
|
|
|
46
|
+
# nil preserves legacy association exports with a warning; false enables safe exports.
|
|
47
|
+
cattr_accessor :unsafe_api_associations, instance_accessor: false
|
|
48
|
+
@@unsafe_api_associations = nil
|
|
49
|
+
|
|
50
|
+
# response formats enabled by default, before additional core and action formats
|
|
51
|
+
cattr_accessor :default_formats, instance_accessor: false
|
|
52
|
+
@@default_formats = %i[html js json xml]
|
|
53
|
+
|
|
54
|
+
# nil allows filtering on all database columns; an empty array disables it
|
|
55
|
+
cattr_accessor :conditions_from_params_allowed_columns, instance_accessor: false
|
|
56
|
+
@@conditions_from_params_allowed_columns = nil
|
|
57
|
+
|
|
58
|
+
# nil leaves exclusions unspecified; [] explicitly accepts unrestricted filtering when the allowed list is nil
|
|
59
|
+
cattr_accessor :conditions_from_params_excluded_columns, instance_accessor: false
|
|
60
|
+
@@conditions_from_params_excluded_columns = nil
|
|
61
|
+
|
|
46
62
|
# action links are used by actions to tie together. you can use them, too! this is a collection of ActiveScaffold::DataStructures::ActionLink objects.
|
|
47
63
|
cattr_reader :action_links, instance_reader: false
|
|
48
64
|
@@action_links = ActiveScaffold::DataStructures::ActionLinks.new
|
|
@@ -138,6 +154,11 @@ module ActiveScaffold::Config
|
|
|
138
154
|
# enable saving user settings in session (per_page, limit, page, sort, search params)
|
|
139
155
|
attr_accessor :store_user_settings
|
|
140
156
|
|
|
157
|
+
# override the default response formats for a specific controller
|
|
158
|
+
attr_accessor :default_formats
|
|
159
|
+
|
|
160
|
+
attr_accessor :unsafe_api_associations, :conditions_from_params_allowed_columns, :conditions_from_params_excluded_columns
|
|
161
|
+
|
|
141
162
|
# lets you specify whether add a create link for each sti child for a specific controller
|
|
142
163
|
attr_accessor :sti_create_links
|
|
143
164
|
|
|
@@ -197,6 +218,10 @@ module ActiveScaffold::Config
|
|
|
197
218
|
@cache_association_options = self.class.cache_association_options
|
|
198
219
|
@conditional_get_support = self.class.conditional_get_support
|
|
199
220
|
@store_user_settings = self.class.store_user_settings
|
|
221
|
+
@default_formats = self.class.default_formats.dup
|
|
222
|
+
@unsafe_api_associations = self.class.unsafe_api_associations
|
|
223
|
+
@conditions_from_params_allowed_columns = self.class.conditions_from_params_allowed_columns&.dup
|
|
224
|
+
@conditions_from_params_excluded_columns = self.class.conditions_from_params_excluded_columns&.dup
|
|
200
225
|
@sti_create_links = self.class.sti_create_links
|
|
201
226
|
|
|
202
227
|
# inherit from the global set of action links
|
|
@@ -135,24 +135,19 @@ module ActiveScaffold # :nodoc:
|
|
|
135
135
|
end
|
|
136
136
|
|
|
137
137
|
def render_embedded(options)
|
|
138
|
-
require 'digest/md5'
|
|
139
|
-
|
|
140
138
|
remote_controller = options[:active_scaffold]
|
|
141
|
-
# It is important that the EID hash remains short as to not contribute
|
|
142
|
-
# to a large session size and thus a possible cookie overflow exception
|
|
143
|
-
# when using rails CookieStore or EncryptedCookieStore. For example,
|
|
144
|
-
# when rendering many embedded scaffolds with constraints or conditions
|
|
145
|
-
# on a single page.
|
|
146
|
-
eid = Digest::MD5.hexdigest(params[:controller] + options.to_s)
|
|
147
139
|
eid_info = {loading: true}
|
|
148
140
|
eid_info[:constraints] = options[:constraints] if options[:constraints]
|
|
149
141
|
eid_info[:conditions] = options[:conditions] if options[:conditions]
|
|
150
142
|
eid_info[:label] = options[:label] if options[:label]
|
|
151
143
|
options[:params] ||= {}
|
|
144
|
+
url_options = {controller: remote_controller.to_s, action: 'index', id: nil}.merge(options[:params])
|
|
145
|
+
url_options[:embedded] = eid_info
|
|
146
|
+
url_options = signed_url_options(url_options)
|
|
147
|
+
eid = url_options[:eid]
|
|
152
148
|
options[:params].merge! eid: eid, embedded: eid_info
|
|
153
149
|
|
|
154
150
|
id = "as_#{eid}-embedded"
|
|
155
|
-
url_options = {controller: remote_controller.to_s, action: 'index', id: nil}.merge(options[:params])
|
|
156
151
|
|
|
157
152
|
if controller.respond_to?(:render_component_into_view, true) && !options[:xhr]
|
|
158
153
|
controller.send(:render_component_into_view, url_options)
|
|
@@ -442,16 +442,24 @@ module ActiveScaffold
|
|
|
442
442
|
Time.zone.now
|
|
443
443
|
end
|
|
444
444
|
|
|
445
|
+
# Override to allow additional normalized duration units offered by the trend dropdown.
|
|
446
|
+
def valid_datetime_trend_unit?(unit)
|
|
447
|
+
DATE_UNITS.include?(unit.upcase) || TIME_UNITS.include?(unit.upcase)
|
|
448
|
+
end
|
|
449
|
+
|
|
445
450
|
def datetime_from_to_for_trend(column, value)
|
|
451
|
+
unit = value['unit'].to_s.downcase.pluralize
|
|
452
|
+
return [nil, nil] unless valid_datetime_trend_unit?(unit)
|
|
453
|
+
|
|
446
454
|
case value['opt']
|
|
447
455
|
when 'PAST'
|
|
448
456
|
trend_number = [value['number'].to_i, 1].max
|
|
449
457
|
now = datetime_now
|
|
450
458
|
if datetime_column_date?(column)
|
|
451
|
-
from = now.beginning_of_day.ago(trend_number.
|
|
459
|
+
from = now.beginning_of_day.ago(trend_number.public_send(unit))
|
|
452
460
|
to = now.end_of_day
|
|
453
461
|
else
|
|
454
|
-
from = now.ago(trend_number.
|
|
462
|
+
from = now.ago(trend_number.public_send(unit))
|
|
455
463
|
to = now
|
|
456
464
|
end
|
|
457
465
|
[from, to]
|
|
@@ -460,10 +468,10 @@ module ActiveScaffold
|
|
|
460
468
|
now = datetime_now
|
|
461
469
|
if datetime_column_date?(column)
|
|
462
470
|
from = now.beginning_of_day
|
|
463
|
-
to = now.end_of_day.in(trend_number.
|
|
471
|
+
to = now.end_of_day.in(trend_number.public_send(unit))
|
|
464
472
|
else
|
|
465
473
|
from = now
|
|
466
|
-
to = now.in(trend_number.
|
|
474
|
+
to = now.in(trend_number.public_send(unit))
|
|
467
475
|
end
|
|
468
476
|
[from, to]
|
|
469
477
|
end
|
|
@@ -276,10 +276,10 @@ module ActiveScaffold
|
|
|
276
276
|
@action_links_urls[link.name_to_cache.to_s] || begin
|
|
277
277
|
url_options = cached_action_link_url_options(link, record)
|
|
278
278
|
if cache_action_link_url?(link, record)
|
|
279
|
-
@action_links_urls[link.name_to_cache.to_s] = url_for(url_options)
|
|
279
|
+
@action_links_urls[link.name_to_cache.to_s] = url_for(signed_url_options(url_options))
|
|
280
280
|
else
|
|
281
281
|
url_options.merge! eid: nil, embedded: nil if link.nested_link?
|
|
282
|
-
url_for(params_for(url_options))
|
|
282
|
+
url_for(signed_url_options(params_for(url_options)))
|
|
283
283
|
end
|
|
284
284
|
end
|
|
285
285
|
end
|
|
@@ -302,11 +302,17 @@ module ActiveScaffold
|
|
|
302
302
|
|
|
303
303
|
def add_query_string_to_cached_url(link, url)
|
|
304
304
|
query_string, non_nested_query_string = query_string_for_action_links(link)
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
parts = [query_string]
|
|
306
|
+
parts << non_nested_query_string&.delete_prefix('&') unless link.nested_link?
|
|
307
|
+
query = parts.compact.join('&')
|
|
308
|
+
# Explicit options from an application override take precedence over
|
|
309
|
+
# return destinations propagated from the current request.
|
|
310
|
+
if url.match?(/[?&]return_to=/)
|
|
311
|
+
query = query.split('&').reject { |part| part.start_with?('return_to=', 'return_to_signature=') }.join('&')
|
|
312
|
+
end
|
|
313
|
+
if query.present?
|
|
307
314
|
url << (url.include?('?') ? '&' : '?')
|
|
308
|
-
url <<
|
|
309
|
-
url << non_nested_query_string if nested_params
|
|
315
|
+
url << query
|
|
310
316
|
end
|
|
311
317
|
url
|
|
312
318
|
end
|
|
@@ -362,9 +368,15 @@ module ActiveScaffold
|
|
|
362
368
|
if nested_singular_association? && action_name == 'index'
|
|
363
369
|
# pass the current path as return_to, for nested listing on singular association, so forms don't return to parent listing
|
|
364
370
|
@query_string_params << :return_to
|
|
371
|
+
@query_string_params << :return_to_signature
|
|
372
|
+
query_string_options.except!(:return_to, :return_to_signature)
|
|
365
373
|
non_nested_query_string_options[:return_to] = request.fullpath
|
|
374
|
+
non_nested_query_string_options = signed_url_options(non_nested_query_string_options)
|
|
366
375
|
end
|
|
367
376
|
|
|
377
|
+
query_string_options.delete(:return_to_signature) unless query_string_options[:return_to]
|
|
378
|
+
non_nested_query_string_options.delete(:return_to_signature) unless non_nested_query_string_options[:return_to]
|
|
379
|
+
|
|
368
380
|
query_string = query_string_options.to_query if query_string_options.present?
|
|
369
381
|
if non_nested_query_string_options.present?
|
|
370
382
|
non_nested_query_string = "#{'&' if query_string}#{non_nested_query_string_options.to_query}"
|
|
@@ -510,7 +522,7 @@ module ActiveScaffold
|
|
|
510
522
|
action_link_id("#{controller_id}#{link.action}", '--ID--')
|
|
511
523
|
end
|
|
512
524
|
end
|
|
513
|
-
action_link_id.sub('--ID--', id)
|
|
525
|
+
action_link_id.sub('--ID--', clean_id(id))
|
|
514
526
|
end
|
|
515
527
|
|
|
516
528
|
def action_link_html(link, url, html_options, record)
|
|
@@ -128,6 +128,7 @@ module ActiveScaffold
|
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
def record_select_params_for_add_existing(association, edit_associated_url_options, record)
|
|
131
|
+
edit_associated_url_options = signed_tab_selection_options(signed_url_options(edit_associated_url_options))
|
|
131
132
|
if ActiveScaffold::Bridges::RecordSelect.callback_registry?
|
|
132
133
|
{
|
|
133
134
|
onselect: 'active_scaffold.add_existing',
|
|
@@ -12,7 +12,9 @@ module ActiveScaffold
|
|
|
12
12
|
:render_parent_action, :nested_singular_association?,
|
|
13
13
|
:main_form_controller, :build_associated,
|
|
14
14
|
:generate_temporary_id, :generated_id,
|
|
15
|
-
:active_scaffold_config_for, :tabbed_by_association
|
|
15
|
+
:active_scaffold_config_for, :tabbed_by_association,
|
|
16
|
+
:signed_embedded_options, :signed_return_to_options, :signed_url_options,
|
|
17
|
+
:signed_tab_selection_options
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
|
|
@@ -23,6 +25,62 @@ module ActiveScaffold
|
|
|
23
25
|
config.user || config.new_user_settings({}, {})
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
# Sign only embedded options supplied by application code, before URL generation.
|
|
29
|
+
def signed_embedded_options(options)
|
|
30
|
+
if options.key?('embedded') || (options[:embedded] && options.key?('controller'))
|
|
31
|
+
options = options.symbolize_keys
|
|
32
|
+
end
|
|
33
|
+
return options unless options[:embedded]
|
|
34
|
+
|
|
35
|
+
target = options[:controller] ? controller_requested(options[:controller]) : controller_path
|
|
36
|
+
payload = ActiveScaffold::ParameterSigning.embedded_payload(options[:embedded], controller: target)
|
|
37
|
+
options.merge(eid: ActiveScaffold::ParameterSigning.signature(payload, purpose: :embedded))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def signed_url_options(options)
|
|
41
|
+
return options unless options.is_a?(Hash)
|
|
42
|
+
|
|
43
|
+
signed_return_to_options(signed_embedded_options(options))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Only sign tab selections constructed by application code, not parameters
|
|
47
|
+
# inherited from the current request through params_for.
|
|
48
|
+
def signed_tab_selection_options(options)
|
|
49
|
+
options = options.symbolize_keys if options.key?('tabbed_by') || options.key?('controller')
|
|
50
|
+
return options unless options[:tabbed_by]
|
|
51
|
+
|
|
52
|
+
target = options[:controller] ? controller_requested(options[:controller]) : controller_path
|
|
53
|
+
payload = ActiveScaffold::ParameterSigning.tab_selection_payload(options, controller: target)
|
|
54
|
+
options.merge(tab_signature: ActiveScaffold::ParameterSigning.signature(payload, purpose: :tab_selection))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Call after overridable URL-option builders, immediately before generating a URL.
|
|
58
|
+
def signed_return_to_options(options)
|
|
59
|
+
return options unless options.is_a?(Hash)
|
|
60
|
+
|
|
61
|
+
options = options.symbolize_keys if options.key?('return_to') || options.key?('return_to_signature')
|
|
62
|
+
if options[:return_to]
|
|
63
|
+
unless options[:return_to].is_a?(String)
|
|
64
|
+
raise ArgumentError, 'return_to must be a URL string'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
options.merge(return_to_signature: ActiveScaffold::ParameterSigning.signature(options[:return_to], purpose: :return_to))
|
|
68
|
+
elsif options.key?(:return_to_signature)
|
|
69
|
+
options.except(:return_to_signature)
|
|
70
|
+
else
|
|
71
|
+
options
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def verify_return_to_parameter
|
|
76
|
+
return if params[:return_to].nil?
|
|
77
|
+
|
|
78
|
+
unless params[:return_to].is_a?(String) &&
|
|
79
|
+
ActiveScaffold::ParameterSigning.valid_signature?(params[:return_to], params[:return_to_signature], purpose: :return_to)
|
|
80
|
+
raise ::ActionController::BadRequest, 'Invalid return_to signature'
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
26
84
|
def generate_temporary_id(record = nil, generated_id = nil)
|
|
27
85
|
unless generated_id
|
|
28
86
|
temp_id = (Time.now.to_f * 1_000_000).to_i.to_s
|
|
@@ -61,6 +119,8 @@ module ActiveScaffold
|
|
|
61
119
|
iframe associated_id authenticity_token _added _removed _popstate _].freeze
|
|
62
120
|
|
|
63
121
|
def params_for(options = {})
|
|
122
|
+
verify_return_to_parameter
|
|
123
|
+
active_scaffold_embedded_params if params[:embedded]
|
|
64
124
|
unless @params_for
|
|
65
125
|
@params_for = {}
|
|
66
126
|
params.except(*BLACKLIST_PARAMS).each do |key, value|
|
|
@@ -70,7 +130,7 @@ module ActiveScaffold
|
|
|
70
130
|
@params_for.delete(:id) if @params_for[:id].nil?
|
|
71
131
|
end
|
|
72
132
|
|
|
73
|
-
url_options = @params_for.merge(options)
|
|
133
|
+
url_options = @params_for.merge(options.slice(:controller))
|
|
74
134
|
if !active_scaffold_config.store_user_settings && controller_requested(url_options[:controller]) == controller_path
|
|
75
135
|
url_options[:search] ||= copy_param search_params if respond_to?(:search_params, true) && search_params.present?
|
|
76
136
|
url_options[:page] ||= params[:page]
|
|
@@ -80,6 +140,8 @@ module ActiveScaffold
|
|
|
80
140
|
url_options[:sort_direction] ||= direction
|
|
81
141
|
end
|
|
82
142
|
end
|
|
143
|
+
url_options.merge!(options)
|
|
144
|
+
url_options.delete(:return_to_signature) unless url_options[:return_to]
|
|
83
145
|
url_options
|
|
84
146
|
end
|
|
85
147
|
|
|
@@ -103,6 +165,7 @@ module ActiveScaffold
|
|
|
103
165
|
|
|
104
166
|
# Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page)
|
|
105
167
|
def main_path_to_return
|
|
168
|
+
verify_return_to_parameter
|
|
106
169
|
if params[:return_to]
|
|
107
170
|
params[:return_to]
|
|
108
171
|
else
|
|
@@ -130,6 +130,7 @@ module ActiveScaffold
|
|
|
130
130
|
# Fix for keeping unique IDs in subform
|
|
131
131
|
id_control = "record_#{column.name}_#{[params[:eid], params[:parent_id] || params[:id]].compact.join '_'}"
|
|
132
132
|
id_control += scope_id(scope) if scope
|
|
133
|
+
id_control = clean_id(id_control)
|
|
133
134
|
|
|
134
135
|
classes = "#{column.name}-input"
|
|
135
136
|
classes += ' numeric-input' if column.number?
|
|
@@ -185,7 +186,7 @@ module ActiveScaffold
|
|
|
185
186
|
if force || (form_columns && update_columns&.intersect?(form_columns))
|
|
186
187
|
url_params = url_options_for_render_field(column, record, scope, subform_controller, url_params)
|
|
187
188
|
options[:class] = "#{options[:class]} update_form".strip
|
|
188
|
-
options['data-update_url'] = url_for(url_params)
|
|
189
|
+
options['data-update_url'] = url_for(signed_url_options(url_params))
|
|
189
190
|
options['data-update_send_form'] = column.update_columns&.any?(Hash) || column.send_form_on_update_column
|
|
190
191
|
options['data-update_send_form_selector'] = column.options[:send_form_selector] if column.options[:send_form_selector]
|
|
191
192
|
options['data-skip-disable-form'] = !column.disable_on_update_column
|
|
@@ -353,7 +354,7 @@ module ActiveScaffold
|
|
|
353
354
|
hidden_field_tag options[:name], '', options
|
|
354
355
|
else
|
|
355
356
|
fields = value.map do |r|
|
|
356
|
-
hidden_field_tag options[:name], r.id, options.merge(id: options[:id] + "_#{r.id}")
|
|
357
|
+
hidden_field_tag options[:name], r.id, options.merge(id: options[:id] + "_#{clean_id r.id.to_s}")
|
|
357
358
|
end
|
|
358
359
|
safe_join fields, ''
|
|
359
360
|
end
|
|
@@ -106,6 +106,7 @@ module ActiveScaffold
|
|
|
106
106
|
url_options[:parent_model] ||= record.class.name
|
|
107
107
|
url_options[:parent_column] ||= column.name
|
|
108
108
|
url_options.reverse_merge! options[:url_options] if options[:url_options]
|
|
109
|
+
url_options = signed_url_options(url_options)
|
|
109
110
|
link_to(link_text, url_options, as_element_attributes(:field_add_new_popup, remote: true, data: {position: :popup}, class: 'as_action'))
|
|
110
111
|
end
|
|
111
112
|
|
|
@@ -5,7 +5,7 @@ module ActiveScaffold
|
|
|
5
5
|
# A bunch of helper methods to produce the common view ids
|
|
6
6
|
module IdHelpers
|
|
7
7
|
def id_from_controller(controller)
|
|
8
|
-
ERB::Util.h
|
|
8
|
+
clean_id ERB::Util.h(controller.to_s.gsub('/', '__'))
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def controller_id(controller = params[:eid] || nested_id || params[:parent_controller] || params[:controller])
|
|
@@ -57,7 +57,7 @@ module ActiveScaffold
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def action_link_id(link_action, link_id)
|
|
60
|
-
"#{controller_id}-#{link_action}-#{link_id}-link"
|
|
60
|
+
clean_id "#{controller_id}-#{link_action}-#{link_id}-link"
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def active_scaffold_column_header_id(column)
|
|
@@ -125,7 +125,7 @@ module ActiveScaffold
|
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
def action_iframe_id(options)
|
|
128
|
-
"#{controller_id}-#{options[:action]}-#{options[:id]}-iframe"
|
|
128
|
+
clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-iframe"
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
def scope_id(scope)
|
|
@@ -376,7 +376,7 @@ module ActiveScaffold
|
|
|
376
376
|
cell_id = ActiveScaffold::Registry.cache :inplace_edit_id, column.cache_key do
|
|
377
377
|
element_cell_id(id: '--ID--', action: 'update_column', name: column.name.to_s)
|
|
378
378
|
end
|
|
379
|
-
tag_options = {id: cell_id.sub('--ID--', record.id.to_s), class: 'in_place_editor_field',
|
|
379
|
+
tag_options = {id: cell_id.sub('--ID--', clean_id(record.id.to_s)), class: 'in_place_editor_field',
|
|
380
380
|
title: @_inplace_edit_title, data: {ie_id: record.to_param}}
|
|
381
381
|
tag_options[:data][:ie_update] = column.inplace_edit if column.inplace_edit != true
|
|
382
382
|
tag_options
|
|
@@ -407,7 +407,7 @@ module ActiveScaffold
|
|
|
407
407
|
INPLACE_EDIT_PLURAL_FORM_UI = %i[select record_select].freeze
|
|
408
408
|
def inplace_edit_data(column)
|
|
409
409
|
data = {}
|
|
410
|
-
data[:ie_url] = url_for(params_for(action: 'update_column', column: column.name, id: '__id__'))
|
|
410
|
+
data[:ie_url] = url_for(signed_url_options(params_for(action: 'update_column', column: column.name, id: '__id__')))
|
|
411
411
|
data[:ie_cancel_text] = column.options[:cancel_text] || as_(:cancel)
|
|
412
412
|
data[:ie_loading_text] = column.options[:loading_text] || as_(:loading)
|
|
413
413
|
data[:ie_save_text] = column.options[:save_text] || as_(:update)
|
|
@@ -422,7 +422,7 @@ module ActiveScaffold
|
|
|
422
422
|
elsif inplace_edit_cloning?(column)
|
|
423
423
|
data[:ie_mode] = :clone
|
|
424
424
|
elsif column.inplace_edit == :ajax
|
|
425
|
-
url = url_for(params_for(controller: params_for[:controller], action: 'render_field', id: '__id__', update_column: column.name))
|
|
425
|
+
url = url_for(signed_url_options(params_for(controller: params_for[:controller], action: 'render_field', id: '__id__', update_column: column.name)))
|
|
426
426
|
plural = column.association&.collection? && !override_form_field?(column) && INPLACE_EDIT_PLURAL_FORM_UI.include?(column.form_ui)
|
|
427
427
|
data[:ie_render_url] = url
|
|
428
428
|
data[:ie_mode] = :ajax
|
|
@@ -478,7 +478,7 @@ module ActiveScaffold
|
|
|
478
478
|
if column.name == :as_marked
|
|
479
479
|
tag_options[:data] = {
|
|
480
480
|
ie_mode: :inline_checkbox,
|
|
481
|
-
ie_url: url_for(params_for(action: 'mark', id: '__id__'))
|
|
481
|
+
ie_url: url_for(signed_url_options(params_for(action: 'mark', id: '__id__')))
|
|
482
482
|
}
|
|
483
483
|
elsif column.inplace_edit
|
|
484
484
|
tag_options[:data] = inplace_edit_data(column)
|
|
@@ -501,7 +501,7 @@ module ActiveScaffold
|
|
|
501
501
|
if !active_scaffold_config.store_user_settings && respond_to?(:search_params) && search_params.present?
|
|
502
502
|
url_options[:search] = search_params
|
|
503
503
|
end
|
|
504
|
-
link_to column_heading_label(column), url_options, options
|
|
504
|
+
link_to column_heading_label(column), signed_url_options(url_options), options
|
|
505
505
|
else
|
|
506
506
|
content_tag(:p, column_heading_label(column))
|
|
507
507
|
end
|
|
@@ -9,7 +9,7 @@ module ActiveScaffold
|
|
|
9
9
|
proc_options: {page_number: page_number, text: text},
|
|
10
10
|
**options.smart_merge(class: 'as_paginate')
|
|
11
11
|
)
|
|
12
|
-
link_to text ? as_(text) : page_number, url_options.merge(page: page_number), attributes
|
|
12
|
+
link_to text ? as_(text) : page_number, signed_url_options(url_options.merge(page: page_number)), attributes
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def pagination_url_options(url_options = nil)
|
|
@@ -53,7 +53,7 @@ module ActiveScaffold
|
|
|
53
53
|
attributes = {
|
|
54
54
|
name: "search[#{column.name}]",
|
|
55
55
|
class: "#{column.name}-input",
|
|
56
|
-
id: "search_#{column.name}",
|
|
56
|
+
id: clean_id("search_#{column.name}"),
|
|
57
57
|
value: field_search_params[column.name.to_s]
|
|
58
58
|
}
|
|
59
59
|
as_element_attributes(:search_control, proc_options: {column: column, search_ui: column.search_ui}, **attributes)
|
|
@@ -12,7 +12,7 @@ module ActiveScaffold
|
|
|
12
12
|
input_helper = override_helper_per_model(:active_scaffold_input_for_tabbed, record.class)
|
|
13
13
|
safe_join([
|
|
14
14
|
send(input_helper, column, record, subsection_id, tab_options, used_tabs.map { |v, _| v }),
|
|
15
|
-
active_scaffold_refresh_link(nil, {'data-update_url' => url_for(add_tab_url)}, record, refresh_opts),
|
|
15
|
+
active_scaffold_refresh_link(nil, {'data-update_url' => url_for(signed_url_options(add_tab_url))}, record, refresh_opts),
|
|
16
16
|
active_scaffold_tabs_for(column, record, subsection_id, tab_options, used_tabs, &)
|
|
17
17
|
])
|
|
18
18
|
end
|
|
@@ -77,7 +77,7 @@ module ActiveScaffold
|
|
|
77
77
|
options[:multipart] ||= true
|
|
78
78
|
options[:class] = "#{options[:class]} as_remote_upload".strip
|
|
79
79
|
output = []
|
|
80
|
-
output << form_tag(url_for_options, options)
|
|
80
|
+
output << form_tag(signed_url_options(url_for_options), options)
|
|
81
81
|
output << content_tag(:iframe, '', id: action_iframe_id(url_for_options), name: action_iframe_id(url_for_options), style: 'display:none')
|
|
82
82
|
safe_join output
|
|
83
83
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'concurrent/map'
|
|
4
|
+
|
|
5
|
+
module ActiveScaffold
|
|
6
|
+
module ParameterFilterWarning
|
|
7
|
+
@warned_controllers = Concurrent::Map.new
|
|
8
|
+
|
|
9
|
+
def self.warn_once(controller)
|
|
10
|
+
key = controller.name || controller
|
|
11
|
+
return unless @warned_controllers.put_if_absent(key, true).nil?
|
|
12
|
+
|
|
13
|
+
ActiveScaffold.deprecator.warn(
|
|
14
|
+
"#{controller}: conditions_from_params implicitly allows filtering on all database columns, " \
|
|
15
|
+
'including hidden or unauthorized values that can be inferred from matching records or counts. ' \
|
|
16
|
+
'In ActiveScaffold 4.5, conditions_from_params_allowed_columns will default to [], disabling ' \
|
|
17
|
+
'these filters. Configure conditions_from_params_allowed_columns or ' \
|
|
18
|
+
'conditions_from_params_excluded_columns explicitly. To retain unrestricted legacy filtering ' \
|
|
19
|
+
'without this warning, set conditions_from_params_allowed_columns = nil and ' \
|
|
20
|
+
'conditions_from_params_excluded_columns = []; this does not prevent inference of hidden values.'
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'openssl'
|
|
5
|
+
|
|
6
|
+
module ActiveScaffold
|
|
7
|
+
module ParameterSigning
|
|
8
|
+
TAB_SELECTION_PARAMETERS = %i[tabbed_by value value_type tab_signature].freeze
|
|
9
|
+
TAB_SELECTION_FIELDS = %i[id generated_id child_association scope parent_controller eid tabbed_by value value_type].freeze
|
|
10
|
+
|
|
11
|
+
def self.signature(data, purpose:)
|
|
12
|
+
key = Rails.application.key_generator.generate_key("active_scaffold/#{purpose}/v1", 32)
|
|
13
|
+
Base64.urlsafe_encode64(OpenSSL::HMAC.digest('SHA256', key, data), padding: false)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.valid_signature?(data, signature, purpose:)
|
|
17
|
+
return false unless signature.is_a?(String) && signature.bytesize == 43
|
|
18
|
+
|
|
19
|
+
ActiveSupport::SecurityUtils.secure_compare(self.signature(data, purpose: purpose), signature)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.embedded_payload(embedded, controller:)
|
|
23
|
+
embedded = embedded.to_unsafe_h if embedded.respond_to?(:to_unsafe_h)
|
|
24
|
+
# to_query normalizes values exactly as URL generation does. Loading is a
|
|
25
|
+
# one-use rendering flag, removed after the initial embedded request.
|
|
26
|
+
[controller.to_s.delete_prefix('/'), embedded.except(:loading, 'loading').to_query].to_json
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.tab_selection_payload(options, controller:)
|
|
30
|
+
fields = TAB_SELECTION_FIELDS.index_with { |key| options[key] || options[key.to_s] }
|
|
31
|
+
[controller.to_s.delete_prefix('/'), fields.to_query].to_json
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/active_scaffold.rb
CHANGED
|
@@ -14,6 +14,8 @@ module ActiveScaffold
|
|
|
14
14
|
autoload :Finder, 'active_scaffold/finder'
|
|
15
15
|
autoload :MarkedModel, 'active_scaffold/marked_model'
|
|
16
16
|
autoload :OrmChecks, 'active_scaffold/orm_checks'
|
|
17
|
+
autoload :ParameterSigning, 'active_scaffold/parameter_signing'
|
|
18
|
+
autoload :ParameterFilterWarning, 'active_scaffold/parameter_filter_warning'
|
|
17
19
|
autoload :Registry, 'active_scaffold/registry'
|
|
18
20
|
autoload :RespondsToParent, 'active_scaffold/responds_to_parent'
|
|
19
21
|
autoload :Routing, 'active_scaffold/extensions/routing_mapper'
|