brick 1.0.138 → 1.0.139

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: 2f044e21a6e4c2120a453b6cb3dc404d4d3e3e15034c638d316cbc418bcb996b
4
- data.tar.gz: f3360e5e7778bacde155e58bf0683d6b75c74d7dd63d336131e82b0a1865199a
3
+ metadata.gz: e13ace06f3c894715f631be750cd0571b9ab1cfe44b15780e9278d7b6a1c88f3
4
+ data.tar.gz: fd0d89eb66a8878fc968e95e7a3c27f1fcf619a06c652c0c58c468d4cf66e451
5
5
  SHA512:
6
- metadata.gz: 413c6fe2526752eab0e24998b852e9ae68ef7f56a6488bc14b777e13a4ad281f6c352af465be9e49f05e20fa597e7750d3c706df762f74eb70a18fda5112a319
7
- data.tar.gz: cb5040c5333dfa0c0fcbd9d1c04c229e538db1b33fc1526ace987d6da8bd1634e50269e5e05249da6205980ac79c3bad792dd5cc2242115349846365a881bf81
6
+ metadata.gz: 58665ea6c29d49542ae83096fa3ad5fa371ed0a12920f86492111319e3ab9a46c8c7d83ab9277377b6dabb51a75adf0a7cb32c4aa37234f54d796fe206563172
7
+ data.tar.gz: f5ee7ebdfa31f76133db652ff0beec175aa5eb319a7f1472da56f0e8e7c79aba12bceb9c26b73fc4c305e69143529416cb5d683660025d1b1e08aa72209a688b
@@ -1042,7 +1042,7 @@ if ActiveSupport::Dependencies.respond_to?(:autoload_module!) # %%% Only works w
1042
1042
  end
1043
1043
  end
1044
1044
 
1045
- Module.class_exec do
1045
+ ::Brick::ADD_CONST_MISSING = lambda do
1046
1046
  alias _brick_const_missing const_missing
1047
1047
  def const_missing(*args)
1048
1048
  requested = args.first.to_s
@@ -1319,7 +1319,14 @@ class Object
1319
1319
  if (base_model = ::Brick.sti_models[full_model_name]&.fetch(:base, nil) || ::Brick.existing_stis[full_model_name]&.constantize)
1320
1320
  is_sti = true
1321
1321
  else
1322
- base_model = ::Brick.config.models_inherit_from
1322
+ # Class for auto-generated models to inherit from
1323
+ base_model = (::Brick.config.models_inherit_from ||= (app.config.brick.fetch(:models_inherit_from, nil) ||
1324
+ begin
1325
+ ::ApplicationRecord
1326
+ rescue StandardError => ex
1327
+ ::ActiveRecord::Base
1328
+ end))
1329
+
1323
1330
  end
1324
1331
  hmts = nil
1325
1332
  code = +"class #{full_name} < #{base_model.name}\n"
@@ -1486,8 +1493,10 @@ class Object
1486
1493
  assoc[:assoc_name]
1487
1494
  end
1488
1495
  options[:optional] = true if assoc.key?(:optional)
1489
- if assoc.key?(:polymorphic)
1490
- options[:polymorphic] = true
1496
+ if assoc.key?(:polymorphic) ||
1497
+ # If a polymorphic association is missing but could be established then go ahead and put it into place.
1498
+ relations[assoc[:inverse_table]][:class_name].constantize.reflect_on_all_associations.find { |inv_assoc| !inv_assoc.belongs_to? && inv_assoc.options[:as].to_s == assoc[:assoc_name] }
1499
+ assoc[:polymorphic] ||= (options[:polymorphic] = true)
1491
1500
  else
1492
1501
  need_class_name = singular_table_name.underscore != assoc_name
1493
1502
  need_fk = "#{assoc_name}_id" != assoc[:fk]
@@ -1548,7 +1557,11 @@ class Object
1548
1557
  assoc[:fk].to_sym
