superset 0.2.6 → 0.3.0
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/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +16 -0
- data/Dockerfile +2 -2
- data/README.md +6 -3
- data/doc/duplicate_dashboards.md +45 -6
- data/lib/superset/base_put_request.rb +4 -4
- data/lib/superset/chart/bulk_delete.rb +1 -1
- data/lib/superset/chart/delete.rb +1 -1
- data/lib/superset/chart/get.rb +7 -11
- data/lib/superset/chart/list.rb +5 -5
- data/lib/superset/chart/put.rb +2 -2
- data/lib/superset/dashboard/bulk_delete.rb +1 -1
- data/lib/superset/dashboard/cascade_ownership/add_new_owner.rb +54 -0
- data/lib/superset/dashboard/datasets/list.rb +15 -15
- data/lib/superset/dashboard/delete.rb +1 -1
- data/lib/superset/dashboard/list.rb +35 -9
- data/lib/superset/dashboard/put.rb +7 -24
- data/lib/superset/dashboard/warm_up_cache.rb +1 -1
- data/lib/superset/database/get_catalogs.rb +38 -0
- data/lib/superset/database/list.rb +2 -2
- data/lib/superset/dataset/bulk_delete.rb +1 -1
- data/lib/superset/dataset/delete.rb +1 -1
- data/lib/superset/dataset/get.rb +8 -4
- data/lib/superset/dataset/list.rb +2 -2
- data/lib/superset/dataset/put.rb +2 -2
- data/lib/superset/dataset/update_schema.rb +4 -2
- data/lib/superset/display.rb +19 -10
- data/lib/superset/request.rb +6 -4
- data/lib/superset/security/permissions_resources/list.rb +2 -2
- data/lib/superset/security/user/list.rb +2 -2
- data/lib/superset/services/duplicate_dashboard.rb +72 -26
- data/lib/superset/services/import_dashboard_across_environment.rb +3 -0
- data/lib/superset/tag/add_to_object.rb +5 -5
- data/lib/superset/tag/list.rb +1 -1
- data/lib/superset/version.rb +1 -1
- data/superset.gemspec +12 -13
- metadata +63 -65
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f9be8bc52c7852af239721ed6e260a12e068bb35042ae0d7a78507d39c498017
|
|
4
|
+
data.tar.gz: 3ddd9c26deca3cc72bd046d83435d22383f2986cee3bcfdebe9e4db0f0749ea3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1e1e71dace1acffd37407100c583f9bb61e29fcffafabdd13bcad834c49366b190a068fbe90b529c809e3c8d786afb9a370656ac47d96adfd740985dbbe9917
|
|
7
|
+
data.tar.gz: bee9ae33375f128d4d9abc11259d9f300ac281c188ec90c26088af85c8620e10350ba44a1f1645403b9994fcadc8760e79d94098e373a2a07666f6991dee418a
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.4.4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
+
## 0.3.0 - 2025-11-26
|
|
4
|
+
* Rename reserved object_id to target_id in https://github.com/rdytech/superset-client/pull/58
|
|
5
|
+
* Add dashboard cascade ownship in https://github.com/rdytech/superset-client/pull/59
|
|
6
|
+
* allow dup dashboard dataset suffix naming override in https://github.com/rdytech/superset-client/pull/61
|
|
7
|
+
* Bump ruby 3 bump gems by https://github.com/rdytech/superset-client/pull/60
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## 0.2.7 - 2025-10-16
|
|
11
|
+
* add to_h method to list classes for Hash output
|
|
12
|
+
* add ids method to list classes for array of ids output
|
|
13
|
+
* add ability to over ride default page_size
|
|
14
|
+
* add ruby console auto timeout set to 30 mins by default
|
|
15
|
+
* add GetCatalogs endpoint caller
|
|
16
|
+
* fix catalog bug related to dashboard export and import across env
|
|
17
|
+
* add tag_equals param to dashboard list class
|
|
18
|
+
|
|
3
19
|
## 0.2.6 - 2025-08-05
|
|
4
20
|
* Bump terminal-table from 1.8.0 to 4.0.0
|
|
5
21
|
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
|
@@ -22,11 +22,14 @@ Build, bundle and open a ruby console
|
|
|
22
22
|
docker-compose build
|
|
23
23
|
docker-compose run --rm app bundle install
|
|
24
24
|
docker-compose run --rm app bin/console
|
|
25
|
+
|
|
26
|
+
# note .. windows users may need to call ruby the bin/console file
|
|
27
|
+
docker-compose run --rm app ruby bin/console
|
|
25
28
|
```
|
|
26
29
|
|
|
27
|
-
## Setup Locally ( no docker )
|
|
30
|
+
## Setup Locally ( no docker )
|
|
28
31
|
|
|
29
|
-
Requires Ruby >=
|
|
32
|
+
Requires Ruby >= 3
|
|
30
33
|
|
|
31
34
|
Bundle install and open a ruby console.
|
|
32
35
|
|
|
@@ -37,7 +40,7 @@ bin/console
|
|
|
37
40
|
|
|
38
41
|
## Including in a Ruby app
|
|
39
42
|
|
|
40
|
-
Add to your Gemfile `gem 'superset'`
|
|
43
|
+
Add to your Gemfile `gem 'superset'`
|
|
41
44
|
And then execute: `bundle install`
|
|
42
45
|
Or install it yourself as `gem install superset`
|
|
43
46
|
|
data/doc/duplicate_dashboards.md
CHANGED
|
@@ -36,7 +36,7 @@ then you could go ahead and run something like this.
|
|
|
36
36
|
```ruby
|
|
37
37
|
Superset::Services::DuplicateDashboard.new(
|
|
38
38
|
source_dashboard_id: 90,
|
|
39
|
-
target_schema: '
|
|
39
|
+
target_schema: 'client_1',
|
|
40
40
|
target_database_id: 2
|
|
41
41
|
).perform
|
|
42
42
|
|
|
@@ -47,12 +47,12 @@ Superset::Services::DuplicateDashboard.new(
|
|
|
47
47
|
# cat log/superset-client.log
|
|
48
48
|
# INFO -- : >>>>>>>>>>>>>>>>> Starting DuplicateDashboard Service <<<<<<<<<<<<<<<<<<<<<<
|
|
49
49
|
# INFO -- : Source Dashboard URL: https://your-superset-host/superset/dashboard/90/
|
|
50
|
-
# INFO -- : Duplicating dashboard 90 into Target Schema:
|
|
50
|
+
# INFO -- : Duplicating dashboard 90 into Target Schema: client_1 in database 2
|
|
51
51
|
# INFO -- : Copy Dashboard/Charts Completed - New Dashboard ID: 401
|
|
52
52
|
# INFO -- : Duplicating Source Dataset examples.video_game_sales with id 11
|
|
53
|
-
# INFO -- : Finished. Duplicate Dataset Name video_game_sales-example_two with id 542
|
|
54
|
-
# INFO -- : Validating Dataset ID: 542 schema update to
|
|
55
|
-
# INFO -- : Successfully updated dataset schema to
|
|
53
|
+
# INFO -- : Finished. Duplicate Dataset Name video_game_sales-example_two-client_1 with id 542
|
|
54
|
+
# INFO -- : Validating Dataset ID: 542 schema update to client_1 on Database: 2
|
|
55
|
+
# INFO -- : Successfully updated dataset schema to client_1 on Database: 2
|
|
56
56
|
# INFO -- : Updating Charts to point to New Datasets and updating Dashboard json_metadata ...
|
|
57
57
|
# INFO -- : Update Chart 55752 to new dataset_id 542
|
|
58
58
|
# INFO -- : Updated new Dashboard json_metadata charts with new dataset ids
|
|
@@ -71,14 +71,53 @@ If your using the embedded dashboards you can also provied attributes for
|
|
|
71
71
|
```ruby
|
|
72
72
|
Superset::Services::DuplicateDashboard.new(
|
|
73
73
|
source_dashboard_id: 37,
|
|
74
|
-
target_schema: '
|
|
74
|
+
target_schema: 'client_1',
|
|
75
75
|
target_database_id: 2,
|
|
76
76
|
allowed_domains: ["https://wylee-coyote-domain/"],
|
|
77
77
|
tags: ["product:acme_fu", "client:wylee_coyote", "embedded"],
|
|
78
78
|
publish: true
|
|
79
79
|
).perform
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Duplication when DB schemas are not used
|
|
86
|
+
|
|
87
|
+
If your multitenant setup is at the database level, and database structures are replicated into the same base schema, ie public,
|
|
88
|
+
then the target resulted datasets name must be overridden in order to get around the superset unique datasets name validation restriction. This can be done through the parameter 'target_dataset_suffix_override'.
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
Superset::Services::DuplicateDashboard.new(
|
|
92
|
+
source_dashboard_id: 90,
|
|
93
|
+
target_schema: 'public',
|
|
94
|
+
target_database_id: 2,
|
|
95
|
+
target_dataset_suffix_override: 'client_1'
|
|
96
|
+
).perform
|
|
97
|
+
|
|
80
98
|
```
|
|
81
99
|
|
|
100
|
+
## Duplication now supports catalogs
|
|
101
|
+
|
|
102
|
+
If you Database infrastructure uses catalogs, you can provide the target catalog as a paramater.
|
|
103
|
+
If there is only 1 catalog in the target database, then it will be used by default.
|
|
104
|
+
|
|
105
|
+
If multiple catalogs exist, and no catalog option is provided, an error will be raised.
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
Superset::Services::DuplicateDashboard.new(
|
|
109
|
+
source_dashboard_id: 90,
|
|
110
|
+
target_schema: 'public',
|
|
111
|
+
target_database_id: 2,
|
|
112
|
+
target_dataset_suffix_override: 'client_1',
|
|
113
|
+
target_catalog_name: 'staging_client_1',
|
|
114
|
+
).perform
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
82
121
|
### What is my Database ID ?
|
|
83
122
|
|
|
84
123
|
``` ruby
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module Superset
|
|
2
2
|
class BasePutRequest < Superset::Request
|
|
3
|
-
attr_reader :
|
|
3
|
+
attr_reader :target_id, :params
|
|
4
4
|
|
|
5
|
-
def initialize(
|
|
6
|
-
@
|
|
5
|
+
def initialize(target_id: ,params: )
|
|
6
|
+
@target_id = target_id
|
|
7
7
|
@params = params
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -19,7 +19,7 @@ module Superset
|
|
|
19
19
|
private
|
|
20
20
|
|
|
21
21
|
def validate
|
|
22
|
-
raise "Error:
|
|
22
|
+
raise "Error: target_id integer is required" unless target_id.present? && target_id.is_a?(Integer)
|
|
23
23
|
raise "Error: params hash is required" unless params.present? && params.is_a?(Hash)
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -18,7 +18,7 @@ module Superset
|
|
|
18
18
|
raise InvalidParameterError, "chart_ids array of integers expected" unless chart_ids.is_a?(Array)
|
|
19
19
|
raise InvalidParameterError, "chart_ids array must contain Integer only values" unless chart_ids.all? { |item| item.is_a?(Integer) }
|
|
20
20
|
|
|
21
|
-
logger.info("
|
|
21
|
+
logger.info("Deleting charts with id: #{chart_ids.join(', ')}")
|
|
22
22
|
response
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -12,7 +12,7 @@ module Superset
|
|
|
12
12
|
def perform
|
|
13
13
|
raise InvalidParameterError, "chart_id integer is required" unless chart_id.present? && chart_id.is_a?(Integer)
|
|
14
14
|
|
|
15
|
-
logger.info("
|
|
15
|
+
logger.info("Deleting chart with id: #{chart_id}")
|
|
16
16
|
response
|
|
17
17
|
end
|
|
18
18
|
|
data/lib/superset/chart/get.rb
CHANGED
|
@@ -17,28 +17,24 @@ module Superset
|
|
|
17
17
|
self
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def result
|
|
21
|
-
[ super ]
|
|
22
|
-
end
|
|
23
|
-
|
|
24
20
|
def datasource_id
|
|
25
|
-
if result
|
|
26
|
-
JSON.parse(result
|
|
27
|
-
elsif result
|
|
28
|
-
JSON.parse(result
|
|
21
|
+
if result['query_context'].present? && JSON.parse(result['query_context'])['datasource'].present?
|
|
22
|
+
JSON.parse(result['query_context'])['datasource']['id']
|
|
23
|
+
elsif result['params'].present? && JSON.parse(result['params'])['datasource'].present?
|
|
24
|
+
JSON.parse(result['params'])['datasource'].match(/^\d+/)[0].to_i
|
|
29
25
|
end
|
|
30
26
|
end
|
|
31
27
|
|
|
32
28
|
def owner_ids
|
|
33
|
-
result
|
|
29
|
+
result['owners'].map{|o| o['id']}
|
|
34
30
|
end
|
|
35
31
|
|
|
36
32
|
def params
|
|
37
|
-
JSON.parse(result
|
|
33
|
+
JSON.parse(result['params']) if result['params'].present?
|
|
38
34
|
end
|
|
39
35
|
|
|
40
36
|
def query_context
|
|
41
|
-
JSON.parse(result
|
|
37
|
+
JSON.parse(result['query_context']) if result['query_context'].present?
|
|
42
38
|
end
|
|
43
39
|
|
|
44
40
|
private
|
data/lib/superset/chart/list.rb
CHANGED
|
@@ -2,13 +2,13 @@ module Superset
|
|
|
2
2
|
module Chart
|
|
3
3
|
class List < Superset::Request
|
|
4
4
|
|
|
5
|
-
attr_reader :
|
|
5
|
+
attr_reader :title_contains, :dashboard_id_eq, :dataset_id_eq
|
|
6
6
|
|
|
7
|
-
def initialize(
|
|
8
|
-
@
|
|
7
|
+
def initialize(title_contains: '', dashboard_id_eq: '', dataset_id_eq: '', **kwargs)
|
|
8
|
+
@title_contains = title_contains
|
|
9
9
|
@dashboard_id_eq = dashboard_id_eq
|
|
10
10
|
@dataset_id_eq = dataset_id_eq
|
|
11
|
-
super(
|
|
11
|
+
super(**kwargs)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def self.call
|
|
@@ -38,7 +38,7 @@ module Superset
|
|
|
38
38
|
def filters
|
|
39
39
|
# TODO filtering across all classes needs a refactor to support multiple options in a more flexible way
|
|
40
40
|
filter_set = []
|
|
41
|
-
filter_set << "(col:slice_name,opr:ct,value:'#{
|
|
41
|
+
filter_set << "(col:slice_name,opr:ct,value:'#{title_contains}')" if title_contains.present?
|
|
42
42
|
filter_set << "(col:dashboards,opr:rel_m_m,value:#{dashboard_id_eq})" if dashboard_id_eq.present? # rel many to many
|
|
43
43
|
filter_set << "(col:datasource_id,opr:eq,value:#{dataset_id_eq})" if dataset_id_eq.present?
|
|
44
44
|
|
data/lib/superset/chart/put.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Usage:
|
|
4
4
|
# params = { owners: [ 58, 3 ] }
|
|
5
|
-
# Superset::Chart::Put.new(
|
|
5
|
+
# Superset::Chart::Put.new(target_id: 202, params: params ).perform
|
|
6
6
|
|
|
7
7
|
module Superset
|
|
8
8
|
module Chart
|
|
@@ -11,7 +11,7 @@ module Superset
|
|
|
11
11
|
private
|
|
12
12
|
|
|
13
13
|
def route
|
|
14
|
-
"chart/#{
|
|
14
|
+
"chart/#{target_id}"
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -20,7 +20,7 @@ module Superset
|
|
|
20
20
|
raise InvalidParameterError, "dashboard_ids array of integers expected" unless dashboard_ids.is_a?(Array)
|
|
21
21
|
raise InvalidParameterError, "dashboard_ids array must contain Integer only values" unless dashboard_ids.all? { |item| item.is_a?(Integer) }
|
|
22
22
|
|
|
23
|
-
logger.info("
|
|
23
|
+
logger.info("Deleting dashboards with id: #{dashboard_ids.join(', ')}")
|
|
24
24
|
response
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module Superset
|
|
2
|
+
module Dashboard
|
|
3
|
+
module CascadeOwnership
|
|
4
|
+
class AddNewOwner < Superset::Request
|
|
5
|
+
attr_reader :dashboard_id, :user_id
|
|
6
|
+
|
|
7
|
+
def initialize(dashboard_id:, user_id:)
|
|
8
|
+
@dashboard_id = dashboard_id
|
|
9
|
+
@user_id = user_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def perform
|
|
13
|
+
raise "Error: dashboard_id integer is required" unless dashboard_id.present? && dashboard_id.is_a?(Integer)
|
|
14
|
+
raise "Error: user_id integer is required" unless user_id.present? && user_id.is_a?(Integer)
|
|
15
|
+
|
|
16
|
+
add_user_to_dashboard_ownership
|
|
17
|
+
add_user_to_charts_ownership
|
|
18
|
+
add_user_to_datasets_ownership
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def add_user_to_dashboard_ownership
|
|
24
|
+
return if current_dashboard_owner_ids.include?(user_id)
|
|
25
|
+
Superset::Dashboard::Put.new(target_id: dashboard_id, params: { "owners": current_dashboard_owner_ids << user_id }).perform
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add_user_to_charts_ownership
|
|
29
|
+
chart_ids = Superset::Dashboard::Charts::List.new(dashboard_id).ids
|
|
30
|
+
chart_ids.each do |chart_id|
|
|
31
|
+
current_chart_owner_ids = Superset::Chart::Get.new(chart_id).result['owners'].map{|c| c['id']}
|
|
32
|
+
next if current_chart_owner_ids.include?(user_id)
|
|
33
|
+
|
|
34
|
+
Superset::Chart::Put.new(target_id: chart_id, params: { "owners": current_chart_owner_ids << user_id }).perform
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def add_user_to_datasets_ownership
|
|
39
|
+
dataset_ids = Superset::Dashboard::Datasets::List.new(dashboard_id: dashboard_id).ids
|
|
40
|
+
dataset_ids.each do |dataset_id|
|
|
41
|
+
current_dataset_owner_ids = Superset::Dataset::Get.new(dataset_id).result['owners'].map{|c| c['id']}
|
|
42
|
+
next if current_dataset_owner_ids.include?(user_id)
|
|
43
|
+
|
|
44
|
+
Superset::Dataset::Put.new(target_id: dataset_id, params: { "owners": current_dataset_owner_ids << user_id }).perform
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def current_dashboard_owner_ids
|
|
49
|
+
@current_dashboard_owner_ids ||= Superset::Dashboard::Get.new(dashboard_id).result['owners'].map{|i| i['id'] }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -30,7 +30,7 @@ module Superset
|
|
|
30
30
|
# For the current superset setup we will assume a dashboard datasets will point to EXACTLY one schema, their own.
|
|
31
31
|
# if not .. we need to know about it. Potentially we could override this check if others do not consider it a problem.
|
|
32
32
|
if all_dashboard_schemas.count > 1
|
|
33
|
-
Rollbar.error("SUPERSET DASHBOARD ERROR: Dashboard id #{id} has multiple dataset schema linked: #{all_dashboard_schemas.to_s}")
|
|
33
|
+
Rollbar.error("SUPERSET DASHBOARD ERROR: Dashboard id #{id} has multiple dataset schema linked: #{all_dashboard_schemas.to_s}") if defined?(Rollbar)
|
|
34
34
|
end
|
|
35
35
|
all_dashboard_schemas
|
|
36
36
|
end
|
|
@@ -48,6 +48,20 @@ module Superset
|
|
|
48
48
|
chart_datasets + filter_datasets(filter_dataset_ids_not_used_in_charts)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
def rows
|
|
52
|
+
datasets_details.map do |d|
|
|
53
|
+
[
|
|
54
|
+
d[:id],
|
|
55
|
+
d[:datasource_name],
|
|
56
|
+
d[:database][:id],
|
|
57
|
+
d[:database][:name],
|
|
58
|
+
d[:database][:backend],
|
|
59
|
+
d[:schema],
|
|
60
|
+
d[:filter_only]
|
|
61
|
+
]
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
51
65
|
private
|
|
52
66
|
|
|
53
67
|
def filter_dataset_ids
|
|
@@ -74,20 +88,6 @@ module Superset
|
|
|
74
88
|
['id', 'datasource_name', 'database_id', 'database_name', 'database_backend', 'schema', 'filter_only'].map(&:to_sym)
|
|
75
89
|
end
|
|
76
90
|
|
|
77
|
-
def rows
|
|
78
|
-
datasets_details.map do |d|
|
|
79
|
-
[
|
|
80
|
-
d[:id],
|
|
81
|
-
d[:datasource_name],
|
|
82
|
-
d[:database][:id],
|
|
83
|
-
d[:database][:name],
|
|
84
|
-
d[:database][:backend],
|
|
85
|
-
d[:schema],
|
|
86
|
-
d[:filter_only]
|
|
87
|
-
]
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
91
|
# when displaying a list of datasets, show dashboard title as well
|
|
92
92
|
def title
|
|
93
93
|
@title ||= [id, dashboard.title].join(' ')
|
|
@@ -5,15 +5,18 @@
|
|
|
5
5
|
module Superset
|
|
6
6
|
module Dashboard
|
|
7
7
|
class List < Superset::Request
|
|
8
|
-
attr_reader :title_contains, :title_equals,
|
|
8
|
+
attr_reader :title_contains, :title_equals,
|
|
9
|
+
:tags_contain, :tags_equal,
|
|
10
|
+
:ids_not_in, :include_filter_dataset_schemas
|
|
9
11
|
|
|
10
|
-
def initialize(
|
|
12
|
+
def initialize(title_contains: '', title_equals: '', tags_contain: [], tags_equal: [], ids_not_in: [], include_filter_dataset_schemas: false, **kwargs)
|
|
11
13
|
@title_contains = title_contains
|
|
12
14
|
@title_equals = title_equals
|
|
15
|
+
@tags_contain = tags_contain
|
|
13
16
|
@tags_equal = tags_equal
|
|
14
17
|
@ids_not_in = ids_not_in
|
|
15
18
|
@include_filter_dataset_schemas = include_filter_dataset_schemas
|
|
16
|
-
super(
|
|
19
|
+
super(**kwargs)
|
|
17
20
|
end
|
|
18
21
|
|
|
19
22
|
def self.call
|
|
@@ -57,8 +60,16 @@ module Superset
|
|
|
57
60
|
end
|
|
58
61
|
end
|
|
59
62
|
|
|
63
|
+
def to_h
|
|
64
|
+
result.map do |d|
|
|
65
|
+
list_attributes.to_h do |la|
|
|
66
|
+
la == :url ? [la, "#{superset_host}#{d[la]}"] : [la, d[la]]
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
60
71
|
def ids
|
|
61
|
-
result.map { |d| d[:id] }
|
|
72
|
+
result.is_a?(Hash) ? [result[:id]] : result.map { |d| d[:id] }
|
|
62
73
|
end
|
|
63
74
|
|
|
64
75
|
private
|
|
@@ -72,15 +83,30 @@ module Superset
|
|
|
72
83
|
filter_set = []
|
|
73
84
|
filter_set << "(col:dashboard_title,opr:ct,value:'#{title_contains}')" if title_contains.present?
|
|
74
85
|
filter_set << "(col:dashboard_title,opr:eq,value:'#{title_equals}')" if title_equals.present?
|
|
75
|
-
filter_set <<
|
|
86
|
+
filter_set << tags_contain_filters if tags_contain.present?
|
|
87
|
+
filter_set << tags_equal_filters if tags_equal.present?
|
|
76
88
|
filter_set << ids_not_in_filters if ids_not_in.present?
|
|
89
|
+
|
|
77
90
|
unless filter_set.empty?
|
|
78
91
|
"filters:!(" + filter_set.join(',') + "),"
|
|
79
92
|
end
|
|
80
93
|
end
|
|
81
94
|
|
|
82
|
-
def
|
|
83
|
-
|
|
95
|
+
def tags_equal_filters
|
|
96
|
+
tags_equal_ids.map { |id| "(col:tags,opr:dashboard_tag_id,value:#{id})" }.join(',')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def tags_equal_ids
|
|
100
|
+
tags_equal.map do |tag_name|
|
|
101
|
+
ids = Superset::Tag::List.new(name_equals: tag_name).rows.map(&:first)
|
|
102
|
+
raise "No ID found for tag: #{tag_name}" if ids.empty?
|
|
103
|
+
raise "Multiple IDs found for tag: #{tag_name}" if ids.size > 1
|
|
104
|
+
ids.first
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def tags_contain_filters
|
|
109
|
+
tags_contain.map {|tag| "(col:tags,opr:dashboard_tags,value:'#{tag}')"}.join(',')
|
|
84
110
|
end
|
|
85
111
|
|
|
86
112
|
def ids_not_in_filters
|
|
@@ -94,8 +120,8 @@ module Superset
|
|
|
94
120
|
def validate_constructor_args
|
|
95
121
|
raise InvalidParameterError, "title_contains must be a String type" unless title_contains.is_a?(String)
|
|
96
122
|
raise InvalidParameterError, "title_equals must be a String type" unless title_equals.is_a?(String)
|
|
97
|
-
raise InvalidParameterError, "
|
|
98
|
-
raise InvalidParameterError, "tags_equal
|
|
123
|
+
raise InvalidParameterError, "tags_contain must be an Array type of String values" unless tags_contain.is_a?(Array) && tags_contain.all? { |item| item.is_a?(String) }
|
|
124
|
+
raise InvalidParameterError, "tags_equal must be an Array type of String values" unless tags_equal.is_a?(Array) && tags_equal.all? { |item| item.is_a?(String) }
|
|
99
125
|
raise InvalidParameterError, "ids_not_in must be an Array type" unless ids_not_in.is_a?(Array)
|
|
100
126
|
end
|
|
101
127
|
end
|
|
@@ -1,36 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
# Example Usage: Update Dashboard Ownership to a new set of users
|
|
5
|
+
# this will override the existing owners and set the new owners
|
|
6
|
+
# params = { owners: [ 58, 3 ] }
|
|
7
|
+
# Superset::Dashboard::Put.new(target_id: 101, params: params ).perform
|
|
8
|
+
|
|
4
9
|
module Superset
|
|
5
10
|
module Dashboard
|
|
6
|
-
class Put < Superset::
|
|
7
|
-
|
|
8
|
-
attr_reader :target_dashboard_id, :params
|
|
9
|
-
|
|
10
|
-
def initialize(target_dashboard_id:, params:)
|
|
11
|
-
@target_dashboard_id = target_dashboard_id
|
|
12
|
-
@params = params
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def perform
|
|
16
|
-
raise "Error: target_dashboard_id integer is required" unless target_dashboard_id.present? && target_dashboard_id.is_a?(Integer)
|
|
17
|
-
raise "Error: params hash is required" unless params.present? && params.is_a?(Hash)
|
|
18
|
-
|
|
19
|
-
response
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def response
|
|
23
|
-
@response ||= client.put(route, params)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def id
|
|
27
|
-
response["result"]["id"]
|
|
28
|
-
end
|
|
11
|
+
class Put < Superset::BasePutRequest
|
|
29
12
|
|
|
30
13
|
private
|
|
31
14
|
|
|
32
15
|
def route
|
|
33
|
-
"dashboard/#{
|
|
16
|
+
"dashboard/#{target_id}"
|
|
34
17
|
end
|
|
35
18
|
end
|
|
36
19
|
end
|
|
@@ -19,7 +19,7 @@ module Superset
|
|
|
19
19
|
begin
|
|
20
20
|
warm_up_dataset(dataset["datasource_name"], dataset["name"])
|
|
21
21
|
rescue => e
|
|
22
|
-
Rollbar.error("Warm up cache failed for the dashboard #{dashboard_id.to_s} and for the dataset #{dataset["datasource_name"]} - #{e}")
|
|
22
|
+
Rollbar.error("Warm up cache failed for the dashboard #{dashboard_id.to_s} and for the dataset #{dataset["datasource_name"]} - #{e}") if defined?(Rollbar)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Superset
|
|
2
|
+
module Database
|
|
3
|
+
class GetCatalogs < Superset::Request
|
|
4
|
+
|
|
5
|
+
attr_reader :id, :include_system_catalogs
|
|
6
|
+
|
|
7
|
+
def initialize(id, include_system_catalogs: false)
|
|
8
|
+
@id = id
|
|
9
|
+
@include_system_catalogs = include_system_catalogs
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.call(id)
|
|
13
|
+
self.new(id).catalogs
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def catalogs
|
|
17
|
+
return result if include_system_catalogs
|
|
18
|
+
|
|
19
|
+
remove_system_catalogs
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def route
|
|
25
|
+
"database/#{id}/catalogs/"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# exclude system catalog values for certain databases that support them
|
|
29
|
+
def remove_system_catalogs
|
|
30
|
+
result - postgres_system_catalogs
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def postgres_system_catalogs
|
|
34
|
+
%w(postgres rdsadmin template1 template0)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -6,10 +6,10 @@ module Superset
|
|
|
6
6
|
class List < Superset::Request
|
|
7
7
|
attr_reader :title_contains, :uuid_equals
|
|
8
8
|
|
|
9
|
-
def initialize(
|
|
9
|
+
def initialize(title_contains: '', uuid_equals: '', **kwargs)
|
|
10
10
|
@title_contains = title_contains
|
|
11
11
|
@uuid_equals = uuid_equals
|
|
12
|
-
super(
|
|
12
|
+
super(**kwargs)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def self.call
|
|
@@ -19,7 +19,7 @@ module Superset
|
|
|
19
19
|
raise InvalidParameterError, "dataset_ids array of integers expected" unless dataset_ids.is_a?(Array)
|
|
20
20
|
raise InvalidParameterError, "dataset_ids array must contain Integer only values" unless dataset_ids.all? { |item| item.is_a?(Integer) }
|
|
21
21
|
|
|
22
|
-
logger.info("
|
|
22
|
+
logger.info("Deleting datasets with id: #{dataset_ids.join(', ')}")
|
|
23
23
|
response
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -12,7 +12,7 @@ module Superset
|
|
|
12
12
|
def perform
|
|
13
13
|
raise InvalidParameterError, "dataset_id integer is required" unless dataset_id.present? && dataset_id.is_a?(Integer)
|
|
14
14
|
|
|
15
|
-
logger.info("
|
|
15
|
+
logger.info("Deleting dataset with id: #{dataset_id}")
|
|
16
16
|
response
|
|
17
17
|
end
|
|
18
18
|
|
data/lib/superset/dataset/get.rb
CHANGED
|
@@ -18,7 +18,11 @@ module Superset
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def rows
|
|
21
|
-
[
|
|
21
|
+
[to_h.values]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_h
|
|
25
|
+
list_attributes.to_h { |a| [a, send(a)] }
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def schema
|
|
@@ -26,7 +30,7 @@ module Superset
|
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
def title
|
|
29
|
-
result['
|
|
33
|
+
result['table_name']
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
def database_name
|
|
@@ -47,8 +51,8 @@ module Superset
|
|
|
47
51
|
"dataset/#{id}"
|
|
48
52
|
end
|
|
49
53
|
|
|
50
|
-
def
|
|
51
|
-
|
|
54
|
+
def list_attributes
|
|
55
|
+
[:title, :schema, :database_name, :database_id]
|
|
52
56
|
end
|
|
53
57
|
end
|
|
54
58
|
end
|