active_scaffold 3.7.13 → 4.0.0.rc1
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 +9 -26
- data/README.md +3 -2
- data/app/assets/config/active_scaffold_manifest.js +3 -0
- data/app/assets/javascripts/active_scaffold.js.erb +24 -34
- data/app/assets/javascripts/jquery/active_scaffold.js +41 -58
- data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +1 -1
- data/app/assets/stylesheets/active_scaffold_colors.scss +0 -7
- data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -2
- data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +7 -7
- data/app/assets/stylesheets/active_scaffold_layout.css +57 -30
- data/app/views/active_scaffold_overrides/_add_existing_form.html.erb +10 -10
- data/app/views/active_scaffold_overrides/_base_form.html.erb +21 -21
- data/app/views/active_scaffold_overrides/_create_form.html.erb +10 -7
- data/app/views/active_scaffold_overrides/_create_form_on_list.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_field_search.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_form.html.erb +11 -14
- data/app/views/active_scaffold_overrides/_form_association.html.erb +21 -12
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +19 -10
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +15 -21
- data/app/views/active_scaffold_overrides/_form_messages.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +7 -6
- data/app/views/active_scaffold_overrides/_human_conditions.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_list.html.erb +15 -8
- data/app/views/active_scaffold_overrides/_list_calculations.html.erb +2 -3
- data/app/views/active_scaffold_overrides/_list_header.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +12 -3
- data/app/views/active_scaffold_overrides/_list_pagination.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_list_pagination_links.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_list_record.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_list_with_header.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_refresh_list.js.erb +2 -2
- data/app/views/active_scaffold_overrides/_render_field.js.erb +4 -4
- data/app/views/active_scaffold_overrides/_row.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_search.html.erb +6 -5
- data/app/views/active_scaffold_overrides/_show.html.erb +3 -3
- data/app/views/active_scaffold_overrides/_show_actions.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_association_vertical.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_actions.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_calculations.js.erb +2 -2
- data/app/views/active_scaffold_overrides/_update_column.js.erb +8 -7
- data/app/views/active_scaffold_overrides/_update_form.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_update_messages.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +4 -3
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +3 -3
- data/app/views/active_scaffold_overrides/add_existing.js.erb +6 -6
- data/app/views/active_scaffold_overrides/add_existing_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/add_tab.js.erb +15 -0
- data/app/views/active_scaffold_overrides/create.html.erb +1 -1
- data/app/views/active_scaffold_overrides/delete.html.erb +4 -4
- data/app/views/active_scaffold_overrides/destroy.js.erb +15 -13
- data/app/views/active_scaffold_overrides/edit_associated.js.erb +3 -3
- data/app/views/active_scaffold_overrides/field_search.html.erb +1 -1
- data/app/views/active_scaffold_overrides/form_messages.js.erb +1 -1
- data/app/views/active_scaffold_overrides/list.html.erb +1 -1
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +13 -8
- data/app/views/active_scaffold_overrides/on_create.js.erb +34 -6
- data/app/views/active_scaffold_overrides/on_mark.js.erb +3 -3
- data/app/views/active_scaffold_overrides/on_update.js.erb +9 -9
- data/app/views/active_scaffold_overrides/render_field.js.erb +1 -1
- data/app/views/active_scaffold_overrides/render_field_inplace.html.erb +1 -1
- data/app/views/active_scaffold_overrides/row.js.erb +2 -2
- data/app/views/active_scaffold_overrides/search.html.erb +1 -1
- data/app/views/active_scaffold_overrides/show.html.erb +3 -3
- data/app/views/active_scaffold_overrides/update.html.erb +2 -2
- data/app/views/active_scaffold_overrides/update_column.js.erb +4 -4
- data/app/views/active_scaffold_overrides/update_row.js.erb +1 -1
- data/lib/active_scaffold/actions/common_search.rb +5 -3
- data/lib/active_scaffold/actions/core.rb +57 -32
- data/lib/active_scaffold/actions/create.rb +19 -17
- data/lib/active_scaffold/actions/delete.rb +10 -12
- data/lib/active_scaffold/actions/field_search.rb +28 -13
- data/lib/active_scaffold/actions/list.rb +34 -34
- data/lib/active_scaffold/actions/mark.rb +5 -5
- data/lib/active_scaffold/actions/nested.rb +64 -56
- data/lib/active_scaffold/actions/search.rb +2 -2
- data/lib/active_scaffold/actions/show.rb +5 -5
- data/lib/active_scaffold/actions/subform.rb +15 -4
- data/lib/active_scaffold/actions/update.rb +20 -20
- data/lib/active_scaffold/active_record_permissions.rb +4 -3
- data/lib/active_scaffold/attribute_params.rb +51 -50
- data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +4 -4
- data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +6 -2
- data/lib/active_scaffold/bridges/active_storage.rb +1 -1
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +3 -3
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +4 -1
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +9 -8
- data/lib/active_scaffold/bridges/cancan.rb +8 -8
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +1 -1
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +4 -3
- data/lib/active_scaffold/bridges/carrierwave.rb +2 -2
- data/lib/active_scaffold/bridges/chosen.rb +1 -5
- data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +4 -2
- data/lib/active_scaffold/bridges/date_picker/ext.rb +20 -12
- data/lib/active_scaffold/bridges/date_picker/helper.rb +37 -33
- data/lib/active_scaffold/bridges/date_picker.rb +1 -4
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +3 -2
- data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +3 -2
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +2 -1
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +4 -9
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +6 -3
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +1 -4
- data/lib/active_scaffold/bridges/file_column.rb +1 -0
- data/lib/active_scaffold/bridges/paper_trail/actions.rb +4 -2
- data/lib/active_scaffold/bridges/paper_trail/config.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +2 -1
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +3 -2
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +10 -9
- data/lib/active_scaffold/bridges/paperclip.rb +2 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +10 -11
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +3 -1
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -7
- data/lib/active_scaffold/bridges/tiny_mce.rb +2 -7
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +7 -7
- data/lib/active_scaffold/bridges.rb +7 -5
- data/lib/active_scaffold/config/base.rb +20 -24
- data/lib/active_scaffold/config/core.rb +27 -39
- data/lib/active_scaffold/config/create.rb +1 -1
- data/lib/active_scaffold/config/delete.rb +9 -9
- data/lib/active_scaffold/config/field_search.rb +4 -9
- data/lib/active_scaffold/config/form.rb +3 -1
- data/lib/active_scaffold/config/list.rb +19 -15
- data/lib/active_scaffold/config/nested.rb +2 -2
- data/lib/active_scaffold/config/search.rb +5 -5
- data/lib/active_scaffold/config/show.rb +1 -1
- data/lib/active_scaffold/config/subform.rb +1 -1
- data/lib/active_scaffold/config/update.rb +4 -5
- data/lib/active_scaffold/configurable.rb +2 -1
- data/lib/active_scaffold/constraints.rb +16 -11
- data/lib/active_scaffold/core.rb +25 -27
- data/lib/active_scaffold/data_structures/action_columns.rb +10 -3
- data/lib/active_scaffold/data_structures/action_link.rb +19 -9
- data/lib/active_scaffold/data_structures/action_links.rb +20 -26
- data/lib/active_scaffold/data_structures/actions.rb +3 -3
- data/lib/active_scaffold/data_structures/association/abstract.rb +8 -4
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +1 -0
- data/lib/active_scaffold/data_structures/association/active_record.rb +1 -4
- data/lib/active_scaffold/data_structures/column.rb +368 -327
- data/lib/active_scaffold/data_structures/columns.rb +3 -2
- data/lib/active_scaffold/data_structures/nested_info.rb +6 -5
- data/lib/active_scaffold/data_structures/proxy_column.rb +68 -0
- data/lib/active_scaffold/data_structures/set.rb +7 -4
- data/lib/active_scaffold/data_structures/sorting.rb +21 -12
- data/lib/active_scaffold/engine.rb +12 -12
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +5 -5
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +29 -31
- data/lib/active_scaffold/extensions/ice_nine.rb +2 -1
- data/lib/active_scaffold/extensions/localize.rb +2 -2
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
- data/lib/active_scaffold/extensions/routing_mapper.rb +5 -4
- data/lib/active_scaffold/extensions/unsaved_associated.rb +3 -2
- data/lib/active_scaffold/finder.rb +71 -78
- data/lib/active_scaffold/helpers/action_link_helpers.rb +37 -49
- data/lib/active_scaffold/helpers/association_helpers.rb +4 -3
- data/lib/active_scaffold/helpers/controller_helpers.rb +18 -16
- data/lib/active_scaffold/helpers/form_column_helpers.rb +69 -53
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +17 -15
- data/lib/active_scaffold/helpers/id_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/list_column_helpers.rb +35 -38
- data/lib/active_scaffold/helpers/pagination_helpers.rb +4 -4
- data/lib/active_scaffold/helpers/search_column_helpers.rb +25 -34
- data/lib/active_scaffold/helpers/show_column_helpers.rb +7 -4
- data/lib/active_scaffold/helpers/tabs_helpers.rb +88 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +15 -13
- data/lib/active_scaffold/marked_model.rb +1 -2
- data/lib/active_scaffold/orm_checks.rb +6 -4
- data/lib/active_scaffold/paginator.rb +3 -2
- data/lib/active_scaffold/registry.rb +5 -0
- data/lib/active_scaffold/tableless.rb +24 -14
- data/lib/active_scaffold/version.rb +4 -4
- data/lib/active_scaffold.rb +8 -34
- data/lib/generators/active_scaffold/controller_generator.rb +20 -20
- data/lib/generators/active_scaffold/install_generator.rb +4 -8
- data/lib/generators/active_scaffold/resource_generator.rb +31 -31
- data/lib/tasks/brakeman.rake +1 -1
- data/shoulda_macros/macros.rb +14 -14
- metadata +11 -232
- data/app/assets/javascripts/prototype/active_scaffold.js +0 -1249
- data/app/assets/javascripts/prototype/active_scaffold_chosen.js +0 -0
- data/app/assets/javascripts/prototype/dhtml_history.js +0 -870
- data/app/assets/javascripts/prototype/form_enhancements.js +0 -117
- data/app/assets/javascripts/prototype/tiny_mce_bridge.js +0 -17
- data/app/views/active_scaffold_overrides/_list_messages_content.html.erb +0 -8
- data/app/views/active_scaffold_overrides/_new_record.js.erb +0 -15
- data/app/views/active_scaffold_overrides/_popup_adapter.html.erb +0 -20
- data/app/views/active_scaffold_overrides/_refresh_create_form.js.erb +0 -12
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +0 -58
- data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -17
- data/lib/active_scaffold/data_structures/action_link_separator.rb +0 -13
- data/lib/active_scaffold/extensions/cow_proxy.rb +0 -102
- data/test/active_scaffold_config_mock.rb +0 -33
- data/test/bridges/bridge_test.rb +0 -88
- data/test/bridges/date_picker_test.rb +0 -31
- data/test/bridges/paper_trail_test.rb +0 -16
- data/test/bridges/paperclip_test.rb +0 -85
- data/test/bridges/tiny_mce_test.rb +0 -61
- data/test/class_with_finder.rb +0 -42
- data/test/company.rb +0 -97
- data/test/config/base_test.rb +0 -17
- data/test/config/core_test.rb +0 -66
- data/test/config/create_test.rb +0 -72
- data/test/config/delete_test.rb +0 -35
- data/test/config/field_search_test.rb +0 -49
- data/test/config/list_test.rb +0 -134
- data/test/config/nested_test.rb +0 -55
- data/test/config/search_test.rb +0 -62
- data/test/config/show_test.rb +0 -45
- data/test/config/subform_test.rb +0 -19
- data/test/config/update_test.rb +0 -52
- data/test/const_mocker.rb +0 -32
- data/test/data_structures/action_columns_test.rb +0 -112
- data/test/data_structures/action_link_test.rb +0 -79
- data/test/data_structures/action_links_test.rb +0 -78
- data/test/data_structures/actions_test.rb +0 -25
- data/test/data_structures/association_column_test.rb +0 -41
- data/test/data_structures/column_test.rb +0 -186
- data/test/data_structures/columns_test.rb +0 -68
- data/test/data_structures/set_test.rb +0 -84
- data/test/data_structures/sorting_test.rb +0 -148
- data/test/data_structures/standard_column_test.rb +0 -23
- data/test/data_structures/validation_reflection_test.rb +0 -69
- data/test/data_structures/virtual_column_test.rb +0 -23
- data/test/extensions/action_view_rendering_test.rb +0 -20
- data/test/extensions/active_record_test.rb +0 -44
- data/test/extensions/routing_mapper_test.rb +0 -73
- data/test/helpers/form_column_helpers_test.rb +0 -34
- data/test/helpers/list_column_helpers_test.rb +0 -53
- data/test/helpers/pagination_helpers_test.rb +0 -65
- data/test/helpers/search_column_helpers_test.rb +0 -15
- data/test/misc/active_record_permissions_test.rb +0 -193
- data/test/misc/attribute_params_test.rb +0 -460
- data/test/misc/calculation_test.rb +0 -39
- data/test/misc/configurable_test.rb +0 -97
- data/test/misc/constraints_test.rb +0 -209
- data/test/misc/convert_numbers_format_test.rb +0 -171
- data/test/misc/finder_test.rb +0 -124
- data/test/misc/lang_test.rb +0 -10
- data/test/misc/parse_datetime_test.rb +0 -159
- data/test/misc/render_test.rb +0 -9
- data/test/misc/tableless_test.rb +0 -56
- data/test/mock_app/.gitignore +0 -2
- data/test/mock_app/Rakefile +0 -7
- data/test/mock_app/app/assets/config/manifest.js +0 -0
- data/test/mock_app/app/controllers/addresses_controller.rb +0 -4
- data/test/mock_app/app/controllers/application_controller.rb +0 -10
- data/test/mock_app/app/controllers/buildings_controller.rb +0 -4
- data/test/mock_app/app/controllers/cars_controller.rb +0 -5
- data/test/mock_app/app/controllers/contacts_controller.rb +0 -4
- data/test/mock_app/app/controllers/floors_controller.rb +0 -6
- data/test/mock_app/app/controllers/people_controller.rb +0 -8
- data/test/mock_app/app/controllers/roles_controller.rb +0 -4
- data/test/mock_app/app/helpers/application_helper.rb +0 -3
- data/test/mock_app/app/models/address.rb +0 -3
- data/test/mock_app/app/models/building.rb +0 -9
- data/test/mock_app/app/models/car.rb +0 -3
- data/test/mock_app/app/models/contact.rb +0 -3
- data/test/mock_app/app/models/file_model.rb +0 -31
- data/test/mock_app/app/models/floor.rb +0 -8
- data/test/mock_app/app/models/person.rb +0 -12
- data/test/mock_app/app/models/role.rb +0 -3
- data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +0 -2
- data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +0 -2
- data/test/mock_app/app/views/people/_first_name_form_column.html.erb +0 -2
- data/test/mock_app/app/views/people/_form.html.erb +0 -2
- data/test/mock_app/app/views/people/list.html.erb +0 -2
- data/test/mock_app/config/application.rb +0 -14
- data/test/mock_app/config/boot.rb +0 -7
- data/test/mock_app/config/database.yml +0 -16
- data/test/mock_app/config/environment.rb +0 -6
- data/test/mock_app/config/environments/development.rb +0 -24
- data/test/mock_app/config/environments/production.rb +0 -49
- data/test/mock_app/config/environments/test.rb +0 -34
- data/test/mock_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/mock_app/config/initializers/inflections.rb +0 -10
- data/test/mock_app/config/initializers/mime_types.rb +0 -5
- data/test/mock_app/config/initializers/secret_token.rb +0 -11
- data/test/mock_app/config/initializers/session_store.rb +0 -8
- data/test/mock_app/config/initializers/wrap_parameters.rb +0 -14
- data/test/mock_app/config/locales/en.yml +0 -5
- data/test/mock_app/config/routes.rb +0 -17
- data/test/mock_app/config.ru +0 -4
- data/test/mock_app/db/schema.rb +0 -68
- data/test/mock_app/db/test.sqlite3 +0 -1
- data/test/model_stub.rb +0 -64
- data/test/performance/list_cars_performance_test.rb +0 -34
- data/test/performance/list_people_performance_test.rb +0 -31
- data/test/performance_test_help.rb +0 -3
- data/test/run_all.rb +0 -6
- data/test/test_helper.rb +0 -71
- data/vendor/assets/javascripts/getprototypeof.js +0 -12
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveScaffold::Actions
|
2
2
|
module Update
|
3
3
|
def self.included(base)
|
4
|
-
base.before_action :update_authorized_filter, :
|
4
|
+
base.before_action :update_authorized_filter, only: %i[edit update]
|
5
5
|
base.helper_method :update_refresh_list?
|
6
6
|
end
|
7
7
|
|
@@ -25,35 +25,35 @@ module ActiveScaffold::Actions
|
|
25
25
|
|
26
26
|
def edit_respond_to_html
|
27
27
|
if successful?
|
28
|
-
render
|
28
|
+
render action: 'update'
|
29
29
|
else
|
30
30
|
return_to_main
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def edit_respond_to_js
|
35
|
-
render
|
35
|
+
render partial: 'update_form'
|
36
36
|
end
|
37
37
|
|
38
38
|
def update_respond_on_iframe
|
39
39
|
do_refresh_list if successful? && active_scaffold_config.update.refresh_list && !render_parent?
|
40
40
|
responds_to_parent do
|
41
|
-
render :
|
41
|
+
render action: 'on_update', formats: [:js], layout: false
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
def update_respond_to_html
|
46
46
|
if successful? # just a regular post
|
47
|
-
message = as_(:updated_model, :
|
47
|
+
message = as_(:updated_model, model: ERB::Util.h(@record.to_label))
|
48
48
|
if params[:dont_close]
|
49
49
|
flash.now[:info] = message
|
50
|
-
render
|
50
|
+
render action: 'update'
|
51
51
|
else
|
52
52
|
flash[:info] = message
|
53
53
|
return_to_main
|
54
54
|
end
|
55
55
|
else
|
56
|
-
render
|
56
|
+
render action: 'update'
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -77,9 +77,9 @@ module ActiveScaffold::Actions
|
|
77
77
|
def update_respond_to_js
|
78
78
|
if successful?
|
79
79
|
record_to_refresh_on_update if !render_parent? && active_scaffold_config.actions.include?(:list)
|
80
|
-
flash.now[:info] = as_(:updated_model, :
|
80
|
+
flash.now[:info] = as_(:updated_model, model: ERB::Util.h((@updated_record || @record).to_label)) if active_scaffold_config.update.persistent
|
81
81
|
end
|
82
|
-
render :
|
82
|
+
render action: 'on_update'
|
83
83
|
end
|
84
84
|
|
85
85
|
def update_respond_to_xml
|
@@ -124,6 +124,7 @@ module ActiveScaffold::Actions
|
|
124
124
|
# we have to revert these changes if validation fails
|
125
125
|
raise ActiveRecord::Rollback, "don't save habtm associations unless record is valid"
|
126
126
|
end
|
127
|
+
|
127
128
|
@record.save! && @record.save_associated!
|
128
129
|
after_update_save(@record)
|
129
130
|
end
|
@@ -131,16 +132,14 @@ module ActiveScaffold::Actions
|
|
131
132
|
@record.errors.add(:base, as_(:version_inconsistency))
|
132
133
|
self.successful = false
|
133
134
|
on_stale_object_error(@record)
|
134
|
-
rescue ActiveRecord::RecordNotSaved =>
|
135
|
+
rescue ActiveRecord::RecordNotSaved => e
|
135
136
|
logger.warn do
|
136
|
-
"\n\n#{
|
137
|
-
Rails.backtrace_cleaner.clean(exception.backtrace).join("\n ") +
|
138
|
-
"\n\n"
|
137
|
+
"\n\n#{e.class} (#{e.message}):\n #{Rails.backtrace_cleaner.clean(e.backtrace).join("\n ")}\n\n"
|
139
138
|
end
|
140
139
|
@record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty?
|
141
140
|
self.successful = false
|
142
|
-
rescue ActiveRecord::ActiveRecordError =>
|
143
|
-
flash[:error] =
|
141
|
+
rescue ActiveRecord::ActiveRecordError => e
|
142
|
+
flash[:error] = e.message
|
144
143
|
self.successful = false
|
145
144
|
end
|
146
145
|
|
@@ -154,7 +153,7 @@ module ActiveScaffold::Actions
|
|
154
153
|
|
155
154
|
value_record = record_for_update_column
|
156
155
|
value = value_for_update_column(value, @column, value_record)
|
157
|
-
value_record.send("#{@column.name}=", value)
|
156
|
+
value_record.send(:"#{@column.name}=", value)
|
158
157
|
before_update_save(@record)
|
159
158
|
self.successful = value_record.save
|
160
159
|
if !successful?
|
@@ -174,12 +173,13 @@ module ActiveScaffold::Actions
|
|
174
173
|
|
175
174
|
def record_for_update_column
|
176
175
|
@record = find_if_allowed(params[:id], :read)
|
177
|
-
raise ActiveScaffold::ActionNotAllowed unless @record.authorized_for?(:
|
176
|
+
raise ActiveScaffold::ActionNotAllowed unless @record.authorized_for?(crud_type: :update, column: @column.name)
|
178
177
|
|
179
178
|
if @column.delegated_association
|
180
179
|
value_record = @record.send(@column.delegated_association.name)
|
181
180
|
value_record ||= @record.association(@column.delegated_association.name).build
|
182
|
-
raise ActiveScaffold::ActionNotAllowed unless value_record.authorized_for?(:
|
181
|
+
raise ActiveScaffold::ActionNotAllowed unless value_record.authorized_for?(crud_type: :update, column: @column.name)
|
182
|
+
|
183
183
|
value_record
|
184
184
|
else
|
185
185
|
@record
|
@@ -217,14 +217,14 @@ module ActiveScaffold::Actions
|
|
217
217
|
end
|
218
218
|
|
219
219
|
def update_ignore?(record = nil)
|
220
|
-
!authorized_for?(:
|
220
|
+
!authorized_for?(crud_type: :update)
|
221
221
|
end
|
222
222
|
|
223
223
|
private
|
224
224
|
|
225
225
|
def update_authorized_filter
|
226
226
|
link = active_scaffold_config.update.link || self.class.active_scaffold_config.update.class.link
|
227
|
-
raise ActiveScaffold::ActionNotAllowed unless
|
227
|
+
raise ActiveScaffold::ActionNotAllowed unless action_link_authorized?(link)
|
228
228
|
end
|
229
229
|
|
230
230
|
def edit_formats
|
@@ -66,8 +66,7 @@ module ActiveScaffold
|
|
66
66
|
base.extend SecurityMethods
|
67
67
|
base.send :include, SecurityMethods
|
68
68
|
class << base
|
69
|
-
attr_accessor :class_security_methods
|
70
|
-
attr_accessor :instance_security_methods
|
69
|
+
attr_accessor :class_security_methods, :instance_security_methods
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
@@ -88,12 +87,13 @@ module ActiveScaffold
|
|
88
87
|
# options[:action] is the name of a method
|
89
88
|
# options[:reason] if returning reason is expected, it will return array with authorized and reason, or nil if no reason
|
90
89
|
def authorized_for?(options = {})
|
91
|
-
raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] &&
|
90
|
+
raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] && %i[create read update delete].exclude?(options[:crud_type])
|
92
91
|
|
93
92
|
not_authorized_reason = ActiveRecordPermissions.not_authorized_reason
|
94
93
|
# collect other possibly-related methods that actually exist
|
95
94
|
methods = cached_authorized_for_methods(options)
|
96
95
|
return ActiveRecordPermissions.default_permission if methods.empty?
|
96
|
+
|
97
97
|
if methods.one?
|
98
98
|
result = send(methods.first)
|
99
99
|
# if not_authorized_reason enabled interpret String as reason for not authorized
|
@@ -108,6 +108,7 @@ module ActiveScaffold
|
|
108
108
|
# if not_authorized_reason enabled interpret String as reason for not authorized
|
109
109
|
authorized, reason = not_authorized_reason && result.is_a?(String) ? [false, result] : [result, nil]
|
110
110
|
next if authorized
|
111
|
+
|
111
112
|
# return array with reason only if requested with options[:reason]
|
112
113
|
return options[:reason] ? [authorized, reason] : authorized
|
113
114
|
end
|
@@ -33,16 +33,10 @@ module ActiveScaffold
|
|
33
33
|
module AttributeParams
|
34
34
|
protected
|
35
35
|
|
36
|
-
# workaround for updating counters twice bug on rails4 (https://github.com/rails/rails/pull/14849)
|
37
|
-
# rails 5 needs this hack for belongs_to, when selecting record, not creating new one (value is Hash)
|
38
|
-
# TODO: remove when rails5 support is removed
|
39
|
-
def belongs_to_counter_cache_hack?(association, value)
|
40
|
-
!params_hash?(value) && association.belongs_to? && association.counter_cache_hack?
|
41
|
-
end
|
42
|
-
|
43
36
|
def multi_parameter_attributes(attributes)
|
44
37
|
params_hash(attributes).each_with_object({}) do |(k, v), result|
|
45
38
|
next unless k.include? '('
|
39
|
+
|
46
40
|
column_name = k.split('(').first
|
47
41
|
result[column_name] ||= []
|
48
42
|
result[column_name] << [k, v]
|
@@ -52,6 +46,7 @@ module ActiveScaffold
|
|
52
46
|
def assign_locking_column(parent_record, attributes)
|
53
47
|
return unless parent_record.persisted? && parent_record.locking_enabled? &&
|
54
48
|
attributes.include?(parent_record.class.locking_column)
|
49
|
+
|
55
50
|
parent_record.write_attribute parent_record.class.locking_column, attributes[parent_record.class.locking_column]
|
56
51
|
end
|
57
52
|
|
@@ -60,25 +55,24 @@ module ActiveScaffold
|
|
60
55
|
#
|
61
56
|
# This is a secure way to apply params to a record, because it's based on a loop over the columns
|
62
57
|
# set. The columns set will not yield unauthorized columns, and it will not yield unregistered columns.
|
63
|
-
def update_record_from_params(parent_record, columns, attributes, avoid_changes = false
|
58
|
+
def update_record_from_params(parent_record, columns, attributes, avoid_changes = false)
|
64
59
|
crud_type = parent_record.new_record? ? :create : :update
|
65
|
-
return parent_record unless parent_record.authorized_for?(:
|
60
|
+
return parent_record unless parent_record.authorized_for?(crud_type: crud_type)
|
66
61
|
|
67
62
|
multi_parameter_attrs = multi_parameter_attributes(attributes)
|
68
63
|
assign_locking_column(parent_record, attributes)
|
69
64
|
|
70
65
|
columns.each_column(for: parent_record, crud_type: crud_type, flatten: true) do |column|
|
71
66
|
# Set any passthrough parameters that may be associated with this column (ie, file column "keep" and "temp" attributes)
|
72
|
-
|
67
|
+
assign_column_params(parent_record, column, attributes)
|
73
68
|
|
74
69
|
if multi_parameter_attrs.key? column.name.to_s
|
75
70
|
parent_record.send(:assign_multiparameter_attributes, multi_parameter_attrs[column.name.to_s])
|
76
71
|
elsif attributes.key? column.name
|
77
|
-
next if search_attributes && params_hash?(attributes[column.name])
|
78
72
|
update_column_from_params(parent_record, column, attributes[column.name], avoid_changes)
|
79
73
|
end
|
80
74
|
rescue StandardError => e
|
81
|
-
message = "on the ActiveScaffold column = :#{column.name} for #{parent_record.inspect} "\
|
75
|
+
message = "on the ActiveScaffold column = :#{column.name} for #{parent_record.inspect} " \
|
82
76
|
"(value from params #{attributes[column.name].inspect})"
|
83
77
|
Rails.logger.error "#{e.class.name}: #{e.message} -- #{message}"
|
84
78
|
raise
|
@@ -87,36 +81,39 @@ module ActiveScaffold
|
|
87
81
|
parent_record
|
88
82
|
end
|
89
83
|
|
84
|
+
def assign_column_params(parent_record, column, attributes)
|
85
|
+
column.params.select { |p| attributes.key? p }.each { |p| parent_record.send(:"#{p}=", attributes[p]) }
|
86
|
+
end
|
87
|
+
|
90
88
|
def update_column_from_params(parent_record, column, attribute, avoid_changes = false)
|
91
89
|
value = column_value_from_param_value(parent_record, column, attribute, avoid_changes)
|
92
90
|
if column.association
|
93
|
-
|
94
|
-
parent_record.association(column.name).target = value
|
95
|
-
parent_record.send("#{column.association.foreign_key}=", value&.id) if column.association.belongs_to?
|
96
|
-
else
|
97
|
-
update_column_association(parent_record, column, attribute, value)
|
98
|
-
end
|
91
|
+
update_column_association(parent_record, column, attribute, value, avoid_changes)
|
99
92
|
else
|
100
|
-
parent_record.send "#{column.name}=", value
|
93
|
+
parent_record.send :"#{column.name}=", value
|
101
94
|
end
|
102
95
|
# needed? probably done on find_or_create_for_params, need more testing
|
103
96
|
if column.association&.reverse_association&.belongs_to?
|
104
|
-
Array(value).each { |v| v.send("#{column.association.reverse}=", parent_record) if v.new_record? }
|
97
|
+
Array(value).each { |v| v.send(:"#{column.association.reverse}=", parent_record) if v.new_record? }
|
105
98
|
end
|
106
99
|
value
|
107
100
|
end
|
108
101
|
|
109
|
-
def
|
110
|
-
|
111
|
-
|
112
|
-
|
102
|
+
def assign_column_association(parent_record, column, attribute, value)
|
103
|
+
parent_record.association(column.name).target = value
|
104
|
+
parent_record.send(:"#{column.association.foreign_key}=", value&.id) if column.association.belongs_to?
|
105
|
+
end
|
106
|
+
|
107
|
+
def update_column_association(parent_record, column, attribute, value, avoid_changes = false)
|
108
|
+
if avoid_changes
|
109
|
+
assign_column_association(parent_record, column, attribute, value)
|
113
110
|
elsif column.association.collection? && column.association.through_singular?
|
114
111
|
through = column.association.through_reflection.name
|
115
112
|
through_record = parent_record.send(through)
|
116
|
-
through_record ||= parent_record.send "build_#{through}"
|
117
|
-
through_record.send "#{column.association.source_reflection.name}=", value
|
113
|
+
through_record ||= parent_record.send :"build_#{through}"
|
114
|
+
through_record.send :"#{column.association.source_reflection.name}=", value
|
118
115
|
else
|
119
|
-
parent_record.send "#{column.name}=", value
|
116
|
+
parent_record.send :"#{column.name}=", value
|
120
117
|
end
|
121
118
|
rescue ActiveRecord::RecordNotSaved
|
122
119
|
parent_record.errors.add column.name, :invalid
|
@@ -126,8 +123,8 @@ module ActiveScaffold
|
|
126
123
|
def column_value_from_param_value(parent_record, column, value, avoid_changes = false)
|
127
124
|
# convert the value, possibly by instantiating associated objects
|
128
125
|
form_ui = column.form_ui || column.column&.type
|
129
|
-
if form_ui && respond_to?("column_value_for_#{form_ui}_type", true)
|
130
|
-
send("column_value_for_#{form_ui}_type", parent_record, column, value)
|
126
|
+
if form_ui && respond_to?(:"column_value_for_#{form_ui}_type", true)
|
127
|
+
send(:"column_value_for_#{form_ui}_type", parent_record, column, value)
|
131
128
|
elsif params_hash? value
|
132
129
|
column_value_from_param_hash_value(parent_record, column, params_hash(value), avoid_changes)
|
133
130
|
else
|
@@ -144,10 +141,8 @@ module ActiveScaffold
|
|
144
141
|
end
|
145
142
|
|
146
143
|
def column_value_for_datetime_type(parent_record, column, value)
|
147
|
-
new_value = self.class.condition_value_for_datetime(column, value, datetime_conversion_for_value(column))
|
148
|
-
if new_value.nil? && value.present?
|
149
|
-
parent_record.errors.add column.name, :invalid
|
150
|
-
end
|
144
|
+
new_value = self.class.condition_value_for_datetime(column, value, datetime_conversion_for_value(column), ui_method: :form_ui)
|
145
|
+
parent_record.errors.add column.name, :invalid if new_value.nil? && value.present?
|
151
146
|
new_value
|
152
147
|
end
|
153
148
|
|
@@ -184,7 +179,7 @@ module ActiveScaffold
|
|
184
179
|
def column_plural_assocation_value_from_value(column, value)
|
185
180
|
# it's an array of ids
|
186
181
|
if value.present?
|
187
|
-
ids = value.
|
182
|
+
ids = value.compact_blank
|
188
183
|
ids.empty? ? [] : column.association.klass.find(ids)
|
189
184
|
else
|
190
185
|
[]
|
@@ -196,8 +191,8 @@ module ActiveScaffold
|
|
196
191
|
manage_nested_record_from_params(parent_record, column, value, avoid_changes)
|
197
192
|
elsif column.association&.collection?
|
198
193
|
# HACK: to be able to delete all associated records, hash will include "0" => ""
|
199
|
-
|
200
|
-
|
194
|
+
value.values.compact_blank
|
195
|
+
.filter_map { |val| manage_nested_record_from_params(parent_record, column, val, avoid_changes) }
|
201
196
|
else
|
202
197
|
value
|
203
198
|
end
|
@@ -205,6 +200,7 @@ module ActiveScaffold
|
|
205
200
|
|
206
201
|
def manage_nested_record_from_params(parent_record, column, attributes, avoid_changes = false)
|
207
202
|
return nil unless build_record_from_params?(attributes, column, parent_record)
|
203
|
+
|
208
204
|
record = find_or_create_for_params(attributes, column, parent_record)
|
209
205
|
if record
|
210
206
|
record_columns = active_scaffold_config_for(record.class).subform.columns
|
@@ -220,6 +216,7 @@ module ActiveScaffold
|
|
220
216
|
def build_record_from_params?(params, column, record)
|
221
217
|
current = record.send(column.name)
|
222
218
|
return true if column.association.collection? && !column.show_blank_record?(current)
|
219
|
+
|
223
220
|
klass = column.association.klass(record)
|
224
221
|
klass && !attributes_hash_is_empty?(params, klass)
|
225
222
|
end
|
@@ -232,11 +229,11 @@ module ActiveScaffold
|
|
232
229
|
klass = parent_column.association.klass(parent_record)
|
233
230
|
if params.key? klass.primary_key
|
234
231
|
record_from_current_or_find(klass, params[klass.primary_key], current)
|
235
|
-
elsif klass.authorized_for?(:
|
232
|
+
elsif klass.authorized_for?(crud_type: :create)
|
236
233
|
association = parent_column.association
|
237
234
|
record = klass.new
|
238
235
|
if association.reverse_association&.belongs_to? && (association.collection? || current.nil?)
|
239
|
-
record.send("#{parent_column.association.reverse}=", parent_record)
|
236
|
+
record.send(:"#{parent_column.association.reverse}=", parent_record)
|
240
237
|
end
|
241
238
|
record
|
242
239
|
end
|
@@ -260,24 +257,27 @@ module ActiveScaffold
|
|
260
257
|
# This isn't a literal emptiness - it's an attempt to discern whether the user intended it to be empty or not.
|
261
258
|
def attributes_hash_is_empty?(hash, klass)
|
262
259
|
hash.all? do |key, value|
|
263
|
-
# convert any possible multi-parameter attributes like 'created_at(5i)' to simply 'created_at'
|
264
|
-
column_name = key.to_s.split('(', 2)[0]
|
265
|
-
|
266
260
|
# datetimes will always have a value. so we ignore them when checking whether the hash is empty.
|
267
261
|
# this could be a bad idea. but the current situation (excess record entry) seems worse.
|
268
262
|
next true if mulitpart_ignored?(key, klass)
|
269
263
|
|
264
|
+
# convert any possible multi-parameter attributes like 'created_at(5i)' to simply 'created_at'
|
265
|
+
column_name = key.to_s.split('(', 2)[0]
|
266
|
+
attribute_is_empty?(column_name, klass, value)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def attribute_is_empty?(column_name, klass, value)
|
271
|
+
if default_value?(column_name, klass, value)
|
270
272
|
# defaults are pre-filled on the form. we can't use them to determine if the user intends a new row.
|
271
273
|
# booleans always have value, so they are ignored if not changed from default
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
value.respond_to?(:empty?) ? value.empty? : false
|
280
|
-
end
|
274
|
+
true
|
275
|
+
elsif params_hash? value
|
276
|
+
attributes_hash_is_empty?(value, klass)
|
277
|
+
elsif value.is_a?(Array)
|
278
|
+
value.all?(&:blank?)
|
279
|
+
else
|
280
|
+
value.respond_to?(:empty?) ? value.empty? : false
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
@@ -287,6 +287,7 @@ module ActiveScaffold
|
|
287
287
|
def mulitpart_ignored?(param_name, klass)
|
288
288
|
column_name, multipart = param_name.to_s.split('(', 2)
|
289
289
|
return false unless multipart
|
290
|
+
|
290
291
|
column_type = ActiveScaffold::OrmChecks.column_type(klass, column_name)
|
291
292
|
MULTIPART_IGNORE_TYPES.include?(column_type) if column_type
|
292
293
|
end
|
@@ -22,10 +22,10 @@ module ActiveScaffold
|
|
22
22
|
|
23
23
|
def configure_active_storage_field(field, field_type)
|
24
24
|
columns << field
|
25
|
-
columns.exclude "#{field}_attachment#{'s' if field_type == :has_many}"
|
26
|
-
columns.exclude "#{field}_blob#{'s' if field_type == :has_many}"
|
27
|
-
columns[field].includes ||= ["#{field}_attachment#{'s' if field_type == :has_many}"
|
28
|
-
columns[field].form_ui ||= "active_storage_#{field_type}"
|
25
|
+
columns.exclude :"#{field}_attachment#{'s' if field_type == :has_many}"
|
26
|
+
columns.exclude :"#{field}_blob#{'s' if field_type == :has_many}"
|
27
|
+
columns[field].includes ||= [:"#{field}_attachment#{'s' if field_type == :has_many}", :"#{field}_blob#{'s' if field_type == :has_many}"]
|
28
|
+
columns[field].form_ui ||= :"active_storage_#{field_type}"
|
29
29
|
columns[field].params.add "delete_#{field}"
|
30
30
|
end
|
31
31
|
end
|
@@ -5,12 +5,16 @@ module ActiveScaffold
|
|
5
5
|
class << self
|
6
6
|
# has_one :"#{name}_attachment", -> { where(name: name) }, class_name: "ActiveStorage::Attachment", as: :record, inverse_of: :record, dependent: false
|
7
7
|
def active_storage_has_one_fields(klass)
|
8
|
-
klass.reflect_on_all_associations(:has_one)
|
8
|
+
klass.reflect_on_all_associations(:has_one)
|
9
|
+
&.select { |reflection| reflection.class_name == 'ActiveStorage::Attachment' }
|
10
|
+
&.collect { |association| association.name[0..-12] } || []
|
9
11
|
end
|
10
12
|
|
11
13
|
# has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "ActiveStorage::Attachment", inverse_of: :record, dependent: false do
|
12
14
|
def active_storage_has_many_fields(klass)
|
13
|
-
klass.reflect_on_all_associations(:has_many)
|
15
|
+
klass.reflect_on_all_associations(:has_many)
|
16
|
+
&.select { |reflection| reflection.class_name == 'ActiveStorage::Attachment' }
|
17
|
+
&.collect { |association| association.name[0..-13] } || []
|
14
18
|
end
|
15
19
|
|
16
20
|
def klass_has_active_storage_fields?(klass)
|
@@ -4,6 +4,6 @@ class ActiveScaffold::Bridges::ActiveStorage < ActiveScaffold::DataStructures::B
|
|
4
4
|
|
5
5
|
def self.install
|
6
6
|
Dir[File.join(__dir__, 'active_storage', '*.rb')].each { |file| require file }
|
7
|
-
ActiveScaffold::Config::Core.
|
7
|
+
ActiveScaffold::Config::Core.prepend ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridge
|
8
8
|
end
|
9
9
|
end
|
@@ -2,7 +2,7 @@ module ActiveScaffold::Bridges
|
|
2
2
|
class Ancestry
|
3
3
|
module AncestryBridge
|
4
4
|
def initialize(model_id)
|
5
|
-
super
|
5
|
+
super
|
6
6
|
|
7
7
|
return unless model.respond_to? :ancestry_column
|
8
8
|
|
@@ -18,7 +18,7 @@ module ActiveScaffold::Bridges
|
|
18
18
|
def active_scaffold_input_ancestry(column, options, ui_options: column.options)
|
19
19
|
record = options[:object]
|
20
20
|
select_options = []
|
21
|
-
select_control_options = {:
|
21
|
+
select_control_options = {selected: record.parent_id}
|
22
22
|
select_control_options[:include_blank] = as_(:_select_) if record.parent_id.nil?
|
23
23
|
method = ui_options[:label_method] || :to_label
|
24
24
|
traverse_ancestry = proc do |key, value|
|
@@ -37,4 +37,4 @@ end
|
|
37
37
|
ActionView::Base.class_eval do
|
38
38
|
include ActiveScaffold::Bridges::Ancestry::FormColumnHelpers
|
39
39
|
end
|
40
|
-
ActiveScaffold::Config::Core.
|
40
|
+
ActiveScaffold::Config::Core.prepend ActiveScaffold::Bridges::Ancestry::AncestryBridge
|
@@ -17,10 +17,13 @@ module ActiveScaffold
|
|
17
17
|
|
18
18
|
def _setup_bitfields
|
19
19
|
return unless model.respond_to?(:bitfields) && model.bitfields.present?
|
20
|
+
|
21
|
+
supported_actions = %i[create update show subform]
|
20
22
|
model.bitfields.each do |column_name, options|
|
21
23
|
columns = options.keys.sort_by { |column| self.columns[column].weight }
|
22
|
-
|
24
|
+
supported_actions.each do |action|
|
23
25
|
next unless actions.include? action
|
26
|
+
|
24
27
|
if send(action).columns.include? column_name
|
25
28
|
send(action).columns.exclude column_name
|
26
29
|
send(action).columns.add_subgroup(column_name) { |group| group.add(*columns) }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class ActiveScaffold::Bridges::Bitfields < ActiveScaffold::DataStructures::Bridge
|
2
2
|
def self.install
|
3
3
|
Dir[File.join(__dir__, 'bitfields', '*.rb')].each { |file| require file }
|
4
|
-
ActiveScaffold::Config::Core.
|
4
|
+
ActiveScaffold::Config::Core.prepend ActiveScaffold::Bridges::Bitfields::BitfieldsBridge
|
5
5
|
ActiveScaffold::Config::Core.after_config_callbacks << :_setup_bitfields
|
6
6
|
end
|
7
7
|
end
|
@@ -10,9 +10,9 @@
|
|
10
10
|
module CanCan
|
11
11
|
module Ability
|
12
12
|
def as_action_aliases
|
13
|
-
alias_action :list, :show_search, :render_field, :
|
14
|
-
alias_action :update_column, :edit_associated, :new_existing, :add_existing, :
|
15
|
-
alias_action :delete, :destroy_existing, :
|
13
|
+
alias_action :list, :show_search, :render_field, to: :read
|
14
|
+
alias_action :update_column, :edit_associated, :new_existing, :add_existing, to: :update
|
15
|
+
alias_action :delete, :destroy_existing, to: :destroy
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -26,8 +26,8 @@ module ActiveScaffold::Bridges
|
|
26
26
|
def active_scaffold(model_id = nil, &block)
|
27
27
|
super
|
28
28
|
authorize_resource(
|
29
|
-
:
|
30
|
-
:
|
29
|
+
class: active_scaffold_config.model,
|
30
|
+
instance: :record
|
31
31
|
)
|
32
32
|
end
|
33
33
|
end
|
@@ -101,19 +101,20 @@ module ActiveScaffold::Bridges
|
|
101
101
|
class InvalidArgument < StandardError; end
|
102
102
|
|
103
103
|
# is usually called with :crud_type and :column, or :action
|
104
|
-
# {:
|
105
|
-
# {:
|
104
|
+
# {crud_type: :update, column: 'some_colum_name'}
|
105
|
+
# {action: 'edit'}
|
106
106
|
# to allow access cancan must allow both :crud_type and :action
|
107
107
|
# if cancan says "no", it delegates to default AS behavior
|
108
108
|
def authorized_for?(options = {})
|
109
109
|
raise InvalidArgument if options[:crud_type].blank? && options[:action].blank?
|
110
|
+
|
110
111
|
if current_ability.present?
|
111
112
|
crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self)
|
112
113
|
action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self)
|
113
114
|
else
|
114
115
|
crud_type_result = action_result = false
|
115
116
|
end
|
116
|
-
result = (crud_type_result && action_result) || super(options.merge(:
|
117
|
+
result = (crud_type_result && action_result) || super(options.merge(reason: nil))
|
117
118
|
# return array with nil reason if requested with options[:reason], we don't have reason but caller expects array
|
118
119
|
options[:reason] ? [result, nil] : result
|
119
120
|
end
|
@@ -2,16 +2,16 @@ class ActiveScaffold::Bridges::Cancan < ActiveScaffold::DataStructures::Bridge
|
|
2
2
|
def self.install
|
3
3
|
require File.join(File.dirname(__FILE__), 'cancan', 'cancan_bridge.rb')
|
4
4
|
|
5
|
-
ActiveScaffold::Core::ClassMethods.
|
6
|
-
ActiveScaffold::Actions::Core.
|
7
|
-
ActiveScaffold::Actions::Nested.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
ActiveScaffold::Core::ClassMethods.prepend ActiveScaffold::Bridges::Cancan::ClassMethods
|
6
|
+
ActiveScaffold::Actions::Core.prepend ActiveScaffold::Bridges::Cancan::Actions::Core
|
7
|
+
ActiveScaffold::Actions::Nested.prepend ActiveScaffold::Bridges::Cancan::Actions::Core
|
8
|
+
ActiveSupport.on_load(:action_controller) { include ActiveScaffold::Bridges::Cancan::ModelUserAccess::Controller }
|
9
|
+
ActiveSupport.on_load(:action_view) { include ActiveScaffold::Bridges::Cancan::AssociationHelpers }
|
10
|
+
ActiveSupport.on_load(:active_record) { include ActiveScaffold::Bridges::Cancan::ModelUserAccess::Model }
|
11
|
+
ActiveSupport.on_load(:active_record) { include ActiveScaffold::Bridges::Cancan::ActiveRecord }
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.install?
|
15
|
-
Object.const_defined?
|
15
|
+
Object.const_defined? :CanCan
|
16
16
|
end
|
17
17
|
end
|
@@ -8,7 +8,7 @@ module ActiveScaffold
|
|
8
8
|
active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'carrierwave_controls', ui_options: ui_options) do
|
9
9
|
cache_field_options = {
|
10
10
|
name: options[:name].gsub(/\[#{column.name}\]$/, "[#{column.name}_cache]"),
|
11
|
-
id: options[:id]
|
11
|
+
id: "#{options[:id]}_cache"
|
12
12
|
}
|
13
13
|
hidden_field(:record, "#{column.name}_cache", cache_field_options)
|
14
14
|
end
|
@@ -4,14 +4,15 @@ module ActiveScaffold
|
|
4
4
|
def active_scaffold_column_carrierwave(record, column, ui_options: column.options)
|
5
5
|
carrierwave = record.send(column.name.to_s)
|
6
6
|
return nil if carrierwave.file.blank?
|
7
|
+
|
7
8
|
thumbnail_style = ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridgeHelpers.thumbnail_style
|
8
9
|
content =
|
9
|
-
if carrierwave.versions.
|
10
|
-
image_tag(carrierwave.url(thumbnail_style), :
|
10
|
+
if carrierwave.versions.key?(thumbnail_style)
|
11
|
+
image_tag(carrierwave.url(thumbnail_style), border: 0)
|
11
12
|
else
|
12
13
|
record.send(record.send(:_mounter, column.name).send(:serialization_column))
|
13
14
|
end
|
14
|
-
link_to(content, carrierwave.url, :
|
15
|
+
link_to(content, carrierwave.url, target: '_blank', rel: 'noopener noreferrer')
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -4,10 +4,10 @@ class ActiveScaffold::Bridges::Carrierwave < ActiveScaffold::DataStructures::Bri
|
|
4
4
|
require File.join(File.dirname(__FILE__), 'carrierwave/list_ui')
|
5
5
|
require File.join(File.dirname(__FILE__), 'carrierwave/carrierwave_bridge_helpers')
|
6
6
|
require File.join(File.dirname(__FILE__), 'carrierwave/carrierwave_bridge')
|
7
|
-
ActiveScaffold::Config::Core.
|
7
|
+
ActiveScaffold::Config::Core.prepend ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridge
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.install?
|
11
|
-
Object.const_defined?
|
11
|
+
Object.const_defined? :CarrierWave
|
12
12
|
end
|
13
13
|
end
|
@@ -3,15 +3,11 @@ class ActiveScaffold::Bridges::Chosen < ActiveScaffold::DataStructures::Bridge
|
|
3
3
|
require File.join(File.dirname(__FILE__), 'chosen/helpers.rb')
|
4
4
|
end
|
5
5
|
|
6
|
-
def self.install?
|
7
|
-
super && %i[jquery prototype].include?(ActiveScaffold.js_framework)
|
8
|
-
end
|
9
|
-
|
10
6
|
def self.stylesheets
|
11
7
|
'chosen'
|
12
8
|
end
|
13
9
|
|
14
10
|
def self.javascripts
|
15
|
-
[
|
11
|
+
['chosen-jquery', 'jquery/active_scaffold_chosen']
|
16
12
|
end
|
17
13
|
end
|