rails_nexus 2.0.6 → 2.1.2

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +110 -0
  3. data/README.md +33 -6
  4. data/SECURITY.md +11 -0
  5. data/THIRD_PARTY_NOTICES.md +14 -0
  6. data/app/assets/config/rails_nexus_manifest.js +1 -1
  7. data/app/assets/javascripts/rails_nexus/application.js +55 -0
  8. data/app/assets/javascripts/rails_nexus/controllers.js +82 -5
  9. data/app/assets/stylesheets/rails_nexus/application.css +170 -60
  10. data/app/controllers/rails_nexus/analytics_controller.rb +13 -26
  11. data/app/controllers/rails_nexus/application_controller.rb +6 -2
  12. data/app/controllers/rails_nexus/backup_controller.rb +22 -19
  13. data/app/controllers/rails_nexus/cron_jobs_controller.rb +1 -9
  14. data/app/controllers/rails_nexus/database_health_controller.rb +0 -10
  15. data/app/controllers/rails_nexus/logged_exceptions_controller.rb +0 -2
  16. data/app/controllers/rails_nexus/n1_patterns_controller.rb +0 -2
  17. data/app/controllers/rails_nexus/settings_controller.rb +1 -39
  18. data/app/controllers/rails_nexus/source_code_controller.rb +9 -13
  19. data/app/controllers/rails_nexus/stats_controller.rb +43 -43
  20. data/app/helpers/rails_nexus/application_helper.rb +5 -0
  21. data/app/helpers/rails_nexus/logged_exceptions_helper.rb +4 -49
  22. data/app/helpers/rails_nexus/source_code_helper.rb +49 -10
  23. data/app/javascript/controllers/rails_nexus_controller.js +6 -2
  24. data/app/javascript/controllers/rails_nexus_sidebar_controller.js +71 -3
  25. data/app/javascript/rails_nexus/application.js +15 -3
  26. data/app/jobs/rails_nexus/backup_job.rb +18 -0
  27. data/app/models/rails_nexus/backup.rb +11 -11
  28. data/app/models/rails_nexus/backup_config.rb +38 -2
  29. data/app/models/rails_nexus/logged_exception.rb +27 -13
  30. data/app/services/rails_nexus/backup_service.rb +342 -120
  31. data/app/views/layouts/rails_nexus/_sidebar_navigation.html.erb +40 -10
  32. data/app/views/layouts/rails_nexus/application.html.erb +72 -14
  33. data/app/views/rails_nexus/backup/_form.html.erb +3 -0
  34. data/app/views/rails_nexus/backup/history.html.erb +17 -2
  35. data/app/views/rails_nexus/backup/index.html.erb +29 -72
  36. data/app/views/rails_nexus/logged_exceptions/_exceptions.html.erb +12 -44
  37. data/app/views/rails_nexus/logged_exceptions/index.html.erb +21 -99
  38. data/app/views/rails_nexus/stats/index.html.erb +1 -1
  39. data/db/seeds/backup_configs.rb +5 -4
  40. data/lib/generators/rails_nexus/install_generator.rb +1 -1
  41. data/lib/generators/rails_nexus/templates/INSTALL.md +1 -0
  42. data/lib/generators/rails_nexus/templates/migration.rb +8 -2
  43. data/lib/generators/rails_nexus/templates/rails_nexus.rb +3 -0
  44. data/lib/generators/rails_nexus/templates/views/layouts/rails_nexus/application.html.erb +1 -1
  45. data/lib/rails_nexus/configuration.rb +10 -0
  46. data/lib/rails_nexus/database_adapter.rb +53 -0
  47. data/lib/rails_nexus/engine.rb +0 -13
  48. data/lib/rails_nexus/logger.rb +1 -12
  49. data/lib/rails_nexus/notifications.rb +27 -20
  50. data/lib/rails_nexus/version.rb +1 -1
  51. data/lib/rails_nexus/webhook_client.rb +151 -0
  52. data/lib/rails_nexus.rb +37 -23
  53. data/lib/tasks/rails_nexus.rake +4 -4
  54. data/rails_nexus.gemspec +3 -2
  55. metadata +9 -16
  56. data/config/importmap.rb +0 -15
