active_scaffold 4.4.4 → 4.4.6

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: b212c764ce6307b7968f811cd89c2042b8cb5d1f79b448ddd838360efc8375ab
4
- data.tar.gz: 4f44ea2e0e00189d67f4027e95decea8b3589e5f3d372d1c53cd289ca70188c7
3
+ metadata.gz: 2475af8fa6929537031a900309db3ff1c3b91bcb9e911ccd61676aa06bf3009f
4
+ data.tar.gz: 0df3c5893800ffc86159e1a9c73e0b022f5b70a64afcc39e6da59266540f37ba
5
5
  SHA512:
6
- metadata.gz: 264149ca1905e0bae13b93a71a3720d9e09d3b2bae57b15a702474dfb40d2d8fad33ea04a8708991d6c983ef6c45159a5fd7133ad143cf95e3d5c74f5b830a34
7
- data.tar.gz: b8bf1c62d6fc8e9063ccb46df88709630a0ce6d1eb9edebcb3058df8e43535f7e0420a4781614bd479197f00f5cdcce423bf1298b15ddd264515701fa7c83b03
6
+ metadata.gz: e37f5f28f8bade8de9c86d69e68166a0ed7d12acde4c0e908c6c92626505b24511578cfb8394d238393659162ef7cc1dcb3916e693630a9192d03ea5acd8fa3e
7
+ data.tar.gz: 2aaae36010f59a87cf009a2ddca97c1f45f620d0493d100ff997f185d732592514acce727b1a929c2411028e6964e20de9007673f874deec8f2eb191a97cb1ae
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,74 @@
1
+ = 4.4.6
2
+ - Execute iframe responses by injecting a nonce-aware script into the parent document, avoiding +eval()+ under a strict Content Security Policy
3
+ - Use RecordSelect's named callback registry for the add-existing subform link when available, avoiding +eval()+ under a strict Content Security Policy while retaining compatibility with older RecordSelect releases.
4
+ - Add named callback registries for datepicker and TinyMCE configuration. Inline JavaScript remains supported in 4.4, but successful evaluation emits a browser deprecation warning because support will be removed in ActiveScaffold 4.5.
5
+
6
+ Define callbacks in an application JavaScript file:
7
+
8
+ ActiveScaffold.datepickerCallbacks.availableDate = function(date) {
9
+ return [date.getDay() !== 0, ''];
10
+ };
11
+ ActiveScaffold.tinymceCallbacks.configureEditor = function(editor) {
12
+ editor.on('init', function() { /* ... */ });
13
+ };
14
+
15
+ Reference their names from configuration instead of embedding function source:
16
+
17
+ config.columns[:starts_on].options[:data] = {beforeshowday: 'availableDate'}
18
+
19
+ # config/tinymce.yml
20
+ default:
21
+ setup: configureEditor
22
+
23
+ Migrate warnings before upgrading to 4.5. Non-callback datepicker settings should use JSON-compatible values.
24
+ - Add explicit HTML translations to +as_+. Move translations containing markup from +key+ to +key.html+. Interpolation follows Rails' HTML translation behavior, escaping unsafe values and preserving already HTML-safe values. Legacy HTML translations remain HTML-safe in 4.4 but emit one deprecation warning per key and scope; ordinary translations will no longer be marked HTML-safe in ActiveScaffold 4.5
25
+
26
+ = 4.4.5
27
+ - Authorize the PaperTrail deleted-records action and allow overriding its version query with +deleted_records_query+
28
+ - Deprecate passing optional boolean arguments positionally; keyword arguments will be required in 4.5.
29
+
30
+ Overrides which only forward arguments can replace anonymous +*+ with +...+. This accepts the positional argument from 4.4 and forwards the keyword argument used by 4.5:
31
+
32
+ # Before
33
+ def find_or_create_for_params(params, parent_column, parent_record, *)
34
+ super
35
+ end
36
+
37
+ # Compatible with both 4.4 and 4.5
38
+ def find_or_create_for_params(params, parent_column, parent_record, ...)
39
+ super
40
+ end
41
+
42
+ An override which reads or changes the optional argument must temporarily accept both forms. It must call +super+ explicitly with keywords; bare +super+ would forward the original positional arguments and keep producing the warning:
43
+
44
+ # Before
45
+ def update_columns_options(column, scope, options, force = false)
46
+ super(column, scope, options, true)
47
+ end
48
+
49
+ # Compatible with both 4.4 and 4.5
50
+ def update_columns_options(column, scope, options, *legacy_force, force: false, **kwargs)
51
+ force = legacy_force.first unless legacy_force.empty?
52
+ force = true
53
+ super(column, scope, options, force: force, **kwargs)
54
+ end
55
+
56
+ After requiring ActiveScaffold 4.5, the compatibility rest argument can be removed:
57
+
58
+ def update_columns_options(column, scope, options, force: false, **kwargs)
59
+ super(column, scope, options, force: true, **kwargs)
60
+ end
61
+
62
+ For methods such as +form_attribute+, where another positional argument followed the boolean, normalize both arguments before calling +super+:
63
+
64
+ def form_attribute(column, record, scope = nil, *legacy_arguments,
65
+ only_value: false, col_class: nil, **kwargs)
66
+ only_value = legacy_arguments.shift unless legacy_arguments.empty?
67
+ col_class = legacy_arguments.shift unless legacy_arguments.empty?
68
+
69
+ super(column, record, scope, only_value: only_value, col_class: col_class, **kwargs)
70
+ end
71
+
1
72
  = 4.4.4
