mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +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)
|
params = Map.put(conn.params, "cq", cq)
|
||||||
conn = Map.put(conn, :params, params)
|
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 =
|
comments =
|
||||||
Comment.search_records(
|
Comment.search_records(
|
||||||
%{
|
%{
|
||||||
query: %{
|
query: %{
|
||||||
bool: %{
|
bool: %{
|
||||||
must: query,
|
must: [query | filters(user)],
|
||||||
must_not: [
|
must_not: %{
|
||||||
%{terms: %{image_tag_ids: conn.assigns.current_filter.hidden_tag_ids}},
|
terms: %{image_tag_ids: conn.assigns.current_filter.hidden_tag_ids}
|
||||||
%{term: %{hidden_from_users: true}}
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sort: %{posted_at: :desc}
|
sort: %{posted_at: :desc}
|
||||||
},
|
},
|
||||||
conn.assigns.pagination,
|
conn.assigns.pagination,
|
||||||
Comment |> preload([image: [:tags], user: [awards: :badge]])
|
Comment |> preload([:deleted_by, image: [:tags], user: [awards: :badge]])
|
||||||
)
|
)
|
||||||
|
|
||||||
rendered =
|
rendered =
|
||||||
|
@ -39,4 +39,8 @@ defmodule PhilomenaWeb.CommentController do
|
||||||
|
|
||||||
render(conn, "index.html", title: "Comments", comments: comments)
|
render(conn, "index.html", title: "Comments", comments: comments)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp filters(%{role: role}) when role in ["moderator", "admin"], do: []
|
||||||
|
defp filters(_user),
|
||||||
|
do: [%{term: %{hidden_from_users: false}}]
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,23 +9,18 @@ defmodule PhilomenaWeb.PostController do
|
||||||
|
|
||||||
params = Map.put(conn.params, "pq", pq)
|
params = Map.put(conn.params, "pq", pq)
|
||||||
conn = Map.put(conn, :params, params)
|
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 =
|
posts =
|
||||||
Post.search_records(
|
Post.search_records(
|
||||||
%{
|
%{
|
||||||
query: %{
|
query: %{
|
||||||
bool: %{
|
bool: %{
|
||||||
must: [
|
must: [query | filters(user)]
|
||||||
query,
|
|
||||||
%{term: %{access_level: "normal"}},
|
|
||||||
],
|
|
||||||
must_not: [
|
|
||||||
%{term: %{hidden_from_users: true}}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
} |> IO.inspect(),
|
||||||
sort: %{created_at: :desc}
|
sort: %{created_at: :desc}
|
||||||
},
|
},
|
||||||
conn.assigns.pagination,
|
conn.assigns.pagination,
|
||||||
|
@ -41,4 +36,20 @@ defmodule PhilomenaWeb.PostController do
|
||||||
|
|
||||||
render(conn, "index.html", title: "Posts", posts: posts)
|
render(conn, "index.html", title: "Posts", posts: posts)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue