Email-like field in /api/v1/accounts/verify_credentials response (for OAuth plugins like Peertube).
Addresses https://git.pleroma.social/pleroma/pleroma-support/-/issues/56.
This commit is contained in:
parent
7f07871639
commit
60b4654038
|
@ -2030,6 +2030,15 @@ def local_nickname(nickname_or_mention) do
|
||||||
|> hd()
|
|> hd()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def full_nickname(%User{} = user) do
|
||||||
|
if String.contains?(user.nickname, "@") do
|
||||||
|
user.nickname
|
||||||
|
else
|
||||||
|
%{host: host} = URI.parse(user.ap_id)
|
||||||
|
user.nickname <> "@" <> host
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def full_nickname(nickname_or_mention),
|
def full_nickname(nickname_or_mention),
|
||||||
do: String.trim_leading(nickname_or_mention, "@")
|
do: String.trim_leading(nickname_or_mention, "@")
|
||||||
|
|
||||||
|
|
|
@ -262,7 +262,9 @@ defp do_render("show.json", %{user: user} = opts) do
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
# Pleroma extension
|
# Pleroma extensions
|
||||||
|
# Note: it's insecure to output :email but fully-qualified nickname may serve as safe stub
|
||||||
|
fqn: User.full_nickname(user),
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
ap_id: user.ap_id,
|
ap_id: user.ap_id,
|
||||||
also_known_as: user.also_known_as,
|
also_known_as: user.also_known_as,
|
||||||
|
|
|
@ -319,6 +319,8 @@ defmodule Pleroma.Web.Router do
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/oauth", Pleroma.Web.OAuth do
|
scope "/oauth", Pleroma.Web.OAuth do
|
||||||
|
# Note: use /api/v1/accounts/verify_credentials for userinfo of signed-in user
|
||||||
|
|
||||||
get("/registration_details", OAuthController, :registration_details)
|
get("/registration_details", OAuthController, :registration_details)
|
||||||
|
|
||||||
post("/mfa/verify", MFAController, :verify, as: :mfa_verify)
|
post("/mfa/verify", MFAController, :verify, as: :mfa_verify)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
</div>
|
</div>
|
||||||
<span class="display-name" style="padding-left: 0.5em;">
|
<span class="display-name" style="padding-left: 0.5em;">
|
||||||
<bdi><%= raw (@author.name |> Formatter.emojify(@author.emoji)) %></bdi>
|
<bdi><%= raw (@author.name |> Formatter.emojify(@author.emoji)) %></bdi>
|
||||||
<span class="nickname"><%= full_nickname(@author) %></span>
|
<span class="nickname">@<%= full_nickname(@author) %></span>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,6 +17,8 @@ defmodule Pleroma.Web.EmbedView do
|
||||||
|
|
||||||
use Phoenix.HTML
|
use Phoenix.HTML
|
||||||
|
|
||||||
|
defdelegate full_nickname(user), to: User
|
||||||
|
|
||||||
@media_types ["image", "audio", "video"]
|
@media_types ["image", "audio", "video"]
|
||||||
|
|
||||||
defp fetch_media_type(%{"mediaType" => mediaType}) do
|
defp fetch_media_type(%{"mediaType" => mediaType}) do
|
||||||
|
@ -30,11 +32,6 @@ defp open_content? do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp full_nickname(user) do
|
|
||||||
%{host: host} = URI.parse(user.ap_id)
|
|
||||||
"@" <> user.nickname <> "@" <> host
|
|
||||||
end
|
|
||||||
|
|
||||||
defp status_title(%Activity{object: %Object{data: %{"name" => name}}}) when is_binary(name),
|
defp status_title(%Activity{object: %Object{data: %{"name" => name}}}) when is_binary(name),
|
||||||
do: name
|
do: name
|
||||||
|
|
||||||
|
|
|
@ -2232,6 +2232,36 @@ test "Notifications are updated", %{user: user} do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "local_nickname/1" do
|
||||||
|
test "returns nickname without host" do
|
||||||
|
assert User.local_nickname("@mentioned") == "mentioned"
|
||||||
|
assert User.local_nickname("a_local_nickname") == "a_local_nickname"
|
||||||
|
assert User.local_nickname("nickname@host.com") == "nickname"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "full_nickname/1" do
|
||||||
|
test "returns fully qualified nickname for local and remote users" do
|
||||||
|
local_user =
|
||||||
|
insert(:user, nickname: "local_user", ap_id: "https://somehost.com/users/local_user")
|
||||||
|
|
||||||
|
remote_user = insert(:user, nickname: "remote@host.com", local: false)
|
||||||
|
|
||||||
|
assert User.full_nickname(local_user) == "local_user@somehost.com"
|
||||||
|
assert User.full_nickname(remote_user) == "remote@host.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "strips leading @ from mentions" do
|
||||||
|
assert User.full_nickname("@mentioned") == "mentioned"
|
||||||
|
assert User.full_nickname("@nickname@host.com") == "nickname@host.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not modify nicknames" do
|
||||||
|
assert User.full_nickname("nickname") == "nickname"
|
||||||
|
assert User.full_nickname("nickname@host.com") == "nickname@host.com"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "avatar fallback" do
|
test "avatar fallback" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
assert User.avatar_url(user) =~ "/images/avi.png"
|
assert User.avatar_url(user) =~ "/images/avi.png"
|
||||||
|
|
|
@ -73,6 +73,7 @@ test "Represent a user account" do
|
||||||
},
|
},
|
||||||
fields: []
|
fields: []
|
||||||
},
|
},
|
||||||
|
fqn: "shp@shitposter.club",
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
ap_id: user.ap_id,
|
ap_id: user.ap_id,
|
||||||
also_known_as: ["https://shitposter.zone/users/shp"],
|
also_known_as: ["https://shitposter.zone/users/shp"],
|
||||||
|
@ -172,6 +173,7 @@ test "Represent a Service(bot) account" do
|
||||||
},
|
},
|
||||||
fields: []
|
fields: []
|
||||||
},
|
},
|
||||||
|
fqn: "shp@shitposter.club",
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
ap_id: user.ap_id,
|
ap_id: user.ap_id,
|
||||||
also_known_as: [],
|
also_known_as: [],
|
||||||
|
|
Loading…
Reference in New Issue