rails_admin 3.1.1 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32f625ca21a5c94c2fc91766ae74ef690a92ff7f882068b70d617ad7b1e1ff3a
4
- data.tar.gz: ed3af9f17b3277f11a4b17db9beffe03d80294b453bb086d7aa819c46ce9cc1d
3
+ metadata.gz: 03f798619ca0b106577088ff39d25d4103d7096198ff66244f4381023033398b
4
+ data.tar.gz: d3bae813acd97182810f9c6ef09fc295888d706810adc314e7992854f7679d84
5
5
  SHA512:
6
- metadata.gz: 2ad917ef318789585952a8e82084d3042960037a441ce1197f752f036e4f581107c37b0dab9466627fbe60e3f22e03d9a62f9af2f92ab9d77b1f5e02cfc85167
7
- data.tar.gz: 02225217c1f2997fccfce31605d494bdc5668778482ccb8c84231cf431efaafa4a830988526c1bfae88cac4a0342d41d1d7bd10b9507a8c60c2da2f1131d3250
6
+ metadata.gz: 5ee60d19acc72d93e8b14c7e568ff924ea54558f9de807845cbd278230dc852d119c332b9866b673aea0757cb3f380d6c5abd09af4c71119626cf47c4cd67e6f
7
+ data.tar.gz: 74de744e2e07902613ebc9be3975ff6d68aaa7b4e4d38b2b7c0e59b30a5e3c3313331208f911a73419ec6551f98e1e7b2ad67976cbc7a0887f547444436e5ffb
data/Gemfile CHANGED
@@ -14,7 +14,7 @@ group :active_record do
14
14
 
15
15
  platforms :ruby, :mswin, :mingw, :x64_mingw do
16
16
  gem 'mysql2', '>= 0.3.14'
17
- gem 'sqlite3', '>= 1.3'
17
+ gem 'sqlite3', '~> 1.3'
18
18
  end
19
19
  end
20
20
 
@@ -29,7 +29,7 @@ group :test do
29
29
  gem 'database_cleaner-active_record', '>= 2.0', require: false
30
30
  gem 'database_cleaner-mongoid', '>= 2.0', require: false
31
31
  gem 'dragonfly', '~> 1.0'
32
- gem 'factory_bot', '>= 4.2'
32
+ gem 'factory_bot', '>= 4.2', '!= 6.4.5'
33
33
  gem 'generator_spec', '>= 0.8'
34
34
  gem 'launchy', '>= 2.2'