data/lib/rails_nexus.rb CHANGED
@@ -1,16 +1,22 @@
1
1
  require "rails"
2
- require "importmap-rails"
2
+ require "active_support/parameter_filter"
3
3
  require "turbo-rails"
4
4
  require "stimulus-rails"
5
5
  require "pagy"
6
6
  require "ipaddr"
7
7
  require "socket"
8
+ require "open3"
8
9
  require "rails_nexus/version"
9
10
  require "rails_nexus/configuration"
10
11
  require "rails_nexus/logger"
12
+ require "rails_nexus/database_adapter"
11
13
  require "rails_nexus/engine"
12
14
 
13
15
  module RailsNexus
16
+ DEFAULT_FILTER_PARAMETERS = %i[
17
+ password passw passwd secret token api_key apikey authorization cookie session
18
+ ].freeze
19
+
14
20
  class << self
15
21
  attr_writer :configuration
16
22
 
@@ -35,6 +41,24 @@ module RailsNexus
35
41
  def logger
36
42
  RailsNexus::Logger
37
43
  end
44
+
45
+ def parameter_filter
46
+ configured = defined?(::Rails) ? ::Rails.application.config.filter_parameters : []
47
+ ActiveSupport::ParameterFilter.new(DEFAULT_FILTER_PARAMETERS + Array(configured))
48
+ end
49
+
50
+ def filter_sensitive_data(value)
51
+ value = value.to_unsafe_h if value.respond_to?(:to_unsafe_h)
52
+
53
+ case value
54
+ when Hash
55
+ parameter_filter.filter(value)
56
+ when Array
57
+ value.map { |entry| filter_sensitive_data(entry) }
58
+ else
59
+ value
60
+ end
61
+ end
38
62
  end
39
63
 
40
64
  # Copyright (c) 2005 Jamis Buck
@@ -78,28 +102,19 @@ module RailsNexus
78
102
 
79
103
  # we log the exception and raise it again, for the normal handling.
80
104
  def log_exception_handler(exception)
81
- log_exception(exception)
105
+ log_exception(exception) if exception.is_a?(StandardError)
82
106
  raise exception
83
107
  end
84
108
 
85
109
  def rescue_action(exception)
86
110
  status = response_code_for_rescue(exception)
87
- log_exception(exception) if status != :not_found
111
+ log_exception(exception) if exception.is_a?(StandardError) && status != :not_found
88
112
  super
89
113
  end
90
114
 
91
- def filter_sub_parameters(params, rails_filter_parameters)
92
- params.each do |key, value|
93
- if(value.class != Hash and value.class != ActiveSupport::HashWithIndifferentAccess)
94
- params[key] = '[FILTERED]' if rails_filter_parameters.include?(key.to_sym)
95
- else
96
- params[key] = filter_sub_parameters(value, rails_filter_parameters)
97
- end
98
- end
99
- params
100
- end
101
-
102
115
  def log_exception(exception)
116
+ return unless exception.is_a?(StandardError)
117
+
103
118
  # Support both the legacy class_attribute and the new configuration DSL
104
119
  deliverer = if self.class.exception_data
105
120
  self.class.exception_data
@@ -113,15 +128,7 @@ module RailsNexus
113
128
  when Proc then deliverer.call(self)
114
129
  end
115
130
 
116
- rails_filter_parameters = defined?(::Rails) ? ::Rails.application.config.filter_parameters : []
117
-
118
- self.request.parameters.each do |key, value|
119
- if(value.class != Hash and value.class != ActiveSupport::HashWithIndifferentAccess)
120
- self.request.parameters[key] = '[FILTERED]' if rails_filter_parameters.include?(key.to_sym)
121
- else
122
- self.request.parameters[key] = filter_sub_parameters(value, rails_filter_parameters)
123
- end
124
- end if rails_filter_parameters.any?
131
+ data = RailsNexus.filter_sensitive_data(data || {})
125
132
 
126
133
  # Log with structured logger
127
134
  RailsNexus::Logger.error(exception, controller: self, extra: data)
