mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
fix admin post/comment search
This commit is contained in:
parent
6047983498
commit
3ff1b1ad6e
2 changed files with 31 additions and 16 deletions
|
@ -9,25 +9,25 @@ defmodule PhilomenaWeb.CommentController do
|
|||
|
||||
params = Map.put(conn.params, "cq", cq)
|
||||
conn = Map.put(conn, :params, params)
|
||||
user = conn.assigns.current_user
|
||||
|
||||
{:ok, query} = Query.compile(conn.assigns.current_user, cq)
|
||||
{:ok, query} = Query.compile(user, cq)
|
||||
|
||||
comments =
|
||||
Comment.search_records(
|
||||
%{
|
||||
query: %{
|
||||
bool: %{
|
||||
must: query,
|
||||
must_not: [
|
||||
%{terms: %{image_tag_ids: conn.assigns.current_filter.hidden_tag_ids}},
|
||||
%{term: %{hidden_from_users: true}}
|
||||
]
|
||||
must: [query | filters(user)],
|
||||
must_not: %{
|
||||
terms: %{image_tag_ids: conn.assigns.current_filter.hidden_tag_ids}
|
||||
}
|
||||
}
|
||||
},
|
||||
sort: %{posted_at: :desc}
|
||||
},
|
||||
conn.assigns.pagination,
|
||||
Comment |> preload([image: [:tags], user: [awards: :badge]])
|
||||
Comment |> preload([:deleted_by, image: [:tags], user: [awards: :badge]])
|
||||
)
|
||||
|
||||
rendered =
|
||||
|
@ -39,4 +39,8 @@ defmodule PhilomenaWeb.CommentController do
|
|||
|
||||
render(conn, "index.html", title: "Comments", comments: comments)
|
||||
end
|
||||
|
||||
defp filters(%{role: role}) when role in ["moderator", "admin"], do: []
|
||||
defp filters(_user),
|
||||
do: [%{term: %{hidden_from_users: false}}]
|
||||
end
|
||||
|
|
|
@ -9,23 +9,18 @@ defmodule PhilomenaWeb.PostController do
|
|||
|
||||
params = Map.put(conn.params, "pq", pq)
|
||||
conn = Map.put(conn, :params, params)
|
||||
user = conn.assigns.current_user
|
||||
|
||||
{:ok, query} = Query.compile(conn.assigns.current_user, pq)
|
||||
{:ok, query} = Query.compile(user, pq)
|
||||
|
||||
posts =
|
||||
Post.search_records(
|
||||
%{
|
||||
query: %{
|
||||
bool: %{
|
||||
must: [
|
||||
query,
|
||||
%{term: %{access_level: "normal"}},
|
||||
],
|
||||
must_not: [
|
||||
%{term: %{hidden_from_users: true}}
|
||||
]
|
||||
must: [query | filters(user)]
|
||||
}
|
||||
},
|
||||
} |> IO.inspect(),
|
||||
sort: %{created_at: :desc}
|
||||
},
|
||||
conn.assigns.pagination,
|
||||
|
@ -41,4 +36,20 @@ defmodule PhilomenaWeb.PostController do
|
|||
|
||||
render(conn, "index.html", title: "Posts", posts: 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"}},
|
||||
%{term: %{deleted: false}}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue