Skip to content

Commit

Permalink
Fix: short links point to the right file downloads
Browse files Browse the repository at this point in the history
The URLs where broken when splitting generation and download.

See #2350
  • Loading branch information
matiasgarciaisaia committed Nov 14, 2024
1 parent 8fe7246 commit 7aeabb7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
16 changes: 4 additions & 12 deletions lib/ask_web/controllers/survey_link_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,26 @@ 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" ->
authorize_admin(project, conn)

{
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" ->
authorize_admin(project, conn)

{
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" ->
Expand All @@ -52,8 +45,7 @@ defmodule AskWeb.SurveyLinkController do
conn,
:disposition_history,
project,
survey,
%{"_format" => "csv"}
survey
)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ask_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/ask_web/controllers/survey_link_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7aeabb7

Please sign in to comment.