@@ -131,3 +138,10 @@ module RailsNexus
131
138
  end
132
139
  end
133
140
  end
141
+
142
+ # Compatibility for applications that integrated the exception concern under
143
+ # the pre-RailsNexus namespace. New integrations should use
144
+ # RailsNexus::ExceptionLoggable.
145
+ module RailsOps
146
+ ExceptionLoggable = RailsNexus::ExceptionLoggable unless const_defined?(:ExceptionLoggable, false)
147
+ end
@@ -254,9 +254,9 @@ namespace :rails_nexus do
254
254
  results = RailsNexus::BackupRunner.run_all
255
255
  results.each do |r|
256
256
  if r[:success]
257
- puts "✓ #{r[:record].model_name} completed"
257
+ puts "✓ #{r[:record].config_name} completed"
258
258
  else
259
- puts "✗ #{r[:record]&.model_name || '?'} failed: #{r[:error]}"
259
+ puts "✗ #{r[:record]&.config_name || '?'} failed: #{r[:error]}"
260
260
  end
261
261
  end
262
262
  end
@@ -269,9 +269,9 @@ namespace :rails_nexus do
269
269
  else
270
270
  results.each do |r|
271
271
  if r[:success]
272
- puts "✓ #{r[:record].model_name} completed"
272
+ puts "✓ #{r[:record].config_name} completed"
273
273
  else
274
- puts "✗ #{r[:record]&.model_name || '?'} failed: #{r[:error]}"
274
+ puts "✗ #{r[:record]&.config_name || '?'} failed: #{r[:error]}"
275
275
  end
276
276
  end
277
277
  end
data/rails_nexus.gemspec CHANGED
@@ -15,10 +15,12 @@ Gem::Specification.new do |spec|
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
16
  spec.metadata["source_code_uri"] = "https://github.com/tamiru/rails_nexus/tree/main"
17
17
  spec.metadata["changelog_uri"] = "https://github.com/tamiru/rails_nexus/blob/main/CHANGELOG.md"
18
+ spec.metadata["bug_tracker_uri"] = "https://github.com/tamiru/rails_nexus/issues"
18
19
  spec.metadata["funding_uri"] = "https://github.com/sponsors/tamiru"
19
20
 
20
21
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
- Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md", "rails_nexus.gemspec"]
22
+ Dir["{app,config,db,lib}/**/*", "CHANGELOG.md", "SECURITY.md", "THIRD_PARTY_NOTICES.md", "MIT-LICENSE", "Rakefile", "README.md", "rails_nexus.gemspec"]
23
+ .reject { |file| file.match?(%r{(?:^|/)(?:\.idea|log|tmp|storage|pkg)(?:/|$)|\.(?:gem|sqlite3|log)\z|Zone\.Identifier\z}) }
22
24
  end
23
25
 
24
26
  spec.required_ruby_version = ">= 3.2.0"
@@ -26,7 +28,6 @@ Gem::Specification.new do |spec|
26
28
  spec.add_dependency "rails", "~> 8.0", ">= 8.0.0"
27
29
  spec.add_dependency "stimulus-rails", "~> 1.3"
28
30
  spec.add_dependency "turbo-rails", "~> 2.0"
29
- spec.add_dependency "importmap-rails", "~> 2.0"
30
31
  spec.add_dependency "pagy", "~> 6.5"
31
32
 
32
33
  spec.add_dependency "ransack", "~> 4.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_nexus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tamiru Hailu
@@ -57,20 +57,6 @@ dependencies:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '2.0'
60
- - !ruby/object:Gem::Dependency
61
- name: importmap-rails
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '2.0'
67
- type: :runtime
68
- prerelease: false
69
- version_requirements: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - "~>"
72
- - !ruby/object:Gem::Version
73
- version: '2.0'
74
60
  - !ruby/object:Gem::Dependency
75
61
  name: pagy
76
62
  requirement: !ruby/object:Gem::Requirement
@@ -110,10 +96,14 @@ executables: []
110
96
  extensions: []
111
97
  extra_rdoc_files: []
112
98
  files:
