Merge branch 'fix/ap-icon' into 'develop'

Do not federate instance avatar

Closes #759

See merge request pleroma/pleroma!977
This commit is contained in:
lambda 2019-03-26 16:12:50 +00:00
commit ff3b09f6b3
3 changed files with 42 additions and 12 deletions

View file

@ -79,17 +79,17 @@ defmodule Pleroma.User do
def superuser?(%User{local: true, info: %User.Info{is_moderator: true}}), do: true def superuser?(%User{local: true, info: %User.Info{is_moderator: true}}), do: true
def superuser?(_), do: false def superuser?(_), do: false
def avatar_url(user) do def avatar_url(user, options \\ []) do
case user.avatar do case user.avatar do
%{"url" => [%{"href" => href} | _]} -> href %{"url" => [%{"href" => href} | _]} -> href
_ -> "#{Web.base_url()}/images/avi.png" _ -> !options[:no_default] && "#{Web.base_url()}/images/avi.png"
end end
end end
def banner_url(user) do def banner_url(user, options \\ []) do
case user.info.banner do case user.info.banner do
%{"url" => [%{"href" => href} | _]} -> href %{"url" => [%{"href" => href} | _]} -> href
_ -> "#{Web.base_url()}/images/banner.png" _ -> !options[:no_default] && "#{Web.base_url()}/images/banner.png"
end end
end end

View file

@ -87,16 +87,10 @@ defmodule Pleroma.Web.ActivityPub.UserView do
"publicKeyPem" => public_key "publicKeyPem" => public_key
}, },
"endpoints" => endpoints, "endpoints" => endpoints,
"icon" => %{
"type" => "Image",
"url" => User.avatar_url(user)
},
"image" => %{
"type" => "Image",
"url" => User.banner_url(user)
},
"tag" => user.info.source_data["tag"] || [] "tag" => user.info.source_data["tag"] || []
} }
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|> Map.merge(Utils.make_json_ld_header()) |> Map.merge(Utils.make_json_ld_header())
end end
@ -294,4 +288,17 @@ defmodule Pleroma.Web.ActivityPub.UserView do
map map
end end
end end
defp maybe_make_image(func, key, user) do
if image = func.(user, no_default: true) do
%{
key => %{
"type" => "Image",
"url" => image
}
}
else
%{}
end
end
end end

View file

@ -16,6 +16,29 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY") assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end end
test "Does not add an avatar image if the user hasn't set one" do
user = insert(:user)
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
refute result["icon"]
refute result["image"]
user =
insert(:user,
avatar: %{"url" => [%{"href" => "https://someurl"}]},
info: %{
banner: %{"url" => [%{"href" => "https://somebanner"}]}
}
)
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
result = UserView.render("user.json", %{user: user})
assert result["icon"]["url"] == "https://someurl"
assert result["image"]["url"] == "https://somebanner"
end
describe "endpoints" do describe "endpoints" do
test "local users have a usable endpoints structure" do test "local users have a usable endpoints structure" do
user = insert(:user) user = insert(:user)