From 7aeabb7b2d861b1800096c3f6bf7e68009cdbe7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Garc=C3=ADa=20Isa=C3=ADa?= Date: Thu, 14 Nov 2024 17:34:09 -0300 Subject: [PATCH] Fix: short links point to the right file downloads The URLs where broken when splitting generation and download. See #2350 --- .../controllers/survey_link_controller.ex | 16 ++++------------ lib/ask_web/router.ex | 2 +- .../controllers/survey_link_controller_test.exs | 8 ++++---- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/ask_web/controllers/survey_link_controller.ex b/lib/ask_web/controllers/survey_link_controller.ex index d98a55a95..a9ad0cfc0 100644 --- a/lib/ask_web/controllers/survey_link_controller.ex +++ b/lib/ask_web/controllers/survey_link_controller.ex @@ -16,13 +16,10 @@ defmodule AskWeb.SurveyLinkController do {name, target} = case target_name do - # FIXME: revisit this. We should remove _format "results" -> { Survey.link_name(survey, :results), - project_survey_get_respondents_results_path(conn, :results, project, survey, %{ - "_format" => "csv" - }) + project_survey_respondents_results_path(conn, :results_csv, project, survey) } "incentives" -> @@ -30,9 +27,7 @@ defmodule AskWeb.SurveyLinkController do { Survey.link_name(survey, :incentives), - project_survey_respondents_incentives_path(conn, :incentives, project, survey, %{ - "_format" => "csv" - }) + project_survey_respondents_incentives_path(conn, :incentives, project, survey) } "interactions" -> @@ -40,9 +35,7 @@ defmodule AskWeb.SurveyLinkController do { Survey.link_name(survey, :interactions), - project_survey_respondents_interactions_path(conn, :interactions, project, survey, %{ - "_format" => "csv" - }) + project_survey_respondents_interactions_path(conn, :interactions, project, survey) } "disposition_history" -> @@ -52,8 +45,7 @@ defmodule AskWeb.SurveyLinkController do conn, :disposition_history, project, - survey, - %{"_format" => "csv"} + survey ) } diff --git a/lib/ask_web/router.ex b/lib/ask_web/router.ex index 0a34f3407..291792d83 100644 --- a/lib/ask_web/router.ex +++ b/lib/ask_web/router.ex @@ -195,7 +195,7 @@ defmodule AskWeb.Router do get "/files", RespondentController, :files_status, as: :files get "/results", RespondentController, :results, as: :get_respondents_results - get "/results_csv", RespondentController, :results_csv + get "/results_csv", RespondentController, :results_csv, as: :respondents_results post "/results", RespondentController, :generate_results, as: :respondents_results get "/disposition_history", RespondentController, :disposition_history, as: :respondents_disposition_history diff --git a/test/ask_web/controllers/survey_link_controller_test.exs b/test/ask_web/controllers/survey_link_controller_test.exs index 9178f7f5c..842c1cfb7 100644 --- a/test/ask_web/controllers/survey_link_controller_test.exs +++ b/test/ask_web/controllers/survey_link_controller_test.exs @@ -32,7 +32,7 @@ defmodule AskWeb.SurveyLinkControllerTest do } assert link.target == - "/api/v1/projects/#{project.id}/surveys/#{survey.id}/respondents/results?_format=csv" + "/api/v1/projects/#{project.id}/surveys/#{survey.id}/respondents/results_csv" response = get(conn, project_survey_links_path(conn, :create, project, survey, "results")) @@ -87,7 +87,7 @@ defmodule AskWeb.SurveyLinkControllerTest do assert ShortLink |> Repo.all() |> length == 1 assert link.target == - "/api/v1/projects/#{project.id}/surveys/#{survey.id}/respondents/incentives?_format=csv" + "/api/v1/projects/#{project.id}/surveys/#{survey.id}/respondents/incentives" response = put(conn, project_survey_links_path(conn, :refresh, project, survey, "incentives")) @@ -134,7 +134,7 @@ defmodule AskWeb.SurveyLinkControllerTest do assert ShortLink |> Repo.all() |> length == 1 assert link.target == - "/api/v1/projects/#{project.id}/surveys/#{survey.id}/respondents/interactions?_format=csv" + "/api/v1/projects/#{project.id}/surveys/#{survey.id}/respondents/interactions" response = put(conn, project_survey_links_path(conn, :refresh, project, survey, "interactions")) @@ -174,7 +174,7 @@ defmodule AskWeb.SurveyLinkControllerTest do } assert link.target == - "/api/v1/projects/#{project.id}/surveys/#{survey.id}/respondents/disposition_history?_format=csv" + "/api/v1/projects/#{project.id}/surveys/#{survey.id}/respondents/disposition_history" response = get(