1549
1558
  end
1550
1559
  end
1551
- options[:inverse_of] = inverse_assoc_name.tr('.', '_').to_sym if inverse_assoc_name && (need_class_name || need_fk || need_inverse_of)
1560
+ if inverse_assoc_name && (need_class_name || need_fk || need_inverse_of) &&
1561
+ (klass = options[:class_name]&.constantize) && (ian = inverse_assoc_name.tr('.', '_').to_sym) &&
1562
+ (klass.is_brick? || klass.reflect_on_association(ian))
1563
+ options[:inverse_of] = ian
1564
+ end
1552
1565
 
1553
1566
  # Prepare a list of entries for "has_many :through"
1554
1567
  if macro == :has_many
@@ -1591,14 +1604,38 @@ class Object
1591
1604
  built_controller = Class.new(controller_base || ActionController::Base) do |new_controller_class|
1592
1605
  (namespace || Object).const_set(class_name.to_sym, new_controller_class)
1593
1606
 
1607
+ # Add a hash for the inline style to the content-security-policy if one is present
1608
+ self.define_method(:add_csp_hash) do |style_value = nil|
1609
+ if (csp = request.content_security_policy)
1610
+ if (cspd = csp.directives.fetch('style-src'))
1611
+ if style_value
1612
+ if (nonce = ::ActionDispatch::ContentSecurityPolicy::Request::NONCE)
1613
+ request.env[nonce] = '' # Generally 'action_dispatch.content_security_policy_nonce'
1614
+ end
1615
+ # Keep only self, if present, and also add this value
1616
+ cspd.select! { |val| val == "'self'" }
1617
+ cspd << style_value
1618
+ else
1619
+ cspd << "'sha256-QHKxqKcUq7AER1QwEu5uQXRQwC8j4iTWkE8mpOmP7ms='"
1620
+ end
1621
+ cspd << 'https://cdn.jsdelivr.net'
1622
+ end
1623
+ if (cspd = csp.directives.fetch('script-src'))
1624
+ cspd << 'https://cdn.jsdelivr.net'
1625
+ end
1626
+ end
1627
+ end
1628
+
1594
1629
  # Brick-specific pages
1595
1630
  case plural_class_name
1596
1631
  when 'BrickGem'
1597
1632
  self.define_method :status do
1598
1633
  instance_variable_set(:@resources, ::Brick.get_status_of_resources)
1634
+ add_csp_hash
1599
1635
  end
1600
1636
  self.define_method :orphans do
1601
1637
  instance_variable_set(:@orphans, ::Brick.find_orphans(::Brick.set_db_schema(params).first))
1638
+ add_csp_hash
1602
1639
  end
1603
1640
  self.define_method :crosstab do
1604
1641
  @relations = ::Brick.relations.each_with_object({}) do |r, s|
@@ -1881,6 +1918,7 @@ class Object
1881
1918
  @_brick_hm_counts = real_model._br_hm_counts
1882
1919
  @_brick_join_array = join_array
1883
1920
  @_brick_erd = params['_brick_erd']&.to_i
1921
+ add_csp_hash
1884
1922
  end
1885
1923
  end
1886
1924
 
@@ -1911,6 +1949,7 @@ class Object
1911
1949
  self.define_method :show do
1912
1950
  _schema, @_is_show_schema_list = ::Brick.set_db_schema(params)
1913
1951
  instance_variable_set("@#{singular_table_name}".to_sym, find_obj)
1952
+ add_csp_hash("'unsafe-inline'")
1914
1953
  end
1915
1954
  end
1916
1955
 
@@ -1928,6 +1967,7 @@ class Object
1928
1967
  end if Object.const_defined?('ActiveStorage')
1929
1968
  end
1930
1969
  instance_variable_set("@#{singular_table_name}".to_sym, new_obj)
1970
+ add_csp_hash
1931
1971
  end
1932
1972
 
