mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-21 21:03:11 +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)
|
conn = Map.put(conn, :params, params)
|
||||||
user = conn.assigns.current_user
|
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 =
|
comments =
|
||||||
Comment.search_records(
|
Comment.search_records(
|
||||||
%{
|
%{
|
||||||
|
@ -39,6 +43,9 @@ defmodule PhilomenaWeb.CommentController do
|
||||||
|
|
||||||
render(conn, "index.html", title: "Comments", comments: comments)
|
render(conn, "index.html", title: "Comments", comments: comments)
|
||||||
end
|
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(%{role: role}) when role in ["moderator", "admin"], do: []
|
||||||
defp filters(_user),
|
defp filters(_user),
|
||||||
|
|
|
@ -11,8 +11,12 @@ defmodule PhilomenaWeb.PostController do
|
||||||
conn = Map.put(conn, :params, params)
|
conn = Map.put(conn, :params, params)
|
||||||
user = conn.assigns.current_user
|
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 =
|
posts =
|
||||||
Post.search_records(
|
Post.search_records(
|
||||||
%{
|
%{
|
||||||
|
@ -28,24 +32,24 @@ defmodule PhilomenaWeb.PostController do
|
||||||
)
|
)
|
||||||
|
|
||||||
rendered =
|
rendered =
|
||||||
posts.entries
|
Renderer.render_collection(posts.entries, conn)
|
||||||
|> Renderer.render_collection(conn)
|
|
||||||
|
|
||||||
posts =
|
posts =
|
||||||
%{posts | entries: Enum.zip(rendered, posts.entries)}
|
%{posts | entries: Enum.zip(rendered, posts.entries)}
|
||||||
|
|
||||||
render(conn, "index.html", title: "Posts", posts: posts)
|
render(conn, "index.html", title: "Posts", posts: posts)
|
||||||
end
|
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: role}) when role in ["moderator", "admin"], do: []
|
||||||
|
|
||||||
defp filters(%{role: "assistant"}) do
|
defp filters(%{role: "assistant"}) do
|
||||||
[
|
[
|
||||||
%{terms: %{access_level: ["normal", "assistant"]}},
|
%{terms: %{access_level: ["normal", "assistant"]}},
|
||||||
%{term: %{deleted: false}}
|
%{term: %{deleted: false}}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp filters(_user) do
|
defp filters(_user) do
|
||||||
[
|
[
|
||||||
%{term: %{access_level: "normal"}},
|
%{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 ->
|
= form_for :tags, Routes.tag_path(@conn, :index), [method: "get", class: "hform", enforce_utf8: false], fn f ->
|
||||||
.field
|
.field
|
||||||
= text_input f, :tq, name: :tq, value: @conn.params["tq"] || "*", class: "input hform__text", placeholder: "Search tags", autocapitalize: "none"
|
= 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
|
.fieldlabel
|
||||||
' For more information, see the
|
' For more information, see the
|
||||||
|
@ -165,4 +165,4 @@ table.table
|
||||||
td Literal
|
td Literal
|
||||||
td Matches the slug of this tag.
|
td Matches the slug of this tag.
|
||||||
td
|
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