2
73
  - Fix the inconsistent behaviour for constraints containing an array with only one value
3
74
  - Wait for dynamically loaded plugins and bridges to finish registering their ready and setup callbacks before initial setup, fixing initialization on directly rendered forms
@@ -0,0 +1,67 @@
1
+ (function(global) {
2
+ var ActiveScaffold = global.ActiveScaffold = global.ActiveScaffold || {};
3
+ var warned = {};
4
+
5
+ ActiveScaffold.datepickerCallbacks = ActiveScaffold.datepickerCallbacks || {};
6
+ ActiveScaffold.tinymceCallbacks = ActiveScaffold.tinymceCallbacks || {};
7
+
8
+ function warnOnce(key, message) {
9
+ if (warned[key]) return;
10
+
11
+ warned[key] = true;
12
+ if (global.console && typeof global.console.warn === 'function') {
13
+ global.console.warn(message);
14
+ }
15
+ }
16
+
17
+ function evaluateLegacy(value, description, wrap) {
18
+ try {
19
+ var evaluated = global.eval(wrap ? '(' + value + ')' : value);
20
+ warnOnce(description + ':' + value,
21
+ 'DEPRECATION WARNING: JavaScript in ' + description + ' is deprecated and will be removed in ActiveScaffold 4.5. ' +
22
+ 'Register callbacks by name and use JSON-compatible values instead.');
23
+ return {success: true, value: evaluated};
24
+ } catch (error) {
25
+ return {success: false};
26
+ }
27
+ }
28
+
29
+ ActiveScaffold.resolveCallback = function(registryName, value, description) {
30
+ if (typeof value === 'function' || typeof value !== 'string') return value;
31
+
32
+ var registry = ActiveScaffold[registryName] || {};
33
+ if (Object.prototype.hasOwnProperty.call(registry, value)) {
34
+ if (typeof registry[value] === 'function') return registry[value];
35
+
36
+ throw new TypeError('ActiveScaffold.' + registryName + '.' + value + ' must be a function');
37
+ }
38
+
39
+ var legacy = evaluateLegacy(value, description, true);
40
+ if (legacy.success) return legacy.value;
41
+
42
+ throw new Error(description + ' references unknown callback ' + value +
43
+ '. Register it in ActiveScaffold.' + registryName + '.');
44
+ };
45
+
46
+ var datepickerCallbackOptions = {
47
+ afterInject: true,
48
+ beforeShow: true,
49
+ beforeShowDay: true,
50
+ calculateWeek: true,
51
+ onChangeMonthYear: true,
52
+ onClose: true,
53
+ onSelect: true,
54
+ onUpdateDatepicker: true
55
+ };
56
+
57
+ ActiveScaffold.resolveDatepickerSetting = function(option, value) {
58
+ if (typeof value !== 'string') return value;
59
+
60
+ if (datepickerCallbackOptions[option]) {
61
+ return ActiveScaffold.resolveCallback('datepickerCallbacks', value, 'datepicker option ' + option);
62
+ }
63
+
64
+ var legacy = evaluateLegacy(value, 'datepicker option ' + option, false);
65
+ return legacy.success ? legacy.value : value;
66
+ };
67
+ })(window);
@@ -6,11 +6,7 @@ jQuery.extend(Object.getPrototypeOf(jQuery.datepicker), {
6
6
  if(this._defaults.hasOwnProperty(attrName)){
7
7
  var attrValue = $target.data(attrName.toLowerCase());
8
8
  if (attrValue !== undefined) {
9
- try {
10
- inlineSettings[attrName] = eval(attrValue);
11
- } catch (err) {
12
- inlineSettings[attrName] = attrValue;
13
- }
9
+ inlineSettings[attrName] = ActiveScaffold.resolveDatepickerSetting(attrName, attrValue);
14
10
  }
15
11
  }
16
12
  }
@@ -46,4 +42,4 @@ jQuery(document).on('change', 'input.datetime_picker', function(e) {
46
42
  $this.data('first-event', true);
47
43
  e.stopImmediatePropagation();
48
44
  }
49
- });
45
+ });
@@ -8,6 +8,8 @@
8
8
 
9
9
  // Load dependencies based on configuration
