motor-admin 0.2.8 → 0.2.12

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: 17e18a7f05b5872257978713dc9bb51c5c19823ec07eed5dd4e2a5035817ab96
4
- data.tar.gz: a1cc9b42cabbc9278a43abaad16a5987847b162b6e04177c25fbaa5438ff3bf8
3
+ metadata.gz: 7d0e456f8e9d1dc83186c2ef270182308da0bb43bab8779eaa391b2f6f3c7a4f
4
+ data.tar.gz: 1f5a52343c0ba8ca6b4c622b221656a9e38ac2df6678a6659653e2469f71c92d
5
5
  SHA512:
6
- metadata.gz: 698d0a1d1b9ae1b2f4589decff0cc54fbae9c49a61a553504963ef71c8a02ecae656dd6a7a163cb28af4ee65155cff31b8240237b5ff6a58a0de76597beff2f4
7
- data.tar.gz: c07b294604ec27c76f35f55f69a0c592a7dd349a6b446efd724090c2eac1e07d71e24785ca4bdb80e960a51735e923bb62775c6b477c375446b19ae40185c505
6
+ metadata.gz: b58213d454339da735ef28bb926eea83b910a9399a38892a34744c85ba64f7cce0c9668d40c10afe839807ea194a2144282e20fc6b0133f2bb215ec3f5a5b0f5
7
+ data.tar.gz: e945c189f9929b3afd5eada7330f8b83cc62386a3ac1718d1956bc4cd6b499933defdf0e0c094221170c4b0d58584cf64024e3ac7084d8ed3dcf3c59b5a21449
@@ -22,7 +22,11 @@ module Motor
22
22
  rescue_from CanCan::AccessDenied do |e|
23
23
  Rails.logger.error(e)
24
24
 
25
- render json: { errors: [e.message] }, status: :forbidden
25
+ if params[:action].in?(%w[create update destroy])
26
+ render json: { errors: [I18n.t('motor.not_authorized_to_perform_action')] }, status: :forbidden
27
+ else
28
+ render json: { errors: [e.message] }, status: :forbidden
29
+ end
26
30
  end
27
31
  end
28
32
  end
@@ -2,13 +2,19 @@
2
2
 
3
3
  module Motor
4
4
  class AlertsMailer < ApplicationMailer
5
+ SenderAddressNotSet = Class.new(StandardError)
6
+ SENDER_NOT_SET_ERROR_MESSAGE =
7
+ 'Please specify your sender address via MOTOR_ALERTS_FROM_ADDRESS environment variable'
8
+
5
9
  def alert_email(alert)
6
10
  @alert = alert
7
11
  @query_result = Queries::RunQuery.call(alert.query)
8
12
 
9
13
  return if @alert.preferences[:send_empty].blank? && @query_result.data.blank?
10
14
 
11
- attachments["#{alert.name.presence || 'data'}.csv"] = generate_csv(@query_result)
15
+ assign_attachment(@alert, @query_result)
16
+
17
+ raise SenderAddressNotSet, SENDER_NOT_SET_ERROR_MESSAGE unless from_address
12
18
 
