brick 1.0.122 → 1.0.123

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: b1f047f700bc850e0e54210cd9669e2877c2d770010f42c82b7f2616ad14f542
4
- data.tar.gz: e89b2be75f7d961b24681b4e6c5aeb8beedef51e2537759f93a68baff1787e60
3
+ metadata.gz: baad039242ee5623097ad6170fec07e5feb0eb2fed6d41a9079f0775cccaceea
4
+ data.tar.gz: 603377f6b2c4437c448630bce6581d3650b8dfc13187e82afbaab1d425d171e2
5
5
  SHA512:
6
- metadata.gz: 54418f3b20260bea82b912383038fce3a019a6daf85e56714a1eb2331c7aa130c44706d64e8d1c86502d9ed7c6f7ece730b8a3d467fbe77ee3e699f8e2eb1586
7
- data.tar.gz: baf068daf69952fd2235b14abddd93420b73984912eef5da6ffc33699db124058b2e6a093d9984d2fe31abbe620e6d51d5bdbecc5cf23297f6c31b4d4450ed71
6
+ metadata.gz: 1f4e48c1a437684929a81ace3e75ab15bb627c006680dba5a7454825fba358142560712f016bf944575aefeb27655716c3212d72a2b9b5a083a09cd2dfa8537c
7
+ data.tar.gz: ea9c376866230e4c2bab7b6c34dfc435a8cf81b568bc22af3a0e69497accca1620152ae311eab6c96649b79ecedf978b880afa88888dc6d1c4d3700bc3ef3060
@@ -1859,18 +1859,27 @@ class Object
1859
1859
  instance_variable_set("@#{singular_table_name}".to_sym, (obj = find_obj))
1860
1860
  upd_params = send(params_name_sym)
1861
1861
  json_overrides = ::Brick.config.json_columns&.fetch(table_name, nil)
1862
- if (json_cols = model.columns.select { |c| c.type == :json || json_overrides&.include?(c.name) }.map(&:name)).present?
1862
+ if model.respond_to?(:devise_modules)
1863
1863
  upd_hash = upd_params.to_h
1864
+ upd_hash['reset_password_token'] = nil if upd_hash['reset_password_token'].blank?
1865
+ upd_hash['reset_password_sent_at'] = nil if upd_hash['reset_password_sent_at'].blank?
1866
+ if model.devise_modules.include?(:invitable)
1867
+ upd_hash['invitation_token'] = nil if upd_hash['invitation_token'].blank?
1868
+ upd_hash['invitation_created_at'] = nil if upd_hash['invitation_created_at'].blank?
1869
+ upd_hash['invitation_sent_at'] = nil if upd_hash['invitation_sent_at'].blank?
1870
+ upd_hash['invitation_accepted_at'] = nil if upd_hash['invitation_accepted_at'].blank?
1871
+ end
1872
+ end
1873
+ if (json_cols = model.columns.select { |c| c.type == :json || json_overrides&.include?(c.name) }.map(&:name)).present?
1874
+ upd_hash ||= upd_params.to_h
1864
1875
  json_cols.each do |c|
1865
1876
  begin
1866
1877
  upd_hash[c] = JSON.parse(upd_hash[c].tr('`', '"').gsub('^^br_btick__', '`'))
1867
1878
  rescue
1868
1879
  end
1869
1880
  end
1870
- obj.send(:update, upd_hash)
1871
- else
1872
- obj.send(:update, upd_params)
1873
1881
  end
1882
+ obj.send(:update, upd_hash || upd_params)
1874
1883
  end
1875
1884
 
1876
1885
  code << " def destroy\n"
@@ -1906,10 +1915,11 @@ class Object
1906
1915
  end
1907
1916
  end
1908
1917
  # Support friendly_id gem
1918
+ id_simplified = id.is_a?(Array) && id.length == 1 ? id.first : id
1909
1919
  if Object.const_defined?('FriendlyId') && model.instance_variable_get(:@friendly_id_config)
1910
- model.friendly.find(id.is_a?(Array) && id.length == 1 ? id.first : id)
1920
+ model.friendly.find(id_simplified)
1911
1921
  else
1912
- model.find(id.is_a?(Array) && id.length == 1 ? id.first : id)
1922
+ model.find(id_simplified)
1913
1923
  end
1914
1924
  end
1915
1925
  end
@@ -2044,8 +2054,18 @@ end.class_exec do
2044
2054
  load inflections
2045
2055
  end
2046
2056
  # Now the Brick initializer since there may be important schema things configured