10
10
  const loadDependencies = async () => {
11
+ await loadScript(RAILS_ASSET_URL('/active_scaffold/callback_registry.js'));
12
+
11
13
  // Always load these
12
14
  await loadScript(RAILS_ASSET_URL('/jquery.ba-throttle-debounce.js'));
13
15
  await loadScript(RAILS_ASSET_URL('/jquery.visible.min.js'));
@@ -0,0 +1,9 @@
1
+ (function(global) {
2
+ global.RecordSelect.registerCallback('active_scaffold.add_existing', function(id) {
3
+ global.ActiveScaffold.record_select_onselect(
4
+ this.obj.attr('data-edit-associated-url'),
5
+ this.obj.attr('data-active-scaffold-id'),
6
+ id
7
+ );
8
+ });
9
+ })(window);
@@ -40,7 +40,7 @@
40
40
  var id = jQuery(this).attr('id');
41
41
  if (tinymce && tinymce.majorVersion >= 6) {
42
42
  settings.selector = '#' + id;
43
- var userSetup = settings.setup ? eval(settings.setup) : function () {};
43
+ var userSetup = settings.setup ? ActiveScaffold.resolveCallback('tinymceCallbacks', settings.setup, 'TinyMCE setup') : function () {};
44
44
  settings.setup = function(editor) {
45
45
  userSetup(editor); // run what the user already had
46
46
 
@@ -7,6 +7,7 @@ module ActiveScaffold
7
7
  autoload :JqueryUiThemeGenerator, 'active_scaffold/assets/jquery_ui_theme_generator'
8
8
 
9
9
  CORE_STYLESHEETS = ['active_scaffold/core'].freeze
10
+ CALLBACK_REGISTRY_JAVASCRIPT = 'active_scaffold/callback_registry'
10
11
  CORE_JAVASCRIPTS = ['jquery.ba-throttle-debounce', 'jquery.visible.min', 'active_scaffold/jquery.editinplace', 'active_scaffold/active_scaffold'].freeze
11
12
 
12
13
  class << self
@@ -34,17 +35,17 @@ module ActiveScaffold
34
35
  def active_scaffold_javascripts(load = :all)
35
36
  case load
36
37
  when :all
37
- jquery_ui_javascripts + CORE_JAVASCRIPTS + ActiveScaffold.javascripts + bridge_javascripts
38
+ [CALLBACK_REGISTRY_JAVASCRIPT] + jquery_ui_javascripts + CORE_JAVASCRIPTS + ActiveScaffold.javascripts + bridge_javascripts
38
39
  when :deps
39
- jquery_ui_javascripts + ActiveScaffold.javascripts + bridge_javascripts
40
+ [CALLBACK_REGISTRY_JAVASCRIPT] + jquery_ui_javascripts + ActiveScaffold.javascripts + bridge_javascripts
40
41
  when :core
41
- CORE_JAVASCRIPTS
42
+ [CALLBACK_REGISTRY_JAVASCRIPT] + CORE_JAVASCRIPTS
42
43
  when :plugins
43
44
  ActiveScaffold.javascripts
44
45
  when :bridges
45
46
  bridge_javascripts
46
47
  when :jquery_ui
47
- jquery_ui_javascripts
48
+ [CALLBACK_REGISTRY_JAVASCRIPT] + jquery_ui_javascripts
48
49
  else
49
50
  raise ArgumentError, "Unknown load mode: #{load.inspect}"
50
51
  end
@@ -57,7 +57,13 @@ module ActiveScaffold
57
57
  #
58
58
  # This is a secure way to apply params to a record, because it's based on a loop over the columns
59
59
  # set. The columns set will not yield unauthorized columns, and it will not yield unregistered columns.
60
- def update_record_from_params(parent_record, columns, attributes, avoid_changes = false, search_attributes: false)
60
+ def update_record_from_params(parent_record, columns, attributes,
61
+ positional_avoid_changes = POSITIONAL_ARGUMENT_NOT_GIVEN,
62
+ avoid_changes: POSITIONAL_ARGUMENT_NOT_GIVEN, search_attributes: false)
63
+ avoid_changes = ActiveScaffold.deprecated_positional_argument(
64
+ positional_avoid_changes, avoid_changes,
65
+ method_name: __method__, argument_name: :avoid_changes, default: false
66
+ )
61
67
  crud_type = parent_record.new_record? ? :create : :update
62
68
  return parent_record unless parent_record.authorized_for?(crud_type: crud_type)
63
69
 
@@ -91,7 +97,13 @@ module ActiveScaffold
91
97
  column.params.select { |p| attributes.key? p }.each { |p| parent_record.send(:"#{p}=", attributes[p]) }
92
98
  end
93
99
 
94
- def update_column_from_params(parent_record, column, attribute, avoid_changes = false)
100
+ def update_column_from_params(parent_record, column, attribute,
101
+ positional_avoid_changes = POSITIONAL_ARGUMENT_NOT_GIVEN,
102
+ avoid_changes: POSITIONAL_ARGUMENT_NOT_GIVEN)
103
+ avoid_changes = ActiveScaffold.deprecated_positional_argument(
104
+ positional_avoid_changes, avoid_changes,
105
+ method_name: __method__, argument_name: :avoid_changes, default: false
106
+ )
95
107
  value = column_value_from_param_value(parent_record, column, attribute, avoid_changes)
96
108
  if column.association
97
109
  update_column_association(parent_record, column, attribute, value, avoid_changes)
@@ -110,7 +122,13 @@ module ActiveScaffold
110
122
  parent_record.send(:"#{column.association.foreign_key}=", value&.id) if column.association.belongs_to?
111
123
  end
112
124
 
113
- def update_column_association(parent_record, column, attribute, value, avoid_changes = false)
125
+ def update_column_association(parent_record, column, attribute, value,
126
+ positional_avoid_changes = POSITIONAL_ARGUMENT_NOT_GIVEN,
127
+ avoid_changes: POSITIONAL_ARGUMENT_NOT_GIVEN)
128
+ avoid_changes = ActiveScaffold.deprecated_positional_argument(
129
+ positional_avoid_changes, avoid_changes,
130
+ method_name: __method__, argument_name: :avoid_changes, default: false
131
+ )
114
132
  if avoid_changes
115
133
  assign_column_association(parent_record, column, attribute, value)
116
134
  elsif column.association.collection? && column.association.through_singular?
@@ -126,7 +144,13 @@ module ActiveScaffold
126
144
  parent_record.association(column.name).target = value
127
145
  end
128
146
 
129
- def column_value_from_param_value(parent_record, column, value, avoid_changes = false)
147
+ def column_value_from_param_value(parent_record, column, value,
148
+ positional_avoid_changes = POSITIONAL_ARGUMENT_NOT_GIVEN,
149
+ avoid_changes: POSITIONAL_ARGUMENT_NOT_GIVEN)
150
+ avoid_changes = ActiveScaffold.deprecated_positional_argument(
151
+ positional_avoid_changes, avoid_changes,
152
+ method_name: __method__, argument_name: :avoid_changes, default: false
153
+ )
130
154
  # convert the value, possibly by instantiating associated objects
131
155
  form_ui = column.form_ui || column.column&.type
132
156
  if form_ui && respond_to?(:"column_value_for_#{form_ui}_type", true)
@@ -205,7 +229,13 @@ module ActiveScaffold
205
229
  end
206
230
  end
207
231
 
208
- def column_value_from_param_hash_value(parent_record, column, value, avoid_changes = false)
232
+ def column_value_from_param_hash_value(parent_record, column, value,
233
+ positional_avoid_changes = POSITIONAL_ARGUMENT_NOT_GIVEN,
234
+ avoid_changes: POSITIONAL_ARGUMENT_NOT_GIVEN)
235
+ avoid_changes = ActiveScaffold.deprecated_positional_argument(
236
+ positional_avoid_changes, avoid_changes,
237
+ method_name: __method__, argument_name: :avoid_changes, default: false
238
+ )
209
239
  if column.association&.singular?
210
240
  manage_nested_record_from_params(parent_record, column, value, avoid_changes)
211
241
  elsif column.association&.collection?
@@ -233,7 +263,13 @@ module ActiveScaffold
233
263
  columns ? subform_cfg.build_action_columns(columns) : subform_cfg.columns
234
264
  end
235
265
 
236
- def manage_nested_record_from_params(parent_record, column, attributes, avoid_changes = false)
266
+ def manage_nested_record_from_params(parent_record, column, attributes,
267
+ positional_avoid_changes = POSITIONAL_ARGUMENT_NOT_GIVEN,
268
+ avoid_changes: POSITIONAL_ARGUMENT_NOT_GIVEN)
269
+ avoid_changes = ActiveScaffold.deprecated_positional_argument(
270
+ positional_avoid_changes, avoid_changes,
271
+ method_name: __method__, argument_name: :avoid_changes, default: false
272
+ )
237
273
  return nil unless avoid_changes || build_record_from_params?(attributes, column, parent_record)
238
274
 
239
275
  record = find_or_create_for_params(attributes, column, parent_record, avoid_changes)
@@ -259,7 +295,13 @@ module ActiveScaffold
259
295
  # Attempts to create or find an instance of the klass of the association in parent_column from the
260
296
  # request parameters given. If params[primary_key] exists it will attempt to find an existing object
261
297
  # otherwise it will build a new one.
262
- def find_or_create_for_params(params, parent_column, parent_record, avoid_changes = false)
298
+ def find_or_create_for_params(params, parent_column, parent_record,
299
+ positional_avoid_changes = POSITIONAL_ARGUMENT_NOT_GIVEN,
300
+ avoid_changes: POSITIONAL_ARGUMENT_NOT_GIVEN)
301
+ avoid_changes = ActiveScaffold.deprecated_positional_argument(
302
+ positional_avoid_changes, avoid_changes,
303
+ method_name: __method__, argument_name: :avoid_changes, default: false
304
+ )
263
305
  current = parent_record.send(parent_column.name)
264
306
  klass = parent_column.association.klass(parent_record)
265
307
  if params.key? klass.primary_key
@@ -277,7 +319,13 @@ module ActiveScaffold
277
319
 
278
320
  # Attempts to find an instance of klass (which must be an ActiveRecord object) with id primary key
279
321
  # Returns record from current if it's included or find from DB
280
- def record_from_current_or_find(klass, id, current, avoid_changes = false)
322
+ def record_from_current_or_find(klass, id, current,
323
+ positional_avoid_changes = POSITIONAL_ARGUMENT_NOT_GIVEN,
324
+ avoid_changes: POSITIONAL_ARGUMENT_NOT_GIVEN)
325
+ avoid_changes = ActiveScaffold.deprecated_positional_argument(
326
+ positional_avoid_changes, avoid_changes,
327
+ method_name: __method__, argument_name: :avoid_changes, default: false
328
+ )
281
329
  record = record_from_current(current, id)
282
330
  record ||= klass.new(klass.primary_key => id) if avoid_changes
283
331
  record ||= klass.find(id)
@@ -3,6 +3,7 @@
3
3
  module ActiveScaffold::Actions
4
4
  module DeletedRecords
5
5
  def self.included(base)
6
+ base.before_action :deleted_authorized_filter, only: :deleted
6
7
  base.class_eval do
7
8
  config = active_scaffold_config
8
9
  if config.actions.include?(:nested) && config.deleted_records.nested_link_group
@@ -14,13 +15,7 @@ module ActiveScaffold::Actions
14
15
  end
15
16
 
16
17
  def deleted
17
- query = PaperTrail::Version.destroys.where(item_type: active_scaffold_config.model.name)
18
- if nested? && nested.child_association&.belongs_to? && PaperTrail::Version.respond_to?(:where_object)
19
- foreign_key = nested.child_association.foreign_key
20
- parent_id = nested.parent_id
21
- parent_id = parent_id&.to_i if self.class.active_scaffold_config.columns[foreign_key]&.number?
22
- query = query.where_object(foreign_key => parent_id)
23
- end
18
+ query = deleted_records_query
24
19
  pager = Paginator.new(query.count, active_scaffold_config.list.per_page) do |offset, per_page|
25
20
  query.offset(offset).limit(per_page).map(&:reify)
26
21
  end
@@ -29,5 +24,26 @@ module ActiveScaffold::Actions
29
24
  @records = @page.items
30
25
  respond_to_action(:list)
31
26
  end
27
+
28
+ protected
29
+
30
+ def deleted_records_query
31
+ query = PaperTrail::Version.destroys.where(item_type: active_scaffold_config.model.name)
32
+ if nested? && nested.child_association&.belongs_to? && PaperTrail::Version.respond_to?(:where_object)
33
+ foreign_key = nested.child_association.foreign_key
34
+ parent_id = nested.parent_id
35
+ parent_id = parent_id&.to_i if self.class.active_scaffold_config.columns[foreign_key]&.number?
36
+ query = query.where_object(foreign_key => parent_id)
37
+ end
38
+ query
39
+ end
40
+
41
+ def deleted_authorized?
42
+ list_authorized?
43
+ end
44
+
45
+ def deleted_authorized_filter
46
+ raise ActiveScaffold::ActionNotAllowed unless deleted_authorized?
47
+ end
32
48
  end
33
49
  end
@@ -10,6 +10,12 @@ class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Br
10
10
  end
11
11
 
12
12
  def self.javascripts
13
- 'record_select'
13
+ assets = ['record_select']
14
+ assets << 'active_scaffold/record_select_bridge' if callback_registry?
15
+ assets
16
+ end
17
+
18
+ def self.callback_registry?
19
+ defined?(::RecordSelect) && ::RecordSelect.respond_to?(:callback_registry?) && ::RecordSelect.callback_registry?
14
20
  end
15
21
  end
@@ -1,12 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/html_safe_translation'
4
+ require 'active_scaffold/translation_html_safety'
5
+
3
6
  class Object
4
7
  def as_(key, options = {})
5
8
  if key.present?
6
- scope = [:active_scaffold, *options.delete(:scope)]
7
- options = options.reverse_merge(scope: scope, default: key.is_a?(String) ? key : key.to_s.titleize)
8
- text = I18n.t(key.to_s, **options).html_safe
9
- # text = nil if text.include?('translation missing:')
9
+ options = options.merge(scope: [:active_scaffold, *options[:scope]])
10
+ options[:default] = key.is_a?(String) ? key : key.to_s.titleize unless options.key?(:default)
11
+
12
+ missing_html_translation = Object.new
13
+ html = ActiveSupport::HtmlSafeTranslation.translate(
14
+ "#{key}.html", **options, default: missing_html_translation
15
+ )
16
+ text =
17
+ if html.equal?(missing_html_translation)
18
+ translation = I18n.t(key.to_s, **options)
19
+ ActiveScaffold::TranslationHtmlSafety.check_once(key, options[:scope], translation) if translation.is_a?(String)
20
+ translation.html_safe # rubocop:disable Rails/OutputSafety
21
+ else
22
+ html
23
+ end
10
24
  end
11
25
  text || key
12
26
  end
@@ -4,7 +4,13 @@ module ActiveScaffold
4
4
  module Helpers
5
5
  module AssociationHelpers
6
6
  # Cache the options for select
7
- def cache_association_options(association, conditions, klass, cache = true)
7
+ def cache_association_options(association, conditions, klass,
8
+ positional_cache = POSITIONAL_ARGUMENT_NOT_GIVEN,
9
+ cache: POSITIONAL_ARGUMENT_NOT_GIVEN)
10
+ cache = ActiveScaffold.deprecated_positional_argument(
11
+ positional_cache, cache,
12
+ method_name: __method__, argument_name: :cache, default: true
13
+ )
8
14
  if active_scaffold_config.cache_association_options && cache
9
15
  @_associations_cache ||= Hash.new { |h, k| h[k] = {} }
10
16
  key = [association.name, association.inverse_klass.name, klass.respond_to?(:cache_key) ? klass.cache_key : klass.name].join('/')
@@ -122,7 +128,22 @@ module ActiveScaffold
122
128
  end
123
129
 
124
130
  def record_select_params_for_add_existing(association, edit_associated_url_options, record)
125
- {onselect: "ActiveScaffold.record_select_onselect(#{url_for(edit_associated_url_options).to_json}, #{active_scaffold_id.to_json}, id);"}
131
+ if ActiveScaffold::Bridges::RecordSelect.callback_registry?
132
+ {
133
+ onselect: 'active_scaffold.add_existing',
134
+ html: {
135
+ data: {
136
+ edit_associated_url: url_for(edit_associated_url_options),
137
+ active_scaffold_id: active_scaffold_id
138
+ }
139
+ }
140
+ }
141
+ else
142
+ {
143
+ onselect: "ActiveScaffold.record_select_onselect(#{url_for(edit_associated_url_options).to_json}, " \
144
+ "#{active_scaffold_id.to_json}, id);"
145
+ }
146
+ end
126
147
  end
127
148
  end
128
149
  end
@@ -52,7 +52,20 @@ module ActiveScaffold
52
52
  handle_exception_on_column(e, column, record)
53
53
  end
54
54
 
55
- def active_scaffold_render_subform_column(column, scope, crud_type, readonly, add_class = false, record = nil, form_columns: nil) # rubocop:disable Metrics/ParameterLists
55
+ def active_scaffold_render_subform_column(column, scope, crud_type, readonly, *positional_arguments,
56
+ add_class: POSITIONAL_ARGUMENT_NOT_GIVEN,
57
+ record: POSITIONAL_ARGUMENT_NOT_GIVEN, form_columns: nil)
58
+ raise ArgumentError, 'too many positional arguments' if positional_arguments.size > 2
59
+
60
+ positional_add_class = positional_arguments.fetch(0, POSITIONAL_ARGUMENT_NOT_GIVEN)
61
+ positional_record = positional_arguments.fetch(1, POSITIONAL_ARGUMENT_NOT_GIVEN)
62
+ add_class = ActiveScaffold.deprecated_positional_argument(
63
+ positional_add_class, add_class,
64
+ method_name: __method__, argument_name: :add_class, default: false
65
+ )
66
+ record = ActiveScaffold.positional_or_keyword_argument(
67
+ positional_record, record, argument_name: :record, default: nil
68
+ )
56
69
  if add_class
57
70
  col_class = []
58
71
  col_class << 'required' if column.required?(action_for_validation(record))
@@ -156,7 +169,13 @@ module ActiveScaffold
156
169
  url_params
157
170
  end
158
171
 
159
- def update_columns_options(column, scope, options, force = false, form_columns: nil, url_params: {})
172
+ def update_columns_options(column, scope, options,
173
+ positional_force = POSITIONAL_ARGUMENT_NOT_GIVEN,
174
+ force: POSITIONAL_ARGUMENT_NOT_GIVEN, form_columns: nil, url_params: {})
175
+ force = ActiveScaffold.deprecated_positional_argument(
176
+ positional_force, force,
177
+ method_name: __method__, argument_name: :force, default: false
178
+ )
160
179
  record = options[:object]
161
180
  subform_controller = controller.class.active_scaffold_controller_for(record.class) if scope
162
181
  form_columns ||= current_form_columns(record, scope, subform_controller)
@@ -249,7 +268,20 @@ module ActiveScaffold
249
268
  as_element(:form_field_description, h(desc) + as_element(:form_field_description_close)) if desc.present?
250
269
  end
251
270
 
252
- def form_attribute(column, record, scope = nil, only_value = false, col_class = nil, form_columns: nil, field: nil)
271
+ def form_attribute(column, record, scope = nil, *positional_arguments,
272
+ only_value: POSITIONAL_ARGUMENT_NOT_GIVEN,
273
+ col_class: POSITIONAL_ARGUMENT_NOT_GIVEN, form_columns: nil, field: nil)
274
+ raise ArgumentError, 'too many positional arguments' if positional_arguments.size > 2
275
+
276
+ positional_only_value = positional_arguments.fetch(0, POSITIONAL_ARGUMENT_NOT_GIVEN)
277
+ positional_col_class = positional_arguments.fetch(1, POSITIONAL_ARGUMENT_NOT_GIVEN)
278
+ only_value = ActiveScaffold.deprecated_positional_argument(
279
+ positional_only_value, only_value,
280
+ method_name: __method__, argument_name: :only_value, default: false
281
+ )
282
+ col_class = ActiveScaffold.positional_or_keyword_argument(
283
+ positional_col_class, col_class, argument_name: :col_class, default: nil
284
+ )
253
285
  column_options = active_scaffold_input_options(column, scope, object: record)
254
286
  collapsible_id = column_options.delete :collapsible_id
255
287
  attributes = field_attributes(column, record)
@@ -293,14 +325,26 @@ module ActiveScaffold
293
325
  column.label unless hidden
294
326
  end
295
327
 
296
- def form_hidden_attribute(column, record, scope = nil, clear = false)
328
+ def form_hidden_attribute(column, record, scope = nil,
329
+ positional_clear = POSITIONAL_ARGUMENT_NOT_GIVEN,
330
+ clear: POSITIONAL_ARGUMENT_NOT_GIVEN)
331
+ clear = ActiveScaffold.deprecated_positional_argument(
332
+ positional_clear, clear,
333
+ method_name: __method__, argument_name: :clear, default: false
334
+ )
297
335
  content_tag :dl, style: 'display: none' do
298
336
  content_tag(:dt, '') <<
299
337
  content_tag(:dd, form_hidden_field(column, record, scope, clear))
300
338
  end
301
339
  end
302
340
 
303
- def form_hidden_field(column, record, scope, clear = false)
341
+ def form_hidden_field(column, record, scope,
342
+ positional_clear = POSITIONAL_ARGUMENT_NOT_GIVEN,
343
+ clear: POSITIONAL_ARGUMENT_NOT_GIVEN)
344
+ clear = ActiveScaffold.deprecated_positional_argument(
345
+ positional_clear, clear,
346
+ method_name: __method__, argument_name: :clear, default: false
347
+ )
304
348
  options = active_scaffold_input_options(column, scope)
305
349
  value = record.send(column.name) unless clear
306
350
  if column.association&.collection?
@@ -57,7 +57,12 @@ module ActiveScaffold
57
57
 
58
58
  # This is the template finder logic, keep it updated with however we find stuff in rails
59
59
  # currently this very similar to the logic in ActionBase::Base.render for options file
60
- def template_exists?(template_name, partial = false)
60
+ def template_exists?(template_name, positional_partial = POSITIONAL_ARGUMENT_NOT_GIVEN,
61
+ partial: POSITIONAL_ARGUMENT_NOT_GIVEN)
62
+ partial = ActiveScaffold.deprecated_positional_argument(
63
+ positional_partial, partial,
64
+ method_name: __method__, argument_name: :partial, default: false
65
+ )
61
66
  if @_view_paths
62
67
  restore_view_paths = lookup_context.view_paths
63
68
  lookup_context.view_paths = @_view_paths
@@ -19,16 +19,10 @@ module ActiveScaffold
19
19
  end
20
20
  response.status = 200 if (300...400).cover? response.status
21
21
 
22
- # Eval in parent scope and replace document location of this frame
23
- # so back button doesn't replay action on targeted forms
24
- # loc = document.location to be set after parent is updated for IE
25
- # with(window.parent) - pull in variables from parent window
26
- # setTimeout - scope the execution in the windows parent for safari
27
- # window.eval - legal eval for Opera
28
- script = "<html><body><script type='text/javascript' charset='utf-8'>
29
- var loc = document.location;
30
- with(window.parent) { setTimeout(function() { window.eval('#{self.class.helpers.escape_javascript script}'); window.loc && loc.replace('about:blank'); }, 1) }
31
- </script></body></html>"
22
+ # Inject the response into the parent document so it executes in the parent scope.
23
+ # Reuse its CSP nonce when one is available, then replace the frame location so the
24
+ # back button doesn't replay the action on targeted forms.
25
+ script = responds_to_parent_html(script)
32
26
 
33
27
  # Clear out the previous render to prevent double render and then render
34
28
  if respond_to?(:erase_results, true)
@@ -41,5 +35,24 @@ module ActiveScaffold
41
35
  render html: script.html_safe, content_type: 'text/html' # rubocop:disable Rails/OutputSafety
42
36
  end
43
37
  alias respond_to_parent responds_to_parent
38
+
39
+ private
40
+
41
+ def responds_to_parent_html(response_javascript)
42
+ escaped_response = self.class.helpers.escape_javascript(response_javascript)
43
+ "<html><body><script type='text/javascript' charset='utf-8'>
44
+ var loc = document.location;
45
+ var responseJavaScript = '#{escaped_response}';
46
+ var parentDocument = window.parent.document;
47
+ var script = parentDocument.createElement('script');
48
+ var nonceSource = parentDocument.querySelector('script[nonce]');
49
+
50
+ if (nonceSource) script.nonce = nonceSource.nonce;
51
+ script.text = responseJavaScript;
52
+ parentDocument.head.appendChild(script);
53
+ script.remove();
54
+ loc.replace('about:blank');
55
+ </script></body></html>"
56
+ end
44
57
  end
45
58
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'concurrent/map'
4
+
5
+ module ActiveScaffold
6
+ module TranslationHtmlSafety
7
+ HTML_PATTERN = /<[^>]+>|&(?:[a-z][a-z0-9]+|#\d+|#x[0-9a-f]+);/i
8
+
9
+ @checked_translations = Concurrent::Map.new
10
+
11
+ class << self
12
+ def check_once(key, scope, translation)
13
+ translation_key_parts = [*scope, key].freeze
14
+ return unless @checked_translations.put_if_absent(translation_key_parts, true).nil?
15
+ return unless translation.match?(HTML_PATTERN)
16
+
17
+ translation_key = translation_key_parts.join('.')
18
+ ActiveScaffold.deprecator.warn(
19
+ "HTML in translation #{translation_key} is deprecated. Move it to #{translation_key}.html. " \
20
+ 'Ordinary translations will no longer be marked HTML-safe in ActiveScaffold 4.5.'
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
@@ -4,7 +4,7 @@ module ActiveScaffold
4
4
  module Version
5
5
  MAJOR = 4
6
6
  MINOR = 4
7
- PATCH = 4
7
+ PATCH = 6
8
8
  FIX = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, FIX].compact.join('.')
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveScaffold
4
+ POSITIONAL_ARGUMENT_NOT_GIVEN = Object.new.freeze
5
+
4
6
  autoload :ActiveRecordPermissions, 'active_scaffold/active_record_permissions'
5
7
  autoload :Assets, 'active_scaffold/assets'
6
8
  autoload :AttributeParams, 'active_scaffold/attribute_params'
@@ -260,7 +262,33 @@ module ActiveScaffold
260
262
  end
261
263
 
262
264
  def self.deprecator
263
- @deprecator ||= ActiveSupport::Deprecation.new('4.3', 'ActiveScaffold')
265
+ @deprecator ||= ActiveSupport::Deprecation.new('4.5', 'ActiveScaffold')
266
+ end
267
+
268
+ def self.deprecated_positional_argument(positional, keyword, method_name:, argument_name:, default:)
269
+ if positional.equal?(POSITIONAL_ARGUMENT_NOT_GIVEN)
270
+ keyword.equal?(POSITIONAL_ARGUMENT_NOT_GIVEN) ? default : keyword
271
+ elsif keyword.equal?(POSITIONAL_ARGUMENT_NOT_GIVEN)
272
+ deprecator.warn(
273
+ "Passing `#{argument_name}` positionally to `#{method_name}` is deprecated; " \
274
+ "use `#{argument_name}:` instead. Positional support will be removed in ActiveScaffold 4.5. " \
275
+ 'Overrides must accept both forms during 4.4 and pass the argument to `super` as a keyword. ' \
276
+ 'See https://github.com/activescaffold/active_scaffold/blob/4-4-stable/CHANGELOG.rdoc'
277
+ )
278
+ positional
279
+ else
280
+ raise ArgumentError, "#{argument_name} was given both positionally and as a keyword"
281
+ end
282
+ end
283
+
284
+ def self.positional_or_keyword_argument(positional, keyword, argument_name:, default:)
285
+ if positional.equal?(POSITIONAL_ARGUMENT_NOT_GIVEN)
286
+ keyword.equal?(POSITIONAL_ARGUMENT_NOT_GIVEN) ? default : keyword
287
+ elsif keyword.equal?(POSITIONAL_ARGUMENT_NOT_GIVEN)
288
+ positional
289
+ else
290
+ raise ArgumentError, "#{argument_name} was given both positionally and as a keyword"
291
+ end
264
292
  end
265
293
 
266
294
  def self.log_exception(exception, message)
@@ -176,11 +176,7 @@
176
176
  if (this._defaults.hasOwnProperty(attrName)) {
177
177
  var attrValue = $input.data(attrName.toLowerCase());
178
178
  if (attrValue !== undefined) {
179
- try {
180
- inlineSettings[attrName] = eval(attrValue);
181
- } catch (err) {
182
- inlineSettings[attrName] = attrValue;
183
- }
179
+ inlineSettings[attrName] = ActiveScaffold.resolveDatepickerSetting(attrName, attrValue);
184
180
  }
185
181
  }
186
182
  }
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.4
4
+ version: 4.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
@@ -110,10 +110,12 @@ files:
110
110
  - app/assets/javascripts/active_scaffold.js.erb
111
111
  - app/assets/javascripts/active_scaffold/active_scaffold.js
112
112
  - app/assets/javascripts/active_scaffold/active_scaffold_chosen.js
113
+ - app/assets/javascripts/active_scaffold/callback_registry.js
113
114
  - app/assets/javascripts/active_scaffold/date_picker_bridge.js
114
115
  - app/assets/javascripts/active_scaffold/draggable_lists.js
115
116
  - app/assets/javascripts/active_scaffold/jquery.editinplace.js
116
117
  - app/assets/javascripts/active_scaffold/load.js
118
+ - app/assets/javascripts/active_scaffold/record_select_bridge.js
117
119
  - app/assets/javascripts/active_scaffold/tiny_mce_bridge.js
118
120
  - app/assets/stylesheets/active_scaffold-ie.scss
119
121
  - app/assets/stylesheets/active_scaffold.scss.erb
@@ -360,6 +362,7 @@ files:
360
362
  - lib/active_scaffold/responds_to_parent.rb
361
363
  - lib/active_scaffold/tableless.rb
362
364
  - lib/active_scaffold/testing/assert_embedded_load.rb
365
+ - lib/active_scaffold/translation_html_safety.rb
363
366
  - lib/active_scaffold/version.rb
364
367
  - lib/generators/active_scaffold/controller/USAGE
365
368
  - lib/generators/active_scaffold/controller/controller_generator.rb