1933
1973
  params_name_sym = (params_name = "#{singular_table_name}_params").to_sym
@@ -1968,6 +2008,7 @@ class Object
1968
2008
  self.define_method :edit do
1969
2009
  _schema, @_is_show_schema_list = ::Brick.set_db_schema(params)
1970
2010
  instance_variable_set("@#{singular_table_name}".to_sym, find_obj)
2011
+ add_csp_hash
1971
2012
  end
1972
2013
 
1973
2014
  code << " def update\n"
@@ -209,6 +209,7 @@ function linkSchemas() {
209
209
  # paths['app/models'] << 'lib/brick/frameworks/active_record/models'
210
210
  config.brick = ActiveSupport::OrderedOptions.new
211
211
  ActiveSupport.on_load(:before_initialize) do |app|
212
+ ::Rails.application.reloader.to_prepare { Module.class_exec &::Brick::ADD_CONST_MISSING }
212
213
  is_development = (ENV['RAILS_ENV'] || ENV['RACK_ENV']) == 'development'
213
214
  ::Brick.enable_models = app.config.brick.fetch(:enable_models, true)
214
215
  ::Brick.enable_controllers = app.config.brick.fetch(:enable_controllers, is_development)
@@ -736,7 +737,7 @@ window.addEventListener(\"popstate\", linkSchemas);
736
737
  end
737
738
  when 'show', 'new', 'update'
738
739
  hm_stuff << if hm_fk_name
739
- if hm_assoc.klass.column_names.include?(hm_fk_name) ||
740
+ if hm_assoc.klass.column_names.include?(hm_fk_name.to_s) ||
740
741
  (hm_fk_name.is_a?(String) && hm_fk_name.include?('.')) # HMT? (Could do a better check for this)
741
742
  predicates = path_keys(hm_assoc, hm_fk_name, pk).map do |k, v|
742
743
  if v == '[sti_type]'
@@ -798,6 +799,10 @@ window.addEventListener(\"popstate\", linkSchemas);
798
799
  left: 0;
799
800
  }
800
801
 
802
+ .flashNotice {
803
+ color: green;
804
+ }
805
+
801
806
  h1, h3 {
802
807
  margin-bottom: 0;
803
808
  }
@@ -1313,7 +1318,7 @@ erDiagram
1313
1318
  </head>
1314
1319
  <body>
1315
1320
  <div id=\"titleBox\"><div id=\"titleSticky\">
1316
- <p style=\"color: green\"><%= notice if request.respond_to?(:flash) %></p>#{"
1321
+ <p class=\"flashNotice\"><%= notice if request.respond_to?(:flash) %></p>#{"
1317
1322
  #{schema_options}" if schema_options}
1318
1323
  <select id=\"tbl\">#{table_options}</select>
1319
1324
  <table id=\"resourceName\"><tr>
@@ -1453,7 +1458,7 @@ end
1453
1458
  # Must load all models, and then find what table names are represented
1454
1459
  # Easily could be multiple files involved (STI for instance)
1455
1460
  +"#{css}
1456
- <p style=\"color: green\"><%= notice if request.respond_to?(:flash) %></p>#{"
1461
+ <p class=\"flashNotice\"><%= notice if request.respond_to?(:flash) %></p>#{"
1457
1462
  #{schema_options}" if schema_options}
1458
1463
  <select id=\"tbl\">#{table_options}</select>
1459
1464
  <h1>Status</h1>
@@ -1503,7 +1508,7 @@ end
1503
1508
  when 'orphans'
1504
1509
  if is_orphans
1505
1510
  +"#{css}
1506
- <p style=\"color: green\"><%= notice if request.respond_to?(:flash) %></p>#{"
1511
+ <p class=\"flashNotice\"><%= notice if request.respond_to?(:flash) %></p>#{"
1507
1512
  #{schema_options}" if schema_options}
1508
1513
  <select id=\"tbl\">#{table_options}</select>
1509
1514
  <h1>Orphans<%= \" for #\{}\" if false %></h1>
@@ -1550,7 +1555,7 @@ end
1550
1555
  c23.141-70.188,89.141-120.906,167.063-120.906c97.25,0,176,78.813,176,176C511.828,227.078,404.391,119.641,271.844,119.641z\" />
1551
1556
  </svg>
1552
1557
 
1553
- <p style=\"color: green\"><%= notice if request.respond_to?(:flash) %></p>#{"
1558
+ <p class=\"flashNotice\"><%= notice if request.respond_to?(:flash) %></p>#{"
1554
1559
  #{schema_options}" if schema_options}
1555
1560
  <select id=\"tbl\">#{table_options}</select>
1556
1561
  <table id=\"resourceName\"><td><h1><%= page_title %></h1></td>
@@ -1716,11 +1721,11 @@ end
1716
1721
  if collection2.empty? %>
1717
1722
  <tr><td>(none)</td></tr>
1718
1723
  <% else
1719
- collection2.each do |#{hm_singular_name}| %>
1720
- <tr><td><%= br_descrip = #{hm_singular_name}.brick_descrip(
1721
- descrip_cols&.first&.map { |col| #{hm_singular_name}.send(col.last) }
1724
+ collection2.each do |br_#{hm_singular_name}| %>
1725
+ <tr><td><%= br_descrip = br_#{hm_singular_name}.brick_descrip(
1726
+ descrip_cols&.first&.map { |col| br_#{hm_singular_name}.send(col.last) }
1722
1727
  )
1723
- link_to(br_descrip, #{hm.first.klass._brick_index(:singular)}_path(slashify(#{obj_pk}))) %></td></tr>
1728
+ link_to(br_descrip, #{hm.first.klass._brick_index(:singular)}_path(slashify(br_#{obj_pk}))) %></td></tr>
1724
1729
  <% end %>
1725
1730
  <% end %>
1726
1731
  </table>"
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 138
8
+ TINY = 139
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
@@ -254,7 +254,7 @@ module Brick
254
254
  next
255
255
  end
256
256
  else
257
- if !a.options.key?(:as) && a.klass.column_names.exclude?(a.foreign_key)
257
+ if !a.options.key?(:as) && a.klass.column_names.exclude?(a.foreign_key.to_s)
258
258
  options = ", #{a.options.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join(', ')}" if a.options.present?
259
259
  puts "WARNING: Model #{model.name} has this association:
260
260
  has_many :#{a.name}#{options}
@@ -922,11 +922,19 @@ In config/initializers/brick.rb appropriate entries would look something like:
922
922
  end
923
923
  end
924
924
 
925
- if ::Brick.config.add_status && instance_variable_get(:@set).named_routes.names.exclude?(:brick_status)
926
- get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: 'brick_status')
925
+ if ::Brick.config.add_status && (status_as = "#{controller_prefix.tr('/', '_')}brick_status".to_sym)
926
+ (
927
+ !(status_route = instance_variable_get(:@set).named_routes.find { |route| route.first == status_as }&.last) ||
928
+ !status_route.ast.to_s.include?("/#{controller_prefix}brick_status/")
929
+ )
930
+ get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: status_as.to_s)
927
931
  end
928
932
 
929
- if ::Brick.config.add_orphans && instance_variable_get(:@set).named_routes.names.exclude?(:brick_orphans)
933
+ if ::Brick.config.add_orphans && (orphans_as = "#{controller_prefix.tr('/', '_')}brick_orphans".to_sym)
934
+ (
935
+ !(orphans_route = instance_variable_get(:@set).named_routes.find { |route| route.first == orphans_as }&.last) ||
936
+ !orphans_route.ast.to_s.include?("/#{controller_prefix}brick_orphans/")
937
+ )
930
938
  get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
931
939
  end
932
940
 
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.138
4
+ version: 1.0.139
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-05-06 00:00:00.000000000 Z
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord