forked from potsda.mn/mobilizon
Split Federation as separate context
This commit is contained in:
parent
f70af917f9
commit
cdb520a95b
|
@ -120,7 +120,7 @@ config :ex_cldr,
|
||||||
default_backend: Mobilizon.Cldr
|
default_backend: Mobilizon.Cldr
|
||||||
|
|
||||||
config :http_signatures,
|
config :http_signatures,
|
||||||
adapter: Mobilizon.Service.HTTPSignatures.Signature
|
adapter: Mobilizon.Federation.HTTPSignatures.Signature
|
||||||
|
|
||||||
config :mobilizon, :activitypub, sign_object_fetches: true
|
config :mobilizon, :activitypub, sign_object_fetches: true
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,8 @@ config :mobilizon, MobilizonWeb.Email.Mailer, adapter: Bamboo.LocalAdapter
|
||||||
# Configure your database
|
# Configure your database
|
||||||
config :mobilizon, Mobilizon.Storage.Repo,
|
config :mobilizon, Mobilizon.Storage.Repo,
|
||||||
types: Mobilizon.Storage.PostgresTypes,
|
types: Mobilizon.Storage.PostgresTypes,
|
||||||
username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
|
username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "postgres",
|
||||||
password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
|
password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "postgres",
|
||||||
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_dev",
|
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_dev",
|
||||||
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
|
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
|
||||||
port: System.get_env("MOBILIZON_DATABASE_PORT") || "5432",
|
port: System.get_env("MOBILIZON_DATABASE_PORT") || "5432",
|
||||||
|
|
|
@ -24,8 +24,8 @@ config :logger,
|
||||||
# Configure your database
|
# Configure your database
|
||||||
config :mobilizon, Mobilizon.Storage.Repo,
|
config :mobilizon, Mobilizon.Storage.Repo,
|
||||||
types: Mobilizon.Storage.PostgresTypes,
|
types: Mobilizon.Storage.PostgresTypes,
|
||||||
username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
|
username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "postgres",
|
||||||
password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
|
password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "postgres",
|
||||||
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_test",
|
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_test",
|
||||||
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
|
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
|
||||||
pool: Ecto.Adapters.SQL.Sandbox
|
pool: Ecto.Adapters.SQL.Sandbox
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Activity do
|
defmodule Mobilizon.Federation.ActivityPub.Activity do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Represents an activity.
|
Represents an activity.
|
||||||
"""
|
"""
|
|
@ -3,25 +3,34 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/activity_pub.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/activity_pub.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.ActivityPub do
|
defmodule Mobilizon.Federation.ActivityPub do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
# ActivityPub context.
|
The ActivityPub context.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import Mobilizon.Service.ActivityPub.Utils
|
import Mobilizon.Federation.ActivityPub.Utils
|
||||||
import Mobilizon.Service.ActivityPub.Visibility
|
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Config, Events, Reports, Users, Share}
|
alias Mobilizon.{Actors, Config, Events, Reports, Users, Share}
|
||||||
alias Mobilizon.Actors.{Actor, Follower}
|
alias Mobilizon.Actors.{Actor, Follower}
|
||||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||||
alias Mobilizon.Reports.Report
|
alias Mobilizon.Reports.Report
|
||||||
alias Mobilizon.Tombstone
|
alias Mobilizon.Tombstone
|
||||||
alias Mobilizon.Service.ActivityPub.{Activity, Converter, Convertible, Relay, Transmogrifier}
|
|
||||||
alias Mobilizon.Service.{Federator, WebFinger}
|
alias Mobilizon.Federation.ActivityPub.{
|
||||||
alias Mobilizon.Service.HTTPSignatures.Signature
|
Activity,
|
||||||
|
Audience,
|
||||||
|
Federator,
|
||||||
|
Relay,
|
||||||
|
Transmogrifier,
|
||||||
|
Visibility,
|
||||||
|
WebFinger
|
||||||
|
}
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils
|
||||||
|
alias Mobilizon.Federation.HTTPSignatures.Signature
|
||||||
|
|
||||||
alias MobilizonWeb.API.Utils, as: APIUtils
|
alias MobilizonWeb.API.Utils, as: APIUtils
|
||||||
alias Mobilizon.Service.ActivityPub.Audience
|
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Utils, as: ConverterUtils
|
|
||||||
alias MobilizonWeb.Email.{Admin, Mailer}
|
alias MobilizonWeb.Email.{Admin, Mailer}
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
@ -50,7 +59,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
def fetch_object_from_url(url) do
|
def fetch_object_from_url(url) do
|
||||||
Logger.info("Fetching object from url #{url}")
|
Logger.info("Fetching object from url #{url}")
|
||||||
|
|
||||||
date = Mobilizon.Service.HTTPSignatures.Signature.generate_date_header()
|
date = Signature.generate_date_header()
|
||||||
|
|
||||||
headers =
|
headers =
|
||||||
[{:Accept, "application/activity+json"}]
|
[{:Accept, "application/activity+json"}]
|
||||||
|
@ -149,7 +158,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
|
|
||||||
* Creates the object, which returns AS data
|
* Creates the object, which returns AS data
|
||||||
* Wraps ActivityStreams data into a `Create` activity
|
* Wraps ActivityStreams data into a `Create` activity
|
||||||
* Creates an `Mobilizon.Service.ActivityPub.Activity` from this
|
* Creates an `Mobilizon.Federation.ActivityPub.Activity` from this
|
||||||
* Federates (asynchronously) the activity
|
* Federates (asynchronously) the activity
|
||||||
* Returns the activity
|
* Returns the activity
|
||||||
"""
|
"""
|
||||||
|
@ -181,7 +190,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
|
|
||||||
* Updates the object, which returns AS data
|
* Updates the object, which returns AS data
|
||||||
* Wraps ActivityStreams data into a `Update` activity
|
* Wraps ActivityStreams data into a `Update` activity
|
||||||
* Creates an `Mobilizon.Service.ActivityPub.Activity` from this
|
* Creates an `Mobilizon.Federation.ActivityPub.Activity` from this
|
||||||
* Federates (asynchronously) the activity
|
* Federates (asynchronously) the activity
|
||||||
* Returns the activity
|
* Returns the activity
|
||||||
"""
|
"""
|
||||||
|
@ -251,7 +260,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
local \\ true,
|
local \\ true,
|
||||||
public \\ true
|
public \\ true
|
||||||
) do
|
) do
|
||||||
with true <- is_public?(object),
|
with true <- Visibility.is_public?(object),
|
||||||
{:ok, %Actor{id: object_owner_actor_id}} <- Actors.get_actor_by_url(object["actor"]),
|
{:ok, %Actor{id: object_owner_actor_id}} <- Actors.get_actor_by_url(object["actor"]),
|
||||||
{:ok, %Share{} = _share} <- Share.create(object["id"], actor.id, object_owner_actor_id),
|
{:ok, %Share{} = _share} <- Share.create(object["id"], actor.id, object_owner_actor_id),
|
||||||
announce_data <- make_announce_data(actor, object, activity_id, public),
|
announce_data <- make_announce_data(actor, object, activity_id, public),
|
||||||
|
@ -549,7 +558,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
Logger.debug("Publishing an activity")
|
Logger.debug("Publishing an activity")
|
||||||
Logger.debug(inspect(activity))
|
Logger.debug(inspect(activity))
|
||||||
|
|
||||||
public = is_public?(activity)
|
public = Visibility.is_public?(activity)
|
||||||
Logger.debug("is public ? #{public}")
|
Logger.debug("is public ? #{public}")
|
||||||
|
|
||||||
if public && is_create_activity?(activity) && Config.get([:instance, :allow_relay]) do
|
if public && is_create_activity?(activity) && Config.get([:instance, :allow_relay]) do
|
||||||
|
@ -629,7 +638,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||||
:ok <- Logger.debug("response okay, now decoding json"),
|
:ok <- Logger.debug("response okay, now decoding json"),
|
||||||
{:ok, data} <- Jason.decode(body) do
|
{:ok, data} <- Jason.decode(body) do
|
||||||
Logger.debug("Got activity+json response at actor's endpoint, now converting data")
|
Logger.debug("Got activity+json response at actor's endpoint, now converting data")
|
||||||
Mobilizon.Service.ActivityPub.Converter.Actor.as_to_model_data(data)
|
Converter.Actor.as_to_model_data(data)
|
||||||
else
|
else
|
||||||
# Actor is gone, probably deleted
|
# Actor is gone, probably deleted
|
||||||
{:ok, %HTTPoison.Response{status_code: 410}} ->
|
{:ok, %HTTPoison.Response{status_code: 410}} ->
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Converter behaviour.
|
Converter behaviour.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Actor do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Actor converter.
|
Actor converter.
|
||||||
|
|
||||||
|
@ -7,12 +7,14 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Actor do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor, as: ActorModel
|
alias Mobilizon.Actors.Actor, as: ActorModel
|
||||||
alias Mobilizon.Service.ActivityPub.{Converter, Convertible, Utils}
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Utils
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
|
||||||
|
|
||||||
@behaviour Converter
|
@behaviour Converter
|
||||||
|
|
||||||
defimpl Convertible, for: ActorModel do
|
defimpl Convertible, for: ActorModel do
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Actor, as: ActorConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor, as: ActorConverter
|
||||||
|
|
||||||
defdelegate model_to_as(actor), to: ActorConverter
|
defdelegate model_to_as(actor), to: ActorConverter
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Address do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Address do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Address converter.
|
Address converter.
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Address do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Addresses.Address, as: AddressModel
|
alias Mobilizon.Addresses.Address, as: AddressModel
|
||||||
alias Mobilizon.Service.ActivityPub.Converter
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter
|
||||||
|
|
||||||
@behaviour Converter
|
@behaviour Converter
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Comment do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Comment do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Comment converter.
|
Comment converter.
|
||||||
|
|
||||||
|
@ -9,17 +9,19 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Comment do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.Comment, as: CommentModel
|
alias Mobilizon.Events.Comment, as: CommentModel
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Converter, Convertible, Visibility}
|
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Utils, as: ConverterUtils
|
|
||||||
alias Mobilizon.Tombstone, as: TombstoneModel
|
alias Mobilizon.Tombstone, as: TombstoneModel
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Visibility
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@behaviour Converter
|
@behaviour Converter
|
||||||
|
|
||||||
defimpl Convertible, for: CommentModel do
|
defimpl Convertible, for: CommentModel do
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Comment, as: CommentConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Comment, as: CommentConverter
|
||||||
|
|
||||||
defdelegate model_to_as(comment), to: CommentConverter
|
defdelegate model_to_as(comment), to: CommentConverter
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Event do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Event do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Event converter.
|
Event converter.
|
||||||
|
|
||||||
|
@ -11,18 +11,19 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Event do
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
alias Mobilizon.Events.Event, as: EventModel
|
alias Mobilizon.Events.Event, as: EventModel
|
||||||
alias Mobilizon.Media.Picture
|
alias Mobilizon.Media.Picture
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Converter, Convertible}
|
alias Mobilizon.Federation.ActivityPub
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Address, as: AddressConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Picture, as: PictureConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Address, as: AddressConverter
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Utils, as: ConverterUtils
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Picture, as: PictureConverter
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils, as: ConverterUtils
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@behaviour Converter
|
@behaviour Converter
|
||||||
|
|
||||||
defimpl Convertible, for: EventModel do
|
defimpl Convertible, for: EventModel do
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Event, as: EventConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Event, as: EventConverter
|
||||||
|
|
||||||
defdelegate model_to_as(event), to: EventConverter
|
defdelegate model_to_as(event), to: EventConverter
|
||||||
end
|
end
|
||||||
|
@ -177,7 +178,7 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Event do
|
||||||
|
|
||||||
@spec do_get_address(map) :: integer | nil
|
@spec do_get_address(map) :: integer | nil
|
||||||
defp do_get_address(map) do
|
defp do_get_address(map) do
|
||||||
map = Mobilizon.Service.ActivityPub.Converter.Address.as_to_model_data(map)
|
map = AddressConverter.as_to_model_data(map)
|
||||||
|
|
||||||
case Addresses.create_address(map) do
|
case Addresses.create_address(map) do
|
||||||
{:ok, %Address{id: address_id}} ->
|
{:ok, %Address{id: address_id}} ->
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Flag do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Flag do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Flag converter.
|
Flag converter.
|
||||||
|
|
||||||
|
@ -13,14 +13,14 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Flag do
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Reports.Report
|
alias Mobilizon.Reports.Report
|
||||||
alias Mobilizon.Service.ActivityPub.Converter
|
|
||||||
alias Mobilizon.Service.ActivityPub.Convertible
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
|
||||||
alias Mobilizon.Service.ActivityPub.Relay
|
alias Mobilizon.Federation.ActivityPub.Relay
|
||||||
|
|
||||||
@behaviour Converter
|
@behaviour Converter
|
||||||
|
|
||||||
defimpl Convertible, for: Report do
|
defimpl Convertible, for: Report do
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Flag, as: FlagConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Flag, as: FlagConverter
|
||||||
|
|
||||||
defdelegate model_to_as(report), to: FlagConverter
|
defdelegate model_to_as(report), to: FlagConverter
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Follower do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Participant converter.
|
Participant converter.
|
||||||
|
|
||||||
|
@ -6,13 +6,14 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Follower do
|
||||||
internal one, and back.
|
internal one, and back.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Actors.Follower, as: FollowerModel
|
alias Mobilizon.Actors.Follower, as: FollowerModel
|
||||||
|
|
||||||
alias Mobilizon.Service.ActivityPub.Convertible
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible
|
||||||
alias Mobilizon.Actors.Actor
|
|
||||||
|
|
||||||
defimpl Convertible, for: FollowerModel do
|
defimpl Convertible, for: FollowerModel do
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Follower, as: FollowerConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Follower,
|
||||||
|
as: FollowerConverter
|
||||||
|
|
||||||
defdelegate model_to_as(follower), to: FollowerConverter
|
defdelegate model_to_as(follower), to: FollowerConverter
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Participant do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Participant do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Participant converter.
|
Participant converter.
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Participant do
|
||||||
|
|
||||||
alias Mobilizon.Events.Participant, as: ParticipantModel
|
alias Mobilizon.Events.Participant, as: ParticipantModel
|
||||||
|
|
||||||
alias Mobilizon.Service.ActivityPub.Convertible
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible
|
||||||
|
|
||||||
defimpl Convertible, for: ParticipantModel do
|
defimpl Convertible, for: ParticipantModel do
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Participant, as: ParticipantConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Participant, as: ParticipantConverter
|
||||||
|
|
||||||
defdelegate model_to_as(participant), to: ParticipantConverter
|
defdelegate model_to_as(participant), to: ParticipantConverter
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Picture do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Picture do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Picture converter.
|
Picture converter.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Tombstone do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Tombstone do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Comment converter.
|
Comment converter.
|
||||||
|
|
||||||
|
@ -6,14 +6,15 @@ defmodule Mobilizon.Service.ActivityPub.Converter.Tombstone do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Tombstone, as: TombstoneModel
|
alias Mobilizon.Tombstone, as: TombstoneModel
|
||||||
alias Mobilizon.Service.ActivityPub.{Converter, Convertible}
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@behaviour Converter
|
@behaviour Converter
|
||||||
|
|
||||||
defimpl Convertible, for: TombstoneModel do
|
defimpl Convertible, for: TombstoneModel do
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Tombstone, as: TombstoneConverter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Tombstone, as: TombstoneConverter
|
||||||
|
|
||||||
defdelegate model_to_as(comment), to: TombstoneConverter
|
defdelegate model_to_as(comment), to: TombstoneConverter
|
||||||
end
|
end
|
|
@ -1,14 +1,16 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.Utils do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Utils do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Various utils for converters
|
Various utils for converters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.Tag
|
alias Mobilizon.Events.Tag
|
||||||
alias Mobilizon.Mention
|
alias Mobilizon.Mention
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@spec fetch_tags([String.t()]) :: [Tag.t()]
|
@spec fetch_tags([String.t()]) :: [Tag.t()]
|
|
@ -1,4 +1,4 @@
|
||||||
defprotocol Mobilizon.Service.ActivityPub.Convertible do
|
defprotocol Mobilizon.Federation.ActivityPub.ActivityStream.Convertible do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Convertible protocol.
|
Convertible protocol.
|
||||||
"""
|
"""
|
|
@ -1,13 +1,13 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Audience do
|
defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Tools for calculating content audience
|
Tools for calculating content audience
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.Comment
|
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||||
alias Mobilizon.Events.Event
|
|
||||||
alias Mobilizon.Events.Participant
|
|
||||||
alias Mobilizon.Share
|
alias Mobilizon.Share
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@ap_public "https://www.w3.org/ns/activitystreams#Public"
|
@ap_public "https://www.w3.org/ns/activitystreams#Public"
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/federator/federator.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/federator/federator.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.Federator do
|
defmodule Mobilizon.Federation.ActivityPub.Federator do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handle federated activities
|
Handle federated activities
|
||||||
"""
|
"""
|
||||||
|
@ -11,8 +11,9 @@ defmodule Mobilizon.Service.Federator do
|
||||||
use GenServer
|
use GenServer
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Activity, Transmogrifier}
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier}
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/signature.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/signature.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.HTTPSignatures.Signature do
|
defmodule Mobilizon.Federation.HTTPSignatures.Signature do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Adapter for the `HTTPSignatures` lib that handles signing and providing public keys to verify HTTPSignatures
|
Adapter for the `HTTPSignatures` lib that handles signing and providing public keys to verify HTTPSignatures
|
||||||
"""
|
"""
|
||||||
|
@ -11,7 +11,8 @@ defmodule Mobilizon.Service.HTTPSignatures.Signature do
|
||||||
@behaviour HTTPSignatures.Adapter
|
@behaviour HTTPSignatures.Adapter
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -111,6 +112,6 @@ defmodule Mobilizon.Service.HTTPSignatures.Signature do
|
||||||
def generate_request_target(method, path), do: "#{method} #{path}"
|
def generate_request_target(method, path), do: "#{method} #{path}"
|
||||||
|
|
||||||
def build_digest(body) do
|
def build_digest(body) do
|
||||||
"SHA-256=" <> (:crypto.hash(:sha256, body) |> Base.encode64())
|
"SHA-256=#{:sha256 |> :crypto.hash(body) |> Base.encode64()}"
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -3,16 +3,16 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/relay.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/relay.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.ActivityPub.Relay do
|
defmodule Mobilizon.Federation.ActivityPub.Relay do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles following and unfollowing relays and instances.
|
Handles following and unfollowing relays and instances.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.{Actor, Follower}
|
alias Mobilizon.Actors.{Actor, Follower}
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Activity, Transmogrifier}
|
alias Mobilizon.Federation.ActivityPub
|
||||||
alias Mobilizon.Service.WebFinger
|
alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier, WebFinger}
|
||||||
|
|
||||||
alias MobilizonWeb.API.Follows
|
alias MobilizonWeb.API.Follows
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/transmogrifier.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/transmogrifier.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
defmodule Mobilizon.Federation.ActivityPub.Transmogrifier do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
A module to handle coding from internal to wire ActivityPub and back.
|
A module to handle coding from internal to wire ActivityPub and back.
|
||||||
"""
|
"""
|
||||||
|
@ -12,11 +12,12 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
alias Mobilizon.Actors.{Actor, Follower}
|
alias Mobilizon.Actors.{Actor, Follower}
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Activity, Converter, Convertible, Utils}
|
|
||||||
alias MobilizonWeb.Email.Participation
|
|
||||||
|
|
||||||
import Mobilizon.Service.ActivityPub.Utils
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.{Activity, Utils}
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Converter, Convertible}
|
||||||
|
|
||||||
|
alias MobilizonWeb.Email.Participation
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
"id" => id
|
"id" => id
|
||||||
} = data
|
} = data
|
||||||
) do
|
) do
|
||||||
with actor_url <- get_actor(data),
|
with actor_url <- Utils.get_actor(data),
|
||||||
{:ok, %Actor{} = actor} <- ActivityPub.get_or_fetch_actor_by_url(actor_url),
|
{:ok, %Actor{} = actor} <- ActivityPub.get_or_fetch_actor_by_url(actor_url),
|
||||||
{:object_not_found, {:ok, %Activity{} = activity, object}} <-
|
{:object_not_found, {:ok, %Activity{} = activity, object}} <-
|
||||||
{:object_not_found,
|
{:object_not_found,
|
||||||
|
@ -146,7 +147,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Reject", "object" => rejected_object, "actor" => _actor, "id" => id} = data
|
%{"type" => "Reject", "object" => rejected_object, "actor" => _actor, "id" => id} = data
|
||||||
) do
|
) do
|
||||||
with actor_url <- get_actor(data),
|
with actor_url <- Utils.get_actor(data),
|
||||||
{:ok, %Actor{} = actor} <- ActivityPub.get_or_fetch_actor_by_url(actor_url),
|
{:ok, %Actor{} = actor} <- ActivityPub.get_or_fetch_actor_by_url(actor_url),
|
||||||
{:object_not_found, {:ok, activity, object}} <-
|
{:object_not_found, {:ok, activity, object}} <-
|
||||||
{:object_not_found,
|
{:object_not_found,
|
||||||
|
@ -175,14 +176,13 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Announce", "object" => object, "actor" => _actor, "id" => _id} = data
|
%{"type" => "Announce", "object" => object, "actor" => _actor, "id" => _id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- Utils.get_actor(data),
|
||||||
# TODO: Is the following line useful?
|
# TODO: Is the following line useful?
|
||||||
{:ok, %Actor{id: actor_id} = _actor} <- ActivityPub.get_or_fetch_actor_by_url(actor),
|
{:ok, %Actor{id: actor_id} = _actor} <- ActivityPub.get_or_fetch_actor_by_url(actor),
|
||||||
:ok <- Logger.debug("Fetching contained object"),
|
:ok <- Logger.debug("Fetching contained object"),
|
||||||
{:ok, object} <- fetch_obj_helper_as_activity_streams(object),
|
{:ok, object} <- fetch_obj_helper_as_activity_streams(object),
|
||||||
:ok <- Logger.debug("Handling contained object"),
|
:ok <- Logger.debug("Handling contained object"),
|
||||||
create_data <-
|
create_data <- Utils.make_create_data(object),
|
||||||
make_create_data(object),
|
|
||||||
:ok <- Logger.debug(inspect(object)),
|
:ok <- Logger.debug(inspect(object)),
|
||||||
{:ok, _activity, entity} <- handle_incoming(create_data),
|
{:ok, _activity, entity} <- handle_incoming(create_data),
|
||||||
:ok <- Logger.debug("Finished processing contained object"),
|
:ok <- Logger.debug("Finished processing contained object"),
|
||||||
|
@ -221,13 +221,12 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
%{"type" => "Update", "object" => %{"type" => "Event"} = object, "actor" => _actor} =
|
%{"type" => "Update", "object" => %{"type" => "Event"} = object, "actor" => _actor} =
|
||||||
update_data
|
update_data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(update_data),
|
with actor <- Utils.get_actor(update_data),
|
||||||
{:ok, %Actor{url: actor_url}} <- Actors.get_actor_by_url(actor),
|
{:ok, %Actor{url: actor_url}} <- Actors.get_actor_by_url(actor),
|
||||||
{:ok, %Event{} = old_event} <-
|
{:ok, %Event{} = old_event} <-
|
||||||
object |> Utils.get_url() |> ActivityPub.fetch_object_from_url(),
|
object |> Utils.get_url() |> ActivityPub.fetch_object_from_url(),
|
||||||
{:ok, object_data} <-
|
{:ok, object_data} <- Converter.Event.as_to_model_data(object),
|
||||||
object |> Converter.Event.as_to_model_data(),
|
{:origin_check, true} <- {:origin_check, Utils.origin_check?(actor_url, update_data)},
|
||||||
{:origin_check, true} <- {:origin_check, origin_check?(actor_url, update_data)},
|
|
||||||
{:ok, %Activity{} = activity, %Event{} = new_event} <-
|
{:ok, %Activity{} = activity, %Event{} = new_event} <-
|
||||||
ActivityPub.update(:event, old_event, object_data, false) do
|
ActivityPub.update(:event, old_event, object_data, false) do
|
||||||
{:ok, activity, new_event}
|
{:ok, activity, new_event}
|
||||||
|
@ -249,7 +248,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
"id" => id
|
"id" => id
|
||||||
} = data
|
} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- Utils.get_actor(data),
|
||||||
{:ok, %Actor{} = actor} <- ActivityPub.get_or_fetch_actor_by_url(actor),
|
{:ok, %Actor{} = actor} <- ActivityPub.get_or_fetch_actor_by_url(actor),
|
||||||
{:ok, object} <- fetch_obj_helper_as_activity_streams(object_id),
|
{:ok, object} <- fetch_obj_helper_as_activity_streams(object_id),
|
||||||
{:ok, activity, object} <-
|
{:ok, activity, object} <-
|
||||||
|
@ -287,10 +286,10 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Delete", "object" => object, "actor" => _actor, "id" => _id} = data
|
%{"type" => "Delete", "object" => object, "actor" => _actor, "id" => _id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- Utils.get_actor(data),
|
||||||
{:ok, %Actor{url: actor_url}} <- Actors.get_actor_by_url(actor),
|
{:ok, %Actor{url: actor_url}} <- Actors.get_actor_by_url(actor),
|
||||||
object_id <- Utils.get_url(object),
|
object_id <- Utils.get_url(object),
|
||||||
{:origin_check, true} <- {:origin_check, origin_check_from_id?(actor_url, object_id)},
|
{:origin_check, true} <- {:origin_check, Utils.origin_check_from_id?(actor_url, object_id)},
|
||||||
{:ok, object} <- ActivityPub.fetch_object_from_url(object_id),
|
{:ok, object} <- ActivityPub.fetch_object_from_url(object_id),
|
||||||
{:ok, activity, object} <- ActivityPub.delete(object, false) do
|
{:ok, activity, object} <- ActivityPub.delete(object, false) do
|
||||||
{:ok, activity, object}
|
{:ok, activity, object}
|
||||||
|
@ -308,7 +307,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Join", "object" => object, "actor" => _actor, "id" => id} = data
|
%{"type" => "Join", "object" => object, "actor" => _actor, "id" => id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- Utils.get_actor(data),
|
||||||
{:ok, %Actor{url: _actor_url} = actor} <- Actors.get_actor_by_url(actor),
|
{:ok, %Actor{url: _actor_url} = actor} <- Actors.get_actor_by_url(actor),
|
||||||
object <- Utils.get_url(object),
|
object <- Utils.get_url(object),
|
||||||
{:ok, object} <- ActivityPub.fetch_object_from_url(object),
|
{:ok, object} <- ActivityPub.fetch_object_from_url(object),
|
||||||
|
@ -324,7 +323,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Leave", "object" => object, "actor" => actor, "id" => _id} = data
|
%{"type" => "Leave", "object" => object, "actor" => actor, "id" => _id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- Utils.get_actor(data),
|
||||||
{:ok, %Actor{} = actor} <- Actors.get_actor_by_url(actor),
|
{:ok, %Actor{} = actor} <- Actors.get_actor_by_url(actor),
|
||||||
object <- Utils.get_url(object),
|
object <- Utils.get_url(object),
|
||||||
{:ok, object} <- ActivityPub.fetch_object_from_url(object),
|
{:ok, object} <- ActivityPub.fetch_object_from_url(object),
|
||||||
|
@ -356,7 +355,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||||
# "id" => id
|
# "id" => id
|
||||||
# } = data
|
# } = data
|
||||||
# ) do
|
# ) do
|
||||||
# with actor <- get_actor(data),
|
# with actor <- Utils.get_actor(data),
|
||||||
# %Actor{} = actor <- ActivityPub.get_or_fetch_actor_by_url(actor),
|
# %Actor{} = actor <- ActivityPub.get_or_fetch_actor_by_url(actor),
|
||||||
# {:ok, object} <- fetch_obj_helper(object_id) || fetch_obj_helper(object_id),
|
# {:ok, object} <- fetch_obj_helper(object_id) || fetch_obj_helper(object_id),
|
||||||
# {:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
|
# {:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
|
|
@ -3,16 +3,18 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/utils.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/utils.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.ActivityPub.Utils do
|
defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
# Various ActivityPub related utils.
|
Various ActivityPub related utils.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Media.Picture
|
alias Mobilizon.Media.Picture
|
||||||
alias Mobilizon.Service.ActivityPub.{Activity, Converter}
|
|
||||||
alias Mobilizon.Service.Federator
|
alias Mobilizon.Federation.ActivityPub.{Activity, Federator, Relay}
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter
|
||||||
|
alias Mobilizon.Federation.HTTPSignatures
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -422,8 +424,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||||
uri = URI.parse(id)
|
uri = URI.parse(id)
|
||||||
|
|
||||||
signature =
|
signature =
|
||||||
Mobilizon.Service.ActivityPub.Relay.get_actor()
|
Relay.get_actor()
|
||||||
|> Mobilizon.Service.HTTPSignatures.Signature.sign(%{
|
|> HTTPSignatures.Signature.sign(%{
|
||||||
"(request-target)": "get #{uri.path}",
|
"(request-target)": "get #{uri.path}",
|
||||||
host: uri.host,
|
host: uri.host,
|
||||||
date: date
|
date: date
|
|
@ -3,13 +3,14 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/visibility.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/activity_pub/visibility.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.ActivityPub.Visibility do
|
defmodule Mobilizon.Federation.ActivityPub.Visibility do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Utility functions related to content visibility
|
Utility functions related to content visibility
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Events.Comment
|
alias Mobilizon.Events.Comment
|
||||||
alias Mobilizon.Service.ActivityPub.Activity
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Activity
|
||||||
|
|
||||||
@public "https://www.w3.org/ns/activitystreams#Public"
|
@public "https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
|
||||||
|
@ -18,8 +19,9 @@ defmodule Mobilizon.Service.ActivityPub.Visibility do
|
||||||
def is_public?(%{data: data}), do: is_public?(data)
|
def is_public?(%{data: data}), do: is_public?(data)
|
||||||
def is_public?(%Activity{data: data}), do: is_public?(data)
|
def is_public?(%Activity{data: data}), do: is_public?(data)
|
||||||
|
|
||||||
def is_public?(data) when is_map(data),
|
def is_public?(data) when is_map(data) do
|
||||||
do: @public in (Map.get(data, "to", []) ++ Map.get(data, "cc", []))
|
@public in (Map.get(data, "to", []) ++ Map.get(data, "cc", []))
|
||||||
|
end
|
||||||
|
|
||||||
def is_public?(%Comment{deleted_at: deleted_at}), do: !is_nil(deleted_at)
|
def is_public?(%Comment{deleted_at: deleted_at}), do: !is_nil(deleted_at)
|
||||||
def is_public?(err), do: raise(ArgumentError, message: "Invalid argument #{inspect(err)}")
|
def is_public?(err), do: raise(ArgumentError, message: "Invalid argument #{inspect(err)}")
|
|
@ -3,16 +3,16 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/web_finger/web_finger.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/web_finger/web_finger.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.WebFinger do
|
defmodule Mobilizon.Federation.ActivityPub.WebFinger do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
# WebFinger
|
Performs the WebFinger requests and responses (JSON only).
|
||||||
|
|
||||||
Performs the WebFinger requests and responses (JSON only)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.XmlBuilder
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.WebFinger.XmlBuilder
|
||||||
|
|
||||||
require Jason
|
require Jason
|
||||||
require Logger
|
require Logger
|
||||||
|
|
|
@ -3,16 +3,13 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/xml_builder.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/xml_builder.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.XmlBuilder do
|
defmodule Mobilizon.Federation.ActivityPub.WebFinger.XmlBuilder do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
XML Builder.
|
Builds XRD for WebFinger host_meta.
|
||||||
|
|
||||||
Needed to build XRD for webfinger host_meta
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def to_xml({tag, attributes, content}) do
|
def to_xml({tag, attributes, content}) do
|
||||||
open_tag = make_open_tag(tag, attributes)
|
open_tag = make_open_tag(tag, attributes)
|
||||||
|
|
||||||
content_xml = to_xml(content)
|
content_xml = to_xml(content)
|
||||||
|
|
||||||
"<#{open_tag}>#{content_xml}</#{tag}>"
|
"<#{open_tag}>#{content_xml}</#{tag}>"
|
||||||
|
@ -26,28 +23,22 @@ defmodule Mobilizon.Service.XmlBuilder do
|
||||||
|
|
||||||
def to_xml({tag, content}), do: to_xml({tag, %{}, content})
|
def to_xml({tag, content}), do: to_xml({tag, %{}, content})
|
||||||
|
|
||||||
def to_xml(content) when is_binary(content) do
|
def to_xml(content) when is_binary(content), do: to_string(content)
|
||||||
to_string(content)
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_xml(content) when is_list(content) do
|
def to_xml(content) when is_list(content) do
|
||||||
for element <- content do
|
content
|
||||||
to_xml(element)
|
|> Enum.map(&to_xml/1)
|
||||||
end
|
|
||||||
|> Enum.join()
|
|> Enum.join()
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_xml(%NaiveDateTime{} = time) do
|
def to_xml(%NaiveDateTime{} = time), do: NaiveDateTime.to_iso8601(time)
|
||||||
NaiveDateTime.to_iso8601(time)
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_doc(content), do: ~s(<?xml version="1.0" encoding="UTF-8"?>) <> to_xml(content)
|
def to_doc(content), do: ~s(<?xml version="1.0" encoding="UTF-8"?>) <> to_xml(content)
|
||||||
|
|
||||||
defp make_open_tag(tag, attributes) do
|
defp make_open_tag(tag, attributes) do
|
||||||
attributes_string =
|
attributes_string =
|
||||||
for {attribute, value} <- attributes do
|
attributes
|
||||||
"#{attribute}=\"#{value}\""
|
|> Enum.map(fn {attribute, value} -> "#{attribute}=\"#{value}\"" end)
|
||||||
end
|
|
||||||
|> Enum.join(" ")
|
|> Enum.join(" ")
|
||||||
|
|
||||||
[tag, attributes_string] |> Enum.join(" ") |> String.trim()
|
[tag, attributes_string] |> Enum.join(" ") |> String.trim()
|
|
@ -23,7 +23,7 @@ defmodule Mix.Tasks.Mobilizon.Relay do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
|
||||||
alias Mix.Tasks.Mobilizon.Common
|
alias Mix.Tasks.Mobilizon.Common
|
||||||
alias Mobilizon.Service.ActivityPub.Relay
|
alias Mobilizon.Federation.ActivityPub.Relay
|
||||||
|
|
||||||
@shortdoc "Manages remote relays"
|
@shortdoc "Manages remote relays"
|
||||||
def run(["follow", target]) do
|
def run(["follow", target]) do
|
||||||
|
|
|
@ -15,6 +15,7 @@ defmodule Mobilizon do
|
||||||
import Cachex.Spec
|
import Cachex.Spec
|
||||||
|
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
alias Mobilizon.Service.Export.{Feed, ICalendar}
|
alias Mobilizon.Service.Export.{Feed, ICalendar}
|
||||||
|
|
||||||
@name Mix.Project.config()[:name]
|
@name Mix.Project.config()[:name]
|
||||||
|
@ -41,7 +42,7 @@ defmodule Mobilizon do
|
||||||
{Oban, Application.get_env(:mobilizon, Oban)},
|
{Oban, Application.get_env(:mobilizon, Oban)},
|
||||||
# workers
|
# workers
|
||||||
Guardian.DB.Token.SweeperServer,
|
Guardian.DB.Token.SweeperServer,
|
||||||
Mobilizon.Service.Federator,
|
ActivityPub.Federator,
|
||||||
cachex_spec(:feed, 2500, 60, 60, &Feed.create_cache/1),
|
cachex_spec(:feed, 2500, 60, 60, &Feed.create_cache/1),
|
||||||
cachex_spec(:ics, 2500, 60, 60, &ICalendar.create_cache/1),
|
cachex_spec(:ics, 2500, 60, 60, &ICalendar.create_cache/1),
|
||||||
cachex_spec(:statistics, 10, 60, 60),
|
cachex_spec(:statistics, 10, 60, 60),
|
||||||
|
@ -94,7 +95,7 @@ defmodule Mobilizon do
|
||||||
defp internal_actor() do
|
defp internal_actor() do
|
||||||
%{
|
%{
|
||||||
id: :internal_actor_init,
|
id: :internal_actor_init,
|
||||||
start: {Task, :start_link, [&Mobilizon.Service.ActivityPub.Relay.init/0]},
|
start: {Task, :start_link, [&ActivityPub.Relay.init/0]},
|
||||||
restart: :temporary
|
restart: :temporary
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,9 +11,10 @@ defmodule Mobilizon.Actors do
|
||||||
alias Mobilizon.Actors.{Actor, Bot, Follower, Member}
|
alias Mobilizon.Actors.{Actor, Bot, Follower, Member}
|
||||||
alias Mobilizon.{Crypto, Events}
|
alias Mobilizon.{Crypto, Events}
|
||||||
alias Mobilizon.Media.File
|
alias Mobilizon.Media.File
|
||||||
alias Mobilizon.Storage.{Page, Repo}
|
|
||||||
alias Mobilizon.Service.Workers.BackgroundWorker
|
alias Mobilizon.Service.Workers.BackgroundWorker
|
||||||
alias Mobilizon.Service.ActivityPub
|
alias Mobilizon.Storage.{Page, Repo}
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ defmodule Mobilizon.Tombstone do
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec create_tombstone(map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
|
@spec create_tombstone(map) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
|
||||||
def create_tombstone(attrs) do
|
def create_tombstone(attrs) do
|
||||||
%__MODULE__{}
|
%__MODULE__{}
|
||||||
|> changeset(attrs)
|
|> changeset(attrs)
|
||||||
|
|
|
@ -3,8 +3,9 @@ defmodule MobilizonWeb.API.Comments do
|
||||||
API for Comments.
|
API for Comments.
|
||||||
"""
|
"""
|
||||||
alias Mobilizon.Events.Comment
|
alias Mobilizon.Events.Comment
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.Activity
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Activity
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Create a comment
|
Create a comment
|
||||||
|
|
|
@ -5,9 +5,9 @@ defmodule MobilizonWeb.API.Events do
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.Activity
|
alias Mobilizon.Federation.ActivityPub
|
||||||
alias Mobilizon.Service.ActivityPub.Utils
|
alias Mobilizon.Federation.ActivityPub.{Activity, Utils}
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Create an event
|
Create an event
|
||||||
|
|
|
@ -5,8 +5,9 @@ defmodule MobilizonWeb.API.Follows do
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.{Actor, Follower}
|
alias Mobilizon.Actors.{Actor, Follower}
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.Activity
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Activity
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@ defmodule MobilizonWeb.API.Groups do
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.Activity
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Activity
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Create a group
|
Create a group
|
||||||
|
|
|
@ -5,7 +5,9 @@ defmodule MobilizonWeb.API.Participations do
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.{Event, Participant}
|
alias Mobilizon.Events.{Event, Participant}
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
alias MobilizonWeb.Email.Participation
|
alias MobilizonWeb.Email.Participation
|
||||||
|
|
||||||
@spec join(Event.t(), Actor.t()) :: {:ok, Participant.t()}
|
@spec join(Event.t(), Actor.t()) :: {:ok, Participant.t()}
|
||||||
|
|
|
@ -8,11 +8,12 @@ defmodule MobilizonWeb.API.Reports do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Reports, as: ReportsAction
|
alias Mobilizon.Reports, as: ReportsAction
|
||||||
alias Mobilizon.Reports.{Note, Report, ReportStatus}
|
alias Mobilizon.Reports.{Note, Report, ReportStatus}
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.Activity
|
|
||||||
alias Mobilizon.Users
|
alias Mobilizon.Users
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Activity
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Create a report/flag on an actor, and optionally on an event or on comments.
|
Create a report/flag on an actor, and optionally on an event or on comments.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -6,9 +6,10 @@ defmodule MobilizonWeb.API.Search do
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.ActorType
|
alias Mobilizon.Actors.ActorType
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Storage.Page
|
alias Mobilizon.Storage.Page
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
8
lib/mobilizon_web/cache/activity_pub.ex
vendored
8
lib/mobilizon_web/cache/activity_pub.ex
vendored
|
@ -3,10 +3,12 @@ defmodule MobilizonWeb.Cache.ActivityPub do
|
||||||
The ActivityPub related functions.
|
The ActivityPub related functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Events, Service, Tombstone}
|
alias Mobilizon.{Actors, Events, Tombstone}
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.{Comment, Event}
|
alias Mobilizon.Events.{Comment, Event}
|
||||||
alias Service.ActivityPub
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Relay
|
||||||
|
|
||||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||||
alias MobilizonWeb.Endpoint
|
alias MobilizonWeb.Endpoint
|
||||||
|
|
||||||
|
@ -73,6 +75,6 @@ defmodule MobilizonWeb.Cache.ActivityPub do
|
||||||
"""
|
"""
|
||||||
@spec get_relay :: {:commit, Actor.t()} | {:ignore, nil}
|
@spec get_relay :: {:commit, Actor.t()} | {:ignore, nil}
|
||||||
def get_relay do
|
def get_relay do
|
||||||
Cachex.fetch(@cache, "relay_actor", &ActivityPub.Relay.get_actor/0)
|
Cachex.fetch(@cache, "relay_actor", &Relay.get_actor/0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,9 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||||
use MobilizonWeb, :controller
|
use MobilizonWeb, :controller
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Actors.Actor, Config}
|
alias Mobilizon.{Actors, Actors.Actor, Config}
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.Federator
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Federator
|
||||||
|
|
||||||
alias MobilizonWeb.ActivityPub.ActorView
|
alias MobilizonWeb.ActivityPub.ActorView
|
||||||
alias MobilizonWeb.Cache
|
alias MobilizonWeb.Cache
|
||||||
|
|
|
@ -7,10 +7,12 @@ defmodule MobilizonWeb.WebFingerController do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles Webfinger requests
|
Handles Webfinger requests
|
||||||
"""
|
"""
|
||||||
|
|
||||||
use MobilizonWeb, :controller
|
use MobilizonWeb, :controller
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.WebFinger
|
||||||
|
|
||||||
plug(MobilizonWeb.Plugs.Federating)
|
plug(MobilizonWeb.Plugs.Federating)
|
||||||
alias Mobilizon.Service.WebFinger
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Provides /.well-known/host-meta
|
Provides /.well-known/host-meta
|
||||||
|
|
|
@ -7,12 +7,15 @@ defmodule MobilizonWeb.Plugs.MappedSignatureToIdentity do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Get actor identity from Signature when handing fetches
|
Get actor identity from Signature when handing fetches
|
||||||
"""
|
"""
|
||||||
alias Mobilizon.Service.HTTPSignatures.Signature
|
|
||||||
alias Mobilizon.Actors.Actor
|
|
||||||
alias Mobilizon.Service.ActivityPub.Utils
|
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
|
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
|
|
||||||
|
alias Mobilizon.Actors.Actor
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Utils
|
||||||
|
alias Mobilizon.Federation.HTTPSignatures.Signature
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def init(options), do: options
|
def init(options), do: options
|
||||||
|
|
|
@ -2,10 +2,12 @@ defmodule MobilizonWeb.Resolvers.Address do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the comment-related GraphQL calls
|
Handles the comment-related GraphQL calls
|
||||||
"""
|
"""
|
||||||
require Logger
|
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
alias Mobilizon.Service.Geospatial
|
alias Mobilizon.Service.Geospatial
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Search an address
|
Search an address
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -11,10 +11,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.{Event, Comment}
|
alias Mobilizon.Events.{Event, Comment}
|
||||||
alias Mobilizon.Reports.{Note, Report}
|
alias Mobilizon.Reports.{Note, Report}
|
||||||
alias Mobilizon.Service.Statistics
|
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
alias Mobilizon.Service.Statistics
|
||||||
alias Mobilizon.Storage.Page
|
alias Mobilizon.Storage.Page
|
||||||
alias Mobilizon.Service.ActivityPub.Relay
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Relay
|
||||||
|
|
||||||
def list_action_logs(
|
def list_action_logs(
|
||||||
_parent,
|
_parent,
|
||||||
|
|
|
@ -3,14 +3,15 @@ defmodule MobilizonWeb.Resolvers.Comment do
|
||||||
Handles the comment-related GraphQL calls.
|
Handles the comment-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import Mobilizon.Service.Admin.ActionLogService
|
||||||
|
|
||||||
|
alias Mobilizon.Actors
|
||||||
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.Comment, as: CommentModel
|
alias Mobilizon.Events.Comment, as: CommentModel
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
alias Mobilizon.Actors.Actor
|
|
||||||
alias Mobilizon.Actors
|
|
||||||
|
|
||||||
alias MobilizonWeb.API.Comments
|
alias MobilizonWeb.API.Comments
|
||||||
import Mobilizon.Service.Admin.ActionLogService
|
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,10 @@ defmodule MobilizonWeb.Resolvers.Config do
|
||||||
Handles the config-related GraphQL calls.
|
Handles the config-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Mobilizon.Config
|
|
||||||
alias Geolix.Adapter.MMDB2.Record.{Country, Location}
|
alias Geolix.Adapter.MMDB2.Record.{Country, Location}
|
||||||
|
|
||||||
|
alias Mobilizon.Config
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Gets config.
|
Gets config.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -9,9 +9,10 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.{Event, Participant, EventParticipantStats}
|
alias Mobilizon.Events.{Event, Participant, EventParticipantStats}
|
||||||
alias Mobilizon.Service.ActivityPub.Activity
|
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Activity
|
||||||
|
|
||||||
alias MobilizonWeb.API
|
alias MobilizonWeb.API
|
||||||
alias MobilizonWeb.Resolvers.Person
|
alias MobilizonWeb.Resolvers.Person
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,10 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.{Actor, Member}
|
alias Mobilizon.Actors.{Actor, Member}
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
alias MobilizonWeb.API
|
alias MobilizonWeb.API
|
||||||
alias MobilizonWeb.Resolvers.Person
|
alias MobilizonWeb.Resolvers.Person
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,11 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.Participant
|
alias Mobilizon.Events.Participant
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Users
|
alias Mobilizon.Users
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Get a person
|
Get a person
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -8,8 +8,8 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
alias Mobilizon.{Actors, Config, Users, Events}
|
alias Mobilizon.{Actors, Config, Users, Events}
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.Users.{Activation, ResetPassword}
|
alias Mobilizon.Service.Users.{Activation, ResetPassword}
|
||||||
alias Mobilizon.Users.User
|
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,10 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Activity, Utils, Convertible}
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.ActivityPub.{Activity, Utils}
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible
|
||||||
|
|
||||||
@private_visibility_empty_collection %{elements: [], total: 0}
|
@private_visibility_empty_collection %{elements: [], total: 0}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule MobilizonWeb.ActivityPub.ObjectView do
|
defmodule MobilizonWeb.ActivityPub.ObjectView do
|
||||||
use MobilizonWeb, :view
|
use MobilizonWeb, :view
|
||||||
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Activity, Utils}
|
alias Mobilizon.Federation.ActivityPub.{Activity, Utils}
|
||||||
|
|
||||||
def render("activity.json", %{activity: %Activity{local: local, data: data} = activity}) do
|
def render("activity.json", %{activity: %Activity{local: local, data: data} = activity}) do
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -2,14 +2,19 @@ defmodule MobilizonWeb.PageView do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
View for our webapp
|
View for our webapp
|
||||||
"""
|
"""
|
||||||
|
|
||||||
use MobilizonWeb, :view
|
use MobilizonWeb, :view
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Tombstone
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Convertible, Utils}
|
|
||||||
alias Mobilizon.Service.Metadata
|
|
||||||
alias Mobilizon.Service.MetadataUtils
|
|
||||||
alias Mobilizon.Service.Metadata.Instance
|
|
||||||
alias Mobilizon.Events.{Comment, Event}
|
alias Mobilizon.Events.{Comment, Event}
|
||||||
|
alias Mobilizon.Tombstone
|
||||||
|
|
||||||
|
alias Mobilizon.Service.Metadata
|
||||||
|
alias Mobilizon.Service.Metadata.Instance
|
||||||
|
alias Mobilizon.Service.Metadata.Utils, as: MetadataUtils
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Utils
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Convertible
|
||||||
|
|
||||||
def render("actor.activity-json", %{conn: %{assigns: %{object: %Actor{} = actor}}}) do
|
def render("actor.activity-json", %{conn: %{assigns: %{object: %Actor{} = actor}}}) do
|
||||||
actor
|
actor
|
||||||
|
|
|
@ -3,21 +3,15 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/html.ex
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/html.ex
|
||||||
|
|
||||||
defmodule Mobilizon.Service.HTML do
|
defmodule Mobilizon.Service.Formatter.DefaultScrubbler do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Service to filter tags out of HTML content
|
Custom strategy to filter HTML content.
|
||||||
"""
|
"""
|
||||||
alias HtmlSanitizeEx.Scrubber
|
|
||||||
alias Mobilizon.Service.HTML.Scrubber.Default
|
|
||||||
|
|
||||||
def filter_tags(html), do: Scrubber.scrub(html, Default)
|
alias HtmlSanitizeEx.Scrubber.Meta
|
||||||
end
|
|
||||||
|
|
||||||
defmodule Mobilizon.Service.HTML.Scrubber.Default do
|
|
||||||
@moduledoc "Custom strategy to filter HTML content"
|
|
||||||
|
|
||||||
require HtmlSanitizeEx.Scrubber.Meta
|
require HtmlSanitizeEx.Scrubber.Meta
|
||||||
alias HtmlSanitizeEx.Scrubber.Meta
|
|
||||||
# credo:disable-for-previous-line
|
# credo:disable-for-previous-line
|
||||||
# No idea how to fix this one…
|
# No idea how to fix this one…
|
||||||
|
|
|
@ -10,18 +10,18 @@ defmodule Mobilizon.Service.Formatter do
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.HTML
|
alias Mobilizon.Service.Formatter.HTML
|
||||||
|
|
||||||
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
|
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
|
||||||
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
|
@markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
|
||||||
|
|
||||||
@auto_linker_config hashtag: true,
|
@auto_linker_config hashtag: true,
|
||||||
hashtag_handler: &Mobilizon.Service.Formatter.hashtag_handler/4,
|
hashtag_handler: &__MODULE__.hashtag_handler/4,
|
||||||
mention: true,
|
mention: true,
|
||||||
mention_handler: &Mobilizon.Service.Formatter.mention_handler/4
|
mention_handler: &__MODULE__.mention_handler/4
|
||||||
|
|
||||||
def escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
|
def escape_mention_handler("@" <> nickname = mention, buffer, _, _) do
|
||||||
case Mobilizon.Actors.get_actor_by_name(nickname) do
|
case Actors.get_actor_by_name(nickname) do
|
||||||
%Actor{} ->
|
%Actor{} ->
|
||||||
# escape markdown characters with `\\`
|
# escape markdown characters with `\\`
|
||||||
# (we don't want something like @user__name to be parsed by markdown)
|
# (we don't want something like @user__name to be parsed by markdown)
|
||||||
|
|
17
lib/service/formatter/html.ex
Normal file
17
lib/service/formatter/html.ex
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Portions of this file are derived from Pleroma:
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/html.ex
|
||||||
|
|
||||||
|
defmodule Mobilizon.Service.Formatter.HTML do
|
||||||
|
@moduledoc """
|
||||||
|
Service to filter tags out of HTML content.
|
||||||
|
"""
|
||||||
|
|
||||||
|
alias HtmlSanitizeEx.Scrubber
|
||||||
|
|
||||||
|
alias Mobilizon.Service.Formatter.DefaultScrubbler
|
||||||
|
|
||||||
|
def filter_tags(html), do: Scrubber.scrub(html, DefaultScrubbler)
|
||||||
|
end
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
defprotocol Mobilizon.Service.Metadata do
|
|
||||||
@doc """
|
|
||||||
Build tags
|
|
||||||
"""
|
|
||||||
def build_tags(entity)
|
|
||||||
end
|
|
||||||
|
|
||||||
defmodule Mobilizon.Service.MetadataUtils do
|
|
||||||
@moduledoc """
|
|
||||||
Tools to convert tags to string
|
|
||||||
"""
|
|
||||||
alias Phoenix.HTML
|
|
||||||
|
|
||||||
def stringify_tags(tags) do
|
|
||||||
Enum.reduce(tags, "", &stringify_tag/2)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp stringify_tag(tag, acc) when is_tuple(tag), do: acc <> HTML.safe_to_string(tag)
|
|
||||||
defp stringify_tag(tag, acc) when is_binary(tag), do: acc <> tag
|
|
||||||
end
|
|
7
lib/service/metadata/metadata.ex
Normal file
7
lib/service/metadata/metadata.ex
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
defprotocol Mobilizon.Service.Metadata do
|
||||||
|
@doc """
|
||||||
|
Build tags
|
||||||
|
"""
|
||||||
|
|
||||||
|
def build_tags(entity)
|
||||||
|
end
|
12
lib/service/metadata/utils.ex
Normal file
12
lib/service/metadata/utils.ex
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
defmodule Mobilizon.Service.Metadata.Utils do
|
||||||
|
@moduledoc """
|
||||||
|
Tools to convert tags to string.
|
||||||
|
"""
|
||||||
|
|
||||||
|
alias Phoenix.HTML
|
||||||
|
|
||||||
|
def stringify_tags(tags), do: Enum.reduce(tags, "", &stringify_tag/2)
|
||||||
|
|
||||||
|
defp stringify_tag(tag, acc) when is_tuple(tag), do: acc <> HTML.safe_to_string(tag)
|
||||||
|
defp stringify_tag(tag, acc) when is_binary(tag), do: acc <> tag
|
||||||
|
end
|
20
mix.exs
20
mix.exs
|
@ -182,7 +182,6 @@ defmodule Mobilizon.Mixfile do
|
||||||
Mobilizon.Addresses,
|
Mobilizon.Addresses,
|
||||||
Mobilizon.Addresses.Address,
|
Mobilizon.Addresses.Address,
|
||||||
Mobilizon.Events,
|
Mobilizon.Events,
|
||||||
Mobilizon.Service.ActivityPub.Activity,
|
|
||||||
Mobilizon.Events.Event,
|
Mobilizon.Events.Event,
|
||||||
Mobilizon.Events.Comment,
|
Mobilizon.Events.Comment,
|
||||||
Mobilizon.Events.FeedToken,
|
Mobilizon.Events.FeedToken,
|
||||||
|
@ -205,7 +204,8 @@ defmodule Mobilizon.Mixfile do
|
||||||
Mobilizon.Users.UserRole,
|
Mobilizon.Users.UserRole,
|
||||||
Mobilizon.Users.Guards,
|
Mobilizon.Users.Guards,
|
||||||
Mobilizon.Storage.Ecto,
|
Mobilizon.Storage.Ecto,
|
||||||
Mobilizon.Storage.Repo
|
Mobilizon.Storage.Repo,
|
||||||
|
Mobilizon.Federation.ActivityPub.Activity
|
||||||
],
|
],
|
||||||
APIs: [
|
APIs: [
|
||||||
MobilizonWeb.API.Comments,
|
MobilizonWeb.API.Comments,
|
||||||
|
@ -276,19 +276,19 @@ defmodule Mobilizon.Mixfile do
|
||||||
MobilizonWeb.Schema.Utils
|
MobilizonWeb.Schema.Utils
|
||||||
],
|
],
|
||||||
ActivityPub: [
|
ActivityPub: [
|
||||||
|
Mobilizon.Federation.ActivityPub,
|
||||||
|
Mobilizon.Federation.ActivityPub.Federator,
|
||||||
|
Mobilizon.Federation.ActivityPub.Transmogrifier,
|
||||||
|
Mobilizon.Federation.ActivityPub.Utils,
|
||||||
|
Mobilizon.Federation.ActivityPub.WebFinger,
|
||||||
|
Mobilizon.Federation.ActivityPub.WebFinger.XmlBuilder,
|
||||||
|
Mobilizon.Federation.HTTPSignatures.Signature,
|
||||||
MobilizonWeb.ActivityPub.ActorView,
|
MobilizonWeb.ActivityPub.ActorView,
|
||||||
MobilizonWeb.ActivityPub.ObjectView,
|
MobilizonWeb.ActivityPub.ObjectView,
|
||||||
MobilizonWeb.ActivityPubController,
|
MobilizonWeb.ActivityPubController,
|
||||||
Mobilizon.Service.ActivityPub,
|
|
||||||
Mobilizon.Service.ActivityPub.Transmogrifier,
|
|
||||||
Mobilizon.Service.ActivityPub.Utils,
|
|
||||||
MobilizonWeb.HTTPSignaturePlug,
|
MobilizonWeb.HTTPSignaturePlug,
|
||||||
MobilizonWeb.WebFingerController,
|
MobilizonWeb.WebFingerController,
|
||||||
MobilizonWeb.NodeInfoController,
|
MobilizonWeb.NodeInfoController
|
||||||
Mobilizon.Service.HTTPSignatures.Signature,
|
|
||||||
Mobilizon.Service.WebFinger,
|
|
||||||
Mobilizon.Service.XmlBuilder,
|
|
||||||
Mobilizon.Service.Federator
|
|
||||||
],
|
],
|
||||||
Services: [
|
Services: [
|
||||||
Mobilizon.Service.EmailChecker,
|
Mobilizon.Service.EmailChecker,
|
||||||
|
|
|
@ -3,19 +3,18 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/activity_pub_test.exs
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/activity_pub_test.exs
|
||||||
|
|
||||||
defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
defmodule Mobilizon.Federation.ActivityPubTest do
|
||||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||||
|
|
||||||
use Mobilizon.DataCase
|
use Mobilizon.DataCase
|
||||||
|
|
||||||
import Mock
|
import Mock
|
||||||
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.HTTPSignatures.Signature
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
alias Mobilizon.Federation.HTTPSignatures.Signature
|
||||||
|
|
||||||
@activity_pub_public_audience "https://www.w3.org/ns/activitystreams#Public"
|
@activity_pub_public_audience "https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.Converter.ActorTest do
|
defmodule Mobilizon.Federation.ActivityPub.ActivityStream.Converter.ActorTest do
|
||||||
use Mobilizon.DataCase
|
use Mobilizon.DataCase
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.ActivityPub.Converter.Actor, as: ActorConverter
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter.Actor, as: ActorConverter
|
||||||
|
|
||||||
describe "actor to AS" do
|
describe "actor to AS" do
|
||||||
test "valid actor to as" do
|
test "valid actor to as" do
|
|
@ -2,10 +2,10 @@
|
||||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Mobilizon.Service.ActivityPub.RelayTest do
|
defmodule Mobilizon.Federation.ActivityPub.RelayTest do
|
||||||
use Mobilizon.DataCase
|
use Mobilizon.DataCase
|
||||||
|
|
||||||
alias Mobilizon.Service.ActivityPub.Relay
|
alias Mobilizon.Federation.ActivityPub.Relay
|
||||||
|
|
||||||
test "gets an actor for the relay" do
|
test "gets an actor for the relay" do
|
||||||
actor = Relay.get_actor()
|
actor = Relay.get_actor()
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/transmogrifier_test.exs
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/transmogrifier_test.exs
|
||||||
|
|
||||||
defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||||
|
|
||||||
use Mobilizon.DataCase
|
use Mobilizon.DataCase
|
||||||
|
@ -14,9 +14,11 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||||
alias Mobilizon.{Actors, Events, Tombstone}
|
alias Mobilizon.{Actors, Events, Tombstone}
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Service.ActivityPub.{Activity, Utils, Convertible}
|
alias Mobilizon.Federation.ActivityPub
|
||||||
alias Mobilizon.Service.ActivityPub.Transmogrifier
|
alias Mobilizon.Federation.ActivityPub.Utils
|
||||||
|
alias Mobilizon.Federation.ActivityPub.{Activity, Relay, Transmogrifier}
|
||||||
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.{Convertible}
|
||||||
|
|
||||||
alias MobilizonWeb.API
|
alias MobilizonWeb.API
|
||||||
|
|
||||||
|
@ -788,7 +790,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it accepts Flag activities" do
|
test "it accepts Flag activities" do
|
||||||
%Actor{url: reporter_url} = Mobilizon.Service.ActivityPub.Relay.get_actor()
|
%Actor{url: reporter_url} = Relay.get_actor()
|
||||||
%Actor{url: reported_url} = reported = insert(:actor)
|
%Actor{url: reported_url} = reported = insert(:actor)
|
||||||
|
|
||||||
%Comment{url: comment_url} = _comment = insert(:comment, actor: reported)
|
%Comment{url: comment_url} = _comment = insert(:comment, actor: reported)
|
|
@ -1,11 +1,11 @@
|
||||||
defmodule Mobilizon.Service.ActivityPub.UtilsTest do
|
defmodule Mobilizon.Federation.ActivityPub.UtilsTest do
|
||||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||||
|
|
||||||
use Mobilizon.DataCase
|
use Mobilizon.DataCase
|
||||||
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
alias Mobilizon.Service.ActivityPub.Converter
|
alias Mobilizon.Federation.ActivityPub.ActivityStream.Converter
|
||||||
|
|
||||||
alias MobilizonWeb.Endpoint
|
alias MobilizonWeb.Endpoint
|
||||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
alias MobilizonWeb.Router.Helpers, as: Routes
|
|
@ -3,12 +3,13 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs
|
||||||
|
|
||||||
defmodule Mobilizon.Service.WebFingerTest do
|
defmodule Mobilizon.Federation.ActivityPub.WebFingerTest do
|
||||||
|
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||||
use Mobilizon.DataCase
|
use Mobilizon.DataCase
|
||||||
alias Mobilizon.Service.WebFinger
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
alias Mobilizon.Federation.ActivityPub.WebFinger
|
||||||
|
|
||||||
@mastodon_account "tcit@social.tcit.fr"
|
@mastodon_account "tcit@social.tcit.fr"
|
||||||
@mastodon_account_username "tcit"
|
@mastodon_account_username "tcit"
|
|
@ -81,7 +81,7 @@
|
||||||
},
|
},
|
||||||
"response": {
|
"response": {
|
||||||
"binary": false,
|
"binary": false,
|
||||||
"body": "# HTTPoison.Error at POST /inbox\n\nException:\n\n ** (HTTPoison.Error) :nxdomain\n (httpoison) lib/httpoison.ex:128: HTTPoison.request!/5\n (mobilizon) lib/service/activity_pub/activity_pub.ex:610: Mobilizon.Service.ActivityPub.fetch_and_prepare_actor_from_url/1\n (mobilizon) lib/service/activity_pub/activity_pub.ex:473: Mobilizon.Service.ActivityPub.make_actor_from_url/2\n (mobilizon) lib/service/activity_pub/activity_pub.ex:122: Mobilizon.Service.ActivityPub.get_or_fetch_actor_by_url/2\n (mobilizon) lib/service/http_signatures/signature.ex:54: Mobilizon.Service.HTTPSignatures.Signature.get_public_key_for_url/1\n (mobilizon) lib/service/http_signatures/signature.ex:74: Mobilizon.Service.HTTPSignatures.Signature.fetch_public_key/1\n (http_signatures) lib/http_signatures/http_signatures.ex:40: HTTPSignatures.validate_conn/1\n (mobilizon) lib/mobilizon_web/http_signature.ex:45: MobilizonWeb.HTTPSignaturePlug.call/2\n (mobilizon) MobilizonWeb.Router.activity_pub_signature/2\n (mobilizon) lib/mobilizon_web/router.ex:1: MobilizonWeb.Router.__pipe_through7__/1\n (phoenix) lib/phoenix/router.ex:283: Phoenix.Router.__call__/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: MobilizonWeb.Endpoint.plug_builder_call/2\n (mobilizon) lib/plug/debugger.ex:122: MobilizonWeb.Endpoint.\"call (overridable 3)\"/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: MobilizonWeb.Endpoint.call/2\n (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3\n (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3\n \n\n## Connection details\n\n### Params\n\n %{\"@context\" => [\"https://www.w3.org/ns/activitystreams\", \"https://litepub.social/litepub/context.jsonld\", %{\"Hashtag\" => \"as:Hashtag\", \"category\" => \"sc:category\", \"ical\" => \"http://www.w3.org/2002/12/cal/ical#\", \"joinMode\" => %{\"@id\" => \"mz:joinMode\", \"@type\" => \"mz:joinModeType\"}, \"joinModeType\" => %{\"@id\" => \"mz:joinModeType\", \"@type\" => \"rdfs:Class\"}, \"maximumAttendeeCapacity\" => \"sc:maximumAttendeeCapacity\", \"mz\" => \"https://joinmobilizon.org/ns#\", \"repliesModerationOption\" => %{\"@id\" => \"mz:repliesModerationOption\", \"@type\" => \"mz:repliesModerationOptionType\"}, \"repliesModerationOptionType\" => %{\"@id\" => \"mz:repliesModerationOptionType\", \"@type\" => \"rdfs:Class\"}, \"sc\" => \"http://schema.org#\", \"uuid\" => \"sc:identifier\"}], \"actor\" => \"http://mobilizon.test/relay\", \"cc\" => [\"https://www.w3.org/ns/activitystreams#Public\"], \"id\" => \"http://mobilizon.test/follow/b7791977-2a75-4715-815b-6e7125065b71\", \"object\" => \"http://mobilizon1.com/relay\", \"to\" => [\"http://mobilizon1.com/relay\"], \"type\" => \"Follow\"}\n\n### Request info\n\n * URI: http://mobilizon1.com:80/inbox\n * Query string: \n\n### Headers\n \n * connection: upgrade\n * content-length: 912\n * content-type: application/activity+json\n * date: Fri, 13 Dec 2019 09:41:41 GMT\n * digest: SHA-256=ibNFcsnBeCCjWZo9We60tKfbRN3el0WCMVdOxtuC1cg=\n * host: mobilizon1.com\n * signature: keyId=\"http://mobilizon.test/relay#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) content-length date digest host\",signature=\"WbyGHT/WdvdRpWek8uCGHrFSblLpg+Iq802R5S2cjNj035OKpxRmu1r8u9Qr5KGIKgZn6LHt9YmB+PNlwsubPtTSkJpE8AAUDMHLKgCrH7A5Q6x6GlARl5bHNo4QtOxkXvnEbn31xfNDNp70QqZb/emw95TnELYUlMLZds0qYutT8U4WdDhSWcVytQmKJWNZXxEj+KlMDUaxag3lGscJ/HY0F+yGNov7FHthid1Y4LTGFsp/tismnMTlba12NH/kXPHtduNsX8uxFslM2ODwqAaospTGEpXmr9CPgbNy7626qgYaR2RdB/fYlCayLI4JJIlH8gOdocGHPrWNtVEHaQ==\"\n * user-agent: hackney/1.15.2\n * x-forwarded-for: 127.0.0.1\n * x-real-ip: 127.0.0.1\n\n### Session\n\n %{}\n",
|
"body": "# HTTPoison.Error at POST /inbox\n\nException:\n\n ** (HTTPoison.Error) :nxdomain\n (httpoison) lib/httpoison.ex:128: HTTPoison.request!/5\n (mobilizon) lib/service/activity_pub/activity_pub.ex:610: Mobilizon.Service.ActivityPub.fetch_and_prepare_actor_from_url/1\n (mobilizon) lib/service/activity_pub/activity_pub.ex:473: Mobilizon.Service.ActivityPub.make_actor_from_url/2\n (mobilizon) lib/service/activity_pub/activity_pub.ex:122: Mobilizon.Service.ActivityPub.get_or_fetch_actor_by_url/2\n (mobilizon) lib/service/http_signatures/signature.ex:54: Mobilizon.Federation.HTTPSignatures.Signature.get_public_key_for_url/1\n (mobilizon) lib/service/http_signatures/signature.ex:74: Mobilizon.Federation.HTTPSignatures.Signature.fetch_public_key/1\n (http_signatures) lib/http_signatures/http_signatures.ex:40: HTTPSignatures.validate_conn/1\n (mobilizon) lib/mobilizon_web/http_signature.ex:45: MobilizonWeb.HTTPSignaturePlug.call/2\n (mobilizon) MobilizonWeb.Router.activity_pub_signature/2\n (mobilizon) lib/mobilizon_web/router.ex:1: MobilizonWeb.Router.__pipe_through7__/1\n (phoenix) lib/phoenix/router.ex:283: Phoenix.Router.__call__/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: MobilizonWeb.Endpoint.plug_builder_call/2\n (mobilizon) lib/plug/debugger.ex:122: MobilizonWeb.Endpoint.\"call (overridable 3)\"/2\n (mobilizon) lib/mobilizon_web/endpoint.ex:1: MobilizonWeb.Endpoint.call/2\n (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:320: :cowboy_stream_h.execute/3\n (cowboy) /home/tcit/dev/frama/mobilizon/deps/cowboy/src/cowboy_stream_h.erl:302: :cowboy_stream_h.request_process/3\n (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3\n \n\n## Connection details\n\n### Params\n\n %{\"@context\" => [\"https://www.w3.org/ns/activitystreams\", \"https://litepub.social/litepub/context.jsonld\", %{\"Hashtag\" => \"as:Hashtag\", \"category\" => \"sc:category\", \"ical\" => \"http://www.w3.org/2002/12/cal/ical#\", \"joinMode\" => %{\"@id\" => \"mz:joinMode\", \"@type\" => \"mz:joinModeType\"}, \"joinModeType\" => %{\"@id\" => \"mz:joinModeType\", \"@type\" => \"rdfs:Class\"}, \"maximumAttendeeCapacity\" => \"sc:maximumAttendeeCapacity\", \"mz\" => \"https://joinmobilizon.org/ns#\", \"repliesModerationOption\" => %{\"@id\" => \"mz:repliesModerationOption\", \"@type\" => \"mz:repliesModerationOptionType\"}, \"repliesModerationOptionType\" => %{\"@id\" => \"mz:repliesModerationOptionType\", \"@type\" => \"rdfs:Class\"}, \"sc\" => \"http://schema.org#\", \"uuid\" => \"sc:identifier\"}], \"actor\" => \"http://mobilizon.test/relay\", \"cc\" => [\"https://www.w3.org/ns/activitystreams#Public\"], \"id\" => \"http://mobilizon.test/follow/b7791977-2a75-4715-815b-6e7125065b71\", \"object\" => \"http://mobilizon1.com/relay\", \"to\" => [\"http://mobilizon1.com/relay\"], \"type\" => \"Follow\"}\n\n### Request info\n\n * URI: http://mobilizon1.com:80/inbox\n * Query string: \n\n### Headers\n \n * connection: upgrade\n * content-length: 912\n * content-type: application/activity+json\n * date: Fri, 13 Dec 2019 09:41:41 GMT\n * digest: SHA-256=ibNFcsnBeCCjWZo9We60tKfbRN3el0WCMVdOxtuC1cg=\n * host: mobilizon1.com\n * signature: keyId=\"http://mobilizon.test/relay#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) content-length date digest host\",signature=\"WbyGHT/WdvdRpWek8uCGHrFSblLpg+Iq802R5S2cjNj035OKpxRmu1r8u9Qr5KGIKgZn6LHt9YmB+PNlwsubPtTSkJpE8AAUDMHLKgCrH7A5Q6x6GlARl5bHNo4QtOxkXvnEbn31xfNDNp70QqZb/emw95TnELYUlMLZds0qYutT8U4WdDhSWcVytQmKJWNZXxEj+KlMDUaxag3lGscJ/HY0F+yGNov7FHthid1Y4LTGFsp/tismnMTlba12NH/kXPHtduNsX8uxFslM2ODwqAaospTGEpXmr9CPgbNy7626qgYaR2RdB/fYlCayLI4JJIlH8gOdocGHPrWNtVEHaQ==\"\n * user-agent: hackney/1.15.2\n * x-forwarded-for: 127.0.0.1\n * x-real-ip: 127.0.0.1\n\n### Session\n\n %{}\n",
|
||||||
"headers": {
|
"headers": {
|
||||||
"Server": "nginx/1.16.1",
|
"Server": "nginx/1.16.1",
|
||||||
"Date": "Fri, 13 Dec 2019 09:41:41 GMT",
|
"Date": "Fri, 13 Dec 2019 09:41:41 GMT",
|
||||||
|
|
|
@ -9,9 +9,10 @@ defmodule Mobilizon.ActorsTest do
|
||||||
alias Mobilizon.Actors.{Actor, Bot, Follower, Member}
|
alias Mobilizon.Actors.{Actor, Bot, Follower, Member}
|
||||||
alias Mobilizon.Events.{Event, Comment}
|
alias Mobilizon.Events.{Event, Comment}
|
||||||
alias Mobilizon.Media.File, as: FileModel
|
alias Mobilizon.Media.File, as: FileModel
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Storage.Page
|
alias Mobilizon.Storage.Page
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
describe "actors" do
|
describe "actors" do
|
||||||
@valid_attrs %{
|
@valid_attrs %{
|
||||||
summary: "some description",
|
summary: "some description",
|
||||||
|
|
|
@ -6,15 +6,16 @@ defmodule MobilizonWeb.API.ReportTest do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.{Comment, Event}
|
alias Mobilizon.Events.{Comment, Event}
|
||||||
alias Mobilizon.Reports.{Note, Report}
|
alias Mobilizon.Reports.{Note, Report}
|
||||||
alias Mobilizon.Service.ActivityPub.Activity
|
|
||||||
alias Mobilizon.Users
|
alias Mobilizon.Users
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.{Activity, Relay}
|
||||||
|
|
||||||
alias MobilizonWeb.API.Reports
|
alias MobilizonWeb.API.Reports
|
||||||
|
|
||||||
describe "reports" do
|
describe "reports" do
|
||||||
test "creates a report on a event" do
|
test "creates a report on a event" do
|
||||||
%Actor{url: relay_reporter_url} = Mobilizon.Service.ActivityPub.Relay.get_actor()
|
%Actor{url: relay_reporter_url} = Relay.get_actor()
|
||||||
%Actor{id: reporter_id} = insert(:actor)
|
%Actor{id: reporter_id} = insert(:actor)
|
||||||
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ defmodule MobilizonWeb.API.ReportTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "creates a report on several comments" do
|
test "creates a report on several comments" do
|
||||||
%Actor{url: relay_reporter_url} = Mobilizon.Service.ActivityPub.Relay.get_actor()
|
%Actor{url: relay_reporter_url} = Relay.get_actor()
|
||||||
%Actor{id: reporter_id} = insert(:actor)
|
%Actor{id: reporter_id} = insert(:actor)
|
||||||
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@ defmodule MobilizonWeb.API.ReportTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "creates a report that gets federated" do
|
test "creates a report that gets federated" do
|
||||||
%Actor{url: relay_reporter_url} = Mobilizon.Service.ActivityPub.Relay.get_actor()
|
%Actor{url: relay_reporter_url} = Relay.get_actor()
|
||||||
%Actor{id: reporter_id} = insert(:actor)
|
%Actor{id: reporter_id} = insert(:actor)
|
||||||
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,10 @@ defmodule MobilizonWeb.API.SearchTest do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
alias Mobilizon.Storage.Page
|
alias Mobilizon.Storage.Page
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
alias MobilizonWeb.API.Search
|
alias MobilizonWeb.API.Search
|
||||||
|
|
||||||
test "search an user by username" do
|
test "search an user by username" do
|
||||||
|
|
|
@ -12,7 +12,8 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Config}
|
alias Mobilizon.{Actors, Config}
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.ActivityPub
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
alias MobilizonWeb.ActivityPub.ActorView
|
alias MobilizonWeb.ActivityPub.ActorView
|
||||||
alias MobilizonWeb.Endpoint
|
alias MobilizonWeb.Endpoint
|
||||||
|
@ -318,7 +319,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||||
# test "it returns the following in a collection", %{conn: conn} do
|
# test "it returns the following in a collection", %{conn: conn} do
|
||||||
# actor = insert(:actor)
|
# actor = insert(:actor)
|
||||||
# actor2 = insert(:actor)
|
# actor2 = insert(:actor)
|
||||||
# Mobilizon.Service.ActivityPub.follow(actor, actor2)
|
# Mobilizon.Federation.ActivityPub.follow(actor, actor2)
|
||||||
|
|
||||||
# result =
|
# result =
|
||||||
# conn
|
# conn
|
||||||
|
|
|
@ -3,14 +3,17 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_test.exs
|
||||||
|
|
||||||
defmodule MobilizonWeb.WebFingerTest do
|
defmodule MobilizonWeb.WebFingerControllerTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
alias Mobilizon.Actors.Actor
|
|
||||||
alias Mobilizon.Service.WebFinger
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.Actors.Actor
|
||||||
|
alias Mobilizon.Federation.ActivityPub.WebFinger
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
Mobilizon.Config.put([:instance, :federating], true)
|
Mobilizon.Config.put([:instance, :federating], true)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ defmodule MobilizonWeb.Resolvers.AdminResolverTest do
|
||||||
alias Mobilizon.Reports.{Note, Report}
|
alias Mobilizon.Reports.{Note, Report}
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Relay
|
||||||
|
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
alias MobilizonWeb.AbsintheHelpers
|
||||||
alias MobilizonWeb.API
|
alias MobilizonWeb.API
|
||||||
|
|
||||||
|
@ -135,7 +137,7 @@ defmodule MobilizonWeb.Resolvers.AdminResolverTest do
|
||||||
name: "I am an instance actor"
|
name: "I am an instance actor"
|
||||||
)
|
)
|
||||||
|
|
||||||
%Actor{} = relay_actor = Mobilizon.Service.ActivityPub.Relay.get_actor()
|
%Actor{} = relay_actor = Relay.get_actor()
|
||||||
insert(:follower, actor: follower_actor, target_actor: relay_actor)
|
insert(:follower, actor: follower_actor, target_actor: relay_actor)
|
||||||
|
|
||||||
query = """
|
query = """
|
||||||
|
@ -182,7 +184,7 @@ defmodule MobilizonWeb.Resolvers.AdminResolverTest do
|
||||||
name: "I am an instance actor"
|
name: "I am an instance actor"
|
||||||
)
|
)
|
||||||
|
|
||||||
%Actor{} = relay_actor = Mobilizon.Service.ActivityPub.Relay.get_actor()
|
%Actor{} = relay_actor = Relay.get_actor()
|
||||||
insert(:follower, actor: relay_actor, target_actor: following_actor)
|
insert(:follower, actor: relay_actor, target_actor: following_actor)
|
||||||
|
|
||||||
query = """
|
query = """
|
||||||
|
|
|
@ -9,7 +9,8 @@ defmodule Mix.Tasks.Mobilizon.RelayTest do
|
||||||
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.{Actor, Follower}
|
alias Mobilizon.Actors.{Actor, Follower}
|
||||||
alias Mobilizon.Service.ActivityPub.Relay
|
|
||||||
|
alias Mobilizon.Federation.ActivityPub.Relay
|
||||||
|
|
||||||
describe "running follow" do
|
describe "running follow" do
|
||||||
test "relay is followed" do
|
test "relay is followed" do
|
||||||
|
|
Loading…
Reference in a new issue