99
+ - CHANGELOG.md
113
100
  - MIT-LICENSE
114
101
  - README.md
115
102
  - Rakefile
103
+ - SECURITY.md
104
+ - THIRD_PARTY_NOTICES.md
116
105
  - app/assets/config/rails_nexus_manifest.js
106
+ - app/assets/javascripts/rails_nexus/application.js
117
107
  - app/assets/javascripts/rails_nexus/controllers.js
118
108
  - app/assets/stylesheets/rails_nexus/application.css
119
109
  - app/controllers/rails_nexus/analytics_controller.rb
@@ -136,6 +126,7 @@ files:
136
126
  - app/javascript/controllers/rails_nexus_theme_controller.js
137
127
  - app/javascript/rails_nexus/application.js
138
128
  - app/jobs/rails_nexus/application_job.rb
129
+ - app/jobs/rails_nexus/backup_job.rb
139
130
  - app/mailers/rails_nexus/application_mailer.rb
140
131
  - app/models/rails_nexus/application_record.rb
141
132
  - app/models/rails_nexus/backup.rb
@@ -177,7 +168,6 @@ files:
177
168
  - app/views/rails_nexus/n1_patterns/index.html.erb
178
169
  - app/views/rails_nexus/settings/index.html.erb
179
170
  - app/views/rails_nexus/stats/index.html.erb
180
- - config/importmap.rb
181
171
  - config/initializers/date_formats.rb
182
172
  - config/locales/en.yml
183
173
  - config/routes.rb
@@ -207,12 +197,14 @@ files:
207
197
  - lib/rails_nexus/breadcrumbs.rb
208
198
  - lib/rails_nexus/cleanup.rb
209
199
  - lib/rails_nexus/configuration.rb
200
+ - lib/rails_nexus/database_adapter.rb
210
201
  - lib/rails_nexus/engine.rb
211
202
  - lib/rails_nexus/logger.rb
212
203
  - lib/rails_nexus/notifications.rb
213
204
  - lib/rails_nexus/ransack_config.rb
214
205
  - lib/rails_nexus/storm_protection.rb
215
206
  - lib/rails_nexus/version.rb
207
+ - lib/rails_nexus/webhook_client.rb
216
208
  - lib/tasks/rails_nexus.rake
217
209
  - lib/tasks/rails_nexus_tasks.rake
218
210
  - rails_nexus.gemspec
@@ -225,6 +217,7 @@ metadata:
225
217
  homepage_uri: https://github.com/tamiru/rails_nexus
226
218
  source_code_uri: https://github.com/tamiru/rails_nexus/tree/main
227
219
  changelog_uri: https://github.com/tamiru/rails_nexus/blob/main/CHANGELOG.md
220
+ bug_tracker_uri: https://github.com/tamiru/rails_nexus/issues
228
221
  funding_uri: https://github.com/sponsors/tamiru
229
222
  rdoc_options: []
230
223
  require_paths:
data/config/importmap.rb DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # RailsNexus has its own entry point, so it never replaces the host app's
4
- # "application" pin. Turbo and Stimulus are served from their Rails gems.
5
- rails_nexus_entrypoint = "rails_nexus/application"
6
-
7
- pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: rails_nexus_entrypoint
8
- pin "@hotwired/stimulus", to: "stimulus.min.js", preload: rails_nexus_entrypoint
9
- pin rails_nexus_entrypoint, to: "rails_nexus/application.js", preload: rails_nexus_entrypoint
10
-
11
- # Gem controllers
12
- pin "rails_nexus/controllers/rails_nexus", to: "controllers/rails_nexus_controller.js", preload: rails_nexus_entrypoint
13
- pin "rails_nexus/controllers/rails_nexus_detail", to: "controllers/rails_nexus_detail_controller.js", preload: rails_nexus_entrypoint
14
- pin "rails_nexus/controllers/rails_nexus_sidebar", to: "controllers/rails_nexus_sidebar_controller.js", preload: rails_nexus_entrypoint
15
- pin "rails_nexus/controllers/rails_nexus_theme", to: "controllers/rails_nexus_theme_controller.js", preload: rails_nexus_entrypoint