Gancio support
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
6e6d07d9d4
commit
70a697201e
4 changed files with 69 additions and 0 deletions
|
@ -29,6 +29,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.PlaceValidator do
|
|||
end
|
||||
|
||||
def changeset(struct, data) do
|
||||
data = fix(data)
|
||||
|
||||
struct
|
||||
|> cast(data, [:type, :name, :longitude, :latitude, :accuracy, :altitude, :radius, :units])
|
||||
|> cast_embed(:address, with: &address_changeset/2)
|
||||
|
@ -51,4 +53,19 @@ def address_changeset(struct, data) do
|
|||
])
|
||||
|> validate_inclusion(:type, ["PostalAddress"])
|
||||
end
|
||||
|
||||
defp fix(data) do
|
||||
data
|
||||
|> fix_address()
|
||||
end
|
||||
|
||||
defp fix_address(%{"address" => address} = data) when is_binary(address) do
|
||||
data
|
||||
|> Map.put("address", %{
|
||||
"type" => "PostalAddress",
|
||||
"streetAddress" => address
|
||||
})
|
||||
end
|
||||
|
||||
defp fix_address(data), do: data
|
||||
end
|
||||
|
|
1
test/fixtures/tesla_mock/gancio-event.json
vendored
Normal file
1
test/fixtures/tesla_mock/gancio-event.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"id":"https://demo.gancio.org/federation/m/1","name":"Demo event","url":"https://demo.gancio.org/event/demo-event","type":"Event","startTime":"2021-07-14T17:30:57.000+02:00","endTime":"2021-07-14T18:30:57.000+02:00","location":{"type":"Place","name":"Colosseo","address":"Piazza del Colosseo, Rome","latitude":null,"longitude":null},"attachment":[],"tag":[{"type":"Hashtag","name":"#test","href":"https://demo.gancio.org/tag/test"}],"published":"2021-07-01T22:33:36.543Z","attributedTo":"https://demo.gancio.org/federation/u/customized","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://demo.gancio.org/federation/u/customized/followers"],"content":"","summary":"Colosseo, Wednesday, 14 July (17:30)","@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"toot":"http://joinmastodon.org/ns#","schema":"http://schema.org#","ProperyValue":"schema:PropertyValue","value":"schema:value","discoverable":"toot:discoverable","Hashtag":"https://www.w3.org/ns/activitystreams#Hashtag","manuallyApprovesFollowers":"as:manuallyApprovesFollowers","focalPoint":{"@container":"@list","@id":"toot:focalPoint"}}]}
|
1
test/fixtures/tesla_mock/gancio-user.json
vendored
Normal file
1
test/fixtures/tesla_mock/gancio-user.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"toot":"http://joinmastodon.org/ns#","schema":"http://schema.org#","ProperyValue":"schema:PropertyValue","value":"schema:value","discoverable":"toot:discoverable","indexable":"toot:indexable"}],"id":"https://demo.gancio.org/federation/u/customized","type":"Application","summary":"Demo instance, you can login with admin@gancio.org / password","name":"customized","preferredUsername":"customized","inbox":"https://demo.gancio.org/federation/u/customized/inbox","outbox":"https://demo.gancio.org/federation/u/customized/outbox","manuallyApprovesFollowers":false,"endpoints":{"sharedInbox":"https://demo.gancio.org/federation/u/customized/inbox"},"discoverable":true,"indexable":true,"attachment":[{"type":"PropertyValue","name":"Website","value":"<a href='https://demo.gancio.org'>https://demo.gancio.org</a>"},{"type":"PropertyValue","name":"Place","value":"Demo"}],"icon":{"type":"Image","mediaType":"image/png","url":"https://demo.gancio.org/logo.png"},"publicKey":{"id":"https://demo.gancio.org/federation/u/customized#main-key","owner":"https://demo.gancio.org/federation/u/customized","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxp9BQ8TvVqu+0xXk7VuZ\nnuO42cHxVI+z/3TQ80AfX5aoUnK/uP7lIPy+NiIgRRu0L4hsjEs+HP6Ny9NAKFtC\nddS3pUrgIDz/AUyKeYRsCycw4XyeX7gaqIan4vCx+ANPDVTc3twDenynHhaXbPsP\nzGeKiAsGIFKRUxc5I5xnQBk6Fy6LZvGwfif07AcECER+nzffSOMPYFVbhlRuBwOg\n/tJcut77KOEpJIQSwqzT0FOw4oFtkvJt/nhpQMkXwOjEuiMOVpPoXUIpWjnbvNmy\nIPXdnKN4QqHi0fAE+FvKGbNmr18vqApT/D4Yen6W1ZWCRdUR1jjl8LNFBkPH/Tad\nkOj+UyRRJjRRqY5mXCI72Bmhwmi/YdS4gt9K73okOZ3atM+9Kfj3azZm8pP7fRkK\n/lwRP8RZFSSpz4w9JtzYmR7P8qTaxwMuq8VrxtFmf1IBChFpyNHUDtmC9MzLBRE7\n+fnpr1bARR3OwO83/xtT+vKNE+2SBvsf7zeFRXa+p5dGaih90rQOwL8EsUItiG61\nm4y9n3Q7BM7XwrZ7sGe3Hey5SWveOEgemfP4ANJBiMQpU69LKM9dGW1FcEX4FlwW\nZx/135nzMXE2cF+y+q/yY2FlacXPqJXMY32mIc+rHMzvFY/ZDzjRY/7Gg2ekjXuN\n1o7Ag7a+5k+r+XkWBNKIHp8CAwEAAQ==\n-----END PUBLIC KEY-----\n"},"url":"https://demo.gancio.org"}
|
|
@ -40,5 +40,55 @@ test "Mobilizon Event object" do
|
|||
assert object.data["name"] == "Mobilizon Launching Party"
|
||||
assert object.data["startTime"] == "2019-12-18T13:00:00Z"
|
||||
assert object.data["endTime"] == "2019-12-18T14:00:00Z"
|
||||
|
||||
assert object.data["location"] == %{
|
||||
"address" => %{
|
||||
"addressCountry" => "France",
|
||||
"addressLocality" => "Nantes",
|
||||
"addressRegion" => "Pays de la Loire",
|
||||
"type" => "PostalAddress"
|
||||
},
|
||||
"name" => "Cour du Château des Ducs de Bretagne",
|
||||
"type" => "Place"
|
||||
}
|
||||
end
|
||||
|
||||
test "Gancio Event object" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{url: "https://demo.gancio.org/federation/m/1"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/gancio-event.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
%{url: "https://demo.gancio.org/federation/u/customized"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/gancio-user.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
assert {:ok, object} = Fetcher.fetch_object_from_id("https://demo.gancio.org/federation/m/1")
|
||||
|
||||
assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
# assert object.data["cc"] == ["https://demo.gancio.org/federation/u/customized/followers"]
|
||||
|
||||
assert object.data["url"] == "https://demo.gancio.org/event/demo-event"
|
||||
|
||||
assert object.data["published"] == "2021-07-01T22:33:36.543Z"
|
||||
assert object.data["name"] == "Demo event"
|
||||
assert object.data["startTime"] == "2021-07-14T15:30:57.000Z"
|
||||
assert object.data["endTime"] == "2021-07-14T16:30:57.000Z"
|
||||
|
||||
assert object.data["location"] == %{
|
||||
"address" => %{
|
||||
"streetAddress" => "Piazza del Colosseo, Rome",
|
||||
"type" => "PostalAddress"
|
||||
},
|
||||
"name" => "Colosseo",
|
||||
"type" => "Place"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue