Allow local quote and private self-quote

This commit is contained in:
tusooa 2023-07-10 18:27:23 -04:00
parent b0a7e795e7
commit 9bcec87aba
No known key found for this signature in database
GPG key ID: 42AEC43D48433C51
2 changed files with 21 additions and 2 deletions

View file

@ -167,9 +167,21 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
end end
end end
defp can_quote?(_draft, _object, visibility) when visibility in ~w(public unlisted local) do
true
end
defp can_quote?(draft, object, "private") do
draft.user.ap_id == object.data["actor"]
end
defp can_quote?(_, _, _) do
false
end
defp quoting_visibility(%{quote_post: %Activity{}} = draft) do defp quoting_visibility(%{quote_post: %Activity{}} = draft) do
with %Object{} = object <- Object.normalize(draft.quote_post, fetch: false), with %Object{} = object <- Object.normalize(draft.quote_post, fetch: false),
visibility when visibility in ~w(public unlisted) <- Visibility.get_visibility(object) do true <- can_quote?(draft, object, Visibility.get_visibility(object)) do
draft draft
else else
_ -> add_error(draft, dgettext("errors", "Cannot quote private message")) _ -> add_error(draft, dgettext("errors", "Cannot quote private message"))

View file

@ -12,15 +12,22 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraftTest do
test "create/2 with a quote post" do test "create/2 with a quote post" do
user = insert(:user) user = insert(:user)
another_user = insert(:user)
{:ok, direct} = CommonAPI.post(user, %{status: ".", visibility: "direct"}) {:ok, direct} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
{:ok, private} = CommonAPI.post(user, %{status: ".", visibility: "private"}) {:ok, private} = CommonAPI.post(user, %{status: ".", visibility: "private"})
{:ok, unlisted} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"}) {:ok, unlisted} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
{:ok, local} = CommonAPI.post(user, %{status: ".", visibility: "local"})
{:ok, public} = CommonAPI.post(user, %{status: ".", visibility: "public"}) {:ok, public} = CommonAPI.post(user, %{status: ".", visibility: "public"})
{:error, _} = ActivityDraft.create(user, %{status: "nice", quote_id: direct.id}) {:error, _} = ActivityDraft.create(user, %{status: "nice", quote_id: direct.id})
{:error, _} = ActivityDraft.create(user, %{status: "nice", quote_id: private.id}) {:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: private.id})
{:error, _} = ActivityDraft.create(another_user, %{status: "nice", quote_id: private.id})
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: unlisted.id}) {:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: unlisted.id})
{:ok, _} = ActivityDraft.create(another_user, %{status: "nice", quote_id: unlisted.id})
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: local.id})
{:ok, _} = ActivityDraft.create(another_user, %{status: "nice", quote_id: local.id})
{:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: public.id}) {:ok, _} = ActivityDraft.create(user, %{status: "nice", quote_id: public.id})
{:ok, _} = ActivityDraft.create(another_user, %{status: "nice", quote_id: public.id})
end end
end end