From ef0eee010567acedec7ed74771ceca64fc4b0837 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 8 Dec 2019 10:00:54 -0500 Subject: [PATCH] validation fixes, make navigate endpoint use * as query if none given --- lib/philomena/users/user.ex | 2 +- .../controllers/image/navigate_controller.ex | 10 +++++++++- lib/philomena_web/templates/setting/edit.html.slime | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/philomena/users/user.ex b/lib/philomena/users/user.ex index 49c93643..a9da7bbb 100644 --- a/lib/philomena/users/user.ex +++ b/lib/philomena/users/user.ex @@ -193,7 +193,7 @@ defmodule Philomena.Users.User do |> propagate_tag_list(:watched_tag_list, :watched_tag_ids) |> validate_inclusion(:theme, ~W(default dark red)) |> validate_inclusion(:images_per_page, 15..50) - |> validate_inclusion(:comments_per_page, 15..50) + |> validate_inclusion(:comments_per_page, 15..100) |> validate_search(:watched_images_query_str, user, true) |> validate_search(:watched_images_exclude_str, user, true) end diff --git a/lib/philomena_web/controllers/image/navigate_controller.ex b/lib/philomena_web/controllers/image/navigate_controller.ex index 9327d711..08a14d89 100644 --- a/lib/philomena_web/controllers/image/navigate_controller.ex +++ b/lib/philomena_web/controllers/image/navigate_controller.ex @@ -62,8 +62,16 @@ defmodule PhilomenaWeb.Image.NavigateController do defp compile_query(conn) do user = conn.assigns.current_user - {:ok, query} = Query.compile(user, conn.params["q"] || "") + {:ok, query} = Query.compile(user, match_all_if_blank(conn.params["q"])) query end + + defp match_all_if_blank(nil), do: "*" + defp match_all_if_blank(input) do + case String.trim(input) == "" do + true -> "*" + false -> input + end + end end \ No newline at end of file diff --git a/lib/philomena_web/templates/setting/edit.html.slime b/lib/philomena_web/templates/setting/edit.html.slime index 4eae82a0..6f548d61 100644 --- a/lib/philomena_web/templates/setting/edit.html.slime +++ b/lib/philomena_web/templates/setting/edit.html.slime @@ -21,6 +21,7 @@ h1 Content Settings .field = label f, :watched_tag_list, "Tags to watch" = render PhilomenaWeb.TagView, "_tag_editor.html", f: f, name: :watched_tag_list, type: :edit, conn: @conn + = error_tag f, :watched_tag_list h4 Watchlist queries and filtering p @@ -31,9 +32,11 @@ h1 Content Settings .field = label f, :watched_images_query_str, "Watch list search string (images found by this search are added to your watched images list)" = textarea f, :watched_images_query_str, class: "input input--wide", autocapitalize: "none" + = error_tag f, :watched_images_query_str .field = label f, :watched_images_exclude_str, "Watch list filter string (any images found by this search are removed from your watched images list)" = textarea f, :watched_images_exclude_str, class: "input input--wide", autocapitalize: "none" + = error_tag f, :watched_images_exclude_str .field => checkbox f, :no_spoilered_in_watched, class: "checkbox" => label f, :no_spoilered_in_watched, "Hide images spoilered by filter in watchlist" @@ -59,13 +62,15 @@ h1 Content Settings .field => label f, :images_per_page => number_input f, :images_per_page, min: 15, max: 50, step: 1, class: "input" + = error_tag f, :images_per_page .fieldlabel i ' This is the number of images per page that are displayed on image listings and searches, up to a maximum of 50. ' For 1080p monitors, try 24. .field => label f, :comments_per_page - => number_input f, :comments_per_page, min: 15, max: 50, step: 1, class: "input" + => number_input f, :comments_per_page, min: 15, max: 100, step: 1, class: "input" + = error_tag f, :comments_per_page .fieldlabel: i This is the number of comments per page that are displayed on image pages. .field => label f, :scale_large_images @@ -74,6 +79,7 @@ h1 Content Settings .field => label f, :theme => select f, :theme, theme_options(@conn), class: "input" + = error_tag f, :theme .fieldlabel: i Preview themes by selecting one from the dropdown. Saving sets the currently selected theme. .block__tab.hidden.flex.flex--maybe-wrap data-tab="metadata"