active_scaffold 4.4.6 → 4.4.8

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +16 -0
  3. data/README.md +101 -0
  4. data/app/views/active_scaffold_overrides/_add_existing_form.html.erb +2 -2
  5. data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -1
  6. data/app/views/active_scaffold_overrides/_field_search.html.erb +1 -0
  7. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +13 -11
  8. data/app/views/active_scaffold_overrides/_list.html.erb +1 -1
  9. data/app/views/active_scaffold_overrides/_new_record.js.erb +3 -3
  10. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +1 -1
  11. data/app/views/active_scaffold_overrides/_search.html.erb +1 -0
  12. data/app/views/active_scaffold_overrides/_show.html.erb +1 -1
  13. data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
  14. data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
  15. data/app/views/active_scaffold_overrides/destroy.js.erb +5 -5
  16. data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
  17. data/lib/active_scaffold/actions/core.rb +182 -14
  18. data/lib/active_scaffold/actions/field_search.rb +8 -1
  19. data/lib/active_scaffold/actions/nested.rb +5 -3
  20. data/lib/active_scaffold/actions/subform.rb +56 -9
  21. data/lib/active_scaffold/actions/update.rb +2 -2
  22. data/lib/active_scaffold/api_association_serializer.rb +27 -0
  23. data/lib/active_scaffold/config/core.rb +25 -0
  24. data/lib/active_scaffold/extensions/action_view_rendering.rb +4 -9
  25. data/lib/active_scaffold/finder.rb +12 -4
  26. data/lib/active_scaffold/helpers/action_link_helpers.rb +18 -6
  27. data/lib/active_scaffold/helpers/association_helpers.rb +1 -0
  28. data/lib/active_scaffold/helpers/controller_helpers.rb +63 -1
  29. data/lib/active_scaffold/helpers/form_column_helpers.rb +1 -1
  30. data/lib/active_scaffold/helpers/form_ui_helpers.rb +1 -0
  31. data/lib/active_scaffold/helpers/list_column_helpers.rb +4 -4
  32. data/lib/active_scaffold/helpers/pagination_helpers.rb +1 -1
  33. data/lib/active_scaffold/helpers/tabs_helpers.rb +1 -1
  34. data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
  35. data/lib/active_scaffold/parameter_signing.rb +34 -0
  36. data/lib/active_scaffold/version.rb +1 -1
  37. data/lib/active_scaffold.rb +1 -0
  38. metadata +3 -1
@@ -197,11 +197,11 @@ module ActiveScaffold::Actions::Nested
197
197
  end
198
198
 
199
199
  def add_existing_respond_to_xml
200
- render xml: response_object, only: active_scaffold_config.list.columns.visible_columns_names, status: response_status
200
+ response_to_api(:xml, active_scaffold_config.list.columns.visible_columns_names)
201
201
  end
202
202
 
203
203
  def add_existing_respond_to_json
204
- render json: response_object, only: active_scaffold_config.list.columns.visible_columns_names, status: response_status
204
+ response_to_api(:json, active_scaffold_config.list.columns.visible_columns_names)
205
205
  end
206
206
 
207
207
  def destroy_existing_respond_to_html
@@ -251,7 +251,9 @@ module ActiveScaffold::Actions::Nested
251
251
  # The actual "add_existing" algorithm
252
252
  def do_add_existing
253
253
  parent_record = nested_parent_record(:update)
254
- @record = active_scaffold_config.model.find(params[:associated_id])
254
+ column = nested.parent_scaffold.active_scaffold_config.columns[nested.association.name]
255
+ scope = associated_record_scope(active_scaffold_config.model, column: column)
256
+ @record = find_if_allowed(params[:associated_id], :read, scope)
255
257
  return false unless parent_record && @record
256
258
 
257
259
  association = parent_record.send(nested.association.name)
