A platform for community discussion. Free, open, simple.
FIX: Redirect old data explorer URLs to the new ones (#38004)
Martin Brennan174ad83901a6
diff --git a/docs/developer-guides/lib/api.rb b/docs/developer-guides/lib/api.rbindex c1a9b12170c..435fc801d4b 100644--- a/docs/developer-guides/lib/api.rb+++ b/docs/developer-guides/lib/api.rb@@ -55,7 +55,7 @@ module APIdef self.fetch_current_stateresult =client.post(- "/admin/plugins/explorer/queries/#{DATA_EXPLORER_QUERY_ID}/run",+ "/admin/plugins/discourse-data-explorer/queries/#{DATA_EXPLORER_QUERY_ID}/run",{ params: { category_id: CATEGORY_ID.to_s }.to_json },).bodydiff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-legacy-route-map.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-legacy-route-map.jsindex d3f3cddb9e9..8b793f78f8f 100644--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-legacy-route-map.js+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-legacy-route-map.js@@ -3,7 +3,9 @@ export default {path: "/plugins",map() {this.route("explorer", function () {- this.route("details", { path: "/:query_id" });+ this.route("queries", function () {+ this.route("details", { path: "/:query_id" });+ });});},};diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/index.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/index.jsindex 6e8af457c58..a6dd333837a 100644--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/index.js+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/index.js@@ -6,20 +6,7 @@ const PLUGIN_ID = "discourse-data-explorer";export default class AdminPluginsExplorerIndexRoute extends Route {@service router;- beforeModel(transition) {- const { id, ...queryParams } = transition.to.queryParams;- if (id) {- this.router.transitionTo(- "adminPlugins.show.explorer.details",- PLUGIN_ID,- id,- { queryParams }- );- return;- }-- this.router.transitionTo("adminPlugins.show.explorer", PLUGIN_ID, {- queryParams,- });+ beforeModel() {+ this.router.replaceWith("adminPlugins.show.explorer", PLUGIN_ID);}}diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/details.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/details.jssimilarity index 93%rename from plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/details.jsrename to plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/details.jsindex 7bd954b7e93..85b66e76cb4 100644--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/details.js+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/details.js@@ -7,7 +7,7 @@ export default class AdminPluginsExplorerQueriesDetailsRoute extends Route {@service router;beforeModel(transition) {- this.router.transitionTo(+ this.router.replaceWith("adminPlugins.show.explorer.details",PLUGIN_ID,transition.to.params.query_id,diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/index.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/index.jsnew file mode 100644index 00000000000..6c69f4ad7f4--- /dev/null+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/index.js@@ -0,0 +1,12 @@+import Route from "@ember/routing/route";+import { service } from "@ember/service";++const PLUGIN_ID = "discourse-data-explorer";++export default class AdminPluginsExplorerQueriesIndexRoute extends Route {+ @service router;++ beforeModel() {+ this.router.replaceWith("adminPlugins.show.explorer", PLUGIN_ID);+ }+}diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/index.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/index.gjsindex 1437b7a623a..f8536b8c52a 100644--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/index.gjs+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/index.gjs@@ -199,15 +199,18 @@ export default <template>-{{/if}}</td>- <td class="d-table__cell-actions">- <LinkTo- {{on "click" @controller.scrollTop}}- @route="adminPlugins.show.explorer.details"- @model={{query.id}}- class="btn btn-default btn-small"- >- {{i18n "edit"}}- </LinkTo>+ <td class="d-table__cell-controls">+ <div class="d-table__cell-actions">+ <LinkTo+ {{on "click" @controller.scrollTop}}+ @route="adminPlugins.show.explorer.details"+ @model={{query.id}}+ class="btn btn-default btn-small"+ >+ {{i18n "explorer.view"}}+ </LinkTo>+ </div>+</td></tr>{{else}}diff --git a/plugins/discourse-data-explorer/config/locales/client.en.yml b/plugins/discourse-data-explorer/config/locales/client.en.ymlindex a78e77372b0..cb8ba055cc0 100644--- a/plugins/discourse-data-explorer/config/locales/client.en.yml+++ b/plugins/discourse-data-explorer/config/locales/client.en.yml@@ -61,6 +61,7 @@ en:null_: "Null"export: "Export"view_json: "View JSON"+ view: "View"save: "Save changes"saverun: "Save changes and run"run: "Run"diff --git a/plugins/discourse-data-explorer/config/routes.rb b/plugins/discourse-data-explorer/config/routes.rbindex 5b4a78c31f8..b3f11d7f95a 100644--- a/plugins/discourse-data-explorer/config/routes.rb+++ b/plugins/discourse-data-explorer/config/routes.rb@@ -27,7 +27,9 @@ Discourse::Application.routes.draw do}mount DiscourseDataExplorer::Engine, at: "/admin/plugins/discourse-data-explorer"- mount DiscourseDataExplorer::Engine,- at: "/admin/plugins/explorer",- as: :legacy_discourse_data_explorer+ get "/admin/plugins/explorer" => redirect("/admin/plugins/discourse-data-explorer")+ get "/admin/plugins/explorer/queries" =>+ redirect("/admin/plugins/discourse-data-explorer/queries")+ get "/admin/plugins/explorer/queries/:id" =>+ redirect("/admin/plugins/discourse-data-explorer/queries/%{id}")enddiff --git a/plugins/discourse-data-explorer/spec/integration/custom_api_key_scopes_spec.rb b/plugins/discourse-data-explorer/spec/integration/custom_api_key_scopes_spec.rbindex 9f311103cfe..e7fdffb798c 100644--- a/plugins/discourse-data-explorer/spec/integration/custom_api_key_scopes_spec.rb+++ b/plugins/discourse-data-explorer/spec/integration/custom_api_key_scopes_spec.rb@@ -66,7 +66,7 @@ describe "API keys scoped to query#run" doit "can only run the queries they're allowed to run" doexpect {- post "/admin/plugins/explorer/queries/#{query1.id}/run.json",+ post "/admin/plugins/discourse-data-explorer/queries/#{query1.id}/run.json",headers: {"Api-Key" => single_query_api_key.key,"Api-Username" => admin.username,@@ -77,7 +77,7 @@ describe "API keys scoped to query#run" doexpect(response.parsed_body["columns"]).to eq(["query1_res"])expect {- post "/admin/plugins/explorer/queries/#{query2.id}/run.json",+ post "/admin/plugins/discourse-data-explorer/queries/#{query2.id}/run.json",headers: {"Api-Key" => single_query_api_key.key,"Api-Username" => admin.username,@@ -88,7 +88,7 @@ describe "API keys scoped to query#run" doit "can run all queries if they're not restricted to any queries" doexpect {- post "/admin/plugins/explorer/queries/#{query1.id}/run.json",+ post "/admin/plugins/discourse-data-explorer/queries/#{query1.id}/run.json",headers: {"Api-Key" => all_queries_api_key.key,"Api-Username" => admin.username,@@ -99,7 +99,7 @@ describe "API keys scoped to query#run" doexpect(response.parsed_body["columns"]).to eq(["query1_res"])expect {- post "/admin/plugins/explorer/queries/#{query2.id}/run.json",+ post "/admin/plugins/discourse-data-explorer/queries/#{query2.id}/run.json",headers: {"Api-Key" => all_queries_api_key.key,"Api-Username" => admin.username,diff --git a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rbindex 9724d55d79f..e8df25acb2b 100644--- a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb+++ b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb@@ -28,25 +28,25 @@ describe DiscourseDataExplorer::QueryController dobefore { SiteSetting.data_explorer_enabled = false }it "denies every request" do- get "/admin/plugins/explorer/queries.json"+ get "/admin/plugins/discourse-data-explorer/queries.json"expect(response.status).to eq(404)- get "/admin/plugins/explorer/schema.json"+ get "/admin/plugins/discourse-data-explorer/schema.json"expect(response.status).to eq(404)- get "/admin/plugins/explorer/queries/3.json"+ get "/admin/plugins/discourse-data-explorer/queries/3.json"expect(response.status).to eq(404)- post "/admin/plugins/explorer/queries.json", params: { id: 3 }+ post "/admin/plugins/discourse-data-explorer/queries.json", params: { id: 3 }expect(response.status).to eq(404)- post "/admin/plugins/explorer/queries/3/run.json"+ post "/admin/plugins/discourse-data-explorer/queries/3/run.json"expect(response.status).to eq(404)- put "/admin/plugins/explorer/queries/3.json"+ put "/admin/plugins/discourse-data-explorer/queries/3.json"expect(response.status).to eq(404)- delete "/admin/plugins/explorer/queries/3.json"+ delete "/admin/plugins/discourse-data-explorer/queries/3.json"expect(response.status).to eq(404)endend@@ -54,7 +54,7 @@ describe DiscourseDataExplorer::QueryController dodescribe "#index" doit "behaves nicely with no user created queries" doDiscourseDataExplorer::Query.destroy_all- get "/admin/plugins/explorer/queries.json"+ get "/admin/plugins/discourse-data-explorer/queries.json"expect(response.status).to eq(200)expect(response_json["queries"].count).to eq(DiscourseDataExplorer::Queries.default.count)end@@ -63,7 +63,7 @@ describe DiscourseDataExplorer::QueryController doDiscourseDataExplorer::Query.destroy_allmake_query("SELECT 1 as value", name: "B")make_query("SELECT 1 as value", name: "A")- get "/admin/plugins/explorer/queries.json"+ get "/admin/plugins/discourse-data-explorer/queries.json"expect(response.status).to eq(200)expect(response_json["queries"].length).to eq(DiscourseDataExplorer::Queries.default.count + 2,@@ -77,7 +77,7 @@ describe DiscourseDataExplorer::QueryController domake_query("SELECT 1 as value", name: "A", hidden: false)make_query("SELECT 1 as value", name: "B", hidden: true)make_query("SELECT 1 as value", name: "C", hidden: true)- get "/admin/plugins/explorer/queries.json"+ get "/admin/plugins/discourse-data-explorer/queries.json"expect(response.status).to eq(200)expect(response_json["queries"].length).to eq(DiscourseDataExplorer::Queries.default.count + 1,@@ -87,7 +87,7 @@ describe DiscourseDataExplorer::QueryController doit "merges default query data with persisted last_run_at and groups" dofreeze_time- post "/admin/plugins/explorer/queries/-1/run.json"+ post "/admin/plugins/discourse-data-explorer/queries/-1/run.json"expect(response.status).to eq(200)# Run persists the default query in the local DB; update it to assert index merges it@@ -95,7 +95,7 @@ describe DiscourseDataExplorer::QueryController dopersisted = DiscourseDataExplorer::Query.find_by(id: -1)persisted.update!(last_run_at: 3.days.ago, groups: [group])- get "/admin/plugins/explorer/queries.json"+ get "/admin/plugins/discourse-data-explorer/queries.json"expect(response.status).to eq(200)expect(response_json["queries"].count).to eq(DiscourseDataExplorer::Queries.default.count)@@ -106,10 +106,10 @@ describe DiscourseDataExplorer::QueryController doendit "doesn't show double-ups of default queries" do- post "/admin/plugins/explorer/queries/-1/run.json"+ post "/admin/plugins/discourse-data-explorer/queries/-1/run.json"expect(response.status).to eq(200)- get "/admin/plugins/explorer/queries.json"+ get "/admin/plugins/discourse-data-explorer/queries.json"expect(response.status).to eq(200)expect(response_json["queries"].count).to eq(DiscourseDataExplorer::Queries.default.count)end@@ -121,7 +121,7 @@ describe DiscourseDataExplorer::QueryController doit "allows group to access system query" doquery = DiscourseDataExplorer::Query.find(-4)- put "/admin/plugins/explorer/queries/#{query.id}.json",+ put "/admin/plugins/discourse-data-explorer/queries/#{query.id}.json",params: {"query" => {"name" => query.name,@@ -140,7 +140,7 @@ describe DiscourseDataExplorer::QueryController doit "returns a proper json error for invalid updates" doquery = DiscourseDataExplorer::Query.find(-4)- put "/admin/plugins/explorer/queries/#{query.id}",+ put "/admin/plugins/discourse-data-explorer/queries/#{query.id}",params: {"query" => {"name" => "",@@ -155,14 +155,14 @@ describe DiscourseDataExplorer::QueryController dodescribe "#destroy" doit "returns 404 when query does not exist" do- delete "/admin/plugins/explorer/queries/999999.json"+ delete "/admin/plugins/discourse-data-explorer/queries/999999.json"expect(response.status).to eq(404)endit "hides the query" doquery = make_query("SELECT 1 as value")- delete "/admin/plugins/explorer/queries/#{query.id}.json"+ delete "/admin/plugins/discourse-data-explorer/queries/#{query.id}.json"expect(response.status).to eq(200)expect(query.reload.hidden).to eq(true)@@ -172,7 +172,7 @@ describe DiscourseDataExplorer::QueryController dodescribe "#run" dodef run_query(id, params = {}, explain = false)params = Hash[params.map { |a| [a[0], a[1].to_s] }]- post "/admin/plugins/explorer/queries/#{id}/run.json",+ post "/admin/plugins/discourse-data-explorer/queries/#{id}/run.json",params: {params: params.to_json,explain: explain,@@ -239,7 +239,7 @@ describe DiscourseDataExplorer::QueryController doSQL# Test with hash format- post "/admin/plugins/explorer/queries/#{query.id}/run.json",+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.json",params: {params: {foo: 42,@@ -256,7 +256,11 @@ describe DiscourseDataExplorer::QueryController doit "can accept empty hash for parameters" doquery = make_query "SELECT 23 as my_value"- post "/admin/plugins/explorer/queries/#{query.id}/run.json", params: { params: {} }+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.json",+ params: {+ params: {+ },+ }expect(response.status).to eq(200)expect(response_json["success"]).to eq(true)expect(response_json["columns"]).to eq(["my_value"])@@ -265,7 +269,7 @@ describe DiscourseDataExplorer::QueryController docontext "when rate limited" dodef unlimited_request(query_id, headers = {})- post "/admin/plugins/explorer/queries/#{query_id}/run.json",+ post "/admin/plugins/discourse-data-explorer/queries/#{query_id}/run.json",params: {params: {}.to_json,},@@ -275,7 +279,7 @@ describe DiscourseDataExplorer::QueryController doenddef limited_request(query_id, headers = {})- post "/admin/plugins/explorer/queries/#{query_id}/run.json",+ post "/admin/plugins/discourse-data-explorer/queries/#{query_id}/run.json",params: {params: {}.to_json,},@@ -464,7 +468,10 @@ describe DiscourseDataExplorer::QueryController doit "can export data in CSV format" doquery = make_query("SELECT 23 as my_value")- post "/admin/plugins/explorer/queries/#{query.id}/run.json", params: { download: 1 }+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.json",+ params: {+ download: 1,+ }expect(response.status).to eq(200)end@@ -484,10 +491,16 @@ describe DiscourseDataExplorer::QueryController dorun_query query.idexpect(response_json["rows"].count).to eq(2)- post "/admin/plugins/explorer/queries/#{query.id}/run.json", params: { limit: 1 }+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.json",+ params: {+ limit: 1,+ }expect(response_json["rows"].count).to eq(1)- post "/admin/plugins/explorer/queries/#{query.id}/run.json", params: { limit: "ALL" }+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.json",+ params: {+ limit: "ALL",+ }expect(response_json["rows"].count).to eq(3)end@@ -501,10 +514,13 @@ describe DiscourseDataExplorer::QueryController doSELECT id FROM postsSQL- post "/admin/plugins/explorer/queries/#{query.id}/run.csv", params: { download: 1 }+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.csv",+ params: {+ download: 1,+ }expect(response.body.split("\n").count).to eq(3)- post "/admin/plugins/explorer/queries/#{query.id}/run.csv",+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.csv",params: {download: 1,limit: 1,@@ -512,7 +528,7 @@ describe DiscourseDataExplorer::QueryController doexpect(response.body.split("\n").count).to eq(2)# The value `ALL` is not supported in csv exports.- post "/admin/plugins/explorer/queries/#{query.id}/run.csv",+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.csv",params: {download: 1,limit: "ALL",@@ -550,7 +566,7 @@ describe DiscourseDataExplorer::QueryController doit "cannot access admin endpoints" doquery = make_query("SELECT 1 as value")- post "/admin/plugins/explorer/queries/#{query.id}/run.json"+ post "/admin/plugins/discourse-data-explorer/queries/#{query.id}/run.json"expect(response.status).to eq(403)enddiff --git a/plugins/discourse-data-explorer/spec/system/query_runner_spec.rb b/plugins/discourse-data-explorer/spec/system/query_runner_spec.rbindex 88b7cacd303..39ee055c37b 100644--- a/plugins/discourse-data-explorer/spec/system/query_runner_spec.rb+++ b/plugins/discourse-data-explorer/spec/system/query_runner_spec.rb@@ -68,20 +68,24 @@ RSpec.describe "Data explorer query runner", type: :system do)end- it "redirects to the new url format" do- visit("/admin/plugins/explorer/?id=#{query_1.id}")+ it "redirects /explorer/queries/:id to the new url format" do+ visit("/admin/plugins/explorer/queries/#{query_1.id}")expect(page).to have_current_path("/admin/plugins/discourse-data-explorer/queries/#{query_1.id}",)end- it "redirects to the new url format with params" do- visit("/admin/plugins/explorer/?id=#{query_1.id}¶ms=%7B%22limit%22%3A%2210%22%7D")+ it "redirects /explorer/queries to the new url format" do+ visit("/admin/plugins/explorer/queries")- expect(page).to have_current_path(- "/admin/plugins/discourse-data-explorer/queries/#{query_1.id}?params=%7B%22limit%22%3A%2210%22%7D",- )+ expect(page).to have_current_path("/admin/plugins/discourse-data-explorer/queries")+ end++ it "redirects /explorer to the new url format" do+ visit("/admin/plugins/explorer")++ expect(page).to have_current_path("/admin/plugins/discourse-data-explorer/queries")endenddiff --git a/plugins/poll/assets/javascripts/discourse/components/poll.gjs b/plugins/poll/assets/javascripts/discourse/components/poll.gjsindex d32d23e46f6..e46ef15fb2d 100644--- a/plugins/poll/assets/javascripts/discourse/components/poll.gjs+++ b/plugins/poll/assets/javascripts/discourse/components/poll.gjs@@ -643,7 +643,7 @@ export default class PollComponent extends Component {// This uses the Data Explorer plugin export as CSV route// There is detection to check if the plugin is enabled before showing the button- ajax(`/admin/plugins/explorer/queries/${queryID}/run.csv`, {+ ajax(`/admin/plugins/discourse-data-explorer/queries/${queryID}/run.csv`, {type: "POST",data: {// needed for data-explorer route compatibility