Keep incoming Link tag

This commit is contained in:
tusooa 2023-07-12 14:08:24 -04:00
parent e9cd004ba1
commit 479a6f11db
No known key found for this signature in database
GPG key ID: 42AEC43D48433C51
2 changed files with 20 additions and 1 deletions

View file

@ -9,15 +9,20 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidator do
import Ecto.Changeset import Ecto.Changeset
require Pleroma.Constants
@primary_key false @primary_key false
embedded_schema do embedded_schema do
# Common # Common
field(:type, :string) field(:type, :string)
field(:name, :string) field(:name, :string)
# Mention, Hashtag # Mention, Hashtag, Link
field(:href, ObjectValidators.Uri) field(:href, ObjectValidators.Uri)
# Link
field(:mediaType, :string)
# Emoji # Emoji
embeds_one :icon, IconObjectValidator, primary_key: false do embeds_one :icon, IconObjectValidator, primary_key: false do
field(:type, :string) field(:type, :string)
@ -68,6 +73,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.TagValidator do
|> validate_required([:type, :name, :icon]) |> validate_required([:type, :name, :icon])
end end
def changeset(struct, %{"type" => "Link"} = data) do
struct
|> cast(data, [:type, :name, :mediaType, :href])
|> validate_inclusion(:mediaType, Pleroma.Constants.activity_json_mime_types())
|> validate_required([:type, :href, :mediaType])
end
def changeset(struct, %{"type" => _} = data) do def changeset(struct, %{"type" => _} = data) do
struct struct
|> cast(data, []) |> cast(data, [])

View file

@ -157,5 +157,12 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest
assert cng.valid? assert cng.valid?
assert cng.changes.quoteUrl == "https://server.example/objects/123" assert cng.changes.quoteUrl == "https://server.example/objects/123"
assert Enum.at(cng.changes.tag, 0).changes == %{
type: "Link",
mediaType: "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
href: "https://server.example/objects/123",
name: "RE: https://server.example/objects/123"
}
end end
end end