nquery 0.1.2 → 0.1.4
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/CHANGELOG.md +36 -0
- data/README.md +54 -0
- data/app/assets/builds/nquery/application.css +110 -6
- data/app/assets/builds/nquery/application.js +401 -37
- data/app/controllers/concerns/nquery/breadcrumbs.rb +2 -13
- data/app/controllers/concerns/nquery/chart_actions.rb +5 -5
- data/app/controllers/concerns/nquery/chart_results.rb +70 -9
- data/app/controllers/concerns/nquery/sharing_page.rb +38 -0
- data/app/controllers/nquery/application_controller.rb +2 -0
- data/app/controllers/nquery/dashboard/cards_controller.rb +28 -0
- data/app/controllers/nquery/dashboards_controller.rb +56 -11
- data/app/controllers/nquery/embed/charts_controller.rb +15 -13
- data/app/controllers/nquery/embed/dashboards_controller.rb +34 -8
- data/app/controllers/nquery/public/charts_controller.rb +19 -0
- data/app/controllers/nquery/public/dashboards_controller.rb +33 -0
- data/app/controllers/nquery/public_resources_controller.rb +79 -0
- data/app/controllers/nquery/queries_controller.rb +25 -48
- data/app/controllers/nquery/sharing/base_controller.rb +89 -0
- data/app/controllers/nquery/sharing/embed_tokens_controller.rb +41 -0
- data/app/controllers/nquery/sharing/embeddings_controller.rb +17 -0
- data/app/controllers/nquery/sharing/public_links_controller.rb +21 -0
- data/app/helpers/nquery/charts_helper.rb +13 -0
- data/app/helpers/nquery/sharing_helper.rb +67 -0
- data/app/javascript/nquery/controllers/chart_preview_controller.js +19 -1
- data/app/javascript/nquery/controllers/clipboard_controller.js +23 -0
- data/app/models/concerns/nquery/shareable.rb +43 -0
- data/app/models/nquery/chart.rb +18 -2
- data/app/models/nquery/dashboard.rb +131 -0
- data/app/models/nquery/data_source.rb +1 -1
- data/app/models/nquery/query.rb +72 -0
- data/app/services/nquery/application_service.rb +9 -0
- data/app/services/nquery/dashboards/card_parameters.rb +37 -0
- data/app/services/nquery/dashboards/filters.rb +75 -0
- data/app/services/nquery/dashboards/parameter_charts.rb +31 -0
- data/app/services/nquery/dashboards/parameter_rows.rb +60 -0
- data/app/views/layouts/nquery/application.html.erb +8 -0
- data/app/views/layouts/nquery/embed.html.erb +3 -1
- data/app/views/nquery/charts/_builder_form.html.erb +13 -6
- data/app/views/nquery/charts/_variable_row.html.erb +10 -0
- data/app/views/nquery/charts/_variables.html.erb +28 -0
- data/app/views/nquery/charts/embed.html.erb +5 -11
- data/app/views/nquery/charts/new.html.erb +2 -1
- data/app/views/nquery/charts/update.turbo_stream.erb +3 -0
- data/app/views/nquery/dashboard/charts/new.html.erb +2 -1
- data/app/views/nquery/dashboards/_chart_card.html.erb +27 -1
- data/app/views/nquery/dashboards/_parameter_chart_ids.html.erb +6 -0
- data/app/views/nquery/dashboards/_parameters.html.erb +159 -0
- data/app/views/nquery/dashboards/edit.html.erb +10 -0
- data/app/views/nquery/dashboards/embed.html.erb +9 -0
- data/app/views/nquery/dashboards/show.html.erb +41 -1
- data/app/views/nquery/embed/charts/show.html.erb +7 -8
- data/app/views/nquery/embed/dashboards/show.html.erb +12 -6
- data/app/views/nquery/embed/unavailable.html.erb +1 -0
- data/app/views/nquery/shared/_icon.html.erb +10 -0
- data/app/views/nquery/shared/_shared_chart_card.html.erb +20 -0
- data/app/views/nquery/shared/_sharing_panel.html.erb +94 -0
- data/app/views/nquery/shared/_sidebar.html.erb +1 -1
- data/app/views/nquery/shared/_topbar.html.erb +3 -0
- data/config/routes.rb +24 -1
- data/db/migrate/20260907120000_add_sharing_to_nquery_charts_and_dashboards.rb +19 -0
- data/db/migrate/20260907130000_remove_embedding_params_from_nquery_charts_and_dashboards.rb +8 -0
- data/db/migrate/20261005145000_add_parameters_to_nquery_dashboards.rb +7 -0
- data/db/migrate/20261005190000_add_parameters_to_nquery_queries.rb +7 -0
- data/lib/nquery/boolean.rb +9 -0
- data/lib/nquery/configuration.rb +6 -0
- data/lib/nquery/dashboard_parameters.rb +56 -0
- data/lib/nquery/data_sources/adapter.rb +10 -1
- data/lib/nquery/data_sources/mysql_adapter.rb +2 -2
- data/lib/nquery/data_sources/postgresql_adapter.rb +2 -2
- data/lib/nquery/data_sources/rails_adapter.rb +2 -7
- data/lib/nquery/data_sources/row_limit.rb +211 -0
- data/lib/nquery/embed_token_service.rb +10 -5
- data/lib/nquery/encryption.rb +1 -1
- data/lib/nquery/parameter_value.rb +97 -0
- data/lib/nquery/query_runner.rb +37 -4
- data/lib/nquery/seeder.rb +29 -7
- data/lib/nquery/statement_binds.rb +112 -0
- data/lib/nquery/version.rb +1 -1
- data/lib/nquery.rb +5 -0
- data/nquery.gemspec +2 -2
- metadata +40 -9
- data/app/javascript/nquery/controllers/query_editor_controller.js +0 -41
- data/app/views/nquery/queries/edit.html.erb +0 -40
- data/app/views/nquery/queries/new.html.erb +0 -37
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
<%= nq_icon(:chart) %>
|
|
11
11
|
<span>New chart</span>
|
|
12
12
|
<% end %>
|
|
13
|
+
<%= link_to dashboard_embed_path(@dashboard), class: "nq-btn" do %>
|
|
14
|
+
<%= nq_icon(:share) %>
|
|
15
|
+
<span>Embed</span>
|
|
16
|
+
<% end %>
|
|
13
17
|
<%= link_to edit_dashboard_path(@dashboard), class: "nq-btn" do %>
|
|
14
18
|
<%= nq_icon(:edit) %>
|
|
15
19
|
<span>Edit</span>
|
|
@@ -36,11 +40,47 @@
|
|
|
36
40
|
<%= nq_flash_card "This dashboard is archived.", type: :warning, toast: false %>
|
|
37
41
|
<% end %>
|
|
38
42
|
|
|
43
|
+
<% can_edit = can_curate_shareable?(@dashboard) %>
|
|
44
|
+
<% wiring_name = params[:wire].to_s.presence if can_edit %>
|
|
45
|
+
<% editing_parameters = can_edit && (params[:edit] == "parameters" || wiring_name.present?) %>
|
|
46
|
+
<% wiring_parameter = @filter_dashboard.parameter_definitions.find { |row| row["name"] == wiring_name } %>
|
|
47
|
+
<% if @filter_dashboard.parameter_definitions.any? || can_edit %>
|
|
48
|
+
<div class="nq-dashboard-filters">
|
|
49
|
+
<%= render "parameters",
|
|
50
|
+
dashboard: @dashboard,
|
|
51
|
+
filter_dashboard: @filter_dashboard,
|
|
52
|
+
cards: @dashboard_cards,
|
|
53
|
+
invalid_parameter_names: @invalid_parameter_names,
|
|
54
|
+
wiring_name: wiring_name,
|
|
55
|
+
editing_parameters: editing_parameters,
|
|
56
|
+
can_edit: can_edit %>
|
|
57
|
+
</div>
|
|
58
|
+
<% end %>
|
|
59
|
+
|
|
60
|
+
<% if wiring_parameter %>
|
|
61
|
+
<% eligible_cards = @dashboard_cards.select { |card| card.chart.uses_parameter?(wiring_parameter["name"]) } %>
|
|
62
|
+
<% unlinked_cards = eligible_cards.reject { |card| @filter_dashboard.parameter_linked_to_chart?(wiring_parameter, card.chart) } %>
|
|
63
|
+
<div class="nq-dashboard-wire">
|
|
64
|
+
<p>Choose <code>{{<%= wiring_parameter["name"] %>}}</code> on each chart.</p>
|
|
65
|
+
<% if unlinked_cards.any? %>
|
|
66
|
+
<%= form_with url: parameter_charts_dashboard_path(@dashboard, name: wiring_parameter["name"], edit: "parameters", wire: wiring_parameter["name"]), method: :patch do %>
|
|
67
|
+
<%= hidden_field_tag "chart_ids[]", "" %>
|
|
68
|
+
<% eligible_cards.each do |card| %>
|
|
69
|
+
<%= hidden_field_tag "chart_ids[]", card.chart.id %>
|
|
70
|
+
<% end %>
|
|
71
|
+
<%= submit_tag "Connect every chart that uses {{#{wiring_parameter["name"]}}}", class: "nq-btn" %>
|
|
72
|
+
<% end %>
|
|
73
|
+
<% end %>
|
|
74
|
+
</div>
|
|
75
|
+
<% end %>
|
|
76
|
+
|
|
39
77
|
<div class="nq-dashboard-grid" data-controller="dashboard-grid">
|
|
40
78
|
<% @dashboard_cards.each do |card| %>
|
|
41
79
|
<%= render "nquery/dashboards/chart_card",
|
|
42
80
|
card: card,
|
|
43
81
|
dashboard: @dashboard,
|
|
44
|
-
card_result: @card_results[card]
|
|
82
|
+
card_result: @card_results[card],
|
|
83
|
+
can_edit: can_edit,
|
|
84
|
+
wiring_parameter: wiring_parameter %>
|
|
45
85
|
<% end %>
|
|
46
86
|
</div>
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
<% if embed_titled? %>
|
|
2
|
+
<h1><%= @chart.name %></h1>
|
|
3
|
+
<% end %>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
data-chart-preview-data-value="<%= @result.to_json %>">
|
|
8
|
-
<canvas data-chart-preview-target="canvas" height="120"></canvas>
|
|
9
|
-
</div>
|
|
5
|
+
<%= render "nquery/shared/shared_chart_card",
|
|
6
|
+
chart: @chart,
|
|
7
|
+
result: @result,
|
|
8
|
+
show_title: false %>
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<% @dashboard.dashboard_cards.each do |card| %>
|
|
4
|
-
<section>
|
|
5
|
-
<h2><%= card.chart.name %></h2>
|
|
6
|
-
</section>
|
|
1
|
+
<% if embed_titled? %>
|
|
2
|
+
<h1><%= @dashboard.name %></h1>
|
|
7
3
|
<% end %>
|
|
4
|
+
|
|
5
|
+
<div class="nq-dashboard-grid nq-embed-grid">
|
|
6
|
+
<% @dashboard_cards.each do |card| %>
|
|
7
|
+
<%= render "nquery/shared/shared_chart_card",
|
|
8
|
+
chart: card.chart,
|
|
9
|
+
result: @card_results[card],
|
|
10
|
+
width: card.width,
|
|
11
|
+
height: card.height %>
|
|
12
|
+
<% end %>
|
|
13
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p class="nq-chart-error"><%= @unavailable_message %></p>
|
|
@@ -41,10 +41,20 @@
|
|
|
41
41
|
<% when "arrow-right" %>
|
|
42
42
|
<path d="M5 12h14" />
|
|
43
43
|
<path d="m12 5 7 7-7 7" />
|
|
44
|
+
<% when "share" %>
|
|
45
|
+
<circle cx="18" cy="5" r="3" />
|
|
46
|
+
<circle cx="6" cy="12" r="3" />
|
|
47
|
+
<circle cx="18" cy="19" r="3" />
|
|
48
|
+
<line x1="8.59" y1="13.51" x2="15.42" y2="17.49" />
|
|
49
|
+
<line x1="15.41" y1="6.51" x2="8.59" y2="10.49" />
|
|
44
50
|
<% when "format" %>
|
|
45
51
|
<path d="M21 10H3" />
|
|
46
52
|
<path d="M21 6H3" />
|
|
47
53
|
<path d="M11 14H3" />
|
|
48
54
|
<path d="M15 18H3" />
|
|
55
|
+
<% when "menu" %>
|
|
56
|
+
<path d="M4 6h16" />
|
|
57
|
+
<path d="M4 12h16" />
|
|
58
|
+
<path d="M4 18h16" />
|
|
49
59
|
<% end %>
|
|
50
60
|
</svg>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<% width = local_assigns.fetch(:width, 12)
|
|
2
|
+
height = local_assigns.fetch(:height, 4)
|
|
3
|
+
show_title = local_assigns.fetch(:show_title, true)
|
|
4
|
+
titled = !respond_to?(:embed_titled?) || embed_titled?
|
|
5
|
+
%>
|
|
6
|
+
<div class="nq-dashboard-card"
|
|
7
|
+
style="grid-column: span <%= width %>; grid-row: span <%= height %>;">
|
|
8
|
+
<% if show_title && titled %>
|
|
9
|
+
<header class="nq-dashboard-card-header">
|
|
10
|
+
<h3 class="nq-dashboard-card-title"><%= chart.name %></h3>
|
|
11
|
+
</header>
|
|
12
|
+
<% end %>
|
|
13
|
+
<div class="nq-chart-preview" data-controller="chart-preview"
|
|
14
|
+
data-chart-preview-type-value="<%= chart.chart_type %>"
|
|
15
|
+
data-chart-preview-x-value="<%= chart.visualization.to_h["x"] %>"
|
|
16
|
+
data-chart-preview-y-value="<%= chart.visualization.to_h["y"] %>"
|
|
17
|
+
data-chart-preview-data-value="<%= result.to_json %>">
|
|
18
|
+
<canvas data-chart-preview-target="canvas" height="80"></canvas>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<% shareable = local_assigns.fetch(:shareable)
|
|
2
|
+
public_url = local_assigns[:public_url]
|
|
3
|
+
embed_url = local_assigns[:embed_url]
|
|
4
|
+
embed_token = local_assigns[:embed_token]
|
|
5
|
+
can_curate = can_curate_shareable?(shareable)
|
|
6
|
+
iframe_height = share_iframe_height(shareable)
|
|
7
|
+
public_sharing_enabled = Nquery.configuration.public_sharing_enabled
|
|
8
|
+
static_embedding_enabled = Nquery.configuration.static_embedding_enabled
|
|
9
|
+
%>
|
|
10
|
+
|
|
11
|
+
<section class="nq-card nq-sharing-section">
|
|
12
|
+
<h2>Public link</h2>
|
|
13
|
+
<% unless public_sharing_enabled %>
|
|
14
|
+
<p class="nq-muted">Public sharing is disabled. Set <code>config.public_sharing_enabled = true</code> in the host app initializer.</p>
|
|
15
|
+
<% end %>
|
|
16
|
+
|
|
17
|
+
<% if public_url %>
|
|
18
|
+
<p class="nq-muted">Anyone with this link can view the visualization without signing in.</p>
|
|
19
|
+
<div class="nq-copy-field">
|
|
20
|
+
<pre class="nq-code" id="public-share-url"><%= public_url %></pre>
|
|
21
|
+
<button type="button" class="nq-btn" data-copy-button data-copy-target="#public-share-url">Copy</button>
|
|
22
|
+
</div>
|
|
23
|
+
<h3>Iframe snippet</h3>
|
|
24
|
+
<div class="nq-copy-field">
|
|
25
|
+
<pre class="nq-code" id="public-share-iframe"><%= share_iframe_snippet(public_url, height: iframe_height) %></pre>
|
|
26
|
+
<button type="button" class="nq-btn" data-copy-button data-copy-target="#public-share-iframe">Copy</button>
|
|
27
|
+
</div>
|
|
28
|
+
<% if can_curate %>
|
|
29
|
+
<div class="nq-actions">
|
|
30
|
+
<%= button_to "Remove public link", shareable_public_link_path(shareable), method: :delete, class: "nq-btn nq-btn-danger", form: { data: { turbo_confirm: "Remove the public link? The public URL will stop working. Embed tokens are revoked separately." } } %>
|
|
31
|
+
</div>
|
|
32
|
+
<% end %>
|
|
33
|
+
<% elsif can_curate && public_sharing_enabled %>
|
|
34
|
+
<p class="nq-muted">Create an unguessable public URL. Anyone with the link can view this visualization.</p>
|
|
35
|
+
<div class="nq-actions">
|
|
36
|
+
<%= button_to "Enable public link", shareable_public_link_path(shareable), method: :post, class: "nq-btn nq-btn-primary" %>
|
|
37
|
+
</div>
|
|
38
|
+
<% elsif can_curate %>
|
|
39
|
+
<p class="nq-muted">Enable public sharing in configuration, then return here to create a link.</p>
|
|
40
|
+
<% else %>
|
|
41
|
+
<p class="nq-muted">No public link yet.</p>
|
|
42
|
+
<% end %>
|
|
43
|
+
</section>
|
|
44
|
+
|
|
45
|
+
<section class="nq-card nq-sharing-section">
|
|
46
|
+
<h2>Static embed</h2>
|
|
47
|
+
<% unless static_embedding_enabled %>
|
|
48
|
+
<p class="nq-muted">Static embedding is disabled. Set <code>config.static_embedding_enabled = true</code> in the host app initializer.</p>
|
|
49
|
+
<% end %>
|
|
50
|
+
|
|
51
|
+
<% if shareable.enable_embedding? %>
|
|
52
|
+
<p class="nq-muted">Embedding is enabled for this visualization.</p>
|
|
53
|
+
<% if can_curate && static_embedding_enabled %>
|
|
54
|
+
<%= button_to "Disable embedding", shareable_embedding_path(shareable), method: :patch, params: { enable_embedding: false }, class: "nq-btn" %>
|
|
55
|
+
<% end %>
|
|
56
|
+
<% elsif can_curate && static_embedding_enabled %>
|
|
57
|
+
<p class="nq-muted">Enable embedding to publish a signed iframe URL.</p>
|
|
58
|
+
<%= button_to "Enable embedding", shareable_embedding_path(shareable), method: :patch, params: { enable_embedding: true }, class: "nq-btn nq-btn-primary" %>
|
|
59
|
+
<% end %>
|
|
60
|
+
|
|
61
|
+
<% if embed_token && embed_url %>
|
|
62
|
+
<p class="nq-muted">Signed embed token (expires <%= embed_token.expires_at&.to_fs(:long) || "never" %>)</p>
|
|
63
|
+
<div class="nq-copy-field">
|
|
64
|
+
<pre class="nq-code" id="static-embed-url"><%= embed_url %></pre>
|
|
65
|
+
<button type="button" class="nq-btn" data-copy-button data-copy-target="#static-embed-url">Copy</button>
|
|
66
|
+
</div>
|
|
67
|
+
<h3>Iframe snippet</h3>
|
|
68
|
+
<div class="nq-copy-field">
|
|
69
|
+
<pre class="nq-code" id="static-embed-iframe"><%= share_iframe_snippet(embed_url, height: iframe_height) %></pre>
|
|
70
|
+
<button type="button" class="nq-btn" data-copy-button data-copy-target="#static-embed-iframe">Copy</button>
|
|
71
|
+
</div>
|
|
72
|
+
<% if can_curate && static_embedding_enabled %>
|
|
73
|
+
<div class="nq-actions">
|
|
74
|
+
<%= button_to "Revoke token", shareable_embed_token_path(shareable, embed_token), method: :delete, class: "nq-btn nq-btn-danger", form: { data: { turbo_confirm: "Revoke this embed token?" } } %>
|
|
75
|
+
</div>
|
|
76
|
+
<% end %>
|
|
77
|
+
<% elsif can_curate && !static_embedding_enabled %>
|
|
78
|
+
<p class="nq-muted">Enable static embedding in configuration, then return here to generate a token.</p>
|
|
79
|
+
<% elsif !can_curate %>
|
|
80
|
+
<p class="nq-muted">No embed token yet.</p>
|
|
81
|
+
<% end %>
|
|
82
|
+
|
|
83
|
+
<% if can_curate && static_embedding_enabled %>
|
|
84
|
+
<%= form_with url: shareable_embed_tokens_path(shareable), method: :post, class: "nq-sharing-token-form" do %>
|
|
85
|
+
<label class="nq-form-row">
|
|
86
|
+
<span>Expires</span>
|
|
87
|
+
<%= select_tag :expires_in, options_for_select(Nquery::SharingHelper::EMBED_EXPIRY_OPTIONS, "1.hour"), class: "nq-input" %>
|
|
88
|
+
</label>
|
|
89
|
+
<div class="nq-actions">
|
|
90
|
+
<%= submit_tag embed_token ? "Regenerate" : "Generate token", class: "nq-btn nq-btn-primary" %>
|
|
91
|
+
</div>
|
|
92
|
+
<% end %>
|
|
93
|
+
<% end %>
|
|
94
|
+
</section>
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
<header class="nq-topbar">
|
|
2
|
+
<button type="button" class="nq-sidebar-toggle" aria-controls="nq-sidebar" aria-expanded="true" aria-label="Hide navigation">
|
|
3
|
+
<%= nq_icon(:menu) %>
|
|
4
|
+
</button>
|
|
2
5
|
<div class="nq-topbar-actions">
|
|
3
6
|
<% if current_nquery_user %>
|
|
4
7
|
<span class="nq-user"><%= current_nquery_user.name %></span>
|
data/config/routes.rb
CHANGED
|
@@ -23,16 +23,25 @@ Nquery::Engine.routes.draw do
|
|
|
23
23
|
resources :dashboards, only: %i[new create], module: :collection
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
resources :queries, only: %i[
|
|
26
|
+
resources :queries, only: %i[update] do
|
|
27
27
|
post :run, on: :collection
|
|
28
28
|
get :schema, on: :collection
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
concern :shareable do
|
|
32
|
+
scope module: :sharing do
|
|
33
|
+
resource :public_link, only: %i[create destroy]
|
|
34
|
+
resource :embedding, only: %i[update]
|
|
35
|
+
resources :embed_tokens, only: %i[create destroy]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
31
39
|
resources :charts, only: %i[new create show edit update destroy] do
|
|
32
40
|
member do
|
|
33
41
|
get :embed
|
|
34
42
|
patch :archive
|
|
35
43
|
end
|
|
44
|
+
concerns :shareable
|
|
36
45
|
end
|
|
37
46
|
|
|
38
47
|
resources :dashboards do
|
|
@@ -42,12 +51,21 @@ Nquery::Engine.routes.draw do
|
|
|
42
51
|
patch :archive
|
|
43
52
|
end
|
|
44
53
|
end
|
|
54
|
+
resources :charts, only: [] do
|
|
55
|
+
concerns :shareable
|
|
56
|
+
end
|
|
57
|
+
resources :cards, only: [], module: :dashboard do
|
|
58
|
+
patch :parameters, on: :member
|
|
59
|
+
end
|
|
45
60
|
|
|
46
61
|
member do
|
|
62
|
+
get :embed
|
|
47
63
|
patch :update_layout
|
|
48
64
|
patch :archive
|
|
49
65
|
patch :unarchive
|
|
66
|
+
patch "parameters/:name/charts", action: :connect_parameter, as: :parameter_charts
|
|
50
67
|
end
|
|
68
|
+
concerns :shareable
|
|
51
69
|
end
|
|
52
70
|
|
|
53
71
|
resources :imports, only: %i[new create]
|
|
@@ -93,5 +111,10 @@ Nquery::Engine.routes.draw do
|
|
|
93
111
|
get "dashboards/show", to: "dashboards#show", as: :public_dashboard
|
|
94
112
|
end
|
|
95
113
|
|
|
114
|
+
scope module: :public, path: "public", as: :public do
|
|
115
|
+
get "charts/:uuid", to: "charts#show", as: :chart
|
|
116
|
+
get "dashboards/:uuid", to: "dashboards#show", as: :dashboard
|
|
117
|
+
end
|
|
118
|
+
|
|
96
119
|
match "*unmatched", to: "errors#not_found", via: :all
|
|
97
120
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddSharingToNqueryChartsAndDashboards < ActiveRecord::Migration[8.1]
|
|
4
|
+
def change
|
|
5
|
+
add_sharing_columns :nquery_charts
|
|
6
|
+
add_sharing_columns :nquery_dashboards
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def add_sharing_columns(table)
|
|
12
|
+
add_column table, :public_uuid, :string
|
|
13
|
+
add_index table, :public_uuid, unique: true
|
|
14
|
+
add_reference table, :made_public_by, foreign_key: { to_table: :nquery_users }
|
|
15
|
+
add_column table, :public_shared_at, :datetime
|
|
16
|
+
add_column table, :enable_embedding, :boolean, null: false, default: false
|
|
17
|
+
add_column table, :embedding_params, :json, null: false, default: {}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class RemoveEmbeddingParamsFromNqueryChartsAndDashboards < ActiveRecord::Migration[8.1]
|
|
4
|
+
def change
|
|
5
|
+
remove_column :nquery_charts, :embedding_params, :json, null: false, default: {}
|
|
6
|
+
remove_column :nquery_dashboards, :embedding_params, :json, null: false, default: {}
|
|
7
|
+
end
|
|
8
|
+
end
|
data/lib/nquery/configuration.rb
CHANGED
|
@@ -10,6 +10,9 @@ module Nquery
|
|
|
10
10
|
attr_accessor :query_timeout
|
|
11
11
|
attr_accessor :query_row_limit
|
|
12
12
|
attr_accessor :embed_secret
|
|
13
|
+
attr_accessor :public_sharing_enabled
|
|
14
|
+
attr_accessor :static_embedding_enabled
|
|
15
|
+
attr_accessor :embed_frame_ancestors
|
|
13
16
|
|
|
14
17
|
def initialize
|
|
15
18
|
@data_sources = { main: { adapter: :rails, name: "Application database" } }
|
|
@@ -19,6 +22,9 @@ module Nquery
|
|
|
19
22
|
@query_timeout = 15
|
|
20
23
|
@query_row_limit = 10_000
|
|
21
24
|
@embed_secret = nil
|
|
25
|
+
@public_sharing_enabled = false
|
|
26
|
+
@static_embedding_enabled = false
|
|
27
|
+
@embed_frame_ancestors = nil
|
|
22
28
|
end
|
|
23
29
|
|
|
24
30
|
def embed_signing_key
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nquery
|
|
4
|
+
# Merges declared dashboard defaults with embed token params and the query string.
|
|
5
|
+
class DashboardParameters
|
|
6
|
+
Result = Data.define(:values, :invalid_names)
|
|
7
|
+
|
|
8
|
+
def self.call(dashboard:, token_params:, request_params:)
|
|
9
|
+
new(dashboard:, token_params:, request_params:).call
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(dashboard:, token_params:, request_params:)
|
|
13
|
+
@dashboard = dashboard
|
|
14
|
+
@token_params = stringify(token_params)
|
|
15
|
+
@request_params = stringify(request_params)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def call
|
|
19
|
+
values = {}
|
|
20
|
+
invalid_names = []
|
|
21
|
+
|
|
22
|
+
@dashboard.parameter_definitions.each do |definition|
|
|
23
|
+
parsed = resolve(definition)
|
|
24
|
+
if parsed == :invalid
|
|
25
|
+
invalid_names << definition["name"]
|
|
26
|
+
elsif parsed != :omitted
|
|
27
|
+
values[definition["name"]] = parsed
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
Result.new(values: values, invalid_names: invalid_names)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def resolve(definition)
|
|
37
|
+
name = definition["name"]
|
|
38
|
+
type = definition["type"]
|
|
39
|
+
[@token_params, @request_params].each do |source|
|
|
40
|
+
next unless source.key?(name)
|
|
41
|
+
|
|
42
|
+
parsed = ParameterValue.parse(type, source[name])
|
|
43
|
+
return parsed unless parsed == :omitted
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
ParameterValue.parse(type, definition["default"])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def stringify(source)
|
|
50
|
+
return {} if source.blank?
|
|
51
|
+
|
|
52
|
+
hash = source.respond_to?(:to_unsafe_h) ? source.to_unsafe_h : source.to_h
|
|
53
|
+
hash.stringify_keys
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -26,13 +26,22 @@ module Nquery
|
|
|
26
26
|
raise NotImplementedError
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def execute_readonly(statement, timeout: 15, row_limit: 10_000)
|
|
29
|
+
def execute_readonly(statement, timeout: 15, row_limit: 10_000, binds: [])
|
|
30
30
|
raise NotImplementedError
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def test_connection
|
|
34
34
|
raise NotImplementedError
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def exec_limited_query(connection, statement, row_limit, binds)
|
|
40
|
+
sql = RowLimit.apply(statement, row_limit)
|
|
41
|
+
return connection.exec_query(sql) if binds.blank?
|
|
42
|
+
|
|
43
|
+
connection.exec_query(sql, "SQL", binds)
|
|
44
|
+
end
|
|
36
45
|
end
|
|
37
46
|
end
|
|
38
47
|
end
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
module Nquery
|
|
4
4
|
module DataSources
|
|
5
5
|
class MysqlAdapter < PostgresqlAdapter
|
|
6
|
-
def execute_readonly(statement, timeout: 15, row_limit: 10_000)
|
|
6
|
+
def execute_readonly(statement, timeout: 15, row_limit: 10_000, binds: [])
|
|
7
7
|
with_connection do |conn|
|
|
8
8
|
rows = []
|
|
9
9
|
columns = []
|
|
10
10
|
duration = Benchmark.realtime do
|
|
11
11
|
conn.transaction do
|
|
12
12
|
conn.execute("SET SESSION TRANSACTION READ ONLY")
|
|
13
|
-
result = conn
|
|
13
|
+
result = exec_limited_query(conn, statement, row_limit, binds)
|
|
14
14
|
columns = result.columns
|
|
15
15
|
rows = result.rows
|
|
16
16
|
raise ActiveRecord::Rollback
|
|
@@ -18,7 +18,7 @@ module Nquery
|
|
|
18
18
|
true
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def execute_readonly(statement, timeout: 15, row_limit: 10_000)
|
|
21
|
+
def execute_readonly(statement, timeout: 15, row_limit: 10_000, binds: [])
|
|
22
22
|
with_connection do |conn|
|
|
23
23
|
rows = []
|
|
24
24
|
columns = []
|
|
@@ -26,7 +26,7 @@ module Nquery
|
|
|
26
26
|
conn.transaction do
|
|
27
27
|
conn.execute("SET TRANSACTION READ ONLY")
|
|
28
28
|
conn.execute("SET statement_timeout = '#{timeout.to_i}s'")
|
|
29
|
-
result = conn
|
|
29
|
+
result = exec_limited_query(conn, statement, row_limit, binds)
|
|
30
30
|
columns = result.columns
|
|
31
31
|
rows = result.rows
|
|
32
32
|
raise ActiveRecord::Rollback
|
|
@@ -18,13 +18,13 @@ module Nquery
|
|
|
18
18
|
true
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def execute_readonly(statement, timeout: 15, row_limit: 10_000)
|
|
21
|
+
def execute_readonly(statement, timeout: 15, row_limit: 10_000, binds: [])
|
|
22
22
|
rows = []
|
|
23
23
|
columns = []
|
|
24
24
|
duration = Benchmark.realtime do
|
|
25
25
|
connection.transaction do
|
|
26
26
|
connection.execute("SET TRANSACTION READ ONLY") if postgresql?
|
|
27
|
-
result = connection
|
|
27
|
+
result = exec_limited_query(connection, statement, row_limit, binds)
|
|
28
28
|
columns = result.columns
|
|
29
29
|
rows = result.rows
|
|
30
30
|
raise ActiveRecord::Rollback
|
|
@@ -49,11 +49,6 @@ module Nquery
|
|
|
49
49
|
def postgresql?
|
|
50
50
|
connection.adapter_name.downcase.include?("postgres")
|
|
51
51
|
end
|
|
52
|
-
|
|
53
|
-
def sanitize_limit(statement, limit)
|
|
54
|
-
stripped = statement.strip.sub(/;\s*\z/, "")
|
|
55
|
-
"#{stripped} LIMIT #{limit.to_i}"
|
|
56
|
-
end
|
|
57
52
|
end
|
|
58
53
|
end
|
|
59
54
|
end
|