Skip to content

Commit

Permalink
fix: detect if dashboard import gets a look file and vice versa, warn…
Browse files Browse the repository at this point in the history
… on importing a deleted dashboard or look (#116)
  • Loading branch information
drstrangelooker authored Dec 14, 2021
1 parent 1100c5a commit a12dc25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/gzr/commands/dashboard/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ def execute(input: $stdin, output: $stdout)

read_file(@file) do |data|

dashboard = sync_dashboard(data,@dest_space_id, output: output)
if data[:deleted]
say_warning("Attempt to import a deleted dashboard!")
say_warning("This may result in errors.")
end

if !data[:dashboard_elements]
say_error("File contains no dashboard_elements! Is this a look?")
raise Gzr::CLI::Error, "import file is not a valid dashboard"
end

dashboard = sync_dashboard(data,@dest_space_id, output: output)

dashboard[:dashboard_filters] ||= []
source_filters = data[:dashboard_filters].sort { |a,b| a[:row] <=> b[:row] }
Expand Down
11 changes: 11 additions & 0 deletions lib/gzr/commands/look/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ def execute(input: $stdin, output: $stdout)
@me ||= query_me("id")

read_file(@file) do |data|

if data[:deleted]
say_warning("Attempt to import a deleted look!")
say_warning("This may result in errors.")
end

if data[:dashboard_elements]
say_error("File contains dashboard_elements! Is this a dashboard?")
raise Gzr::CLI::Error, "import file is not a valid look"
end

look = upsert_look(@me.id,create_fetch_query(data[:query]).id,@dest_space_id,data,output: output)
upsert_plans_for_look(look.id,@me.id,data[:scheduled_plans]) if data[:scheduled_plans]
output.puts "Imported look #{look.id}" unless @options[:plain]
Expand Down

0 comments on commit a12dc25

Please sign in to comment.