13
19
  mail(
14
20
  from: from_address,
@@ -19,6 +25,10 @@ module Motor
19
25
 
20
26
  private
21
27
 
28
+ def assign_attachment(alert, query_result)
29
+ attachments["#{alert.name.presence || 'data'}.csv"] = generate_csv(query_result)
30
+ end
31
+
22
32
  def generate_csv(_query_result)
23
33
  rows = [@query_result.columns.pluck(:name)] + @query_result.data
24
34
 
@@ -32,7 +42,9 @@ module Motor
32
42
  from ||= mailer_config_from_address
33
43
  from ||= "reports@#{ENV['HOST'].delete_prefix('www.')}" if ENV['HOST'].present?
34
44
 
35
- from || 'reports@example.com'
45
+ from ||= 'reports@example.com' if Rails.env.development?
46
+
47
+ from
36
48
  end
37
49
 
38
50
  def application_mailer_default_from
@@ -264,3 +264,5 @@ en:
264
264
  add_database: Add Database
265
265
  audio: Audio
266
266
  video: Video
267
+ display_column: Display column
268
+ not_authorized_to_perform_action: You are not authorized to perform this action.
@@ -264,6 +264,8 @@ es:
264
264
  add_database: Añadir base de datos
265
265
  audio: Audio
266
266
  video: Video
267
+ display_column: Columna de visualización
268
+ not_authorized_to_perform_action: No está autorizado a realizar esta acción.
267
269
  i:
268
270
  locale: es
269
271
  select:
@@ -260,6 +260,8 @@ pt:
260
260
  write_only: "Somente gravação"
261
261
  audio: Áudio
262
262
  video: Vídeo
263
+ display_column: Coluna de exibição
264
+ not_authorized_to_perform_action: Não está autorizado a realizar esta acção.
263
265
  i:
264
266
  locale: pt
265
267
  select:
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ if Rails::VERSION::MAJOR == 7
4
+ module ArLazyPreload
5
+ module Relation
6
+ def preload_associations(records)
7
+ preload = preload_values
8
+ preload += includes_values unless eager_loading?
9
+ scope = strict_loading_value ? ActiveRecord::Relation::StrictLoadingScope : nil
10
+ preload.each do |associations|
11
+ preloader_associations = ActiveRecord::Associations::Preloader.new(records: records,
12
+ associations: associations,
13
+ scope: scope).call
14
+
15
+ preloader_associations.each do |preloader_association|
16
+ handle_preloaded_records(preloader_association.preloaded_records)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -23,3 +23,4 @@ require_relative './active_record_utils/active_storage_blob_patch'
23
23
  require_relative './active_record_utils/active_record_filter_patch'
24
24
  require_relative './active_record_utils/active_record_connection_column_patch'
25
25
  require_relative './active_record_utils/action_text_attribute_patch'
26
+ require_relative './active_record_utils/ar_lazy_preload_patch'
@@ -83,18 +83,52 @@ module Motor
83
83
  # @param result [ActiveRecord::Result]
84
84
  # @return [Hash]
85
85
  def build_columns_hash(result)
86
- result.columns.map do |column_name|
87
- column_type = result.column_types[column_name]
86
+ result.columns.map.with_index do |column_name, index|
87
+ column_type_class = result.column_types[column_name]
88
+
89
+ column_type =
90
+ if column_type_class
91
+ ActiveRecordUtils::Types.find_name_for_type(column_type_class)
92
+ else
93
+ not_nil_value = result.rows.reduce(nil) do |acc, row|
94
+ column = row[index]
95
+
96
+ break column unless column.nil?
97
+
98
+ acc
99
+ end
100
+
101
+ fetch_column_type_from_value(not_nil_value)
102
+ end
88
103
 
89
104
  {
90
105
  name: column_name,
91
106
  display_name: column_name.humanize,
92
- column_type: ActiveRecordUtils::Types.find_name_for_type(column_type),
107
+ column_type: column_type,
93
108
  is_array: column_type.class.to_s == 'ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array'
94
109
  }
95
110
  end
96
111
  end
97
112
 
113
+ # @param value [Object]
114
+ # @return [String]
115
+ def fetch_column_type_from_value(value)
116
+ case value
117
+ when Integer
118
+ 'integer'
119
+ when Float
120
+ 'float'
121
+ when Time
122
+ 'datetime'
123
+ when Date
124
+ 'date'
125
+ when TrueClass, FalseClass
126
+ 'boolean'
127
+ else
128
+ 'string'
129
+ end
130
+ end
131
+
98
132
  # @param query [Motor::Query]
99
133
  # @param limit [Integer]
100
134
  # @param variables_hash [Hash]
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Motor
4
4
  module Resources
5
- RESOURCE_ATTRS = %w[display_name icon custom_sql visible].freeze
5
+ RESOURCE_ATTRS = %w[display_name display_column icon custom_sql visible].freeze
6
6
  COLUMN_ATTRS = %w[name display_name column_type access_type default_value reference virtual format].freeze
7
7
  ASSOCIATION_ATTRS = %w[name display_name model_name icon visible foreign_key primary_key options virtual
8
8
  polymorphic slug].freeze
data/lib/motor/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Motor
4
- VERSION = '0.2.8'
4
+ VERSION = '0.2.12'
5
5
  end
@@ -2601,9 +2601,9 @@
2601
2601
  "icons/zoom-out.svg.gz": "icons/zoom-out.svg.gz",
2602
2602
  "icons/zoom-question.svg": "icons/zoom-question.svg",
2603
2603
  "icons/zoom-question.svg.gz": "icons/zoom-question.svg.gz",
2604
- "main-c332e3fdad0c8e350a4c.css.gz": "main-c332e3fdad0c8e350a4c.css.gz",
2605
- "main-c332e3fdad0c8e350a4c.js.LICENSE.txt": "main-c332e3fdad0c8e350a4c.js.LICENSE.txt",
2606
- "main-c332e3fdad0c8e350a4c.js.gz": "main-c332e3fdad0c8e350a4c.js.gz",
2607
- "main.css": "main-c332e3fdad0c8e350a4c.css",
2608
- "main.js": "main-c332e3fdad0c8e350a4c.js"
2604
+ "main-192e078f9e813b1ffe93.css.gz": "main-192e078f9e813b1ffe93.css.gz",
2605
+ "main-192e078f9e813b1ffe93.js.LICENSE.txt": "main-192e078f9e813b1ffe93.js.LICENSE.txt",
2606
+ "main-192e078f9e813b1ffe93.js.gz": "main-192e078f9e813b1ffe93.js.gz",
2607
+ "main.css": "main-192e078f9e813b1ffe93.css",
2608
+ "main.js": "main-192e078f9e813b1ffe93.js"
2609
2609
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motor-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Matsyburka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-13 00:00:00.000000000 Z
11
+ date: 2021-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-filter
@@ -165,6 +165,7 @@ files:
165
165
  - lib/motor/active_record_utils/active_record_filter_patch.rb
166
166
  - lib/motor/active_record_utils/active_storage_blob_patch.rb
167
167
  - lib/motor/active_record_utils/active_storage_links_extension.rb
168
+ - lib/motor/active_record_utils/ar_lazy_preload_patch.rb
168
169
  - lib/motor/active_record_utils/defined_scopes_extension.rb
169
170
  - lib/motor/active_record_utils/fetch_methods.rb
170
171
  - lib/motor/active_record_utils/types.rb
@@ -1523,8 +1524,8 @@ files:
1523
1524
  - ui/dist/icons/zoom-money.svg.gz
1524
1525
  - ui/dist/icons/zoom-out.svg.gz
1525
1526
  - ui/dist/icons/zoom-question.svg.gz
1526
- - ui/dist/main-c332e3fdad0c8e350a4c.css.gz
1527
- - ui/dist/main-c332e3fdad0c8e350a4c.js.gz
1527
+ - ui/dist/main-192e078f9e813b1ffe93.css.gz
1528
+ - ui/dist/main-192e078f9e813b1ffe93.js.gz
1528
1529
  - ui/dist/manifest.json
1529
1530
  homepage:
1530
1531
  licenses: