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 +4 -4
- data/app/controllers/motor/api_base_controller.rb +5 -1
- data/app/mailers/motor/alerts_mailer.rb +14 -2
- data/config/locales/en.yml +2 -0
- data/config/locales/es.yml +2 -0
- data/config/locales/pt.yml +2 -0
- data/lib/motor/active_record_utils/ar_lazy_preload_patch.rb +22 -0
- data/lib/motor/active_record_utils.rb +1 -0
- data/lib/motor/queries/run_query.rb +37 -3
- data/lib/motor/resources.rb +1 -1
- data/lib/motor/version.rb +1 -1
- data/ui/dist/{main-c332e3fdad0c8e350a4c.css.gz → main-192e078f9e813b1ffe93.css.gz} +0 -0
- data/ui/dist/main-192e078f9e813b1ffe93.js.gz +0 -0
- data/ui/dist/manifest.json +5 -5
- metadata +5 -4
- data/ui/dist/main-c332e3fdad0c8e350a4c.js.gz +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d0e456f8e9d1dc83186c2ef270182308da0bb43bab8779eaa391b2f6f3c7a4f
|
4
|
+
data.tar.gz: 1f5a52343c0ba8ca6b4c622b221656a9e38ac2df6678a6659653e2469f71c92d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
45
|
+
from ||= 'reports@example.com' if Rails.env.development?
|
46
|
+
|
47
|
+
from
|
36
48
|
end
|
37
49
|
|
38
50
|
def application_mailer_default_from
|
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
data/config/locales/pt.yml
CHANGED
@@ -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
|
-
|
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:
|
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]
|
data/lib/motor/resources.rb
CHANGED
@@ -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
Binary file
|
Binary file
|
data/ui/dist/manifest.json
CHANGED
@@ -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-
|
2605
|
-
"main-
|
2606
|
-
"main-
|
2607
|
-
"main.css": "main-
|
2608
|
-
"main.js": "main-
|
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.
|
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-
|
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-
|
1527
|
-
- ui/dist/main-
|
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:
|
Binary file
|