35
35
  gem 'mini_magick', '>= 3.4'
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # RailsAdmin
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/rails_admin.svg)][gem]
4
- [![Build Status](https://img.shields.io/github/workflow/status/railsadminteam/rails_admin/Test)][ghactions]
4
+ [![Build Status](https://github.com/railsadminteam/rails_admin/actions/workflows/test.yml/badge.svg)][ghactions]
5
5
  [![Coverage Status](https://img.shields.io/coveralls/railsadminteam/rails_admin.svg)][coveralls]
6
6
  [![Code Climate](https://codeclimate.com/github/railsadminteam/rails_admin.svg)][codeclimate]
7
7
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=rails_admin&package-manager=bundler&version-scheme=semver)][semver]
8
8
 
9
9
  [gem]: https://rubygems.org/gems/rails_admin
10
- [ghactions]: https://github.com/railsadminteam/rails_admin/actions
10
+ [ghactions]: https://github.com/railsadminteam/rails_admin/actions/workflows/test.yml
11
11
  [coveralls]: https://coveralls.io/r/railsadminteam/rails_admin
12
12
  [codeclimate]: https://codeclimate.com/github/railsadminteam/rails_admin
13
13
  [semver]: https://dependabot.com/compatibility-score.html?dependency-name=rails_admin&package-manager=bundler&version-scheme=semver
@@ -98,6 +98,8 @@ This library aims to support and is [tested against][ghactions] the following Ru
98
98
  - Ruby 2.6
99
99
  - Ruby 2.7
100
100
  - Ruby 3.0
101
+ - Ruby 3.1
102
+ - Ruby 3.2
101
103
  - [JRuby][]
102
104
 
103
105
  [jruby]: http://jruby.org/
@@ -19,8 +19,8 @@
19
19
  <%= stylesheet_link_tag "rails_admin.css", media: :all, data: {'turbo-track': 'reload'} %>
20
20
  <%= javascript_inline_importmap_tag(RailsAdmin::Engine.importmap.to_json(resolver: self)) %>
21
21
  <%= javascript_importmap_module_preload_tags(RailsAdmin::Engine.importmap) %>
22
- <%= javascript_importmap_shim_nonce_configuration_tag %>
23
- <%= javascript_importmap_shim_tag %>
22
+ <%= javascript_importmap_shim_nonce_configuration_tag if respond_to? :javascript_importmap_shim_nonce_configuration_tag %>
23
+ <%= javascript_importmap_shim_tag if respond_to? :javascript_importmap_shim_tag %>
24
24
  <%= # Preload jQuery and make it global, unless jQuery UI fails to initialize
25
25
  tag.script "import jQuery from 'jquery'; window.jQuery = jQuery;".html_safe, type: "module" %>
26
26
  <%= javascript_import_module_tag 'rails_admin' %>
@@ -133,7 +133,7 @@
133
133
  <% end %>
134
134
  <% properties.map{ |property| property.bind(:object, object) }.each do |property| %>
135
135
  <% value = property.pretty_value %>
136
- <td class="<%= [property.sticky? && 'sticky', property.css_class, property.type_css_class].select(&:present?).join(' ') %>" title="<%= strip_tags(value.to_s) %>">
136
+ <td class="<%= [property.sticky? && 'sticky', property.css_class, property.type_css_class].select(&:present?).join(' ') %>" title="<%= value %>">
137
137
  <%= value %>
138
138
  </td>
139
139
  <% end %>
@@ -11,7 +11,7 @@ module RailsAdmin
11
11
  end
12
12
 
13
13
  def format
14
- imports = packager.import("rails_admin@#{RailsAdmin::Version.js}")
14
+ imports = packager.import("rails_admin@#{RailsAdmin::Version.js}", from: 'jspm.io')
15
15
 
16
16
  # Use ESM compatible version to work around https://github.com/cljsjs/packages/issues/1579
17
17
  imports['@popperjs/core'].gsub!('lib/index.js', 'dist/esm/popper.js')
@@ -71,9 +71,9 @@ module RailsAdmin
71
71
  def key_accessor
72
72
  case type
73
73
  when :has_many, :has_and_belongs_to_many
74
- "#{name.to_s.singularize}_ids".to_sym
74
+ :"#{name.to_s.singularize}_ids"
75
75
  when :has_one
76
- "#{name}_id".to_sym
76
+ :"#{name}_id"
77
77
  else
78
78
  foreign_key
79
79
  end
@@ -172,7 +172,7 @@ module RailsAdmin
172
172
  # "0055" is the filter index, no use here. o is the operator, v the value
173
173
  def filter_scope(scope, filters, fields = config.list.fields.select(&:filterable?))
174
174
  filters.each_pair do |field_name, filters_dump|
175
- filters_dump.each do |_, filter_dump|
175
+ filters_dump.each_value do |filter_dump|
176
176
  wb = WhereBuilder.new(scope)
177
177
  field = fields.detect { |f| f.name.to_s == field_name }
178
178
  value = parse_field_value(field, filter_dump[:v])
@@ -256,7 +256,8 @@ module RailsAdmin
256
256
 
257
257
  def build_statement_for_boolean
258
258
  return ["(#{@column} IS NULL OR #{@column} = ?)", false] if %w[false f 0].include?(@value)
259
- return ["(#{@column} = ?)", true] if %w[true t 1].include?(@value)
259
+
260
+ ["(#{@column} = ?)", true] if %w[true t 1].include?(@value)
260
261
  end
261
262
 
262
263
  def column_for_value(value)
@@ -0,0 +1,348 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+ require 'rails_admin/adapters/active_record/association'
5
+ require 'rails_admin/adapters/active_record/model_extension'
6
+ require 'rails_admin/adapters/active_record/property'
7
+
8
+ module RailsAdmin
9
+ module Adapters
10
+ module ActiveRecord
11
+ DISABLED_COLUMN_TYPES = %i[tsvector blob binary spatial hstore geometry].freeze
12
+
13
+ def model_with_extension
14
+ @model_with_extension ||=
15
+ begin
16
+ klass = Class.new(model) do
17
+ include ModelExtension
18
+ end
19
+ klass.instance_eval <<-RUBY, __FILE__, __LINE__+1
20
+ def name
21
+ "#{@model_name.to_s}"
22
+ end
23
+ RUBY
24
+ klass
25
+ end
26
+ end
27
+
28
+ def new(params = {})
29
+ model_with_extension.new(params)
30
+ end
31
+
32
+ def get(id, scope = nil)
33
+ scope = model_with_extension.merge(scope || scoped)
34
+ scope.where(primary_key => id).first
35
+ end
36
+
37
+ def scoped
38
+ model_with_extension.all
39
+ end
40
+
41
+ def first(options = {}, scope = nil)
42
+ all(options, scope).first
43
+ end
44
+
45
+ def all(options = {}, scope = nil)
46
+ scope = model_with_extension.merge(scope || scoped)
47
+ scope = scope.includes(options[:include]) if options[:include]
48
+ scope = scope.limit(options[:limit]) if options[:limit]
49
+ scope = bulk_scope(scope, options) if options[:bulk_ids]
50
+ scope = query_scope(scope, options[:query]) if options[:query]
51
+ scope = filter_scope(scope, options[:filters]) if options[:filters]
52
+ scope = scope.send(Kaminari.config.page_method_name, options[:page]).per(options[:per]) if options[:page] && options[:per]
53
+ scope = sort_scope(scope, options) if options[:sort]
54
+ scope
55
+ end
56
+
57
+ def count(options = {}, scope = nil)
58
+ all(options.merge(limit: false, page: false), scope).count(:all)
59
+ end
60
+
61
+ def destroy(objects)
62
+ Array.wrap(objects).each(&:destroy)
63
+ end
64
+
65
+ def associations
66
+ model.reflect_on_all_associations.collect do |association|
67
+ Association.new(association, model)
68
+ end
69
+ end
70
+
71
+ def properties
72
+ columns = model.columns.reject do |c|
73
+ c.type.blank? ||
74
+ DISABLED_COLUMN_TYPES.include?(c.type.to_sym) ||
75
+ c.try(:array)
76
+ end
77
+ columns.collect do |property|
78
+ Property.new(property, model)
79
+ end
80
+ end
81
+
82
+ def base_class
83
+ model.base_class
84
+ end
85
+
86
+ delegate :primary_key, :table_name, to: :model, prefix: false
87
+
88
+ def quoted_table_name
89
+ model.quoted_table_name
90
+ end
91
+
92
+ def quote_column_name(name)
93
+ model.connection.quote_column_name(name)
94
+ end
95
+
96
+ def encoding
97
+ adapter =
98
+ if ::ActiveRecord::Base.respond_to?(:connection_db_config)
99
+ ::ActiveRecord::Base.connection_db_config.configuration_hash[:adapter]
100
+ else
101
+ ::ActiveRecord::Base.connection_config[:adapter]
102
+ end
103
+ case adapter
104
+ when 'postgresql'
105
+ ::ActiveRecord::Base.connection.select_one("SELECT ''::text AS str;").values.first.encoding
106
+ when 'mysql2'
107
+ if RUBY_ENGINE == 'jruby'
108
+ ::ActiveRecord::Base.connection.select_one("SELECT '' AS str;").values.first.encoding
109
+ else
110
+ ::ActiveRecord::Base.connection.raw_connection.encoding
111
+ end
112
+ when 'oracle_enhanced'
113
+ ::ActiveRecord::Base.connection.select_one('SELECT dummy FROM DUAL').values.first.encoding
114
+ else
115
+ ::ActiveRecord::Base.connection.select_one("SELECT '' AS str;").values.first.encoding
116
+ end
117
+ end
118
+
119
+ def embedded?
120
+ false
121
+ end
122
+
123
+ def cyclic?
124
+ false
125
+ end
126
+
127
+ def adapter_supports_joins?
128
+ true
129
+ end
130
+
131
+ private
132
+
133
+ def bulk_scope(scope, options)
134
+ scope.where(primary_key => options[:bulk_ids])
135
+ end
136
+
137
+ def sort_scope(scope, options)
138
+ direction = options[:sort_reverse] ? :asc : :desc
139
+ case options[:sort]
140
+ when String, Symbol
141
+ scope.reorder("#{options[:sort]} #{direction}")
142
+ when Array
143
+ scope.reorder(options[:sort].zip(Array.new(options[:sort].size) { direction }).to_h)
144
+ when Hash
145
+ scope.reorder(options[:sort].map { |table_name, column| "#{table_name}.#{column}" }.
146
+ zip(Array.new(options[:sort].size) { direction }).to_h)
147
+ else
148
+ raise ArgumentError.new("Unsupported sort value: #{options[:sort]}")
149
+ end
150
+ end
151
+
152
+ class WhereBuilder
153
+ def initialize(scope)
154
+ @statements = []
155
+ @values = []
156
+ @tables = []
157
+ @scope = scope
158
+ end
159
+
160
+ def add(field, value, operator)
161
+ field.searchable_columns.flatten.each do |column_infos|
162
+ statement, value1, value2 = StatementBuilder.new(column_infos[:column], column_infos[:type], value, operator, @scope.connection.adapter_name).to_statement
163
+ @statements << statement if statement.present?
164
+ @values << value1 unless value1.nil?
165
+ @values << value2 unless value2.nil?
166
+ table, column = column_infos[:column].split('.')
167
+ @tables.push(table) if column
168
+ end
169
+ end
170
+
171
+ def build
172
+ scope = @scope.where(@statements.join(' OR '), *@values)
173
+ scope = scope.references(*@tables.uniq) if @tables.any?
174
+ scope
175
+ end
176
+ end
177
+
178
+ def query_scope(scope, query, fields = config.list.fields.select(&:queryable?))
179
+ if config.list.search_by
180
+ scope.send(config.list.search_by, query)
181
+ else
182
+ wb = WhereBuilder.new(scope)
183
+ fields.each do |field|
184
+ value = parse_field_value(field, query)
185
+ wb.add(field, value, field.search_operator)
186
+ end
187
+ # OR all query statements
188
+ wb.build
189
+ end
190
+ end
191
+
192
+ # filters example => {"string_field"=>{"0055"=>{"o"=>"like", "v"=>"test_value"}}, ...}
193
+ # "0055" is the filter index, no use here. o is the operator, v the value
194
+ def filter_scope(scope, filters, fields = config.list.fields.select(&:filterable?))
195
+ filters.each_pair do |field_name, filters_dump|
196
+ filters_dump.each_value do |filter_dump|
197
+ wb = WhereBuilder.new(scope)
198
+ field = fields.detect { |f| f.name.to_s == field_name }
199
+ value = parse_field_value(field, filter_dump[:v])
200
+
201
+ wb.add(field, value, (filter_dump[:o] || RailsAdmin::Config.default_search_operator))
202
+ # AND current filter statements to other filter statements
203
+ scope = wb.build
204
+ end
205
+ end
206
+ scope
207
+ end
208
+
209
+ def build_statement(column, type, value, operator)
210
+ StatementBuilder.new(column, type, value, operator, model.connection.adapter_name).to_statement
211
+ end
212
+
213
+ class StatementBuilder < RailsAdmin::AbstractModel::StatementBuilder
214
+ def initialize(column, type, value, operator, adapter_name)
215
+ super column, type, value, operator
216
+ @adapter_name = adapter_name
217
+ end
218
+
219
+ protected
220
+
221
+ def unary_operators
222
+ case @type
223
+ when :boolean
224
+ boolean_unary_operators
225
+ when :uuid
226
+ uuid_unary_operators
227
+ when :integer, :decimal, :float
228
+ numeric_unary_operators
229
+ else
230
+ generic_unary_operators
231
+ end
232
+ end
233
+
234
+ private
235
+
236
+ def generic_unary_operators
237
+ {
238
+ '_blank' => ["(#{@column} IS NULL OR #{@column} = '')"],
239
+ '_present' => ["(#{@column} IS NOT NULL AND #{@column} != '')"],
240
+ '_null' => ["(#{@column} IS NULL)"],
241
+ '_not_null' => ["(#{@column} IS NOT NULL)"],
242
+ '_empty' => ["(#{@column} = '')"],
243
+ '_not_empty' => ["(#{@column} != '')"],
244
+ }
245
+ end
246
+
247
+ def boolean_unary_operators
248
+ generic_unary_operators.merge(
249
+ '_blank' => ["(#{@column} IS NULL)"],
250
+ '_empty' => ["(#{@column} IS NULL)"],
251
+ '_present' => ["(#{@column} IS NOT NULL)"],
252
+ '_not_empty' => ["(#{@column} IS NOT NULL)"],
253
+ )
254
+ end
255
+ alias_method :numeric_unary_operators, :boolean_unary_operators
256
+ alias_method :uuid_unary_operators, :boolean_unary_operators
257
+
258
+ def range_filter(min, max)
259
+ if min && max && min == max
260
+ ["(#{@column} = ?)", min]
261
+ elsif min && max
262
+ ["(#{@column} BETWEEN ? AND ?)", min, max]
263
+ elsif min
264
+ ["(#{@column} >= ?)", min]
265
+ elsif max
266
+ ["(#{@column} <= ?)", max]
267
+ end
268
+ end
269
+
270
+ def build_statement_for_type
271
+ case @type
272
+ when :boolean then build_statement_for_boolean
273
+ when :integer, :decimal, :float then build_statement_for_integer_decimal_or_float
274
+ when :string, :text, :citext then build_statement_for_string_or_text
275
+ when :enum then build_statement_for_enum
276
+ when :belongs_to_association then build_statement_for_belongs_to_association
277
+ when :uuid then build_statement_for_uuid
278
+ end
279
+ end
280
+
281
+ def build_statement_for_boolean
282
+ case @value
283
+ when 'false', 'f', '0'
284
+ ["(#{@column} IS NULL OR #{@column} = ?)", false]
285
+ when 'true', 't', '1'
286
+ ["(#{@column} = ?)", true]
287
+ end
288
+ end
289
+
290
+ def column_for_value(value)
291
+ ["(#{@column} = ?)", value]
292
+ end
293
+
294
+ def build_statement_for_belongs_to_association
295
+ return if @value.blank?
296
+
297
+ ["(#{@column} = ?)", @value.to_i] if @value.to_i.to_s == @value
298
+ end
299
+
300
+ def build_statement_for_string_or_text
301
+ return if @value.blank?
302
+
303
+ return ["(#{@column} = ?)", @value] if ['is', '='].include?(@operator)
304
+
305
+ @value = @value.mb_chars.downcase unless %w[postgresql postgis].include? ar_adapter
306
+
307
+ @value =
308
+ case @operator
309
+ when 'default', 'like', 'not_like'
310
+ "%#{@value}%"
311
+ when 'starts_with'
312
+ "#{@value}%"
313
+ when 'ends_with'
314
+ "%#{@value}"
315
+ else
316
+ return
317
+ end
318
+
319
+ if %w[postgresql postgis].include? ar_adapter
320
+ if @operator == 'not_like'
321
+ ["(#{@column} NOT ILIKE ?)", @value]
322
+ else
323
+ ["(#{@column} ILIKE ?)", @value]
324
+ end
325
+ elsif @operator == 'not_like'
326
+ ["(LOWER(#{@column}) NOT LIKE ?)", @value]
327
+ else
328
+ ["(LOWER(#{@column}) LIKE ?)", @value]
329
+ end
330
+ end
331
+
332
+ def build_statement_for_enum
333
+ return if @value.blank?
334
+
335
+ ["(#{@column} IN (?))", Array.wrap(@value)]
336
+ end
337
+
338
+ def build_statement_for_uuid
339
+ column_for_value(@value) if /\A[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\z/.match?(@value.to_s)
340
+ end
341
+
342
+ def ar_adapter
343
+ @adapter_name.downcase
344
+ end
345
+ end
346
+ end
347
+ end
348
+ end
@@ -92,9 +92,9 @@ module RailsAdmin
92
92
  def key_accessor
93
93
  case macro.to_sym
94
94
  when :has_many
95
- "#{name.to_s.singularize}_ids".to_sym
95
+ :"#{name.to_s.singularize}_ids"
96
96
  when :has_one
97
- "#{name}_id".to_sym
97
+ :"#{name}_id"
98
98
  when :embedded_in, :embeds_one, :embeds_many
99
99
  nil
100
100
  else
@@ -21,6 +21,7 @@ module RailsAdmin
21
21
  Moped::Errors::InvalidObjectId
22
22
  BSON::ObjectId::Invalid
23
23
  BSON::InvalidObjectId
24
+ BSON::Error::InvalidObjectId
24
25
  ].exclude?(e.class.to_s)
25
26
  end
26
27
  end
@@ -31,6 +31,7 @@ module RailsAdmin
31
31
  Mongoid::Errors::InvalidFind
32
32
  Moped::Errors::InvalidObjectId
33
33
  BSON::InvalidObjectId
34
+ BSON::Error::InvalidObjectId
34
35
  ].exclude?(e.class.to_s)
35
36
  end
36
37
 
@@ -152,7 +153,7 @@ module RailsAdmin
152
153
  statements = []
153
154
 
154
155
  filters.each_pair do |field_name, filters_dump|
155
- filters_dump.each do |_, filter_dump|
156
+ filters_dump.each_value do |filter_dump|
156
157
  field = fields.detect { |f| f.name.to_s == field_name }
157
158
  next unless field
158
159
 
@@ -251,7 +252,8 @@ module RailsAdmin
251
252
 
252
253
  def build_statement_for_boolean
253
254
  return {@column => false} if %w[false f 0].include?(@value)
254
- return {@column => true} if %w[true t 1].include?(@value)
255
+
256
+ {@column => true} if %w[true t 1].include?(@value)
255
257
  end
256
258
 
257
259
  def column_for_value(value)
@@ -357,7 +357,7 @@ module RailsAdmin
357
357
 
358
358
  def generic_field_help
359
359
  model = abstract_model.model_name.underscore
360
- model_lookup = "admin.help.#{model}.#{name}".to_sym
360
+ model_lookup = :"admin.help.#{model}.#{name}"
361
361
  translated = I18n.translate(model_lookup, help: generic_help, default: [generic_help])
362
362
  (translated.is_a?(Hash) ? translated.to_a.first[1] : translated).html_safe
363
363
  end
@@ -13,9 +13,9 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
13
13
  fields << field
14
14
  associations =
15
15
  if properties.type == :has_many
16
- ["#{name}_attachments".to_sym, "#{name}_blobs".to_sym]
16
+ [:"#{name}_attachments", :"#{name}_blobs"]
17
17
  else
18
- ["#{name}_attachment".to_sym, "#{name}_blob".to_sym]
18
+ [:"#{name}_attachment", :"#{name}_blob"]
19
19
  end
20
20
  children_fields = associations.map do |child_name|
21
21
  child_association = parent.abstract_model.associations.detect { |p| p.name.to_sym == child_name }
@@ -7,7 +7,7 @@ require 'rails_admin/config/fields/types/file_upload'
7
7
  RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
8
8
  model = parent.abstract_model.model
9
9
  if defined?(::CarrierWave) && model.is_a?(CarrierWave::Mount) && model.uploaders.include?(attachment_name = properties.name.to_s.chomp('_file_name').to_sym)
10
- columns = [model.uploader_options[attachment_name][:mount_on] || attachment_name, "#{attachment_name}_content_type".to_sym, "#{attachment_name}_file_size".to_sym]
10
+ columns = [model.uploader_options[attachment_name][:mount_on] || attachment_name, :"#{attachment_name}_content_type", :"#{attachment_name}_file_size"]
11
11
  field = RailsAdmin::Config::Fields::Types.load(
12
12
  %i[serialized json].include?(properties.type) ? :multiple_carrierwave : :carrierwave,
13
13
  ).new(parent, attachment_name, properties)
@@ -10,7 +10,7 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
10
10
  field = RailsAdmin::Config::Fields::Types.load(:dragonfly).new(parent, attachment_name, properties)
11
11
  children_fields = []
12
12
  extensions.each do |ext|
13
- children_column_name = "#{attachment_name}_#{ext}".to_sym
13
+ children_column_name = :"#{attachment_name}_#{ext}"
14
14
  child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
15
15
  next unless child_properties
16
16
 
@@ -11,7 +11,7 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
11
11
  field = RailsAdmin::Config::Fields::Types.load(:paperclip).new(parent, attachment_name, properties)
12
12
  children_fields = []
13
13
  extensions.each do |ext|
14
- children_column_name = "#{attachment_name}_#{ext}".to_sym
14
+ children_column_name = :"#{attachment_name}_#{ext}"
15
15
  child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
16
16
  next unless child_properties
17
17
 
@@ -16,7 +16,7 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
16
16
  field = RailsAdmin::Config::Fields::Types.load(:shrine).new(parent, attachment_name, properties)
17
17
  fields << field
18
18
 
19
- data_field_name = "#{attachment_name}_data".to_sym
19
+ data_field_name = :"#{attachment_name}_data"
20
20
  child_properties = parent.abstract_model.properties.detect { |p| p.name == data_field_name }
21
21
  next true unless child_properties
22
22
 
@@ -38,7 +38,7 @@ module RailsAdmin
38
38
  end
39
39
 
40
40
  def method_name
41
- nested_form ? "#{name}_attributes".to_sym : super
41
+ nested_form ? :"#{name}_attributes" : super
42
42
  end
43
43
 
44
44
  def multiple?
@@ -20,7 +20,7 @@ module RailsAdmin
20
20
  end
21
21
 
22
22
  def method_name
23
- nested_form ? "#{name}_attributes".to_sym : super
23
+ nested_form ? :"#{name}_attributes" : super
24
24
  end
25
25
 
26
26
  # Reader for validation errors of the bound object
@@ -28,7 +28,7 @@ module RailsAdmin
28
28
  end
29
29
 
30
30
  def method_name
31
- nested_form ? "#{name}_attributes".to_sym : super
31
+ nested_form ? :"#{name}_attributes" : super
32
32
  end
33
33
 
34
34
  def multiple?
@@ -48,7 +48,9 @@ module RailsAdmin
48
48
  end
49
49
 
50
50
  def excluded?
51
- @excluded ||= !RailsAdmin::AbstractModel.all.collect(&:model_name).include?(abstract_model.try(:model_name))
51
+ return @excluded if defined?(@excluded)
52
+
53
+ @excluded = !RailsAdmin::AbstractModel.all.collect(&:model_name).include?(abstract_model.try(:model_name))
52
54
  end
53
55
 
54
56
  def object_label
@@ -364,23 +364,22 @@ module RailsAdmin
364
364
 
365
365
  private
366
366
 
367
- def lchomp(base, arg)
368
- base.to_s.reverse.chomp(arg.to_s.reverse).reverse
369
- end
370
-
371
367
  def viable_models
372
368
  included_models.collect(&:to_s).presence || begin
373
369
  @@system_models ||= # memoization for tests
374
370
  ([Rails.application] + Rails::Engine.subclasses.collect(&:instance)).flat_map do |app|
375
371
  (app.paths['app/models'].to_a + app.config.eager_load_paths).collect do |load_path|
376
372
  Dir.glob(app.root.join(load_path)).collect do |load_dir|
373
+ path_prefix = "#{app.root.join(load_dir)}/"
377
374
  Dir.glob("#{load_dir}/**/*.rb").collect do |filename|
378
375
  # app/models/module/class.rb => module/class.rb => module/class => Module::Class
379
- lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize
376
+ filename.delete_prefix(path_prefix).chomp('.rb').camelize
380
377
  end
381
378
  end
382
379
  end
383
380
  end.flatten.reject { |m| m.starts_with?('Concerns::') } # rubocop:disable Style/MultilineBlockChain
381
+
382
+ @@system_models + @registry.keys.collect(&:to_s)
384
383
  end
385
384
  end
386
385
 
@@ -146,7 +146,7 @@ module RailsAdmin
146
146
  versions = object.nil? ? versions_for_model(model) : object.public_send(model.model.versions_association_name)
147
147
  versions = versions.where('event LIKE ?', "%#{query}%") if query.present?
148
148
  versions = versions.order(sort)
149
- versions = all ? versions : versions.send(Kaminari.config.page_method_name, current_page).per(per_page)
149
+ versions = versions.send(Kaminari.config.page_method_name, current_page).per(per_page) unless all
150
150
  paginated_proxies = Kaminari.paginate_array([], total_count: versions.try(:total_count) || versions.count)
151
151
  paginated_proxies = paginated_proxies.send(
152
152
  paginated_proxies.respond_to?(Kaminari.config.page_method_name) ? Kaminari.config.page_method_name : :page,
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'csv'
@@ -4,7 +4,7 @@ module RailsAdmin
4
4
  class Version
5
5
  MAJOR = 3
6
6
  MINOR = 1
7
- PATCH = 1
7
+ PATCH = 3
8
8
  PRE = nil
9
9
 
10
10
  class << self
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rails_admin",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data.",
5
5
  "homepage": "https://github.com/railsadminteam/rails_admin",
6
6
  "license": "MIT",
@@ -88,7 +88,7 @@ import I18n from "./i18n";
88
88
  $(document).ready(triggerDomReady);
89
89
  document.addEventListener("turbo:render", triggerDomReady);
90
90
 
91
- document.addEventListener("rails_admin.dom_ready", function () {
91
+ document.addEventListener("rails_admin.dom_ready", function (event) {
92
92
  $(".nav.nav-pills li.active").removeClass("active");
93
93
  $(
94
94
  '.nav.nav-pills li[data-model="' + $(".page-header").data("model") + '"]'
@@ -129,6 +129,12 @@ import I18n from "./i18n";
129
129
  $("a[data-method]").on("click", function (event) {
130
130
  window.Turbo.session.drive = false;
131
131
  });
132
+
133
+ // Trigger via jQuery for compatibility with existing user codes
134
+ $(document).trigger(
135
+ "rails_admin.dom_ready",
136
+ event.detail ? [event.detail] : null
137
+ );
132
138
  });
133
139
 
134
140
  $(document).on("click", ".bulk-link", function (event) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2022-12-18 00:00:00.000000000 Z
15
+ date: 2024-07-06 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activemodel-serializers-xml
@@ -195,6 +195,7 @@ files:
195
195
  - lib/rails_admin.rb
196
196
  - lib/rails_admin/abstract_model.rb
197
197
  - lib/rails_admin/adapters/active_record.rb
198
+ - lib/rails_admin/adapters/active_record.rb.bak
198
199
  - lib/rails_admin/adapters/active_record/association.rb
199
200
  - lib/rails_admin/adapters/active_record/object_extension.rb
200
201
  - lib/rails_admin/adapters/active_record/property.rb
@@ -466,7 +467,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
466
467
  - !ruby/object:Gem::Version
467
468
  version: 1.8.11
468
469
  requirements: []
469
- rubygems_version: 3.3.7
470
+ rubygems_version: 3.2.33
470
471
  signing_key:
471
472
  specification_version: 4
472
473
  summary: Admin for Rails