@@ -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) do |blank_record|
30
- if params[:tabbed_by] && params[:value]
31
- @tab_id = params.delete(:value)
32
- assign_tabbed_by(blank_record, @column, params.delete(:tabbed_by), @tab_id, params.delete(:value_type))
33
- end
34
- end
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 = value_type&.constantize || association.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
- record.send :"#{tabbed_by}=", klass&.find(value) || value
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.find(params[:associated_id]).tap do |record|
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
- column = params.delete(:column)
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
+ # columns excluded from parameter filtering, even when explicitly allowed
59
+ cattr_accessor :conditions_from_params_excluded_columns, instance_accessor: false
60
+ @@conditions_from_params_excluded_columns = []
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.send(value['unit'].downcase.singularize.to_sym))
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.send(value['unit'].downcase.singularize.to_sym))
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.send(value['unit'].downcase.singularize.to_sym))
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.send(value['unit'].downcase.singularize.to_sym))
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
- nested_params = !link.nested_link? && non_nested_query_string
306
- if query_string || nested_params
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 << query_string if query_string
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}"
@@ -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|
@@ -80,6 +140,7 @@ module ActiveScaffold
80
140
  url_options[:sort_direction] ||= direction
81
141
  end
82
142
  end
143
+ url_options.delete(:return_to_signature) unless url_options[:return_to]
83
144
  url_options
84
145
  end
85
146
 
@@ -103,6 +164,7 @@ module ActiveScaffold
103
164
 
104
165
  # Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page)
105
166
  def main_path_to_return
167
+ verify_return_to_parameter
106
168
  if params[:return_to]
107
169
  params[:return_to]
108
170
  else
@@ -185,7 +185,7 @@ module ActiveScaffold
185
185
  if force || (form_columns && update_columns&.intersect?(form_columns))
186
186
  url_params = url_options_for_render_field(column, record, scope, subform_controller, url_params)
187
187
  options[:class] = "#{options[:class]} update_form".strip
188
- options['data-update_url'] = url_for(url_params)
188
+ options['data-update_url'] = url_for(signed_url_options(url_params))
189
189
  options['data-update_send_form'] = column.update_columns&.any?(Hash) || column.send_form_on_update_column
190
190
  options['data-update_send_form_selector'] = column.options[:send_form_selector] if column.options[:send_form_selector]
191
191
  options['data-skip-disable-form'] = !column.disable_on_update_column
@@ -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
 
@@ -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)
@@ -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,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
@@ -4,7 +4,7 @@ module ActiveScaffold
4
4
  module Version
5
5
  MAJOR = 4
6
6
  MINOR = 4
7
- PATCH = 6
7
+ PATCH = 8
8
8
  FIX = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, FIX].compact.join('.')
@@ -14,6 +14,7 @@ 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'
17
18
  autoload :Registry, 'active_scaffold/registry'
18
19
  autoload :RespondsToParent, 'active_scaffold/responds_to_parent'
19
20
  autoload :Routing, 'active_scaffold/extensions/routing_mapper'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.6
4
+ version: 4.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
@@ -223,6 +223,7 @@ files:
223
223
  - lib/active_scaffold/actions/subform.rb
224
224
  - lib/active_scaffold/actions/update.rb
225
225
  - lib/active_scaffold/active_record_permissions.rb
226
+ - lib/active_scaffold/api_association_serializer.rb
226
227
  - lib/active_scaffold/assets.rb
227
228
  - lib/active_scaffold/assets/css_deps_generator.rb
228
229
  - lib/active_scaffold/assets/jquery_ui_manifest.rb
@@ -357,6 +358,7 @@ files:
357
358
  - lib/active_scaffold/marked_model.rb
358
359
  - lib/active_scaffold/orm_checks.rb
359
360
  - lib/active_scaffold/paginator.rb
361
+ - lib/active_scaffold/parameter_signing.rb
360
362
  - lib/active_scaffold/railties/tasks.rake
361
363
  - lib/active_scaffold/registry.rb
362
364
  - lib/active_scaffold/responds_to_parent.rb