Merge branch 'feature/1737-magic-key-field' into 'develop'
User, Webfinger: Remove OStatus vestiges Closes #1737 See merge request pleroma/pleroma!2471
This commit is contained in:
commit
33f2976020
|
@ -113,7 +113,6 @@ defmodule Pleroma.User do
|
||||||
field(:is_admin, :boolean, default: false)
|
field(:is_admin, :boolean, default: false)
|
||||||
field(:show_role, :boolean, default: true)
|
field(:show_role, :boolean, default: true)
|
||||||
field(:settings, :map, default: nil)
|
field(:settings, :map, default: nil)
|
||||||
field(:magic_key, :string, default: nil)
|
|
||||||
field(:uri, Types.Uri, default: nil)
|
field(:uri, Types.Uri, default: nil)
|
||||||
field(:hide_followers_count, :boolean, default: false)
|
field(:hide_followers_count, :boolean, default: false)
|
||||||
field(:hide_follows_count, :boolean, default: false)
|
field(:hide_follows_count, :boolean, default: false)
|
||||||
|
@ -387,7 +386,6 @@ def remote_user_changeset(struct \\ %User{local: false}, params) do
|
||||||
:banner,
|
:banner,
|
||||||
:locked,
|
:locked,
|
||||||
:last_refreshed_at,
|
:last_refreshed_at,
|
||||||
:magic_key,
|
|
||||||
:uri,
|
:uri,
|
||||||
:follower_address,
|
:follower_address,
|
||||||
:following_address,
|
:following_address,
|
||||||
|
|
|
@ -86,54 +86,24 @@ def represent_user(user, "XML") do
|
||||||
|> XmlBuilder.to_doc()
|
|> XmlBuilder.to_doc()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_magic_key("data:application/magic-public-key," <> magic_key) do
|
|
||||||
{:ok, magic_key}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp get_magic_key(nil) do
|
|
||||||
Logger.debug("Undefined magic key.")
|
|
||||||
{:ok, nil}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp get_magic_key(_) do
|
|
||||||
{:error, "Missing magic key data."}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp webfinger_from_xml(doc) do
|
defp webfinger_from_xml(doc) do
|
||||||
with magic_key <- XML.string_from_xpath(~s{//Link[@rel="magic-public-key"]/@href}, doc),
|
subject = XML.string_from_xpath("//Subject", doc)
|
||||||
{:ok, magic_key} <- get_magic_key(magic_key),
|
|
||||||
topic <-
|
|
||||||
XML.string_from_xpath(
|
|
||||||
~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href},
|
|
||||||
doc
|
|
||||||
),
|
|
||||||
subject <- XML.string_from_xpath("//Subject", doc),
|
|
||||||
subscribe_address <-
|
|
||||||
XML.string_from_xpath(
|
|
||||||
~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template},
|
|
||||||
doc
|
|
||||||
),
|
|
||||||
ap_id <-
|
|
||||||
XML.string_from_xpath(
|
|
||||||
~s{//Link[@rel="self" and @type="application/activity+json"]/@href},
|
|
||||||
doc
|
|
||||||
) do
|
|
||||||
data = %{
|
|
||||||
"magic_key" => magic_key,
|
|
||||||
"topic" => topic,
|
|
||||||
"subject" => subject,
|
|
||||||
"subscribe_address" => subscribe_address,
|
|
||||||
"ap_id" => ap_id
|
|
||||||
}
|
|
||||||
|
|
||||||
{:ok, data}
|
subscribe_address =
|
||||||
else
|
~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template}
|
||||||
{:error, e} ->
|
|> XML.string_from_xpath(doc)
|
||||||
{:error, e}
|
|
||||||
|
|
||||||
e ->
|
ap_id =
|
||||||
{:error, e}
|
~s{//Link[@rel="self" and @type="application/activity+json"]/@href}
|
||||||
end
|
|> XML.string_from_xpath(doc)
|
||||||
|
|
||||||
|
data = %{
|
||||||
|
"subject" => subject,
|
||||||
|
"subscribe_address" => subscribe_address,
|
||||||
|
"ap_id" => ap_id
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, data}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp webfinger_from_json(doc) do
|
defp webfinger_from_json(doc) do
|
||||||
|
@ -146,9 +116,6 @@ defp webfinger_from_json(doc) do
|
||||||
{"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "self"} ->
|
{"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "self"} ->
|
||||||
Map.put(data, "ap_id", link["href"])
|
Map.put(data, "ap_id", link["href"])
|
||||||
|
|
||||||
{_, "http://ostatus.org/schema/1.0/subscribe"} ->
|
|
||||||
Map.put(data, "subscribe_address", link["template"])
|
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Logger.debug("Unhandled type: #{inspect(link["type"])}")
|
Logger.debug("Unhandled type: #{inspect(link["type"])}")
|
||||||
data
|
data
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Pleroma.Repo.Migrations.RemoveMagicKeyField do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:users) do
|
||||||
|
remove(:magic_key, :string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -67,7 +67,7 @@ test "it work for AP-only user" do
|
||||||
assert data["magic_key"] == nil
|
assert data["magic_key"] == nil
|
||||||
assert data["salmon"] == nil
|
assert data["salmon"] == nil
|
||||||
|
|
||||||
assert data["topic"] == "https://mstdn.jp/users/kPherox.atom"
|
assert data["topic"] == nil
|
||||||
assert data["subject"] == "acct:kPherox@mstdn.jp"
|
assert data["subject"] == "acct:kPherox@mstdn.jp"
|
||||||
assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
|
assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
|
||||||
assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
|
assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
|
||||||
|
|
Loading…
Reference in New Issue