Return accepts_newsletter to account owner only

This commit is contained in:
Alex Gleason 2021-06-12 15:50:11 -05:00
parent a0f2cba0d8
commit 6109532083
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 28 additions and 0 deletions

View File

@ -292,6 +292,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|> maybe_put_allow_following_move(user, opts[:for])
|> maybe_put_unread_conversation_count(user, opts[:for])
|> maybe_put_unread_notification_count(user, opts[:for])
|> maybe_put_accepts_newsletter(user, opts[:for])
end
defp username_from_nickname(string) when is_binary(string) do
@ -403,6 +404,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
defp maybe_put_unread_notification_count(data, _, _), do: data
defp maybe_put_accepts_newsletter(data, %User{id: user_id}, %User{id: user_id} = user) do
Kernel.put_in(
data,
[:pleroma, :accepts_newsletter],
user.accepts_newsletter
)
end
defp maybe_put_accepts_newsletter(data, _, _), do: data
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
defp image_url(_), do: nil
end

View File

@ -470,6 +470,23 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
end
end
test "shows accepts_newsletter only to the account owner" do
user = insert(:user)
other_user = insert(:user)
user = User.get_cached_by_ap_id(user.ap_id)
assert AccountView.render(
"show.json",
%{user: user, for: other_user}
)[:pleroma][:accepts_newsletter] == nil
assert AccountView.render(
"show.json",
%{user: user, for: user}
)[:pleroma][:accepts_newsletter] == user.accepts_newsletter
end
describe "follow requests counter" do
test "shows zero when no follow requests are pending" do
user = insert(:user)