diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex index 5bbf7d40..6d42e57c 100644 --- a/lib/philomena_web/controllers/comment_controller.ex +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -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 diff --git a/lib/philomena_web/controllers/post_controller.ex b/lib/philomena_web/controllers/post_controller.ex index 37b07a41..d90ca51a 100644 --- a/lib/philomena_web/controllers/post_controller.ex +++ b/lib/philomena_web/controllers/post_controller.ex @@ -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