2047
- if File.exist?(brick_initializer = ::Rails.root.join('config/initializers/brick.rb'))
2057
+ if !::Brick.initializer_loaded && File.exist?(brick_initializer = ::Rails.root.join('config/initializers/brick.rb'))
2048
2058
  ::Brick.initializer_loaded = load brick_initializer
2059
+
2060
+ # After loading the initializer, add compatibility for ActiveStorage and ActionText if those haven't already been
2061
+ # defined. (Further JSON configuration for ActiveStorage metadata happens later in the after_initialize hook.)
2062
+ ['ActiveStorage', 'ActionText'].each do |ar_extension|
2063
+ if Object.const_defined?(ar_extension) &&
2064
+ (extension = Object.const_get(ar_extension)).respond_to?(:table_name_prefix) &&
2065
+ !::Brick.config.table_name_prefixes.key?(as_tnp = extension.table_name_prefix)
2066
+ ::Brick.config.table_name_prefixes[as_tnp] = ar_extension
2067
+ end
2068
+ end
2049
2069
  end
2050
2070
  # Load the initializer for the Apartment gem a little early so that if .excluded_models and
2051
2071
  # .default_schema are specified then we can work with non-tenanted models more appropriately
@@ -188,6 +188,17 @@ function linkSchemas() {
188
188
  (app.config.assets.paths ||= []) << assets_path
189
189
  end
190
190
 
191
+ # Treat ActiveStorage::Blob metadata as JSON
192
+ if ::Brick.config.table_name_prefixes.fetch('active_storage_', nil) == 'ActiveStorage' &&
193
+ ActiveStorage.const_defined?('Blob')
194
+ unless (md = (::Brick.config.model_descrips ||= {})).key?('ActiveStorage::Blob')
195
+ md['ActiveStorage::Blob'] = '[filename]'
196
+ end
197
+ unless (asbm = (::Brick.config.json_columns['active_storage_blobs'] ||= [])).include?('metadata')
198
+ asbm << 'metadata'
199
+ end
200
+ end
201
+
191
202
  # Smarten up Avo so it recognises Brick's querystring option for Apartment multi-tenancy
192
203
  if Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace)
193
204
  module ::Avo
@@ -586,7 +597,11 @@ window.addEventListener(\"popstate\", linkSchemas);
586
597
  return possible_template
587
598
  end
588
599
  rescue StandardError => e
589
- find_template_err = e # Can come up with stuff like Devise which has its own view templates
600
+ # Search through the routes to confirm that something might match (Devise stuff for instance, which has its own view templates),
601
+ # and bubble the same exception (probably an ActionView::MissingTemplate) if a legitimate option is found.
602
+ raise if ::Rails.application.routes.set.find { |x| args[1].include?(x.defaults[:controller]) && args[0] == x.defaults[:action] }
603
+
604
+ find_template_err = e
590
605
  end
591
606
  # Used to also have: ActionView.version < ::Gem::Version.new('5.0') &&
592
607
  model_name = set_brick_model(args, @_brick_req_params)&.name
@@ -646,7 +661,7 @@ window.addEventListener(\"popstate\", linkSchemas);
646
661
  (hm_fk_name.is_a?(String) && hm_fk_name.include?('.')) # HMT? (Could do a better check for this)
647
662
  predicates = path_keys(hm_assoc, hm_fk_name, pk).map do |k, v|
648
663
  if v == '[sti_type]'
649
- "'#{k}': @#{obj_name}.#{hm_assoc.active_record.inheritance_column}"
664
+ "'#{k}': (@#{obj_name}.#{hm_assoc.active_record.inheritance_column}).constantize.base_class.name"
650
665
  else
651
666
  v.is_a?(String) ? "'#{k}': '#{v}'" : "'#{k}': @#{obj_name}.#{v}"
652
667
  end
@@ -1551,8 +1566,12 @@ end
1551
1566
  <head>
1552
1567
  #{css}
1553
1568
  <title><%=
1554
- model = (obj = @#{obj_name})&.class
1555
- model_name = @#{obj_name}.#{inh_col = @_brick_model.inheritance_column} if obj.respond_to?(:#{inh_col})
1569
+ base_model = (model = (obj = @#{obj_name})&.class).base_class
1570
+ see_all_path = send(\"#\{base_model._brick_index}_path\")
1571
+ if obj.respond_to?(:#{inh_col = @_brick_model.inheritance_column}) &&
1572
+ (model_name = @#{obj_name}.#{inh_col}) != base_model.name
1573
+ see_all_path << \"?#{inh_col}=#\{model_name}\"
1574
+ end
1556
1575
  page_title = (\"#\{model_name ||= model.name}: #\{obj&.brick_descrip || controller_name}\")
1557
1576
  %></title>
1558
1577
  </head>
@@ -1596,7 +1615,7 @@ end
1596
1615
  if (description = (relation = Brick.relations[tbl_name = #{model_name}.table_name])&.fetch(:description, nil)) %><%=
1597
1616
  description %><br><%
1598
1617
  end
1599
- %><%= link_to '(See all #{obj_name.pluralize})', #{@_brick_model._brick_index}_path %>
1618
+ %><%= link_to \"(See all #\{model_name.pluralize})\", see_all_path %>
1600
1619
  #{erd_markup}
1601
1620
  <% if obj
1602
1621
  # path_options = [obj.#{pk}]
@@ -1612,11 +1631,11 @@ end
1612
1631
  <%= form_for(obj.becomes(#{model_name}), options) do |f| %>
1613
1632
  <table class=\"shadow\">
1614
1633
  <% has_fields = false
1615
- @#{obj_name}.attributes.each do |k, val|
1616
- col = #{model_name}.columns_hash[k] %>
1617
- <tr>
1618
- <% next if (#{(pk || []).inspect}.include?(k) && !bts.key?(k)) ||
1634
+ @#{obj_name}.attributes.each do |k, val|
1635
+ next if !(col = #{model_name}.columns_hash[k]) ||
1636
+ (#{(pk || []).inspect}.include?(k) && !bts.key?(k)) ||
1619
1637
  ::Brick.config.metadata_columns.include?(k) %>
1638
+ <tr>
1620
1639
  <th class=\"show-field\"<%= \" title=\\\"#\{col.comment}\\\"\".html_safe if col.respond_to?(:comment) && !col.comment.blank? %>>
1621
1640
  <% has_fields = true
1622
1641
  if (bt = bts[k])
@@ -1680,9 +1699,13 @@ end
1680
1699
  if is_bcrypt?(val) # || .readonly?
1681
1700
  is_revert = false %>
1682
1701
  <%= hide_bcrypt(val, nil, 1000) %>
1683
- <% elsif col_type == :string %>
1684
- <%= f.text_field(k.to_sym, html_options) %>
1685
- <% else
1702
+ <% elsif col_type == :string
1703
+ if model.respond_to?(:enumerized_attributes) && (opts = model.enumerized_attributes[k]&.options).present? %>
1704
+ <%= f.select(k.to_sym, [[\"(No #\{k} chosen)\", '^^^brick_NULL^^^']] + opts, { value: val || '^^^brick_NULL^^^' }, html_options) %><%
1705
+ else %>
1706
+ <%= f.text_field(k.to_sym, html_options) %><%
1707
+ end
1708
+ else
1686
1709
  is_includes_text = true %>
1687
1710
  <%= f.hidden_field(k.to_sym, html_options) %>
1688
1711
  <trix-editor input=\"<%= f.field_id(k) %>\"></trix-editor>
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 122
8
+ TINY = 123
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/brick.rb CHANGED
@@ -1694,6 +1694,29 @@ if Gem::Specification.all_names.any? { |g| g.start_with?('ransack-') }
1694
1694
  end
1695
1695
  end
1696
1696
 
1697
+ # Patch Enumerize so that #becomes works when an STI subclass is becoming a base class
1698
+ # which does not include Enumerize.
1699
+ # (See https://github.com/brainspec/enumerize/issues/426)
1700
+ if Object.const_defined?('Enumerize') && Enumerize.const_defined?('ActiveRecordSupport')
1701
+ Enumerize::ActiveRecordSupport::InstanceMethods.class_exec do
1702
+ def becomes(klass)
1703
+ became = super
1704
+ klass = self.class unless klass.respond_to?(:enumerized_attributes)
1705
+ klass.enumerized_attributes.each do |attr|
1706
+ begin
1707
+ if became.respond_to?(setter = "#{attr.name}=")
1708
+ became.send(setter, send(attr.name))
1709
+ end
1710
+ rescue ActiveModel::MissingAttributeError
1711
+ rescue ActiveRecord::SerializationTypeMismatch
1712
+ became.send(setter, send(attr.name).to_ary)
1713
+ end
1714
+ end
1715
+ became
1716
+ end
1717
+ end
1718
+ end
1719
+
1697
1720
  # Keyword arguments updates for Rails <= 5.2.x and Ruby >= 3.0
1698
1721
  if ActiveRecord.version < ::Gem::Version.new('6.0') && ruby_version >= ::Gem::Version.new('3.0')
1699
1722
  admsm = ActionDispatch::MiddlewareStack::Middleware
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.122
4
+ version: 1.0.123
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-23 00:00:00.000000000 Z
11
+ date: 2023-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord