Merge remote-tracking branch 'origin/main'

This commit is contained in:
778a69cd 2023-12-19 13:16:16 +01:00
commit 00c408a502
11 changed files with 182 additions and 18 deletions

View file

@ -50,8 +50,8 @@ LABEL org.opencontainers.image.title="mobilizon" \
org.opencontainers.image.revision=$VCS_REF \ org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.created=$BUILD_DATE org.opencontainers.image.created=$BUILD_DATE
RUN apk add --no-cache curl openssl ca-certificates ncurses-libs file postgresql-client libgcc libstdc++ imagemagick python3 py3-pip py3-pillow py3-cffi py3-brotli gcc g++ musl-dev python3-dev pango libxslt-dev ttf-cantarell openssl1.1-compat RUN apk add --no-cache curl openssl ca-certificates ncurses-libs file postgresql-client libgcc libstdc++ imagemagick python3 py3-pip py3-pillow py3-cffi py3-brotli gcc g++ musl-dev python3-dev pango libxslt-dev ttf-cantarell
RUN pip --no-cache-dir install weasyprint pyexcel-ods3 RUN pip --no-cache-dir install --break-system-packages weasyprint pyexcel-ods3
# Create every data directory # Create every data directory
RUN mkdir -p /var/lib/mobilizon/uploads && chown nobody:nobody /var/lib/mobilizon/uploads RUN mkdir -p /var/lib/mobilizon/uploads && chown nobody:nobody /var/lib/mobilizon/uploads

View file

@ -16,7 +16,6 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
alias Mobilizon.Federation.{NodeInfo, WebFinger} alias Mobilizon.Federation.{NodeInfo, WebFinger}
alias Mobilizon.GraphQL.API.Follows alias Mobilizon.GraphQL.API.Follows
alias Mobilizon.Service.Workers.Background alias Mobilizon.Service.Workers.Background
import Mobilizon.Federation.ActivityPub.Utils, only: [create_full_domain_string: 1]
require Logger require Logger
@ -185,7 +184,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
defp fetch_actor("http://" <> address), do: fetch_actor(address) defp fetch_actor("http://" <> address), do: fetch_actor(address)
defp fetch_actor(address) do defp fetch_actor(address) do
%URI{host: host} = uri = URI.parse("http://" <> address) %URI{host: host} = URI.parse("http://" <> address)
cond do cond do
String.contains?(address, "@") -> String.contains?(address, "@") ->

View file

@ -24,16 +24,23 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Address do
} }
res = res =
if is_nil(object["address"]) or not is_map(object["address"]) do cond do
res is_binary(object["address"]) ->
else Map.merge(res, %{
Map.merge(res, %{ "street" => object["address"]
"country" => object["address"]["addressCountry"], })
"postal_code" => object["address"]["postalCode"],
"region" => object["address"]["addressRegion"], is_map(object["address"]) ->
"street" => object["address"]["streetAddress"], Map.merge(res, %{
"locality" => object["address"]["addressLocality"] "country" => object["address"]["addressCountry"],
}) "postal_code" => object["address"]["postalCode"],
"region" => object["address"]["addressRegion"],
"street" => object["address"]["streetAddress"],
"locality" => object["address"]["addressLocality"]
})
is_nil(object["address"]) ->
res
end end
latitude = Map.get(object, "latitude") latitude = Map.get(object, "latitude")

View file

@ -198,6 +198,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
defp calculate_timezone(_object, nil), do: nil defp calculate_timezone(_object, nil), do: nil
defp calculate_timezone(_object, %Address{geom: nil}), do: nil
defp calculate_timezone(_object, %Address{geom: geom}) do defp calculate_timezone(_object, %Address{geom: geom}) do
TimezoneDetector.detect( TimezoneDetector.detect(
nil, nil,

View file

@ -278,8 +278,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
end end
@spec get_address(map | binary | nil) :: Address.t() | nil @spec get_address(map | binary | nil) :: Address.t() | nil
def get_address(address_url) when is_binary(address_url) do def get_address(text_address) when is_binary(text_address) do
get_address(%{"id" => address_url}) get_address(%{"type" => "Place", "name" => text_address})
end end
def get_address(%{"id" => url} = map) when is_map(map) and is_binary(url) do def get_address(%{"id" => url} = map) when is_map(map) and is_binary(url) do

View file

@ -25,9 +25,10 @@ defmodule Mobilizon.Federation.NodeInfo do
defp extract_application_actor(body) do defp extract_application_actor(body) do
body body
|> Enum.find(%{rel: @application_uri, href: nil}, fn %{rel: rel, href: href} -> |> Map.get("links", [])
|> Enum.find(%{"rel" => @application_uri, "href" => nil}, fn %{"rel" => rel, "href" => href} ->
rel == @application_uri and is_binary(href) rel == @application_uri and is_binary(href)
end) end)
|> Map.get(:href) |> Map.get("href")
end end
end end

1
src/i18n/th.json Normal file
View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1,74 @@
defmodule Mobilizon.Federation.ActivityStream.Converter.AddressTest do
use Mobilizon.DataCase
alias Mobilizon.Addresses.Address
alias Mobilizon.Federation.ActivityStream.Converter.Address, as: AddressConverter
describe "address to AS" do
test "valid address to as" do
data =
AddressConverter.model_to_as(%Address{
country: "France",
locality: "Lyon",
description: "Locaux'Motiv",
postal_code: "69007",
street: "10Bis Rue Jangot"
})
assert is_map(data)
assert data["type"] == "Place"
assert data["name"] == "Locaux'Motiv"
assert data["address"]["type"] == "PostalAddress"
assert data["address"]["addressLocality"] == "Lyon"
assert data["address"]["postalCode"] == "69007"
assert data["address"]["addressCountry"] == "France"
assert data["address"]["streetAddress"] == "10Bis Rue Jangot"
end
end
describe "AS to Address" do
test "basic AS data to model" do
address =
AddressConverter.as_to_model_data(%{
"type" => "Place",
"name" => "Federazione Anarchica Torinese",
"address" => "corso Palermo 46",
"latitude" => nil,
"longitude" => nil
})
assert address["description"] == "Federazione Anarchica Torinese"
assert address["street"] == "corso Palermo 46"
assert address["locality"] == nil
assert address["geom"] == nil
end
test "AS data with PostalAddress to model" do
address =
AddressConverter.as_to_model_data(%{
"type" => "Place",
"name" => "Federazione Anarchica Torinese",
"address" => %{
"streetAddress" => "Corso Palermo, 46",
"addressCountry" => "Italia",
"postalCode" => "10152",
"addressLocality" => "Torino"
},
"latitude" => 45.08281,
"longitude" => 7.69311
})
assert address["description"] == "Federazione Anarchica Torinese"
assert address["street"] == "Corso Palermo, 46"
assert address["locality"] == "Torino"
assert address["postal_code"] == "10152"
assert address["country"] == "Italia"
assert address["geom"] == %Geo.Point{
coordinates: {7.69311, 45.08281},
srid: 4326
}
end
end
end

View file

@ -0,0 +1,60 @@
defmodule Mobilizon.Federation.NodeInfoTest do
use Mobilizon.DataCase
import Mox
alias Mobilizon.Federation.NodeInfo
alias Mobilizon.Service.HTTP.WebfingerClient.Mock, as: WebfingerClientMock
@instance_domain "event-federation.eu"
@nodeinfo_fixture_path "test/fixtures/nodeinfo/wp-event-federation.json"
@nodeinfo_regular_fixture_path "test/fixtures/nodeinfo/regular.json"
describe "getting application actor" do
test "from wordpress event federation" do
nodeinfo_data = @nodeinfo_fixture_path |> File.read!() |> Jason.decode!()
WebfingerClientMock
|> expect(:call, fn
%{
method: :get,
url: "https://event-federation.eu/.well-known/nodeinfo"
},
_opts ->
{:ok, %Tesla.Env{status: 200, body: nodeinfo_data}}
end)
assert "https://event-federation.eu/actor-relay" ==
NodeInfo.application_actor(@instance_domain)
end
test "with no FEP-2677 information" do
nodeinfo_data = @nodeinfo_regular_fixture_path |> File.read!() |> Jason.decode!()
WebfingerClientMock
|> expect(:call, fn
%{
method: :get,
url: "https://event-federation.eu/.well-known/nodeinfo"
},
_opts ->
{:ok, %Tesla.Env{status: 200, body: nodeinfo_data}}
end)
assert nil == NodeInfo.application_actor(@instance_domain)
end
test "with no result" do
WebfingerClientMock
|> expect(:call, fn
%{
method: :get,
url: "https://event-federation.eu/.well-known/nodeinfo"
},
_opts ->
{:ok, %Tesla.Env{status: 404, body: ""}}
end)
assert nil == NodeInfo.application_actor(@instance_domain)
end
end
end

8
test/fixtures/nodeinfo/regular.json vendored Normal file
View file

@ -0,0 +1,8 @@
{
"links": [
{
"rel": "http:\/\/nodeinfo.diaspora.software\/ns\/schema\/2.0",
"href": "https:\/\/event-federation.eu\/wp-json\/activitypub\/1.0\/nodeinfo"
}
]
}

View file

@ -0,0 +1,12 @@
{
"links": [
{
"rel": "http:\/\/nodeinfo.diaspora.software\/ns\/schema\/2.0",
"href": "https:\/\/event-federation.eu\/wp-json\/activitypub\/1.0\/nodeinfo"
},
{
"rel": "https://www.w3.org/ns/activitystreams#Application",
"href": "https://event-federation.eu/actor-relay"
}
]
}