Only render public comments

This commit is contained in:
Chocobozzz
2019-04-26 09:56:25 +02:00
parent 69974ff745
commit 25153d2ae1
4 changed files with 49 additions and 21 deletions

View File

@@ -42,7 +42,16 @@ defmodule MobilizonWeb.ActivityPubController do
true <- event.visibility in [:public, :unlisted] do
conn
|> put_resp_header("content-type", "application/activity+json")
|> json(ObjectView.render("event.json", %{event: event |> Utils.make_event_data()}))
|> json(
ObjectView.render(
"event.json",
%{
event:
event
|> Utils.make_event_data()
}
)
)
else
{:ignore, _} ->
{:error, :not_found}
@@ -55,15 +64,22 @@ defmodule MobilizonWeb.ActivityPubController do
@spec comment(Plug.Conn.t(), map()) :: Plug.Conn.t()
def comment(conn, %{"uuid" => uuid}) do
with {status, %Comment{} = comment} when status in [:ok, :commit] <-
Events.get_cached_comment_full_by_uuid(uuid) do
# Comments are always public for now
# TODO : Make comments maybe restricted
# true <- comment.public do
Events.get_cached_comment_full_by_uuid(uuid),
true <- comment.visibility in [:public, :unlisted] do
conn
|> put_resp_header("content-type", "application/activity+json")
|> json(ObjectView.render("comment.json", %{comment: comment |> Utils.make_comment_data()}))
|> json(
ObjectView.render(
"comment.json",
%{
comment:
comment
|> Utils.make_comment_data()
}
)
)
else
{:ignore, _} ->
_ ->
{:error, :not_found}
end
end

View File

@@ -60,10 +60,8 @@ defmodule MobilizonWeb.PageController do
case get_format(conn) do
"html" ->
with {status, %Comment{} = comment} when status in [:ok, :commit] <-
Events.get_cached_comment_full_by_uuid(uuid) do
# Comments are always public for now
# TODO : Make comments maybe restricted
# true <- comment.public do
Events.get_cached_comment_full_by_uuid(uuid),
true <- comment.visibility in [:public, :unlisted] do
render_with_meta(conn, comment)
else
_ -> {:error, :not_found}