mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-20 20:34:23 +01:00
render errors for invalid searches
This commit is contained in:
parent
187178cdd4
commit
b7ee2f9c50
3 changed files with 19 additions and 8 deletions
|
@ -11,8 +11,12 @@ defmodule PhilomenaWeb.CommentController do
|
|||
conn = Map.put(conn, :params, params)
|
||||
user = conn.assigns.current_user
|
||||
|
||||
{:ok, query} = Query.compile(user, cq)
|
||||
user
|
||||
|> Query.compile(cq)
|
||||
|> render_index(conn, user)
|
||||
end
|
||||
|
||||
defp render_index({:ok, query}, conn, user) do
|
||||
comments =
|
||||
Comment.search_records(
|
||||
%{
|
||||
|
@ -39,6 +43,9 @@ defmodule PhilomenaWeb.CommentController do
|
|||
|
||||
render(conn, "index.html", title: "Comments", comments: comments)
|
||||
end
|
||||
defp render_index({:error, msg}, conn, _user) do
|
||||
render(conn, "index.html", title: "Comments", error: msg, comments: [])
|
||||
end
|
||||
|
||||
defp filters(%{role: role}) when role in ["moderator", "admin"], do: []
|
||||
defp filters(_user),
|
||||
|
|
|
@ -11,8 +11,12 @@ defmodule PhilomenaWeb.PostController do
|
|||
conn = Map.put(conn, :params, params)
|
||||
user = conn.assigns.current_user
|
||||
|
||||
{:ok, query} = Query.compile(user, pq)
|
||||
user
|
||||
|> Query.compile(pq)
|
||||
|> render_index(conn, user)
|
||||
end
|
||||
|
||||
defp render_index({:ok, query}, conn, user) do
|
||||
posts =
|
||||
Post.search_records(
|
||||
%{
|
||||
|
@ -28,24 +32,24 @@ defmodule PhilomenaWeb.PostController do
|
|||
)
|
||||
|
||||
rendered =
|
||||
posts.entries
|
||||
|> Renderer.render_collection(conn)
|
||||
Renderer.render_collection(posts.entries, conn)
|
||||
|
||||
posts =
|
||||
%{posts | entries: Enum.zip(rendered, posts.entries)}
|
||||
|
||||
render(conn, "index.html", title: "Posts", posts: posts)
|
||||
end
|
||||
defp render_index({:error, msg}, conn, _user) do
|
||||
render(conn, "index.html", title: "Posts", error: msg, posts: [])
|
||||
end
|
||||
|
||||
defp filters(%{role: role}) when role in ["moderator", "admin"], do: []
|
||||
|
||||
defp filters(%{role: "assistant"}) do
|
||||
[
|
||||
%{terms: %{access_level: ["normal", "assistant"]}},
|
||||
%{term: %{deleted: false}}
|
||||
]
|
||||
end
|
||||
|
||||
defp filters(_user) do
|
||||
[
|
||||
%{term: %{access_level: "normal"}},
|
||||
|
|
|
@ -3,7 +3,7 @@ h1 Tags
|
|||
= form_for :tags, Routes.tag_path(@conn, :index), [method: "get", class: "hform", enforce_utf8: false], fn f ->
|
||||
.field
|
||||
= text_input f, :tq, name: :tq, value: @conn.params["tq"] || "*", class: "input hform__text", placeholder: "Search tags", autocapitalize: "none"
|
||||
= submit "Search", class: "hform__button button", data: [disable_with: false]
|
||||
= submit "Search", class: "hform__button button"
|
||||
|
||||
.fieldlabel
|
||||
' For more information, see the
|
||||
|
@ -165,4 +165,4 @@ table.table
|
|||
td Literal
|
||||
td Matches the slug of this tag.
|
||||
td
|
||||
code = link "slug:-fwslash-mlp-fwslash-", to: Routes.tag_path(@conn, :index, tq: "slug:-fwslash-mlp-fwslash-")
|
||||
code = link "slug:-fwslash-mlp-fwslash-", to: Routes.tag_path(@conn, :index, tq: "slug:-fwslash-mlp-fwslash-")
|
||||
|
|
Loading…
Reference in a new issue