active_scaffold 3.7.6 → 3.7.7
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 +8 -0
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +1 -1
- data/lib/active_scaffold/actions/core.rb +14 -2
- data/lib/active_scaffold/actions/field_search.rb +1 -1
- data/lib/active_scaffold/actions/update.rb +7 -5
- data/lib/active_scaffold/core.rb +2 -2
- data/lib/active_scaffold/data_structures/action_link.rb +9 -2
- data/lib/active_scaffold/data_structures/action_links.rb +9 -2
- data/lib/active_scaffold/data_structures/column.rb +16 -8
- data/lib/active_scaffold/helpers/action_link_helpers.rb +6 -6
- data/lib/active_scaffold/helpers/association_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/controller_helpers.rb +1 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
- data/lib/active_scaffold/orm_checks.rb +2 -2
- data/lib/active_scaffold/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5777dd56be3d144f2c62d8b2fa3cf8a0e765155d3afd445b5d150ce25c203155
|
4
|
+
data.tar.gz: 2c2ef1fbe12d539b84d81d48d1a2d373f3634a864664d61ab27099c783f404c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e13283f6ae89cf8618e070ee0e6afa87a47389eaee7043a669ab771f82c6aec2dbbdf2317c57ca6872785622e601d0d1278140e53cf24ca5245a88f9353dfe97
|
7
|
+
data.tar.gz: ea569709001c16bae097715c62fe9a9717597c288b2504d2c930e55aa01b28e77b53c29583d3e0462c86f329aebae8c8a82d73c832b14332a8999ee777d42e3c
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
= 3.7.7
|
2
|
+
- Fix usage with mongoid, broken on 3.7.5
|
3
|
+
- Support proc or lambda in label of action links
|
4
|
+
- Set successful to false when update_column is not authorized for the column
|
5
|
+
- Use action link's label for flash message when custom action is not authorized
|
6
|
+
- Add default_value to columns, so default_value can be defined in AS config, overriding DB default
|
7
|
+
- Fix caching query from association_klass_scoped in subforms, when returns different queries for the same association on different rows
|
8
|
+
|
1
9
|
= 3.7.6
|
2
10
|
- Respect :label_method set in form_ui_options on list.
|
3
11
|
- Fix grouped search for PostgreSQL
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<h4><%= link.confirm(h(record&.to_label)) -%></h4>
|
5
5
|
|
6
6
|
<p class="form-footer">
|
7
|
-
<%= submit_tag as_(link.label), :class => 'submit' %>
|
7
|
+
<%= submit_tag as_(link.label(record)), :class => 'submit' %>
|
8
8
|
<%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %>
|
9
9
|
</p>
|
10
10
|
|
@@ -294,7 +294,7 @@ module ActiveScaffold::Actions
|
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
|
-
def
|
297
|
+
def empty_model
|
298
298
|
relation = beginning_of_chain
|
299
299
|
if nested? && nested.plural_association? && nested.match_model?(active_scaffold_config.model)
|
300
300
|
build_options = sti_nested_build_options(relation.klass)
|
@@ -302,6 +302,18 @@ module ActiveScaffold::Actions
|
|
302
302
|
relation.respond_to?(:build) ? relation.build(build_options || {}) : relation.new
|
303
303
|
end
|
304
304
|
|
305
|
+
def new_model
|
306
|
+
empty_model.tap do |record|
|
307
|
+
assign_default_attributes record
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
def assign_default_attributes(record)
|
312
|
+
active_scaffold_config.columns.each do |column|
|
313
|
+
record.write_attribute column.name, column.default_value if column.default_value?
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
305
317
|
def sti_nested_build_options(klass)
|
306
318
|
config = active_scaffold_config_for(klass)
|
307
319
|
return unless config
|
@@ -391,7 +403,7 @@ module ActiveScaffold::Actions
|
|
391
403
|
get_row(crud_type_or_security_options)
|
392
404
|
if @record.nil?
|
393
405
|
self.successful = false
|
394
|
-
flash[:error] = as_(:no_authorization_for_action, :action => action_name)
|
406
|
+
flash[:error] = as_(:no_authorization_for_action, :action => @action_link&.label(nil) || action_name)
|
395
407
|
else
|
396
408
|
yield @record
|
397
409
|
end
|
@@ -12,7 +12,7 @@ module ActiveScaffold::Actions
|
|
12
12
|
# FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations.
|
13
13
|
# This facilitates for example, textual searches against associations via .search_sql
|
14
14
|
def show_search
|
15
|
-
@record =
|
15
|
+
@record = empty_model
|
16
16
|
super
|
17
17
|
end
|
18
18
|
|
@@ -150,9 +150,8 @@ module ActiveScaffold::Actions
|
|
150
150
|
params.delete(:original_html)
|
151
151
|
params.delete(:original_value)
|
152
152
|
@column = active_scaffold_config.columns[column]
|
153
|
-
value_record = record_for_update_column
|
154
|
-
return unless value_record
|
155
153
|
|
154
|
+
value_record = record_for_update_column
|
156
155
|
value = value_for_update_column(value, @column, value_record)
|
157
156
|
value_record.send("#{@column.name}=", value)
|
158
157
|
before_update_save(@record)
|
@@ -168,16 +167,19 @@ module ActiveScaffold::Actions
|
|
168
167
|
end
|
169
168
|
end
|
170
169
|
after_update_save(@record)
|
170
|
+
rescue ActiveScaffold::ActionNotAllowed
|
171
|
+
self.successful = false
|
171
172
|
end
|
172
173
|
|
173
174
|
def record_for_update_column
|
174
175
|
@record = find_if_allowed(params[:id], :read)
|
175
|
-
|
176
|
+
raise ActiveScaffold::ActionNotAllowed unless @record.authorized_for?(:crud_type => :update, :column => @column.name)
|
176
177
|
|
177
178
|
if @column.delegated_association
|
178
179
|
value_record = @record.send(@column.delegated_association.name)
|
179
180
|
value_record ||= @record.association(@column.delegated_association.name).build
|
180
|
-
|
181
|
+
raise ActiveScaffold::ActionNotAllowed unless value_record.authorized_for?(:crud_type => :update, :column => @column.name)
|
182
|
+
value_record
|
181
183
|
else
|
182
184
|
@record
|
183
185
|
end
|
@@ -185,7 +187,7 @@ module ActiveScaffold::Actions
|
|
185
187
|
|
186
188
|
def value_for_update_column(param_value, column, record)
|
187
189
|
unless param_value
|
188
|
-
param_value =
|
190
|
+
param_value = column.default_for_empty_value
|
189
191
|
param_value = false if param_value == true
|
190
192
|
end
|
191
193
|
value = column_value_from_param_value(record, column, param_value)
|
data/lib/active_scaffold/core.rb
CHANGED
@@ -267,12 +267,12 @@ module ActiveScaffold
|
|
267
267
|
end
|
268
268
|
|
269
269
|
def self.mongoid_column_type_cast(value, column)
|
270
|
-
return Time.zone.at(value.to_i) if
|
270
|
+
return Time.zone.at(value.to_i) if [Time, DateTime].include?(column.type) && value =~ /\A\d+\z/
|
271
271
|
column.type.evolve value
|
272
272
|
end
|
273
273
|
|
274
274
|
def self.active_record_column_type_cast(value, column_or_type)
|
275
|
-
return Time.zone.at(value.to_i) if
|
275
|
+
return Time.zone.at(value.to_i) if %i[time datetime].include?(column_or_type.type) && value =~ /\A\d+\z/
|
276
276
|
cast_type = column_or_type.is_a?(ActiveRecord::ConnectionAdapters::Column) ? ActiveRecord::Type.lookup(column_or_type.type) : column_or_type
|
277
277
|
cast_type ? cast_type.cast(value) : value
|
278
278
|
end
|
@@ -77,8 +77,15 @@ module ActiveScaffold::DataStructures
|
|
77
77
|
|
78
78
|
# what string to use to represent this action
|
79
79
|
attr_writer :label
|
80
|
-
def label
|
81
|
-
|
80
|
+
def label(record = nil)
|
81
|
+
case @label
|
82
|
+
when Symbol
|
83
|
+
ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) }
|
84
|
+
when Proc
|
85
|
+
@label.call(record)
|
86
|
+
else
|
87
|
+
@label
|
88
|
+
end
|
82
89
|
end
|
83
90
|
|
84
91
|
# image to use {:name => 'arrow.png', :size => '16x16'}
|
@@ -139,8 +139,15 @@ module ActiveScaffold::DataStructures
|
|
139
139
|
end
|
140
140
|
|
141
141
|
attr_writer :label
|
142
|
-
def label
|
143
|
-
|
142
|
+
def label(record)
|
143
|
+
case @label
|
144
|
+
when Symbol
|
145
|
+
ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) }
|
146
|
+
when Proc
|
147
|
+
@label.call(record)
|
148
|
+
else
|
149
|
+
@label
|
150
|
+
end
|
144
151
|
end
|
145
152
|
|
146
153
|
def method_missing(name, *args, &block)
|
@@ -37,6 +37,19 @@ module ActiveScaffold::DataStructures
|
|
37
37
|
@params ||= NO_PARAMS.dup
|
38
38
|
end
|
39
39
|
|
40
|
+
def default_value
|
41
|
+
@default_value || @db_default_value
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_value=(value)
|
45
|
+
raise ArgumentError, "Can't set default value for non-DB columns (virtual columns or associations)" unless column
|
46
|
+
@default_value = value
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_value?
|
50
|
+
defined? @default_value
|
51
|
+
end
|
52
|
+
|
40
53
|
# the display-name of the column. this will be used, for instance, as the column title in the table and as the field name in the form.
|
41
54
|
# if left alone it will utilize human_attribute_name which includes localization
|
42
55
|
attr_writer :label
|
@@ -377,6 +390,7 @@ module ActiveScaffold::DataStructures
|
|
377
390
|
if @column.nil? && active_record? && active_record_class._default_attributes.key?(name.to_s)
|
378
391
|
@column = active_record_class._default_attributes[name.to_s]
|
379
392
|
end
|
393
|
+
@db_default_value = ActiveScaffold::OrmChecks.default_value active_record_class, name if @column
|
380
394
|
@delegated_association = delegated_association
|
381
395
|
@cache_key = [@active_record_class.name, name].compact.map(&:to_s).join('#')
|
382
396
|
setup_association_info
|
@@ -455,10 +469,8 @@ module ActiveScaffold::DataStructures
|
|
455
469
|
return nil unless column
|
456
470
|
if column.is_a?(ActiveModel::Attribute)
|
457
471
|
column.value
|
458
|
-
|
459
|
-
|
460
|
-
elsif mongoid?
|
461
|
-
column.default_val
|
472
|
+
else
|
473
|
+
default_value
|
462
474
|
end
|
463
475
|
end
|
464
476
|
|
@@ -487,10 +499,6 @@ module ActiveScaffold::DataStructures
|
|
487
499
|
ActiveScaffold::OrmChecks.column_type active_record_class, name
|
488
500
|
end
|
489
501
|
|
490
|
-
def default_value
|
491
|
-
ActiveScaffold::OrmChecks.column_type active_record_class, name
|
492
|
-
end
|
493
|
-
|
494
502
|
def attributes=(opts)
|
495
503
|
opts.each do |setting, value|
|
496
504
|
send "#{setting}=", value
|
@@ -68,7 +68,7 @@ module ActiveScaffold
|
|
68
68
|
group_tag = :li
|
69
69
|
end
|
70
70
|
content = content_tag(group_tag, :class => html_classes.presence, :onclick => ('' if hover_via_click?)) do
|
71
|
-
content_tag(:div, as_(link.label), :class => link.name.to_s.downcase) << content_tag(:ul, content)
|
71
|
+
content_tag(:div, as_(link.label(record)), :class => link.name.to_s.downcase) << content_tag(:ul, content)
|
72
72
|
end
|
73
73
|
else
|
74
74
|
content = render_action_link(link, record, options)
|
@@ -86,7 +86,7 @@ module ActiveScaffold
|
|
86
86
|
end
|
87
87
|
if link.action.nil? || (link.type == :member && options.key?(:authorized) && !options[:authorized])
|
88
88
|
html_class = "disabled #{link.action}#{" #{link.html_options[:class]}" if link.html_options[:class].present?}"
|
89
|
-
html_options = {:link => action_link_text(link, options), :class => html_class, :title => options[:not_authorized_reason]}
|
89
|
+
html_options = {:link => action_link_text(link, record, options), :class => html_class, :title => options[:not_authorized_reason]}
|
90
90
|
action_link_html(link, nil, html_options, record)
|
91
91
|
else
|
92
92
|
url = action_link_url(link, record)
|
@@ -298,8 +298,8 @@ module ActiveScaffold
|
|
298
298
|
url_options
|
299
299
|
end
|
300
300
|
|
301
|
-
def action_link_text(link, options)
|
302
|
-
text = image_tag(link.image[:name], :size => link.image[:size], :alt => options[:link] || link.label, :title => options[:link] || link.label) if link.image
|
301
|
+
def action_link_text(link, record, options)
|
302
|
+
text = image_tag(link.image[:name], :size => link.image[:size], :alt => options[:link] || link.label(record), :title => options[:link] || link.label(record)) if link.image
|
303
303
|
text || options[:link]
|
304
304
|
end
|
305
305
|
|
@@ -329,7 +329,7 @@ module ActiveScaffold
|
|
329
329
|
def action_link_html_options(link, record, options)
|
330
330
|
link_id = get_action_link_id(link, record)
|
331
331
|
html_options = link.html_options.merge(:class => [link.html_options[:class], link.action.to_s].compact.join(' '))
|
332
|
-
html_options[:link] = action_link_text(link, options)
|
332
|
+
html_options[:link] = action_link_text(link, record, options)
|
333
333
|
|
334
334
|
# Needs to be in html_options to as the adding _method to the url is no longer supported by Rails
|
335
335
|
html_options[:method] = link.method if link.method != :get
|
@@ -388,7 +388,7 @@ module ActiveScaffold
|
|
388
388
|
|
389
389
|
def action_link_html(link, url, html_options, record)
|
390
390
|
label = html_options.delete(:link)
|
391
|
-
label ||= link.label
|
391
|
+
label ||= link.label(record)
|
392
392
|
if url.nil?
|
393
393
|
content_tag(:a, label, html_options)
|
394
394
|
else
|
@@ -6,7 +6,7 @@ module ActiveScaffold
|
|
6
6
|
def cache_association_options(association, conditions, klass, cache = true)
|
7
7
|
if active_scaffold_config.cache_association_options && cache
|
8
8
|
@_associations_cache ||= Hash.new { |h, k| h[k] = {} }
|
9
|
-
key = [association.name, association.inverse_klass.name, klass.name].join('/')
|
9
|
+
key = [association.name, association.inverse_klass.name, klass.respond_to?(:cache_key) ? klass.cache_key : klass.name].join('/')
|
10
10
|
@_associations_cache[key][conditions] ||= yield
|
11
11
|
else
|
12
12
|
yield
|
@@ -31,8 +31,8 @@ module ActiveScaffold
|
|
31
31
|
end
|
32
32
|
|
33
33
|
conditions ||= send(association_helper_method(association, :options_for_association_conditions), association, record)
|
34
|
+
klass = send(association_helper_method(association, :association_klass_scoped), association, klass, record)
|
34
35
|
cache_association_options(association, conditions, klass, cache) do
|
35
|
-
klass = send(association_helper_method(association, :association_klass_scoped), association, klass, record)
|
36
36
|
relation = klass.where(conditions)
|
37
37
|
column = column_for_association(association, record)
|
38
38
|
if column&.includes
|
@@ -181,6 +181,7 @@ module ActiveScaffold
|
|
181
181
|
parent_record.send("build_#{association.name}")
|
182
182
|
else
|
183
183
|
association.klass.new.tap do |record|
|
184
|
+
assign_default_attributes record
|
184
185
|
save_record_to_association(record, association.reverse_association, parent_record) # set inverse
|
185
186
|
end
|
186
187
|
end
|
@@ -157,7 +157,7 @@ module ActiveScaffold
|
|
157
157
|
cache_keys ||= [method, model.name]
|
158
158
|
ActiveScaffold::Registry.cache(*cache_keys) do
|
159
159
|
model_names = [model.name]
|
160
|
-
model_names << model.base_class.name if model.base_class != model
|
160
|
+
model_names << model.base_class.name if model.respond_to?(:base_class) && model.base_class != model
|
161
161
|
method_with_class = model_names.find do |model_name|
|
162
162
|
method_with_class = "#{clean_class_name(model_name)}_#{method}"
|
163
163
|
break method_with_class if respond_to?(method_with_class)
|
@@ -85,9 +85,9 @@ module ActiveScaffold
|
|
85
85
|
|
86
86
|
def default_value(klass, column_name)
|
87
87
|
if ActiveScaffold::OrmChecks.mongoid? klass
|
88
|
-
columns_hash(klass)[column_name]&.default_val
|
88
|
+
columns_hash(klass)[column_name.to_s]&.default_val
|
89
89
|
elsif ActiveScaffold::OrmChecks.active_record? klass
|
90
|
-
klass._default_attributes[column_name]&.value
|
90
|
+
klass._default_attributes[column_name.to_s]&.value
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.7.
|
4
|
+
version: 3.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Many, see README
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|