From c79dfd5b21389d4a441c5b40da17d1eee8bdb2f9 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sat, 7 Dec 2019 21:30:47 -0500 Subject: [PATCH] more comprehensive blankness check for personal titles and secondary roles --- .../controllers/filter/hide_controller.ex | 1 - .../controllers/filter/spoiler_controller.ex | 1 - .../controllers/tag/watch_controller.ex | 1 - .../views/user_attribution_view.ex | 22 ++++++++++++------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/philomena_web/controllers/filter/hide_controller.ex b/lib/philomena_web/controllers/filter/hide_controller.ex index 35af1f96..0bbc7577 100644 --- a/lib/philomena_web/controllers/filter/hide_controller.ex +++ b/lib/philomena_web/controllers/filter/hide_controller.ex @@ -3,7 +3,6 @@ defmodule PhilomenaWeb.Filter.HideController do alias Philomena.Filters alias Philomena.Tags.Tag - alias Philomena.Repo plug PhilomenaWeb.FilterBannedUsersPlug plug :authorize_filter diff --git a/lib/philomena_web/controllers/filter/spoiler_controller.ex b/lib/philomena_web/controllers/filter/spoiler_controller.ex index 73307803..0f317c04 100644 --- a/lib/philomena_web/controllers/filter/spoiler_controller.ex +++ b/lib/philomena_web/controllers/filter/spoiler_controller.ex @@ -3,7 +3,6 @@ defmodule PhilomenaWeb.Filter.SpoilerController do alias Philomena.Filters alias Philomena.Tags.Tag - alias Philomena.Repo plug PhilomenaWeb.FilterBannedUsersPlug plug :authorize_filter diff --git a/lib/philomena_web/controllers/tag/watch_controller.ex b/lib/philomena_web/controllers/tag/watch_controller.ex index abd0f508..2ff6e476 100644 --- a/lib/philomena_web/controllers/tag/watch_controller.ex +++ b/lib/philomena_web/controllers/tag/watch_controller.ex @@ -3,7 +3,6 @@ defmodule PhilomenaWeb.Tag.WatchController do alias Philomena.Tags.Tag alias Philomena.Users - alias Philomena.Repo plug :load_resource, model: Tag, id_field: "slug", id_name: "tag_id", persisted: true diff --git a/lib/philomena_web/views/user_attribution_view.ex b/lib/philomena_web/views/user_attribution_view.ex index 83f1cf71..49d12748 100644 --- a/lib/philomena_web/views/user_attribution_view.ex +++ b/lib/philomena_web/views/user_attribution_view.ex @@ -49,15 +49,21 @@ defmodule PhilomenaWeb.UserAttributionView do |> staff_role(user) end - defp personal_title(labels, %{personal_title: t}) when t not in [nil, ""], - do: [{"label--primary", t} | labels] - defp personal_title(labels, _user), - do: labels + defp personal_title(labels, %{personal_title: t}) do + case blank?(t) do + true -> labels + false -> [{"label--primary", t} | labels] + end + end + defp personal_title(labels, _user), do: labels - defp secondary_role(labels, %{secondary_role: t}) when t not in [nil, ""], - do: [{"label--warning", t} | labels] - defp secondary_role(labels, _user), - do: labels + defp secondary_role(labels, %{secondary_role: t}) do + case blank?(t) do + true -> labels + false -> [{"label--warning", t} | labels] + end + end + defp secondary_role(labels, _user), do: labels defp staff_role(labels, %{hide_default_role: false, role: "admin"}), do: [{"label--danger", "Site Administrator"} | labels]