TagValidator: allow Link tags, don't go nuclear for unrecognized Tag types
This commit is contained in:
parent
31f5bafe64
commit
0cd15c997c
5 changed files with 105 additions and 0 deletions
|
@ -24,6 +24,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidator do
|
|||
field(:url, ObjectValidators.Uri)
|
||||
end
|
||||
|
||||
field(:mediaType, ObjectValidators.MIME)
|
||||
field(:updated, ObjectValidators.DateTime)
|
||||
field(:id, ObjectValidators.Uri)
|
||||
end
|
||||
|
@ -68,6 +69,14 @@ def changeset(struct, %{"type" => "Emoji"} = data) do
|
|||
|> validate_required([:type, :name, :icon])
|
||||
end
|
||||
|
||||
def changeset(struct, %{"type" => "Link"} = data) do
|
||||
struct
|
||||
|> cast(data, [:type, :name, :href, :mediaType])
|
||||
end
|
||||
|
||||
# Fallback
|
||||
def changeset(struct, data), do: cast(struct, data, [:type, :name])
|
||||
|
||||
def icon_changeset(struct, data) do
|
||||
struct
|
||||
|> cast(data, [:type, :url])
|
||||
|
|
29
test/fixtures/fep-e232.json
vendored
Normal file
29
test/fixtures/fep-e232.json
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"id": "https://mitra.social/objects/01839574-d41f-01a7-8eef-abfe0badcd6a",
|
||||
"type": "Note",
|
||||
"attributedTo": "https://mitra.social/users/silverpill",
|
||||
"content": "Quote test<p class=\"inline-quote\">RE: <a href=\"https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749\">https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749</a></p>",
|
||||
"published": "2022-10-01T21:30:05.211215Z",
|
||||
"tag": [
|
||||
{
|
||||
"name": "@silverpill@mitra.social",
|
||||
"type": "Mention",
|
||||
"href": "https://mitra.social/users/silverpill"
|
||||
},
|
||||
{
|
||||
"name": "RE: https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749",
|
||||
"type": "Link",
|
||||
"href": "https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749",
|
||||
"mediaType": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"https://mitra.social/users/silverpill"
|
||||
],
|
||||
"cc": [
|
||||
"https://mitra.social/users/silverpill/followers"
|
||||
],
|
||||
"quoteUrl": "https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749"
|
||||
}
|
14
test/fixtures/tesla_mock/mitra.social_01830912-1357-d4c5-e4a2-76eab347e749.json
vendored
Normal file
14
test/fixtures/tesla_mock/mitra.social_01830912-1357-d4c5-e4a2-76eab347e749.json
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"id": "https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749",
|
||||
"type": "Note",
|
||||
"attributedTo": "https://mitra.social/users/silverpill",
|
||||
"content": "FEP-e232 (Object Links) has been accepted into FEP repository:<br>\n<br>\n<a href=\"https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-e232.md\" rel=\"noopener noreferrer\">https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-e232.md</a><br>\n<br>\nThis document has the \"DRAFT\" status. It is not finalized and still can be updated based on the feedback from implementers.",
|
||||
"published": "2022-09-04T15:15:23.095610Z",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://mitra.social/users/silverpill/followers"
|
||||
]
|
||||
}
|
|
@ -130,6 +130,47 @@ test "it accepts quote posts" do
|
|||
assert Object.normalize("https://misskey.io/notes/8vs6wxufd0")
|
||||
end
|
||||
|
||||
test "it accepts FEP-e232 quote posts" do
|
||||
insert(:user, ap_id: "https://mitra.social/users/silverpill")
|
||||
|
||||
object = File.read!("test/fixtures/fep-e232.json") |> Jason.decode!()
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Create",
|
||||
"actor" => "https://mitra.social/users/silverpill",
|
||||
"object" => object
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
# Object was created in the database
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["quoteUrl"] ==
|
||||
"https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749"
|
||||
|
||||
# The Link tag was normalized
|
||||
assert object.data["tag"] == [
|
||||
%{
|
||||
"href" => "https://mitra.social/users/silverpill",
|
||||
"name" => "@silverpill@mitra.social",
|
||||
"type" => "Mention"
|
||||
},
|
||||
%{
|
||||
"href" => "https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749",
|
||||
"mediaType" =>
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||
"name" =>
|
||||
"RE: https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
|
||||
# It fetched the quoted post
|
||||
assert Object.normalize("https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749")
|
||||
end
|
||||
|
||||
test "it fixes both the Create and object contexts in a reply" do
|
||||
insert(:user, ap_id: "https://mk.absturztau.be/users/8ozbzjs3o8")
|
||||
insert(:user, ap_id: "https://p.helene.moe/users/helene")
|
||||
|
|
|
@ -1389,6 +1389,18 @@ def get("https://misskey.io/notes/8vs6wxufd0", _, _, _) do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
File.read!(
|
||||
"test/fixtures/tesla_mock/mitra.social_01830912-1357-d4c5-e4a2-76eab347e749.json"
|
||||
),
|
||||
headers: activitypub_object_headers()
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
Loading…
Reference in a new issue