motor-admin 0.1.37 → 0.1.43
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.
- checksums.yaml +4 -4
- data/app/controllers/motor/alerts_controller.rb +12 -6
- data/app/controllers/motor/configs_controller.rb +1 -0
- data/app/controllers/motor/dashboards_controller.rb +4 -0
- data/app/controllers/motor/forms_controller.rb +4 -0
- data/app/controllers/motor/queries_controller.rb +4 -0
- data/app/controllers/motor/resources_controller.rb +1 -0
- data/app/controllers/motor/ui_controller.rb +4 -0
- data/app/models/motor/alert.rb +2 -2
- data/app/models/motor/dashboard.rb +1 -1
- data/app/models/motor/form.rb +1 -1
- data/app/models/motor/query.rb +2 -1
- data/app/views/motor/ui/show.html.erb +1 -1
- data/lib/generators/motor/templates/install.rb +10 -10
- data/lib/motor.rb +11 -3
- data/lib/motor/active_record_utils/defined_scopes_extension.rb +1 -1
- data/lib/motor/admin.rb +8 -0
- data/lib/motor/alerts/persistance.rb +17 -3
- data/lib/motor/alerts/scheduler.rb +1 -1
- data/lib/motor/api_query/apply_scope.rb +12 -5
- data/lib/motor/build_schema.rb +3 -3
- data/lib/motor/build_schema/find_display_column.rb +32 -29
- data/lib/motor/build_schema/load_from_rails.rb +32 -16
- data/lib/motor/build_schema/merge_schema_configs.rb +8 -4
- data/lib/motor/build_schema/reorder_schema.rb +10 -4
- data/lib/motor/configs.rb +17 -0
- data/lib/motor/configs/build_configs_hash.rb +83 -0
- data/lib/motor/configs/build_ui_app_tag.rb +71 -0
- data/lib/motor/configs/load_from_cache.rb +81 -0
- data/lib/motor/configs/sync_from_file.rb +36 -0
- data/lib/motor/configs/sync_from_hash.rb +126 -0
- data/lib/motor/configs/sync_middleware.rb +72 -0
- data/lib/motor/configs/sync_with_remote.rb +47 -0
- data/lib/motor/configs/write_to_file.rb +36 -0
- data/lib/motor/dashboards/persistance.rb +15 -5
- data/lib/motor/forms/persistance.rb +15 -5
- data/lib/motor/net_http_utils.rb +38 -0
- data/lib/motor/queries/persistance.rb +13 -3
- data/lib/motor/railtie.rb +11 -0
- data/lib/motor/tasks/motor.rake +37 -0
- data/lib/motor/version.rb +1 -1
- data/ui/dist/{main-358ea31cd7020f915067.css.gz → main-c3893a249308242d20f5.css.gz} +0 -0
- data/ui/dist/main-c3893a249308242d20f5.js.gz +0 -0
- data/ui/dist/manifest.json +5 -5
- metadata +16 -5
- data/lib/motor/ui_configs.rb +0 -82
- data/ui/dist/main-358ea31cd7020f915067.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: d06115fe373a464d0e64a5f15b6c895d549e7cef2068e9a9e9d9712cc003046d
|
4
|
+
data.tar.gz: d01b6707a80c0d30b8c43c40d9c86a7ee98475cf02ee6b8a296aac3ae25a9d27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a9b94292f85849ececb737e5d8a962a7b18989d218c72db520eb6e771b9b703083be6c54bf1894f31e1d894af3fca02065653e97497966c3b1dadbfafb098ac
|
7
|
+
data.tar.gz: c18e73dfd82fa82bf182cc445c22565a73a29006309ccd0ecb1ab92d1f610fe797ee9d4ff6cb84382e039d146ca99d16648a84717f169168e3dc834571c67b7d
|
@@ -18,12 +18,15 @@ module Motor
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def create
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
if Motor::Alerts::Persistance.name_already_exists?(@alert)
|
22
|
+
name_already_exists_response
|
23
|
+
else
|
24
|
+
ApplicationRecord.transaction { @alert.save! }
|
25
|
+
Motor::Alerts::ScheduledAlertsCache.clear
|
26
|
+
Motor::Configs::WriteToFile.call
|
27
|
+
|
28
|
+
render json: { data: Motor::ApiQuery::BuildJson.call(@alert, params) }
|
29
|
+
end
|
27
30
|
rescue Motor::Alerts::Persistance::InvalidInterval
|
28
31
|
invalid_interval_response
|
29
32
|
end
|
@@ -31,6 +34,7 @@ module Motor
|
|
31
34
|
def update
|
32
35
|
Motor::Alerts::Persistance.update_from_params!(@alert, alert_params)
|
33
36
|
Motor::Alerts::ScheduledAlertsCache.clear
|
37
|
+
Motor::Configs::WriteToFile.call
|
34
38
|
|
35
39
|
render json: { data: Motor::ApiQuery::BuildJson.call(@alert, params) }
|
36
40
|
rescue Motor::Alerts::Persistance::NameAlreadyExists
|
@@ -42,6 +46,8 @@ module Motor
|
|
42
46
|
def destroy
|
43
47
|
@alert.update!(deleted_at: Time.current)
|
44
48
|
|
49
|
+
Motor::Configs::WriteToFile.call
|
50
|
+
|
45
51
|
head :ok
|
46
52
|
end
|
47
53
|
|
@@ -22,6 +22,7 @@ module Motor
|
|
22
22
|
render json: { errors: [{ source: 'title', detail: 'Title already exists' }] }, status: :unprocessable_entity
|
23
23
|
else
|
24
24
|
ApplicationRecord.transaction { @dashboard.save! }
|
25
|
+
Motor::Configs::WriteToFile.call
|
25
26
|
|
26
27
|
render json: { data: Motor::ApiQuery::BuildJson.call(@dashboard, params) }
|
27
28
|
end
|
@@ -31,6 +32,7 @@ module Motor
|
|
31
32
|
|
32
33
|
def update
|
33
34
|
Motor::Dashboards::Persistance.update_from_params!(@dashboard, dashboard_params)
|
35
|
+
Motor::Configs::WriteToFile.call
|
34
36
|
|
35
37
|
render json: { data: Motor::ApiQuery::BuildJson.call(@dashboard, params) }
|
36
38
|
rescue Motor::Dashboards::Persistance::TitleAlreadyExists
|
@@ -40,6 +42,8 @@ module Motor
|
|
40
42
|
def destroy
|
41
43
|
@dashboard.update!(deleted_at: Time.current)
|
42
44
|
|
45
|
+
Motor::Configs::WriteToFile.call
|
46
|
+
|
43
47
|
head :ok
|
44
48
|
end
|
45
49
|
|
@@ -22,6 +22,7 @@ module Motor
|
|
22
22
|
render json: { errors: [{ source: 'name', detail: 'Name already exists' }] }, status: :unprocessable_entity
|
23
23
|
else
|
24
24
|
ApplicationRecord.transaction { @form.save! }
|
25
|
+
Motor::Configs::WriteToFile.call
|
25
26
|
|
26
27
|
render json: { data: Motor::ApiQuery::BuildJson.call(@form, params) }
|
27
28
|
end
|
@@ -31,6 +32,7 @@ module Motor
|
|
31
32
|
|
32
33
|
def update
|
33
34
|
Motor::Forms::Persistance.update_from_params!(@form, form_params)
|
35
|
+
Motor::Configs::WriteToFile.call
|
34
36
|
|
35
37
|
render json: { data: Motor::ApiQuery::BuildJson.call(@form, params) }
|
36
38
|
rescue Motor::Forms::Persistance::NameAlreadyExists
|
@@ -40,6 +42,8 @@ module Motor
|
|
40
42
|
def destroy
|
41
43
|
@form.update!(deleted_at: Time.current)
|
42
44
|
|
45
|
+
Motor::Configs::WriteToFile.call
|
46
|
+
|
43
47
|
head :ok
|
44
48
|
end
|
45
49
|
|
@@ -22,6 +22,7 @@ module Motor
|
|
22
22
|
render json: { errors: [{ source: 'name', detail: 'Name already exists' }] }, status: :unprocessable_entity
|
23
23
|
else
|
24
24
|
ApplicationRecord.transaction { @query.save! }
|
25
|
+
Motor::Configs::WriteToFile.call
|
25
26
|
|
26
27
|
render json: { data: Motor::ApiQuery::BuildJson.call(@query, params) }
|
27
28
|
end
|
@@ -31,6 +32,7 @@ module Motor
|
|
31
32
|
|
32
33
|
def update
|
33
34
|
Motor::Queries::Persistance.update_from_params!(@query, query_params)
|
35
|
+
Motor::Configs::WriteToFile.call
|
34
36
|
|
35
37
|
render json: { data: Motor::ApiQuery::BuildJson.call(@query, params) }
|
36
38
|
rescue Motor::Queries::Persistance::NameAlreadyExists
|
@@ -40,6 +42,8 @@ module Motor
|
|
40
42
|
def destroy
|
41
43
|
@query.update!(deleted_at: Time.current)
|
42
44
|
|
45
|
+
Motor::Configs::WriteToFile.call
|
46
|
+
|
43
47
|
head :ok
|
44
48
|
end
|
45
49
|
|
@@ -7,12 +7,16 @@ module Motor
|
|
7
7
|
def index
|
8
8
|
Motor.reload! if Motor.development?
|
9
9
|
|
10
|
+
Motor::Configs::SyncFromFile.call
|
11
|
+
|
10
12
|
render :show
|
11
13
|
end
|
12
14
|
|
13
15
|
def show
|
14
16
|
Motor.reload! if Motor.development?
|
15
17
|
|
18
|
+
Motor::Configs::SyncFromFile.call
|
19
|
+
|
16
20
|
render :show
|
17
21
|
end
|
18
22
|
end
|
data/app/models/motor/alert.rb
CHANGED
@@ -7,8 +7,8 @@ module Motor
|
|
7
7
|
belongs_to :query
|
8
8
|
belongs_to :author, polymorphic: true, optional: true
|
9
9
|
|
10
|
-
has_many :alert_locks
|
11
|
-
has_many :taggable_tags, as: :taggable
|
10
|
+
has_many :alert_locks, dependent: :destroy
|
11
|
+
has_many :taggable_tags, as: :taggable, dependent: :destroy
|
12
12
|
has_many :tags, through: :taggable_tags, class_name: 'Motor::Tag'
|
13
13
|
|
14
14
|
serialize :preferences, HashSerializer
|
@@ -6,7 +6,7 @@ module Motor
|
|
6
6
|
|
7
7
|
belongs_to :author, polymorphic: true, optional: true
|
8
8
|
|
9
|
-
has_many :taggable_tags, as: :taggable
|
9
|
+
has_many :taggable_tags, as: :taggable, dependent: :destroy
|
10
10
|
has_many :tags, through: :taggable_tags, class_name: 'Motor::Tag'
|
11
11
|
|
12
12
|
serialize :preferences, HashSerializer
|
data/app/models/motor/form.rb
CHANGED
@@ -6,7 +6,7 @@ module Motor
|
|
6
6
|
|
7
7
|
belongs_to :author, polymorphic: true, optional: true
|
8
8
|
|
9
|
-
has_many :taggable_tags, as: :taggable
|
9
|
+
has_many :taggable_tags, as: :taggable, dependent: :destroy
|
10
10
|
has_many :tags, through: :taggable_tags, class_name: 'Motor::Tag'
|
11
11
|
|
12
12
|
serialize :preferences, HashSerializer
|
data/app/models/motor/query.rb
CHANGED
@@ -6,8 +6,9 @@ module Motor
|
|
6
6
|
|
7
7
|
belongs_to :author, polymorphic: true, optional: true
|
8
8
|
|
9
|
-
has_many :taggable_tags, as: :taggable
|
9
|
+
has_many :taggable_tags, as: :taggable, dependent: :destroy
|
10
10
|
has_many :tags, through: :taggable_tags, class_name: 'Motor::Tag'
|
11
|
+
has_many :alerts, dependent: :destroy
|
11
12
|
|
12
13
|
serialize :preferences, HashSerializer
|
13
14
|
|
@@ -1 +1 @@
|
|
1
|
-
<%= raw(Motor::
|
1
|
+
<%= raw(Motor::Configs::BuildUiAppTag.call) %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
2
2
|
def self.up
|
3
|
-
create_table :motor_queries
|
3
|
+
create_table :motor_queries do |t|
|
4
4
|
t.column :name, :string, null: false
|
5
5
|
t.column :description, :string
|
6
6
|
t.column :sql_body, :string, null: false
|
@@ -18,7 +18,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
18
18
|
where: 'deleted_at IS NULL'
|
19
19
|
end
|
20
20
|
|
21
|
-
create_table :motor_dashboards
|
21
|
+
create_table :motor_dashboards do |t|
|
22
22
|
t.column :title, :string, null: false
|
23
23
|
t.column :description, :string
|
24
24
|
t.column :preferences, :string, null: false, default: '{}'
|
@@ -35,7 +35,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
35
35
|
where: 'deleted_at IS NULL'
|
36
36
|
end
|
37
37
|
|
38
|
-
create_table :motor_forms
|
38
|
+
create_table :motor_forms do |t|
|
39
39
|
t.column :name, :string, null: false
|
40
40
|
t.column :description, :string
|
41
41
|
t.column :api_path, :string, null: false
|
@@ -54,7 +54,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
54
54
|
where: 'deleted_at IS NULL'
|
55
55
|
end
|
56
56
|
|
57
|
-
create_table :motor_resources
|
57
|
+
create_table :motor_resources do |t|
|
58
58
|
t.column :name, :string, null: false, index: { unique: true }
|
59
59
|
t.column :preferences, :string, null: false, default: '{}'
|
60
60
|
|
@@ -63,7 +63,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
63
63
|
t.index :updated_at
|
64
64
|
end
|
65
65
|
|
66
|
-
create_table :motor_configs
|
66
|
+
create_table :motor_configs do |t|
|
67
67
|
t.column :key, :string, null: false, index: { unique: true }
|
68
68
|
t.column :value, :string, null: false, default: '{}'
|
69
69
|
|
@@ -72,7 +72,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
72
72
|
t.index :updated_at
|
73
73
|
end
|
74
74
|
|
75
|
-
create_table :motor_alerts
|
75
|
+
create_table :motor_alerts do |t|
|
76
76
|
t.references :query, null: false, foreign_key: { to_table: :motor_queries }, index: true
|
77
77
|
t.column :name, :string, null: false
|
78
78
|
t.column :description, :string
|
@@ -92,7 +92,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
92
92
|
where: 'deleted_at IS NULL'
|
93
93
|
end
|
94
94
|
|
95
|
-
create_table :motor_alert_locks
|
95
|
+
create_table :motor_alert_locks do |t|
|
96
96
|
t.references :alert, null: false, foreign_key: { to_table: :motor_alerts }
|
97
97
|
t.column :lock_timestamp, :string, null: false
|
98
98
|
|
@@ -101,7 +101,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
101
101
|
t.index %i[alert_id lock_timestamp], unique: true
|
102
102
|
end
|
103
103
|
|
104
|
-
create_table :motor_tags
|
104
|
+
create_table :motor_tags do |t|
|
105
105
|
t.column :name, :string, null: false
|
106
106
|
|
107
107
|
t.timestamps
|
@@ -111,7 +111,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
111
111
|
unique: true
|
112
112
|
end
|
113
113
|
|
114
|
-
create_table :motor_taggable_tags
|
114
|
+
create_table :motor_taggable_tags do |t|
|
115
115
|
t.references :tag, null: false, foreign_key: { to_table: :motor_tags }, index: true
|
116
116
|
t.column :taggable_id, :integer, null: false
|
117
117
|
t.column :taggable_type, :string, null: false
|
@@ -121,7 +121,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
121
121
|
unique: true
|
122
122
|
end
|
123
123
|
|
124
|
-
create_table :motor_audits
|
124
|
+
create_table :motor_audits do |t|
|
125
125
|
t.column :auditable_id, :integer
|
126
126
|
t.column :auditable_type, :string
|
127
127
|
t.column :associated_id, :integer
|
data/lib/motor.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'concurrent/executor/fixed_thread_pool'
|
4
|
+
require 'concurrent/timer_task'
|
3
5
|
require 'cancancan'
|
4
6
|
require 'ar_lazy_preload'
|
5
7
|
require 'js_regex'
|
@@ -7,6 +9,9 @@ require 'fugit'
|
|
7
9
|
require 'csv'
|
8
10
|
require 'active_record/filter'
|
9
11
|
require 'audited'
|
12
|
+
require 'uri'
|
13
|
+
require 'net/http'
|
14
|
+
require 'net/https'
|
10
15
|
|
11
16
|
module Motor
|
12
17
|
PATH = Pathname.new(__dir__)
|
@@ -18,7 +23,8 @@ module Motor
|
|
18
23
|
Dir[PATH.join('./motor/**/*.rb')].each do |f|
|
19
24
|
next if f.ends_with?('alerts/scheduler.rb')
|
20
25
|
next if f.ends_with?('alerts/scheduled_alerts_cache.rb')
|
21
|
-
next if f.ends_with?('
|
26
|
+
next if f.ends_with?('configs/load_from_cache.rb')
|
27
|
+
next if f.ends_with?('configs/sync_from_file.rb')
|
22
28
|
|
23
29
|
load f
|
24
30
|
end
|
@@ -47,13 +53,15 @@ end
|
|
47
53
|
require 'motor/version'
|
48
54
|
require 'motor/admin'
|
49
55
|
require 'motor/assets'
|
56
|
+
require 'motor/active_record_utils'
|
50
57
|
require 'motor/build_schema'
|
51
58
|
require 'motor/api_query'
|
52
59
|
require 'motor/tags'
|
53
|
-
require 'motor/
|
60
|
+
require 'motor/configs'
|
54
61
|
require 'motor/queries'
|
55
62
|
require 'motor/dashboards'
|
56
63
|
require 'motor/forms'
|
57
64
|
require 'motor/alerts'
|
58
65
|
require 'motor/hash_serializer'
|
59
|
-
require 'motor/
|
66
|
+
require 'motor/net_http_utils'
|
67
|
+
require 'motor/railtie'
|
data/lib/motor/admin.rb
CHANGED
@@ -28,6 +28,14 @@ module Motor
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
initializer 'motor.configs.sync_middleware' do
|
32
|
+
next if Motor::Configs::SYNC_ACCESS_KEY.blank?
|
33
|
+
|
34
|
+
require 'motor/configs/sync_middleware'
|
35
|
+
|
36
|
+
Rails.application.config.middleware.insert_after(Rails::Rack::Logger, Motor::Configs::SyncMiddleware)
|
37
|
+
end
|
38
|
+
|
31
39
|
initializer 'motor.filter_params' do
|
32
40
|
Rails.application.config.filter_parameters += %i[io]
|
33
41
|
end
|
@@ -43,30 +43,44 @@ module Motor
|
|
43
43
|
retry
|
44
44
|
end
|
45
45
|
|
46
|
-
def update_from_params!(alert, params)
|
46
|
+
def update_from_params!(alert, params, force_replace: false)
|
47
|
+
tag_ids = alert.tags.ids
|
48
|
+
|
47
49
|
alert = assign_attributes(alert, params)
|
48
50
|
|
49
|
-
raise NameAlreadyExists if name_already_exists?(alert)
|
51
|
+
raise NameAlreadyExists if !force_replace && name_already_exists?(alert)
|
50
52
|
raise InvalidInterval unless alert.cron
|
51
53
|
|
52
54
|
ApplicationRecord.transaction do
|
55
|
+
archive_with_existing_name(alert) if force_replace
|
56
|
+
|
53
57
|
alert.save!
|
54
58
|
end
|
55
59
|
|
56
|
-
alert.
|
60
|
+
alert.touch if tags_changed?(tag_ids, alert) && params[:updated_at].blank?
|
57
61
|
|
58
62
|
alert
|
59
63
|
rescue ActiveRecord::RecordNotUnique
|
60
64
|
retry
|
61
65
|
end
|
62
66
|
|
67
|
+
def tags_changed?(previous_ids, alert)
|
68
|
+
previous_ids.sort != alert.tags.reload.ids.sort
|
69
|
+
end
|
70
|
+
|
63
71
|
def assign_attributes(alert, params)
|
64
72
|
alert.assign_attributes(params.slice(*ALERT_ATTRIBUTES))
|
65
73
|
alert.preferences[:interval] = normalize_interval(alert.preferences[:interval])
|
74
|
+
alert.updated_at = [params[:updated_at], Time.current].min if params[:updated_at].present?
|
66
75
|
|
67
76
|
Motor::Tags.assign_tags(alert, params[:tags])
|
68
77
|
end
|
69
78
|
|
79
|
+
def archive_with_existing_name(alert)
|
80
|
+
Motor::Alert.where(['lower(name) = ? AND id != ?', alert.name.to_s.downcase, alert.id])
|
81
|
+
.update_all(deleted_at: Time.current)
|
82
|
+
end
|
83
|
+
|
70
84
|
def normalize_interval(interval)
|
71
85
|
interval.to_s.gsub(NORMALIZE_INTERVAL_REGEXP, 'every ')
|
72
86
|
end
|
@@ -13,13 +13,20 @@ module Motor
|
|
13
13
|
if rel.klass.defined_scopes.include?(scope_symbol)
|
14
14
|
rel.public_send(scope_symbol)
|
15
15
|
else
|
16
|
-
|
17
|
-
|
16
|
+
apply_filter_scope(rel, scope)
|
17
|
+
end
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
+
def apply_filter_scope(rel, scope)
|
21
|
+
configs = Motor::Resource.find_by_name(rel.klass.name.underscore)
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
return rel unless configs
|
24
|
+
|
25
|
+
scope_configs = configs.preferences[:scopes].find { |s| s[:name] == scope }
|
26
|
+
|
27
|
+
return rel unless scope_configs
|
28
|
+
|
29
|
+
ApiQuery::Filter.call(rel, scope_configs[:preferences][:filter])
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|