From ecfe60bcaa76957eda245c33009ec40807713ac7 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Thu, 10 Sep 2020 11:20:25 -0400 Subject: [PATCH] don't recode tag slugs, fixes #18 --- .../controllers/api/json/tag_controller.ex | 2 -- .../controllers/filter/hide_controller.ex | 1 - .../controllers/filter/spoiler_controller.ex | 1 - .../controllers/tag/watch_controller.ex | 1 - .../controllers/tag_controller.ex | 1 - .../plugs/recode_parameter_plug.ex | 18 ------------------ .../templates/tag/_tag.html.slime | 2 +- 7 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 lib/philomena_web/plugs/recode_parameter_plug.ex diff --git a/lib/philomena_web/controllers/api/json/tag_controller.ex b/lib/philomena_web/controllers/api/json/tag_controller.ex index d10795ce..f7d02ebd 100644 --- a/lib/philomena_web/controllers/api/json/tag_controller.ex +++ b/lib/philomena_web/controllers/api/json/tag_controller.ex @@ -5,8 +5,6 @@ defmodule PhilomenaWeb.Api.Json.TagController do alias Philomena.Repo import Ecto.Query - plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show] - def show(conn, %{"id" => slug}) do tag = Tag diff --git a/lib/philomena_web/controllers/filter/hide_controller.ex b/lib/philomena_web/controllers/filter/hide_controller.ex index 622d0399..eac0b5cd 100644 --- a/lib/philomena_web/controllers/filter/hide_controller.ex +++ b/lib/philomena_web/controllers/filter/hide_controller.ex @@ -7,7 +7,6 @@ defmodule PhilomenaWeb.Filter.HideController do plug PhilomenaWeb.FilterBannedUsersPlug plug :authorize_filter - plug PhilomenaWeb.RecodeParameterPlug, name: "tag" plug :load_resource, model: Tag, id_field: "slug", id_name: "tag", persisted: true def create(conn, _params) do diff --git a/lib/philomena_web/controllers/filter/spoiler_controller.ex b/lib/philomena_web/controllers/filter/spoiler_controller.ex index 3522bd8d..a2628358 100644 --- a/lib/philomena_web/controllers/filter/spoiler_controller.ex +++ b/lib/philomena_web/controllers/filter/spoiler_controller.ex @@ -7,7 +7,6 @@ defmodule PhilomenaWeb.Filter.SpoilerController do plug PhilomenaWeb.FilterBannedUsersPlug plug :authorize_filter - plug PhilomenaWeb.RecodeParameterPlug, name: "tag" plug :load_resource, model: Tag, id_field: "slug", id_name: "tag", persisted: true def create(conn, _params) do diff --git a/lib/philomena_web/controllers/tag/watch_controller.ex b/lib/philomena_web/controllers/tag/watch_controller.ex index 66dd8a46..10098448 100644 --- a/lib/philomena_web/controllers/tag/watch_controller.ex +++ b/lib/philomena_web/controllers/tag/watch_controller.ex @@ -4,7 +4,6 @@ defmodule PhilomenaWeb.Tag.WatchController do alias Philomena.Tags.Tag alias Philomena.Users - plug PhilomenaWeb.RecodeParameterPlug, name: "tag_id" plug :load_resource, model: Tag, id_field: "slug", id_name: "tag_id", persisted: true def create(conn, _params) do diff --git a/lib/philomena_web/controllers/tag_controller.ex b/lib/philomena_web/controllers/tag_controller.ex index 194d4be6..99e56174 100644 --- a/lib/philomena_web/controllers/tag_controller.ex +++ b/lib/philomena_web/controllers/tag_controller.ex @@ -9,7 +9,6 @@ defmodule PhilomenaWeb.TagController do alias Philomena.Interactions import Ecto.Query - plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show] plug PhilomenaWeb.CanaryMapPlug, update: :edit plug :load_and_authorize_resource, diff --git a/lib/philomena_web/plugs/recode_parameter_plug.ex b/lib/philomena_web/plugs/recode_parameter_plug.ex deleted file mode 100644 index 0cd5c0c4..00000000 --- a/lib/philomena_web/plugs/recode_parameter_plug.ex +++ /dev/null @@ -1,18 +0,0 @@ -defmodule PhilomenaWeb.RecodeParameterPlug do - def init(opts), do: opts - - def call(conn, name: name) do - fixed_value = - conn - |> Map.get(:params) - |> Map.get(name) - |> to_string() - |> URI.encode_www_form() - |> String.replace("%2B", "+") - |> String.replace("%25", "%") - - params = Map.put(conn.params, name, fixed_value) - - %{conn | params: params} - end -end diff --git a/lib/philomena_web/templates/tag/_tag.html.slime b/lib/philomena_web/templates/tag/_tag.html.slime index 8df114ee..e654f35a 100644 --- a/lib/philomena_web/templates/tag/_tag.html.slime +++ b/lib/philomena_web/templates/tag/_tag.html.slime @@ -10,7 +10,7 @@ span.tag.dropdown data-tag-category="#{@tag.category}" data-tag-id="#{@tag.id}" span.tag__state.hidden title="Hidden" | H - a.tag__name< href="/tags/#{@tag.slug}" title="#{@tag.short_description}" = @tag.name + a.tag__name< href=Routes.tag_path(@conn, :show, @tag) title="#{@tag.short_description}" = @tag.name div.dropdown__content a.tag__dropdown__link.hidden data-method="delete" data-remote="true" data-tag-action="unwatch" href=Routes.tag_watch_path(@conn, :delete, @tag) Unwatch