Merge branch 'fix-credo-warnings' into 'master'
Fix credo warnings See merge request framasoft/mobilizon!188
This commit is contained in:
commit
bcda0fc428
@ -4,7 +4,9 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/mix/tasks/pleroma/common.ex
|
||||
|
||||
defmodule Mix.Tasks.Mobilizon.Common do
|
||||
@moduledoc "Common functions to be reused in mix tasks"
|
||||
@moduledoc """
|
||||
Common functions to be reused in mix tasks
|
||||
"""
|
||||
|
||||
def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
|
||||
display = if defname || defval, do: "#{prompt} [#{defname || defval}]", else: "#{prompt}"
|
||||
@ -13,17 +15,21 @@ defmodule Mix.Tasks.Mobilizon.Common do
|
||||
case Mix.shell().prompt(display) do
|
||||
"\n" ->
|
||||
case defval do
|
||||
nil -> get_option(options, opt, prompt, defval)
|
||||
defval -> defval
|
||||
nil ->
|
||||
get_option(options, opt, prompt, defval)
|
||||
|
||||
defval ->
|
||||
defval
|
||||
end
|
||||
|
||||
opt ->
|
||||
opt |> String.trim()
|
||||
String.trim(opt)
|
||||
end
|
||||
end
|
||||
|
||||
def start_mobilizon do
|
||||
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
|
||||
|
||||
{:ok, _} = Application.ensure_all_started(:mobilizon)
|
||||
end
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
defmodule Mix.Tasks.Mobilizon.CreateBot do
|
||||
@moduledoc """
|
||||
Creates a bot from a source
|
||||
Creates a bot from a source.
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Users
|
||||
|
||||
alias Mobilizon.{Actors, Users}
|
||||
alias Mobilizon.Actors.Bot
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
require Logger
|
||||
|
||||
@shortdoc "Register user"
|
||||
@ -25,7 +26,8 @@ defmodule Mix.Tasks.Mobilizon.CreateBot do
|
||||
}) do
|
||||
bot
|
||||
else
|
||||
e -> Logger.error(inspect(e))
|
||||
error ->
|
||||
Logger.error(inspect(error))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,11 +4,6 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/mix/tasks/pleroma/instance.ex
|
||||
|
||||
defmodule Mix.Tasks.Mobilizon.Instance do
|
||||
use Mix.Task
|
||||
alias Mix.Tasks.Mobilizon.Common
|
||||
|
||||
@shortdoc "Generates a new config"
|
||||
@preferred_cli_env "prod"
|
||||
@moduledoc """
|
||||
Generates a new config
|
||||
|
||||
@ -31,6 +26,13 @@ defmodule Mix.Tasks.Mobilizon.Instance do
|
||||
- `--dbpass DBPASS` - the password to use for the database connection
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
|
||||
alias Mix.Tasks.Mobilizon.Common
|
||||
|
||||
@preferred_cli_env "prod"
|
||||
|
||||
@shortdoc "Generates a new config"
|
||||
def run(["gen" | options]) do
|
||||
{options, [], []} =
|
||||
OptionParser.parse(
|
||||
|
@ -4,11 +4,6 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/mix/tasks/pleroma/relay.ex
|
||||
|
||||
defmodule Mix.Tasks.Mobilizon.Relay do
|
||||
use Mix.Task
|
||||
alias Mobilizon.Service.ActivityPub.Relay
|
||||
alias Mix.Tasks.Mobilizon.Common
|
||||
|
||||
@shortdoc "Manages remote relays"
|
||||
@moduledoc """
|
||||
Manages remote relays
|
||||
|
||||
@ -24,6 +19,13 @@ defmodule Mix.Tasks.Mobilizon.Relay do
|
||||
|
||||
Example: ``mix mobilizon.relay unfollow https://example.org/relay``
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
|
||||
alias Mix.Tasks.Mobilizon.Common
|
||||
alias Mobilizon.Service.ActivityPub.Relay
|
||||
|
||||
@shortdoc "Manages remote relays"
|
||||
def run(["follow", target]) do
|
||||
Common.start_mobilizon()
|
||||
|
||||
|
@ -1,16 +1,19 @@
|
||||
defmodule Mix.Tasks.Mobilizon.Toot do
|
||||
@moduledoc """
|
||||
Creates a bot from a source
|
||||
Creates a bot from a source.
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
|
||||
alias MobilizonWeb.API
|
||||
|
||||
require Logger
|
||||
|
||||
@shortdoc "Toot to an user"
|
||||
def run([from, content]) do
|
||||
Mix.Task.run("app.start")
|
||||
|
||||
case MobilizonWeb.API.Comments.create_comment(from, content) do
|
||||
case API.Comments.create_comment(from, content) do
|
||||
{:ok, _, _} ->
|
||||
Mix.shell().info("Tooted")
|
||||
|
||||
|
@ -23,7 +23,7 @@ defmodule Mobilizon do
|
||||
@spec named_version :: String.t()
|
||||
def named_version, do: "#{@name} #{@version}"
|
||||
|
||||
@spec user_agent :: String.t(:w)
|
||||
@spec user_agent :: String.t()
|
||||
def user_agent do
|
||||
info = "#{MobilizonWeb.Endpoint.url()} <#{Config.get([:instance, :email], "")}>"
|
||||
|
||||
|
@ -11,11 +11,11 @@ defmodule Mobilizon.Actors.Actor do
|
||||
alias Mobilizon.Actors.{ActorOpenness, ActorType, ActorVisibility, Follower, Member}
|
||||
alias Mobilizon.Events.{Event, FeedToken}
|
||||
alias Mobilizon.Media.File
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
require Logger
|
||||
|
||||
|
@ -10,8 +10,8 @@ defmodule Mobilizon.Events.Comment do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.{Comment, CommentVisibility, Event}
|
||||
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
text: String.t(),
|
||||
|
@ -16,8 +16,8 @@ defmodule Mobilizon.Events.Event do
|
||||
EventVisibility,
|
||||
JoinOptions,
|
||||
Participant,
|
||||
Tag,
|
||||
Session,
|
||||
Tag,
|
||||
Track
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,9 @@ defmodule Mobilizon.Events.EventOptions do
|
||||
import Ecto.Changeset
|
||||
|
||||
alias Mobilizon.Events.{
|
||||
CommentModeration,
|
||||
EventOffer,
|
||||
EventParticipationCondition,
|
||||
CommentModeration
|
||||
EventParticipationCondition
|
||||
}
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
|
@ -7,8 +7,8 @@ defmodule Mobilizon.Events.Tag do
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
alias Mobilizon.Events.TagRelation
|
||||
alias Mobilizon.Events.Tag.TitleSlug
|
||||
alias Mobilizon.Events.TagRelation
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
title: String.t(),
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule MobilizonWeb.API.Comments do
|
||||
@moduledoc """
|
||||
API for Comments
|
||||
API for Comments.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors
|
||||
@ -8,6 +8,7 @@ defmodule MobilizonWeb.API.Comments do
|
||||
alias Mobilizon.Events.Comment
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
|
||||
alias MobilizonWeb.API.Utils
|
||||
|
||||
@doc """
|
||||
|
@ -1,12 +1,14 @@
|
||||
defmodule MobilizonWeb.API.Events do
|
||||
@moduledoc """
|
||||
API for Events
|
||||
API for Events.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
|
||||
alias MobilizonWeb.API.Utils
|
||||
|
||||
@doc """
|
||||
|
@ -6,6 +6,7 @@ defmodule MobilizonWeb.API.Follows do
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{Actor, Follower}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
|
||||
require Logger
|
||||
|
||||
def follow(%Actor{} = follower, %Actor{} = followed) do
|
||||
|
@ -1,12 +1,14 @@
|
||||
defmodule MobilizonWeb.API.Groups do
|
||||
@moduledoc """
|
||||
API for Events
|
||||
API for Groups.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.API.Utils
|
||||
|
||||
@doc """
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule MobilizonWeb.API.Participations do
|
||||
@moduledoc """
|
||||
Common API to join events and groups
|
||||
Common API to join events and groups.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
@ -1,18 +1,19 @@
|
||||
defmodule MobilizonWeb.API.Reports do
|
||||
@moduledoc """
|
||||
API for Reports
|
||||
API for Reports.
|
||||
"""
|
||||
|
||||
import MobilizonWeb.API.Utils
|
||||
import Mobilizon.Service.Admin.ActionLogService
|
||||
|
||||
import MobilizonWeb.API.Utils
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
alias Mobilizon.Reports, as: ReportsAction
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
alias Mobilizon.Reports.{Note, Report, ReportStatus}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
@ -62,7 +63,7 @@ defmodule MobilizonWeb.API.Reports do
|
||||
"""
|
||||
def update_report_status(%Actor{} = actor, %Report{} = report, state) do
|
||||
with {:valid_state, true} <-
|
||||
{:valid_state, Mobilizon.Reports.ReportStatus.valid_value?(state)},
|
||||
{:valid_state, ReportStatus.valid_value?(state)},
|
||||
{:ok, report} <- ReportsAction.update_report(report, %{"status" => state}),
|
||||
{:ok, _} <- log_action(actor, "update", report) do
|
||||
{:ok, report}
|
||||
@ -73,7 +74,7 @@ defmodule MobilizonWeb.API.Reports do
|
||||
|
||||
defp get_report_comments(%Actor{id: actor_id}, comment_ids) do
|
||||
{:get_report_comments,
|
||||
Events.list_comments_by_actor_and_ids(actor_id, comment_ids) |> Enum.map(& &1.url)}
|
||||
actor_id |> Events.list_comments_by_actor_and_ids(comment_ids) |> Enum.map(& &1.url)}
|
||||
end
|
||||
|
||||
defp get_report_comments(_, _), do: {:get_report_comments, nil}
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule MobilizonWeb.API.Utils do
|
||||
@moduledoc """
|
||||
Utils for API
|
||||
Utils for API.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
3
lib/mobilizon_web/cache/activity_pub.ex
vendored
3
lib/mobilizon_web/cache/activity_pub.ex
vendored
@ -6,6 +6,7 @@ defmodule MobilizonWeb.Cache.ActivityPub do
|
||||
alias Mobilizon.{Actors, Events, Service}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.{Comment, Event}
|
||||
alias Service.ActivityPub
|
||||
|
||||
@cache :activity_pub
|
||||
|
||||
@ -65,6 +66,6 @@ defmodule MobilizonWeb.Cache.ActivityPub do
|
||||
"""
|
||||
@spec get_relay :: {:commit, Actor.t()} | {:ignore, nil}
|
||||
def get_relay do
|
||||
Cachex.fetch(@cache, "relay_actor", &Service.ActivityPub.Relay.get_actor/0)
|
||||
Cachex.fetch(@cache, "relay_actor", &ActivityPub.Relay.get_actor/0)
|
||||
end
|
||||
end
|
||||
|
@ -6,10 +6,12 @@
|
||||
defmodule MobilizonWeb.MediaProxyController do
|
||||
use MobilizonWeb, :controller
|
||||
|
||||
alias Plug.Conn
|
||||
|
||||
alias Mobilizon.Config
|
||||
|
||||
alias MobilizonWeb.ReverseProxy
|
||||
alias MobilizonWeb.MediaProxy
|
||||
alias MobilizonWeb.ReverseProxy
|
||||
|
||||
@default_proxy_opts [max_body_length: 25 * 1_048_576, http: [follow_redirect: true]]
|
||||
|
||||
@ -21,10 +23,10 @@ defmodule MobilizonWeb.MediaProxyController do
|
||||
ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts))
|
||||
else
|
||||
false ->
|
||||
send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404))
|
||||
send_resp(conn, 404, Conn.Status.reason_phrase(404))
|
||||
|
||||
{:error, :invalid_signature} ->
|
||||
send_resp(conn, 403, Plug.Conn.Status.reason_phrase(403))
|
||||
send_resp(conn, 403, Conn.Status.reason_phrase(403))
|
||||
|
||||
{:wrong_filename, filename} ->
|
||||
redirect(conn, external: MediaProxy.build_url(sig64, url64, filename))
|
||||
|
@ -9,6 +9,9 @@ defmodule MobilizonWeb.NodeInfoController do
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Service.Statistics
|
||||
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
@node_info_supported_versions ["2.0", "2.1"]
|
||||
@node_info_schema_uri "http://nodeinfo.diaspora.software/ns/schema/"
|
||||
|
||||
@ -18,8 +21,7 @@ defmodule MobilizonWeb.NodeInfoController do
|
||||
|> Enum.map(fn version ->
|
||||
%{
|
||||
rel: @node_info_schema_uri <> version,
|
||||
href:
|
||||
MobilizonWeb.Router.Helpers.node_info_url(MobilizonWeb.Endpoint, :nodeinfo, version)
|
||||
href: Routes.node_info_url(Endpoint, :nodeinfo, version)
|
||||
}
|
||||
end)
|
||||
|
||||
|
@ -47,7 +47,7 @@ defmodule MobilizonWeb.MIME do
|
||||
|
||||
new_filename =
|
||||
if length(parts) > 1 do
|
||||
Enum.drop(parts, -1) |> Enum.join(".")
|
||||
parts |> Enum.drop(-1) |> Enum.join(".")
|
||||
else
|
||||
Enum.join(parts)
|
||||
end
|
||||
@ -60,7 +60,9 @@ defmodule MobilizonWeb.MIME do
|
||||
new_filename <> "." <> ext
|
||||
|
||||
true ->
|
||||
Enum.join([new_filename, String.split(content_type, "/") |> List.last()], ".")
|
||||
extension = content_type |> String.split("/") |> List.last()
|
||||
|
||||
Enum.join([new_filename, extension], ".")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -60,7 +60,8 @@ defmodule MobilizonWeb.Plugs.UploadedMedia do
|
||||
|
||||
defp get_media(conn, {:static_dir, directory}, _, opts) do
|
||||
static_opts =
|
||||
Map.get(opts, :static_plug_opts)
|
||||
opts
|
||||
|> Map.get(:static_plug_opts)
|
||||
|> Map.put(:at, [@path])
|
||||
|> Map.put(:from, directory)
|
||||
|
||||
|
@ -12,7 +12,7 @@ defmodule MobilizonWeb.Resolvers.Address do
|
||||
"""
|
||||
@spec search(map(), map(), map()) :: {:ok, list(Address.t())}
|
||||
def search(_parent, %{query: query, page: _page, limit: _limit}, %{context: %{ip: ip}}) do
|
||||
country = Geolix.lookup(ip) |> Map.get(:country, nil)
|
||||
country = ip |> Geolix.lookup() |> Map.get(:country, nil)
|
||||
|
||||
local_addresses = Task.async(fn -> Addresses.search_addresses(query, country: country) end)
|
||||
|
||||
@ -40,7 +40,7 @@ defmodule MobilizonWeb.Resolvers.Address do
|
||||
"""
|
||||
@spec reverse_geocode(map(), map(), map()) :: {:ok, list(Address.t())}
|
||||
def reverse_geocode(_parent, %{longitude: longitude, latitude: latitude}, %{context: %{ip: ip}}) do
|
||||
country = Geolix.lookup(ip) |> Map.get(:country, nil)
|
||||
country = ip |> Geolix.lookup() |> Map.get(:country, nil)
|
||||
|
||||
local_addresses =
|
||||
Task.async(fn -> Addresses.reverse_geocode(longitude, latitude, country: country) end)
|
||||
|
@ -1,35 +1,36 @@
|
||||
defmodule MobilizonWeb.Resolvers.Admin do
|
||||
@moduledoc """
|
||||
Handles the report-related GraphQL calls
|
||||
Handles the report-related GraphQL calls.
|
||||
"""
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Users.User
|
||||
import Mobilizon.Users.Guards
|
||||
alias Mobilizon.Admin.ActionLog
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.Statistics
|
||||
|
||||
def list_action_logs(_parent, %{page: page, limit: limit}, %{
|
||||
context: %{current_user: %User{role: role}}
|
||||
})
|
||||
import Mobilizon.Users.Guards
|
||||
|
||||
alias Mobilizon.Admin.ActionLog
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Service.Statistics
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
def list_action_logs(
|
||||
_parent,
|
||||
%{page: page, limit: limit},
|
||||
%{context: %{current_user: %User{role: role}}}
|
||||
)
|
||||
when is_moderator(role) do
|
||||
with action_logs <- Mobilizon.Admin.list_action_logs(page, limit) do
|
||||
action_logs =
|
||||
Enum.map(action_logs, fn %ActionLog{
|
||||
target_type: target_type,
|
||||
action: action,
|
||||
actor: actor,
|
||||
id: id,
|
||||
inserted_at: inserted_at
|
||||
} = action_log ->
|
||||
action_logs
|
||||
|> Enum.map(fn %ActionLog{
|
||||
target_type: target_type,
|
||||
action: action,
|
||||
actor: actor,
|
||||
id: id,
|
||||
inserted_at: inserted_at
|
||||
} = action_log ->
|
||||
with data when is_map(data) <-
|
||||
transform_action_log(String.to_existing_atom(target_type), action, action_log) do
|
||||
Map.merge(data, %{
|
||||
actor: actor,
|
||||
id: id,
|
||||
inserted_at: inserted_at
|
||||
})
|
||||
Map.merge(data, %{actor: actor, id: id, inserted_at: inserted_at})
|
||||
end
|
||||
end)
|
||||
|> Enum.filter(& &1)
|
||||
|
@ -1,11 +1,12 @@
|
||||
defmodule MobilizonWeb.Resolvers.Comment do
|
||||
@moduledoc """
|
||||
Handles the comment-related GraphQL calls
|
||||
Handles the comment-related GraphQL calls.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Events.Comment
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.API.Comments
|
||||
|
||||
require Logger
|
||||
|
@ -1,19 +1,22 @@
|
||||
defmodule MobilizonWeb.Resolvers.Event do
|
||||
@moduledoc """
|
||||
Handles the event-related GraphQL calls
|
||||
Handles the event-related GraphQL calls.
|
||||
"""
|
||||
|
||||
import Mobilizon.Service.Admin.ActionLogService
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Addresses
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Media.Picture
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias MobilizonWeb.Resolvers.Person
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
import Mobilizon.Service.Admin.ActionLogService
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.API
|
||||
alias MobilizonWeb.Resolvers.Person
|
||||
|
||||
# We limit the max number of events that can be retrieved
|
||||
@event_max_limit 100
|
||||
@ -142,7 +145,7 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
{:has_event, {:ok, %Event{} = event}} <-
|
||||
{:has_event, Mobilizon.Events.get_event_with_preload(event_id)},
|
||||
{:error, :participant_not_found} <- Mobilizon.Events.get_participant(event_id, actor_id),
|
||||
{:ok, _activity, participant} <- MobilizonWeb.API.Participations.join(event, actor),
|
||||
{:ok, _activity, participant} <- API.Participations.join(event, actor),
|
||||
participant <-
|
||||
participant
|
||||
|> Map.put(:event, event)
|
||||
@ -178,7 +181,7 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
with {:is_owned, %Actor{} = actor} <- User.owns_actor(user, actor_id),
|
||||
{:has_event, {:ok, %Event{} = event}} <-
|
||||
{:has_event, Mobilizon.Events.get_event_with_preload(event_id)},
|
||||
{:ok, _activity, _participant} <- MobilizonWeb.API.Participations.leave(event, actor) do
|
||||
{:ok, _activity, _participant} <- API.Participations.leave(event, actor) do
|
||||
{:ok, %{event: %{id: event_id}, actor: %{id: actor_id}}}
|
||||
else
|
||||
{:has_event, _} ->
|
||||
|
@ -1,11 +1,13 @@
|
||||
defmodule MobilizonWeb.Resolvers.FeedToken do
|
||||
@moduledoc """
|
||||
Handles the feed tokens-related GraphQL calls
|
||||
Handles the feed tokens-related GraphQL calls.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.FeedToken
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
|
@ -1,13 +1,15 @@
|
||||
defmodule MobilizonWeb.Resolvers.Group do
|
||||
@moduledoc """
|
||||
Handles the group-related GraphQL calls
|
||||
Handles the group-related GraphQL calls.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{Actor, Member}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
|
||||
alias MobilizonWeb.API
|
||||
alias MobilizonWeb.Resolvers.Person
|
||||
|
||||
require Logger
|
||||
@ -31,7 +33,8 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||
def list_groups(_parent, %{page: page, limit: limit}, _resolution) do
|
||||
{
|
||||
:ok,
|
||||
Actors.list_groups(page, limit)
|
||||
page
|
||||
|> Actors.list_groups(limit)
|
||||
|> Enum.map(fn actor -> Person.proxify_pictures(actor) end)
|
||||
}
|
||||
end
|
||||
@ -49,7 +52,7 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||
%Activity{data: %{"object" => %{"type" => "Group"} = _object}},
|
||||
%Actor{} = group
|
||||
} <-
|
||||
MobilizonWeb.API.Groups.create_group(
|
||||
API.Groups.create_group(
|
||||
user,
|
||||
%{
|
||||
preferred_username: args.preferred_username,
|
||||
|
@ -1,15 +1,18 @@
|
||||
defmodule MobilizonWeb.Resolvers.Report do
|
||||
@moduledoc """
|
||||
Handles the report-related GraphQL calls
|
||||
Handles the report-related GraphQL calls.
|
||||
"""
|
||||
alias Mobilizon.Reports
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Users.User
|
||||
alias MobilizonWeb.API.Reports, as: ReportsAPI
|
||||
|
||||
import Mobilizon.Users.Guards
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Reports
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.API.Reports, as: ReportsAPI
|
||||
|
||||
def list_reports(
|
||||
_parent,
|
||||
%{page: page, limit: limit, status: status},
|
||||
|
@ -1,16 +1,16 @@
|
||||
defmodule MobilizonWeb.Resolvers.User do
|
||||
@moduledoc """
|
||||
Handles the user-related GraphQL calls
|
||||
Handles the user-related GraphQL calls.
|
||||
"""
|
||||
|
||||
import Mobilizon.Users.Guards
|
||||
|
||||
alias Mobilizon.{Actors, Config, Users, Events}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Users.{ResetPassword, Activation}
|
||||
alias Mobilizon.Service.Users.{Activation, ResetPassword}
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
import Mobilizon.Users.Guards
|
||||
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
|
@ -4,12 +4,11 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/reverse_proxy.ex
|
||||
|
||||
defmodule MobilizonWeb.ReverseProxy do
|
||||
@keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since) ++
|
||||
~w(if-unmodified-since if-none-match if-range range)
|
||||
@keep_req_headers ~w(accept user-agent accept-encoding cache-control
|
||||
if-modified-since if-unmodified-since if-none-match if-range range)
|
||||
@resp_cache_headers ~w(etag date last-modified cache-control)
|
||||
@keep_resp_headers @resp_cache_headers ++
|
||||
~w(content-type content-disposition content-encoding content-range) ++
|
||||
~w(accept-ranges vary)
|
||||
@keep_resp_headers @resp_cache_headers ++ ~w(content-type content-disposition
|
||||
content-encoding content-range accept-ranges vary)
|
||||
@default_cache_control_header "public, max-age=1209600"
|
||||
@valid_resp_codes [200, 206, 304]
|
||||
@max_read_duration :timer.seconds(30)
|
||||
@ -21,9 +20,11 @@ defmodule MobilizonWeb.ReverseProxy do
|
||||
|
||||
MobilizonWeb.ReverseProxy.call(conn, url, options)
|
||||
|
||||
It is not meant to be added into a plug pipeline, but to be called from another plug or controller.
|
||||
It is not meant to be added into a plug pipeline, but to be called from another
|
||||
plug or controller.
|
||||
|
||||
Supports `#{inspect(@methods)}` HTTP methods, and only allows `#{inspect(@valid_resp_codes)}` status codes.
|
||||
Supports `#{inspect(@methods)}` HTTP methods, and only allows
|
||||
`#{inspect(@valid_resp_codes)}` status codes.
|
||||
|
||||
Responses are chunked to the client while downloading from the upstream.
|
||||
|
||||
@ -32,34 +33,54 @@ defmodule MobilizonWeb.ReverseProxy do
|
||||
* request: `#{inspect(@keep_req_headers)}`
|
||||
* response: `#{inspect(@keep_resp_headers)}`
|
||||
|
||||
If no caching headers (`#{inspect(@resp_cache_headers)}`) are returned by upstream, `cache-control` will be
|
||||
set to `#{inspect(@default_cache_control_header)}`.
|
||||
If no caching headers (`#{inspect(@resp_cache_headers)}`) are returned by
|
||||
upstream, `cache-control` will be set to `#{inspect(@default_cache_control_header)}`.
|
||||
|
||||
Options:
|
||||
|
||||
* `redirect_on_failure` (default `false`). Redirects the client to the real remote URL if there's any HTTP
|
||||
errors. Any error during body processing will not be redirected as the response is chunked. This may expose
|
||||
remote URL, clients IPs, ….
|
||||
* `redirect_on_failure` (default `false`). Redirects the client to the real
|
||||
remote URL if there's any HTTP errors. Any error during body processing will
|
||||
not be redirected as the response is chunked. This may expose remote URL,
|
||||
clients IPs, ….
|
||||
|
||||
* `max_body_length` (default `#{inspect(@max_body_length)}`): limits the content length to be approximately the
|
||||
specified length. It is validated with the `content-length` header and also verified when proxying.
|
||||
* `max_body_length` (default `#{inspect(@max_body_length)}`): limits the
|
||||
content length to be approximately the specified length. It is validated with
|
||||
the `content-length` header and also verified when proxying.
|
||||
|
||||
* `max_read_duration` (default `#{inspect(@max_read_duration)}` ms): the total time the connection is allowed to
|
||||
read from the remote upstream.
|
||||
* `max_read_duration` (default `#{inspect(@max_read_duration)}` ms): the total
|
||||
time the connection is allowed to read from the remote upstream.
|
||||
|
||||
* `inline_content_types`:
|
||||
* `true` will not alter `content-disposition` (up to the upstream),
|
||||
* `false` will add `content-disposition: attachment` to any request,
|
||||
* a list of whitelisted content types
|
||||
|
||||
* `keep_user_agent` will forward the client's user-agent to the upstream. This may be useful if the upstream is
|
||||
doing content transformation (encoding, …) depending on the request.
|
||||
* `keep_user_agent` will forward the client's user-agent to the upstream.
|
||||
This may be useful if the upstream is doing content transformation
|
||||
(encoding, …) depending on the request.
|
||||
|
||||
* `req_headers`, `resp_headers` additional headers.
|
||||
|
||||
* `http`: options for [hackney](https://github.com/benoitc/hackney).
|
||||
|
||||
"""
|
||||
|
||||
import Plug.Conn
|
||||
|
||||
alias Plug.Conn
|
||||
|
||||
require Logger
|
||||
|
||||
@type option ::
|
||||
{:keep_user_agent, boolean}
|
||||
| {:max_read_duration, :timer.time() | :infinity}
|
||||
| {:max_body_length, non_neg_integer | :infinity}
|
||||
| {:http, []}
|
||||
| {:req_headers, [{String.t(), String.t()}]}
|
||||
| {:resp_headers, [{String.t(), String.t()}]}
|
||||
| {:inline_content_types, boolean | [String.t()]}
|
||||
| {:redirect_on_failure, boolean}
|
||||
|
||||
@hackney Application.get_env(:mobilizon, :hackney, :hackney)
|
||||
@httpoison Application.get_env(:mobilizon, :httpoison, HTTPoison)
|
||||
|
||||
@ -78,20 +99,7 @@ defmodule MobilizonWeb.ReverseProxy do
|
||||
"video/quicktime"
|
||||
]
|
||||
|
||||
require Logger
|
||||
import Plug.Conn
|
||||
|
||||
@type option() ::
|
||||
{:keep_user_agent, boolean}
|
||||
| {:max_read_duration, :timer.time() | :infinity}
|
||||
| {:max_body_length, non_neg_integer() | :infinity}
|
||||
| {:http, []}
|
||||
| {:req_headers, [{String.t(), String.t()}]}
|
||||
| {:resp_headers, [{String.t(), String.t()}]}
|
||||
| {:inline_content_types, boolean() | [String.t()]}
|
||||
| {:redirect_on_failure, boolean()}
|
||||
|
||||
@spec call(Plug.Conn.t(), url :: String.t(), [option()]) :: Plug.Conn.t()
|
||||
@spec call(Plug.Conn.t(), url :: String.t(), [option]) :: Plug.Conn.t()
|
||||
def call(_conn, _url, _opts \\ [])
|
||||
|
||||
def call(conn = %{method: method}, url, opts) when method in @methods do
|
||||
@ -114,7 +122,8 @@ defmodule MobilizonWeb.ReverseProxy do
|
||||
response(conn, client, url, code, headers, opts)
|
||||
else
|
||||
{:ok, code, headers} ->
|
||||
head_response(conn, url, code, headers, opts)
|
||||
conn
|
||||
|> head_response(url, code, headers, opts)
|
||||
|> halt()
|
||||
|
||||
{:error, {:invalid_http_response, code}} ->
|
||||
@ -124,7 +133,7 @@ defmodule MobilizonWeb.ReverseProxy do
|
||||
|> error_or_redirect(
|
||||
url,
|
||||
code,
|
||||
"Request failed: " <> Plug.Conn.Status.reason_phrase(code),
|
||||
"Request failed: " <> Conn.Status.reason_phrase(code),
|
||||
opts
|
||||
)
|
||||
|> halt()
|
||||
@ -140,7 +149,7 @@ defmodule MobilizonWeb.ReverseProxy do
|
||||
|
||||
def call(conn, _, _) do
|
||||
conn
|
||||
|> send_resp(400, Plug.Conn.Status.reason_phrase(400))
|
||||
|> send_resp(400, Conn.Status.reason_phrase(400))
|
||||
|> halt()
|
||||
end
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
defmodule MobilizonWeb.Schema do
|
||||
@moduledoc """
|
||||
GraphQL schema representation
|
||||
GraphQL schema representation.
|
||||
"""
|
||||
|
||||
use Absinthe.Schema
|
||||
|
||||
alias Mobilizon.{Actors, Events, Users, Addresses, Media, Reports}
|
||||
alias Mobilizon.{Actors, Addresses, Events, Media, Reports, Users}
|
||||
alias Mobilizon.Actors.{Actor, Follower, Member}
|
||||
alias Mobilizon.Events.{Event, Comment, Participant}
|
||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
import_types(MobilizonWeb.Schema.Custom.UUID)
|
||||
|
@ -1,13 +1,18 @@
|
||||
defmodule MobilizonWeb.Schema.Actors.GroupType do
|
||||
@moduledoc """
|
||||
Schema representation for Group
|
||||
Schema representation for Group.
|
||||
"""
|
||||
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||
import_types(MobilizonWeb.Schema.Actors.MemberType)
|
||||
alias MobilizonWeb.Resolvers.{Member, Group}
|
||||
|
||||
alias Mobilizon.Events
|
||||
|
||||
alias MobilizonWeb.Resolvers.{Group, Member}
|
||||
|
||||
import_types(MobilizonWeb.Schema.Actors.MemberType)
|
||||
|
||||
@desc """
|
||||
Represents a group of actors
|
||||
"""
|
||||
|
@ -1,11 +1,14 @@
|
||||
defmodule MobilizonWeb.Schema.AdminType do
|
||||
@moduledoc """
|
||||
Schema representation for ActionLog
|
||||
Schema representation for ActionLog.
|
||||
"""
|
||||
|
||||
use Absinthe.Schema.Notation
|
||||
alias MobilizonWeb.Resolvers.Admin
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
|
||||
alias MobilizonWeb.Resolvers.Admin
|
||||
|
||||
@desc "An action log"
|
||||
object :action_log do
|
||||
|
@ -1,14 +1,19 @@
|
||||
defmodule MobilizonWeb.Schema.EventType do
|
||||
@moduledoc """
|
||||
Schema representation for Event
|
||||
Schema representation for Event.
|
||||
"""
|
||||
|
||||
use Absinthe.Schema.Notation
|
||||
alias Mobilizon.{Actors, Addresses}
|
||||
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||
|
||||
alias Mobilizon.{Actors, Addresses}
|
||||
|
||||
alias MobilizonWeb.Resolvers.{Event, Picture, Tag}
|
||||
|
||||
import_types(MobilizonWeb.Schema.AddressType)
|
||||
import_types(MobilizonWeb.Schema.Events.ParticipantType)
|
||||
import_types(MobilizonWeb.Schema.TagType)
|
||||
alias MobilizonWeb.Resolvers.{Picture, Event, Tag}
|
||||
|
||||
@desc "An event"
|
||||
object :event do
|
||||
|
@ -1,12 +1,15 @@
|
||||
defmodule MobilizonWeb.Schema.Events.FeedTokenType do
|
||||
@moduledoc """
|
||||
Schema representation for Participant
|
||||
Schema representation for Participant.
|
||||
"""
|
||||
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||
|
||||
alias Mobilizon.{Actors, Users}
|
||||
|
||||
alias MobilizonWeb.Resolvers
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Actors
|
||||
|
||||
@desc "Represents a participant to an event"
|
||||
object :feed_token do
|
||||
|
@ -1,12 +1,15 @@
|
||||
defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
||||
@moduledoc """
|
||||
Schema representation for Participant
|
||||
Schema representation for Participant.
|
||||
"""
|
||||
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||
|
||||
alias Mobilizon.{Actors, Events}
|
||||
|
||||
alias MobilizonWeb.Resolvers
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Actors
|
||||
|
||||
@desc "Represents a participant to an event"
|
||||
object :participant do
|
||||
|
@ -36,7 +36,7 @@ defmodule MobilizonWeb.Upload do
|
||||
|
||||
alias Mobilizon.Config
|
||||
|
||||
alias MobilizonWeb.MIME
|
||||
alias MobilizonWeb.{MIME, Upload, Uploaders}
|
||||
|
||||
require Logger
|
||||
|
||||
@ -69,8 +69,8 @@ defmodule MobilizonWeb.Upload do
|
||||
|
||||
with {:ok, upload} <- prepare_upload(upload, opts),
|
||||
upload = %__MODULE__{upload | path: upload.path || "#{upload.id}/#{upload.name}"},
|
||||
{:ok, upload} <- MobilizonWeb.Upload.Filter.filter(opts.filters, upload),
|
||||
{:ok, url_spec} <- MobilizonWeb.Uploaders.Uploader.put_file(opts.uploader, upload) do
|
||||
{:ok, upload} <- Upload.Filter.filter(opts.filters, upload),
|
||||
{:ok, url_spec} <- Uploaders.Uploader.put_file(opts.uploader, upload) do
|
||||
{:ok,
|
||||
%{
|
||||
"type" => opts.activity_type || get_type(upload.content_type),
|
||||
@ -98,7 +98,7 @@ defmodule MobilizonWeb.Upload do
|
||||
with opts <- get_opts(opts),
|
||||
%URI{path: "/media/" <> path, host: host} <- URI.parse(url),
|
||||
{:same_host, true} <- {:same_host, host == MobilizonWeb.Endpoint.host()} do
|
||||
MobilizonWeb.Uploaders.Uploader.remove_file(opts.uploader, path)
|
||||
Uploaders.Uploader.remove_file(opts.uploader, path)
|
||||
else
|
||||
%URI{} = _uri ->
|
||||
{:error, "URL doesn't match pattern"}
|
||||
|
@ -11,9 +11,10 @@ defmodule MobilizonWeb.Upload.Filter.Dedupe do
|
||||
alias MobilizonWeb.Upload
|
||||
|
||||
def filter(%Upload{name: name} = upload) do
|
||||
extension = String.split(name, ".") |> List.last()
|
||||
extension = name |> String.split(".") |> List.last()
|
||||
shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower)
|
||||
filename = shasum <> "." <> extension
|
||||
|
||||
{:ok, %Upload{upload | id: shasum, path: filename}}
|
||||
end
|
||||
end
|
||||
|
@ -3,14 +3,13 @@ defmodule MobilizonWeb.ActivityPub.ActorView do
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
alias Mobilizon.Service.ActivityPub.{Activity, Utils}
|
||||
|
||||
@private_visibility_empty_collection %{elements: [], total: 0}
|
||||
|
||||
def render("actor.json", %{actor: actor}) do
|
||||
public_key = Mobilizon.Service.ActivityPub.Utils.pem_to_public_key_pem(actor.keys)
|
||||
public_key = Utils.pem_to_public_key_pem(actor.keys)
|
||||
|
||||
%{
|
||||
"id" => actor.url,
|
||||
|
@ -1,9 +1,10 @@
|
||||
defmodule MobilizonWeb.JsonLD.ObjectView do
|
||||
use MobilizonWeb, :view
|
||||
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Events.Event
|
||||
|
||||
alias MobilizonWeb.JsonLD.ObjectView
|
||||
alias MobilizonWeb.MediaProxy
|
||||
|
||||
|
@ -4,12 +4,12 @@ defmodule MobilizonWeb.PageView do
|
||||
"""
|
||||
use MobilizonWeb, :view
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
alias Mobilizon.Service.ActivityPub.{Converter, Utils}
|
||||
alias Mobilizon.Service.Metadata
|
||||
alias Mobilizon.Service.MetadataUtils
|
||||
|
||||
def render("actor.activity-json", %{conn: %{assigns: %{object: actor}}}) do
|
||||
public_key = Mobilizon.Service.ActivityPub.Utils.pem_to_public_key_pem(actor.keys)
|
||||
public_key = Utils.pem_to_public_key_pem(actor.keys)
|
||||
|
||||
%{
|
||||
"id" => Actor.build_url(actor.preferred_username, :page),
|
||||
@ -47,12 +47,12 @@ defmodule MobilizonWeb.PageView do
|
||||
|
||||
def render("event.activity-json", %{conn: %{assigns: %{object: event}}}) do
|
||||
event
|
||||
|> Mobilizon.Service.ActivityPub.Converters.Event.model_to_as()
|
||||
|> Converter.Event.model_to_as()
|
||||
|> Map.merge(Utils.make_json_ld_header())
|
||||
end
|
||||
|
||||
def render("comment.activity-json", %{conn: %{assigns: %{object: comment}}}) do
|
||||
comment = Mobilizon.Service.ActivityPub.Converters.Comment.model_to_as(comment)
|
||||
comment = Converter.Comment.model_to_as(comment)
|
||||
|
||||
%{
|
||||
"actor" => comment["actor"],
|
||||
@ -84,7 +84,7 @@ defmodule MobilizonWeb.PageView do
|
||||
end
|
||||
end
|
||||
|
||||
defp index_file_path() do
|
||||
defp index_file_path do
|
||||
Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html")
|
||||
end
|
||||
end
|
||||
|
@ -5,28 +5,19 @@
|
||||
|
||||
defmodule Mobilizon.Service.ActivityPub do
|
||||
@moduledoc """
|
||||
# ActivityPub
|
||||
|
||||
Every ActivityPub method
|
||||
# ActivityPub context.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Comment, Participant}
|
||||
alias Mobilizon.Service.ActivityPub.Transmogrifier
|
||||
alias Mobilizon.Service.WebFinger
|
||||
import Mobilizon.Service.ActivityPub.{Utils, Visibility}
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.{Actors, Config, Events}
|
||||
alias Mobilizon.Actors.{Actor, Follower}
|
||||
|
||||
alias Mobilizon.Service.Federator
|
||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||
alias Mobilizon.Service.ActivityPub.{Activity, Converter, Convertible, Relay, Transmogrifier}
|
||||
alias Mobilizon.Service.{Federator, WebFinger}
|
||||
alias Mobilizon.Service.HTTPSignatures.Signature
|
||||
|
||||
alias Mobilizon.Service.ActivityPub.{Activity, Convertible}
|
||||
|
||||
require Logger
|
||||
import Mobilizon.Service.ActivityPub.Utils
|
||||
import Mobilizon.Service.ActivityPub.Visibility
|
||||
|
||||
@doc """
|
||||
Get recipients for an activity or object
|
||||
@ -452,7 +443,8 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
|
||||
def leave(object, actor, local \\ true)
|
||||
|
||||
# TODO: If we want to use this for exclusion we need to have an extra field for the actor that excluded the participant
|
||||
# TODO: If we want to use this for exclusion we need to have an extra field
|
||||
# for the actor that excluded the participant
|
||||
def leave(
|
||||
%Event{id: event_id, url: event_url} = event,
|
||||
%Actor{id: actor_id, url: actor_url} = _actor,
|
||||
@ -543,7 +535,8 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
|
||||
if public && !is_delete_activity?(activity) && Config.get([:instance, :allow_relay]) do
|
||||
Logger.info(fn -> "Relaying #{activity.data["id"]} out" end)
|
||||
Mobilizon.Service.ActivityPub.Relay.publish(activity)
|
||||
|
||||
Relay.publish(activity)
|
||||
end
|
||||
|
||||
followers =
|
||||
@ -702,7 +695,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
%Activity{
|
||||
recipients: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: event.organizer_actor.url,
|
||||
data: event |> Mobilizon.Service.ActivityPub.Converters.Event.model_to_as(),
|
||||
data: Converter.Event.model_to_as(event),
|
||||
local: local
|
||||
}
|
||||
end
|
||||
@ -713,7 +706,7 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
%Activity{
|
||||
recipients: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: comment.actor.url,
|
||||
data: comment |> Mobilizon.Service.ActivityPub.Converters.Comment.model_to_as(),
|
||||
data: Converter.Comment.model_to_as(comment),
|
||||
local: local
|
||||
}
|
||||
end
|
||||
|
@ -1,16 +1,11 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter do
|
||||
@moduledoc """
|
||||
Converter behaviour
|
||||
Converter behaviour.
|
||||
|
||||
This module allows to convert from ActivityStream format to our own internal one, and back
|
||||
This module allows to convert from ActivityStream format to our own internal
|
||||
one, and back.
|
||||
"""
|
||||
@callback as_to_model_data(map()) :: map()
|
||||
@callback model_to_as(struct()) :: map()
|
||||
end
|
||||
|
||||
defprotocol Mobilizon.Service.ActivityPub.Convertible do
|
||||
@type activitystreams :: map()
|
||||
|
||||
@spec model_to_as(t) :: activitystreams
|
||||
def model_to_as(convertible)
|
||||
@callback as_to_model_data(map) :: map
|
||||
@callback model_to_as(struct) :: map
|
||||
end
|
||||
|
@ -1,19 +1,27 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converters.Actor do
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter.Actor do
|
||||
@moduledoc """
|
||||
Actor converter
|
||||
Actor converter.
|
||||
|
||||
This module allows to convert events from ActivityStream format to our own internal one, and back
|
||||
This module allows to convert events from ActivityStream format to our own
|
||||
internal one, and back.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor, as: ActorModel
|
||||
alias Mobilizon.Service.ActivityPub.Converter
|
||||
alias Mobilizon.Service.ActivityPub.{Converter, Convertible}
|
||||
|
||||
@behaviour Converter
|
||||
|
||||
defimpl Convertible, for: ActorModel do
|
||||
alias Mobilizon.Service.ActivityPub.Converter.Actor, as: ActorConverter
|
||||
|
||||
defdelegate model_to_as(actor), to: ActorConverter
|
||||
end
|
||||
|
||||
@doc """
|
||||
Converts an AP object data to our internal data structure
|
||||
Converts an AP object data to our internal data structure.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map()) :: map()
|
||||
@spec as_to_model_data(map) :: map
|
||||
def as_to_model_data(object) do
|
||||
avatar =
|
||||
object["icon"]["url"] &&
|
||||
@ -43,10 +51,10 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Actor do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert an actor struct to an ActivityStream representation
|
||||
Convert an actor struct to an ActivityStream representation.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(ActorModel.t()) :: map()
|
||||
@spec model_to_as(ActorModel.t()) :: map
|
||||
def model_to_as(%ActorModel{} = actor) do
|
||||
%{
|
||||
"type" => Atom.to_string(actor.type),
|
||||
@ -63,9 +71,3 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Actor do
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
defimpl Mobilizon.Service.ActivityPub.Convertible, for: Mobilizon.Actors.Actor do
|
||||
alias Mobilizon.Service.ActivityPub.Converters.Actor, as: ActorConverter
|
||||
|
||||
defdelegate model_to_as(actor), to: ActorConverter
|
||||
end
|
@ -1,21 +1,21 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converters.Address do
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter.Address do
|
||||
@moduledoc """
|
||||
Flag converter
|
||||
Address converter.
|
||||
|
||||
This module allows to convert reports from ActivityStream format to our own internal one, and back.
|
||||
|
||||
Note: Reports are named Flag in AS.
|
||||
This module allows to convert reports from ActivityStream format to our own
|
||||
internal one, and back.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Addresses.Address, as: AddressModel
|
||||
alias Mobilizon.Service.ActivityPub.Converter
|
||||
|
||||
@behaviour Converter
|
||||
|
||||
@doc """
|
||||
Converts an AP object data to our internal data structure
|
||||
Converts an AP object data to our internal data structure.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map()) :: map()
|
||||
@spec as_to_model_data(map) :: map
|
||||
def as_to_model_data(object) do
|
||||
res = %{
|
||||
"description" => object["name"],
|
||||
@ -48,10 +48,10 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Address do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert an event struct to an ActivityStream representation
|
||||
Convert an event struct to an ActivityStream representation.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(AddressModel.t()) :: map()
|
||||
@spec model_to_as(AddressModel.t()) :: map
|
||||
def model_to_as(%AddressModel{} = address) do
|
||||
res = %{
|
||||
"type" => "Place",
|
@ -1,25 +1,35 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converters.Comment do
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter.Comment do
|
||||
@moduledoc """
|
||||
Comment converter
|
||||
Comment converter.
|
||||
|
||||
This module allows to convert events from ActivityStream format to our own internal one, and back
|
||||
This module allows to convert events from ActivityStream format to our own
|
||||
internal one, and back.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.Comment, as: CommentModel
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.ActivityPub.Converter
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.{Converter, Convertible}
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Converter
|
||||
|
||||
defimpl Convertible, for: CommentModel do
|
||||
alias Mobilizon.Service.ActivityPub.Converter.Comment, as: CommentConverter
|
||||
|
||||
defdelegate model_to_as(comment), to: CommentConverter
|
||||
end
|
||||
|
||||
@doc """
|
||||
Converts an AP object data to our internal data structure
|
||||
Converts an AP object data to our internal data structure.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map()) :: map()
|
||||
@spec as_to_model_data(map) :: map
|
||||
def as_to_model_data(object) do
|
||||
{:ok, %Actor{id: actor_id}} = ActivityPub.get_or_fetch_by_url(object["actor"])
|
||||
|
||||
Logger.debug("Inserting full comment")
|
||||
Logger.debug(inspect(object))
|
||||
|
||||
@ -62,6 +72,7 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Comment do
|
||||
end
|
||||
else
|
||||
Logger.debug("No parent object for this comment")
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
@ -72,7 +83,7 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Comment do
|
||||
Make an AS comment object from an existing `Comment` structure.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(CommentModel.t()) :: map()
|
||||
@spec model_to_as(CommentModel.t()) :: map
|
||||
def model_to_as(%CommentModel{} = comment) do
|
||||
object = %{
|
||||
"type" => "Note",
|
||||
@ -91,9 +102,3 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Comment do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defimpl Mobilizon.Service.ActivityPub.Convertible, for: Mobilizon.Events.Comment do
|
||||
alias Mobilizon.Service.ActivityPub.Converters.Comment, as: CommentConverter
|
||||
|
||||
defdelegate model_to_as(comment), to: CommentConverter
|
||||
end
|
@ -1,31 +1,36 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter.Event do
|
||||
@moduledoc """
|
||||
Event converter
|
||||
Event converter.
|
||||
|
||||
This module allows to convert events from ActivityStream format to our own internal one, and back
|
||||
This module allows to convert events from ActivityStream format to our own
|
||||
internal one, and back.
|
||||
"""
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Media
|
||||
alias Mobilizon.Media.Picture
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.Event, as: EventModel
|
||||
alias Mobilizon.Service.ActivityPub.Converter
|
||||
alias Mobilizon.Service.ActivityPub.Converters.Address, as: AddressConverter
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Tag
|
||||
alias Mobilizon.Addresses
|
||||
alias Mobilizon.Addresses.Address
|
||||
|
||||
@behaviour Converter
|
||||
alias Mobilizon.{Actors, Addresses, Events, Media}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Events.Event, as: EventModel
|
||||
alias Mobilizon.Events.{EventOptions, Tag}
|
||||
alias Mobilizon.Media.Picture
|
||||
alias Mobilizon.Service.ActivityPub.{Converter, Convertible, Utils}
|
||||
alias Mobilizon.Service.ActivityPub.Converter.Address, as: AddressConverter
|
||||
alias Mobilizon.Service.ActivityPub.Converter.Picture, as: PictureConverter
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Converter
|
||||
|
||||
defimpl Convertible, for: EventModel do
|
||||
alias Mobilizon.Service.ActivityPub.Converter.Event, as: EventConverter
|
||||
|
||||
defdelegate model_to_as(event), to: EventConverter
|
||||
end
|
||||
|
||||
@doc """
|
||||
Converts an AP object data to our internal data structure
|
||||
Converts an AP object data to our internal data structure.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map()) :: map()
|
||||
@spec as_to_model_data(map) :: map
|
||||
def as_to_model_data(object) do
|
||||
Logger.debug("event as_to_model_data")
|
||||
Logger.debug(inspect(object))
|
||||
@ -73,15 +78,58 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
|
||||
{:ok, Map.put(entity, "options", options)}
|
||||
else
|
||||
err ->
|
||||
{:error, err}
|
||||
error ->
|
||||
{:error, error}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert an event struct to an ActivityStream representation.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(EventModel.t()) :: map
|
||||
def model_to_as(%EventModel{} = event) do
|
||||
to =
|
||||
if event.visibility == :public,
|
||||
do: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
else: [event.organizer_actor.followers_url]
|
||||
|
||||
res = %{
|
||||
"type" => "Event",
|
||||
"to" => to,
|
||||
"cc" => [],
|
||||
"attributedTo" => event.organizer_actor.url,
|
||||
"name" => event.title,
|
||||
"actor" => event.organizer_actor.url,
|
||||
"uuid" => event.uuid,
|
||||
"category" => event.category,
|
||||
"content" => event.description,
|
||||
"publish_at" => (event.publish_at || event.inserted_at) |> date_to_string(),
|
||||
"updated_at" => event.updated_at |> date_to_string(),
|
||||
"mediaType" => "text/html",
|
||||
"startTime" => event.begins_on |> date_to_string(),
|
||||
"joinOptions" => to_string(event.join_options),
|
||||
"endTime" => event.ends_on |> date_to_string(),
|
||||
"tag" => event.tags |> build_tags(),
|
||||
"id" => event.url,
|
||||
"url" => event.url
|
||||
}
|
||||
|
||||
res =
|
||||
if is_nil(event.physical_address),
|
||||
do: res,
|
||||
else: Map.put(res, "location", AddressConverter.model_to_as(event.physical_address))
|
||||
|
||||
if is_nil(event.picture),
|
||||
do: res,
|
||||
else: Map.put(res, "attachment", [PictureConverter.model_to_as(event.picture)])
|
||||
end
|
||||
|
||||
# Get only elements that we have in EventOptions
|
||||
@spec get_options(map) :: map
|
||||
defp get_options(object) do
|
||||
keys =
|
||||
Mobilizon.Events.EventOptions
|
||||
EventOptions
|
||||
|> struct
|
||||
|> Map.keys()
|
||||
|> List.delete(:__struct__)
|
||||
@ -93,6 +141,7 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
end)
|
||||
end
|
||||
|
||||
@spec get_address(map | binary | nil) :: integer | nil
|
||||
defp get_address(address_url) when is_bitstring(address_url) do
|
||||
get_address(%{"id" => address_url})
|
||||
end
|
||||
@ -117,8 +166,9 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
|
||||
defp get_address(nil), do: nil
|
||||
|
||||
@spec do_get_address(map) :: integer | nil
|
||||
defp do_get_address(map) do
|
||||
map = Mobilizon.Service.ActivityPub.Converters.Address.as_to_model_data(map)
|
||||
map = Mobilizon.Service.ActivityPub.Converter.Address.as_to_model_data(map)
|
||||
|
||||
case Addresses.create_address(map) do
|
||||
{:ok, %Address{id: address_id}} ->
|
||||
@ -129,6 +179,7 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
end
|
||||
end
|
||||
|
||||
@spec fetch_tags([String.t()]) :: [String.t()]
|
||||
defp fetch_tags(tags) do
|
||||
Logger.debug("fetching tags")
|
||||
|
||||
@ -143,6 +194,7 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
end)
|
||||
end
|
||||
|
||||
@spec build_tags([String.t()]) :: String.t()
|
||||
defp build_tags(tags) do
|
||||
Enum.map(tags, fn %Tag{} = tag ->
|
||||
%{
|
||||
@ -163,54 +215,7 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert an event struct to an ActivityStream representation
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(EventModel.t()) :: map()
|
||||
def model_to_as(%EventModel{} = event) do
|
||||
to =
|
||||
if event.visibility == :public,
|
||||
do: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
else: [event.organizer_actor.followers_url]
|
||||
|
||||
res = %{
|
||||
"type" => "Event",
|
||||
"to" => to,
|
||||
"cc" => [],
|
||||
"attributedTo" => event.organizer_actor.url,
|
||||
"name" => event.title,
|
||||
"actor" => event.organizer_actor.url,
|
||||
"uuid" => event.uuid,
|
||||
"category" => event.category,
|
||||
"content" => event.description,
|
||||
"publish_at" => (event.publish_at || event.inserted_at) |> date_to_string(),
|
||||
"updated_at" => event.updated_at |> date_to_string(),
|
||||
"mediaType" => "text/html",
|
||||
"startTime" => event.begins_on |> date_to_string(),
|
||||
"endTime" => event.ends_on |> date_to_string(),
|
||||
"joinOptions" => to_string(event.join_options),
|
||||
"tag" => event.tags |> build_tags(),
|
||||
"id" => event.url,
|
||||
"url" => event.url
|
||||
}
|
||||
|
||||
res =
|
||||
if is_nil(event.physical_address),
|
||||
do: res,
|
||||
else: Map.put(res, "location", AddressConverter.model_to_as(event.physical_address))
|
||||
|
||||
if is_nil(event.picture),
|
||||
do: res,
|
||||
else: Map.put(res, "attachment", [Utils.make_picture_data(event.picture)])
|
||||
end
|
||||
|
||||
@spec date_to_string(DateTime.t() | nil) :: String.t()
|
||||
defp date_to_string(nil), do: nil
|
||||
defp date_to_string(date), do: DateTime.to_iso8601(date)
|
||||
end
|
||||
|
||||
defimpl Mobilizon.Service.ActivityPub.Convertible, for: Mobilizon.Events.Event do
|
||||
alias Mobilizon.Service.ActivityPub.Converters.Event, as: EventConverter
|
||||
|
||||
defdelegate model_to_as(event), to: EventConverter
|
||||
defp date_to_string(%DateTime{} = date), do: DateTime.to_iso8601(date)
|
||||
end
|
@ -1,11 +1,13 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converters.Flag do
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter.Flag do
|
||||
@moduledoc """
|
||||
Flag converter
|
||||
Flag converter.
|
||||
|
||||
This module allows to convert reports from ActivityStream format to our own internal one, and back.
|
||||
This module allows to convert reports from ActivityStream format to our own
|
||||
internal one, and back.
|
||||
|
||||
Note: Reports are named Flag in AS.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
@ -16,10 +18,10 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Flag do
|
||||
@behaviour Converter
|
||||
|
||||
@doc """
|
||||
Converts an AP object data to our internal data structure
|
||||
Converts an AP object data to our internal data structure.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map()) :: map()
|
||||
@spec as_to_model_data(map) :: map
|
||||
def as_to_model_data(object) do
|
||||
with params <- as_to_model(object) do
|
||||
%{
|
||||
@ -33,6 +35,21 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Flag do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert an event struct to an ActivityStream representation
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(EventModel.t()) :: map
|
||||
def model_to_as(%Report{} = report) do
|
||||
%{
|
||||
"type" => "Flag",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"actor" => report.reporter.url,
|
||||
"id" => report.url
|
||||
}
|
||||
end
|
||||
|
||||
@spec as_to_model(map) :: map
|
||||
def as_to_model(%{"object" => objects} = object) do
|
||||
with {:ok, %Actor{} = reporter} <- Actors.get_actor_by_url(object["actor"]),
|
||||
%Actor{} = reported <-
|
||||
@ -72,18 +89,4 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Flag do
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert an event struct to an ActivityStream representation
|
||||
"""
|
||||
@impl Converter
|
||||
@spec model_to_as(EventModel.t()) :: map()
|
||||
def model_to_as(%Report{} = report) do
|
||||
%{
|
||||
"type" => "Flag",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"actor" => report.reporter.url,
|
||||
"id" => report.url
|
||||
}
|
||||
end
|
||||
end
|
31
lib/service/activity_pub/converter/participant.ex
Normal file
31
lib/service/activity_pub/converter/participant.ex
Normal file
@ -0,0 +1,31 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter.Participant do
|
||||
@moduledoc """
|
||||
Participant converter.
|
||||
|
||||
This module allows to convert reports from ActivityStream format to our own
|
||||
internal one, and back.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Events.Participant, as: ParticipantModel
|
||||
|
||||
alias Mobilizon.Service.ActivityPub.Convertible
|
||||
|
||||
defimpl Convertible, for: ParticipantModel do
|
||||
alias Mobilizon.Service.ActivityPub.Converter.Participant, as: ParticipantConverter
|
||||
|
||||
defdelegate model_to_as(participant), to: ParticipantConverter
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert an event struct to an ActivityStream representation.
|
||||
"""
|
||||
@spec model_to_as(ParticipantModel.t()) :: map
|
||||
def model_to_as(%ParticipantModel{} = participant) do
|
||||
%{
|
||||
"type" => "Join",
|
||||
"id" => participant.url,
|
||||
"actor" => participant.actor.url,
|
||||
"object" => participant.event.url
|
||||
}
|
||||
end
|
||||
end
|
28
lib/service/activity_pub/converter/picture.ex
Normal file
28
lib/service/activity_pub/converter/picture.ex
Normal file
@ -0,0 +1,28 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter.Picture do
|
||||
@moduledoc """
|
||||
Picture converter.
|
||||
|
||||
This module allows to convert events from ActivityStream format to our own
|
||||
internal one, and back.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Media.Picture, as: PictureModel
|
||||
|
||||
@doc """
|
||||
Convert a picture struct to an ActivityStream representation.
|
||||
"""
|
||||
@spec model_to_as(PictureModel.t()) :: map
|
||||
def model_to_as(%PictureModel{file: file}) do
|
||||
%{
|
||||
"type" => "Document",
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => file.content_type,
|
||||
"href" => file.url
|
||||
}
|
||||
],
|
||||
"name" => file.name
|
||||
}
|
||||
end
|
||||
end
|
@ -1,29 +0,0 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converters.Participant do
|
||||
@moduledoc """
|
||||
Flag converter
|
||||
|
||||
This module allows to convert reports from ActivityStream format to our own internal one, and back.
|
||||
|
||||
Note: Reports are named Flag in AS.
|
||||
"""
|
||||
alias Mobilizon.Events.Participant, as: ParticipantModel
|
||||
|
||||
@doc """
|
||||
Convert an event struct to an ActivityStream representation
|
||||
"""
|
||||
@spec model_to_as(ParticipantModel.t()) :: map()
|
||||
def model_to_as(%ParticipantModel{} = participant) do
|
||||
%{
|
||||
"type" => "Join",
|
||||
"id" => participant.url,
|
||||
"actor" => participant.actor.url,
|
||||
"object" => participant.event.url
|
||||
}
|
||||
end
|
||||
|
||||
defimpl Mobilizon.Service.ActivityPub.Convertible, for: Mobilizon.Events.Participant do
|
||||
alias Mobilizon.Service.ActivityPub.Converters.Participant, as: ParticipantConverter
|
||||
|
||||
defdelegate model_to_as(event), to: ParticipantConverter
|
||||
end
|
||||
end
|
10
lib/service/activity_pub/convertible.ex
Normal file
10
lib/service/activity_pub/convertible.ex
Normal file
@ -0,0 +1,10 @@
|
||||
defprotocol Mobilizon.Service.ActivityPub.Convertible do
|
||||
@moduledoc """
|
||||
Convertible protocol.
|
||||
"""
|
||||
|
||||
@type activity_streams :: map
|
||||
|
||||
@spec model_to_as(t) :: activity_streams
|
||||
def model_to_as(convertible)
|
||||
end
|
@ -5,13 +5,13 @@
|
||||
|
||||
defmodule Mobilizon.Service.ActivityPub.Relay do
|
||||
@moduledoc """
|
||||
Handles following and unfollowing relays and instances
|
||||
Handles following and unfollowing relays and instances.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.{Activity, Transmogrifier}
|
||||
|
||||
alias MobilizonWeb.API.Follows
|
||||
|
||||
@ -72,9 +72,7 @@ defmodule Mobilizon.Service.ActivityPub.Relay do
|
||||
def publish(%Activity{data: %{"object" => object}} = _activity) do
|
||||
with %Actor{id: actor_id} = actor <- get_actor(),
|
||||
{:ok, object} <-
|
||||
Mobilizon.Service.ActivityPub.Transmogrifier.fetch_obj_helper_as_activity_streams(
|
||||
object
|
||||
) do
|
||||
Transmogrifier.fetch_obj_helper_as_activity_streams(object) do
|
||||
ActivityPub.announce(actor, object, "#{object["id"]}/announces/#{actor_id}", true, false)
|
||||
else
|
||||
e ->
|
||||
|
@ -7,12 +7,13 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
@moduledoc """
|
||||
A module to handle coding from internal to wire ActivityPub and back.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{Actor, Follower}
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Comment, Participant}
|
||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.{Visibility, Utils}
|
||||
alias Mobilizon.Service.ActivityPub.{Converter, Convertible, Utils, Visibility}
|
||||
|
||||
require Logger
|
||||
|
||||
@ -24,7 +25,8 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
if is_binary(Enum.at(actor, 0)) do
|
||||
Enum.at(actor, 0)
|
||||
else
|
||||
Enum.find(actor, fn %{"type" => type} -> type in ["Person", "Service", "Application"] end)
|
||||
actor
|
||||
|> Enum.find(fn %{"type" => type} -> type in ["Person", "Service", "Application"] end)
|
||||
|> Map.get("id")
|
||||
end
|
||||
end
|
||||
@ -120,7 +122,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
def handle_incoming(%{"id" => ""}), do: :error
|
||||
|
||||
def handle_incoming(%{"type" => "Flag"} = data) do
|
||||
with params <- Mobilizon.Service.ActivityPub.Converters.Flag.as_to_model(data) do
|
||||
with params <- Converter.Flag.as_to_model(data) do
|
||||
params = %{
|
||||
reporter_url: params["reporter"].url,
|
||||
reported_actor_url: params["reported"].url,
|
||||
@ -866,7 +868,7 @@ defmodule Mobilizon.Service.ActivityPub.Transmogrifier do
|
||||
|
||||
def fetch_obj_helper_as_activity_streams(object) do
|
||||
with {:ok, object} <- fetch_obj_helper(object) do
|
||||
{:ok, Mobilizon.Service.ActivityPub.Convertible.model_to_as(object)}
|
||||
{:ok, Convertible.model_to_as(object)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,25 +5,20 @@
|
||||
|
||||
defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
@moduledoc """
|
||||
# Utils
|
||||
|
||||
Various utils
|
||||
# Various ActivityPub related utils.
|
||||
"""
|
||||
|
||||
alias Ecto.Changeset
|
||||
|
||||
alias Mobilizon.Addresses
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.{Actors, Addresses, Events, Reports, Users}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Events.{Comment, Event}
|
||||
alias Mobilizon.Media.Picture
|
||||
alias Mobilizon.Reports
|
||||
alias Mobilizon.Reports.Report
|
||||
alias Mobilizon.Service.ActivityPub.{Activity, Converters}
|
||||
alias Mobilizon.Service.ActivityPub.{Activity, Converter}
|
||||
alias Mobilizon.Service.Federator
|
||||
alias Mobilizon.Storage.Repo
|
||||
alias Mobilizon.Users
|
||||
|
||||
alias MobilizonWeb.{Email, Endpoint}
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
@ -70,7 +65,8 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
_ -> 5
|
||||
end
|
||||
|
||||
Mobilizon.Service.Federator.enqueue(:publish, activity, priority)
|
||||
Federator.enqueue(:publish, activity, priority)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@ -125,7 +121,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
def insert_full_object(%{"object" => %{"type" => "Event"} = object_data, "type" => "Create"})
|
||||
when is_map(object_data) do
|
||||
with {:ok, object_data} <-
|
||||
Converters.Event.as_to_model_data(object_data),
|
||||
Converter.Event.as_to_model_data(object_data),
|
||||
{:ok, %Event{} = event} <- Events.create_event(object_data) do
|
||||
{:ok, event}
|
||||
end
|
||||
@ -145,7 +141,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
"""
|
||||
def insert_full_object(%{"object" => %{"type" => "Note"} = object_data, "type" => "Create"})
|
||||
when is_map(object_data) do
|
||||
with data <- Converters.Comment.as_to_model_data(object_data),
|
||||
with data <- Converter.Comment.as_to_model_data(object_data),
|
||||
{:ok, %Comment{} = comment} <- Events.create_comment(data) do
|
||||
{:ok, comment}
|
||||
else
|
||||
@ -161,7 +157,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
"""
|
||||
def insert_full_object(%{"type" => "Flag"} = object_data)
|
||||
when is_map(object_data) do
|
||||
with data <- Converters.Flag.as_to_model_data(object_data),
|
||||
with data <- Converter.Flag.as_to_model_data(object_data),
|
||||
{:ok, %Report{} = report} <- Reports.create_report(data) do
|
||||
Enum.each(Users.list_moderators(), fn moderator ->
|
||||
moderator
|
||||
@ -193,7 +189,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
when is_map(object_data) do
|
||||
with {:event_not_found, %Event{} = event} <-
|
||||
{:event_not_found, Events.get_event_by_url(event_url)},
|
||||
{:ok, object_data} <- Converters.Event.as_to_model_data(object_data),
|
||||
{:ok, object_data} <- Converter.Event.as_to_model_data(object_data),
|
||||
{:ok, %Event{} = event} <- Events.update_event(event, object_data) do
|
||||
{:ok, event}
|
||||
end
|
||||
@ -205,7 +201,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
})
|
||||
when is_map(object_data) and type_actor in @actor_types do
|
||||
with {:ok, %Actor{} = actor} <- Actors.get_actor_by_url(actor_url),
|
||||
object_data <- Converters.Actor.as_to_model_data(object_data),
|
||||
object_data <- Converter.Actor.as_to_model_data(object_data),
|
||||
{:ok, %Actor{} = actor} <- Actors.update_actor(actor, object_data) do
|
||||
{:ok, actor}
|
||||
end
|
||||
@ -251,21 +247,10 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Convert a picture model into an AS Link representation
|
||||
Convert a picture model into an AS Link representation.
|
||||
"""
|
||||
# TODO: Move me to Mobilizon.Service.ActivityPub.Converters
|
||||
def make_picture_data(%Picture{file: file} = _picture) do
|
||||
%{
|
||||
"type" => "Document",
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => file.content_type,
|
||||
"href" => file.url
|
||||
}
|
||||
],
|
||||
"name" => file.name
|
||||
}
|
||||
def make_picture_data(%Picture{} = picture) do
|
||||
Converter.Picture.model_to_as(picture)
|
||||
end
|
||||
|
||||
@doc """
|
||||
@ -274,7 +259,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
def make_picture_data(picture) when is_map(picture) do
|
||||
with {:ok, %{"url" => [%{"href" => url, "mediaType" => content_type}], "size" => size}} <-
|
||||
MobilizonWeb.Upload.store(picture.file),
|
||||
{:ok, %Picture{file: _file} = pic} <-
|
||||
{:ok, %Picture{file: _file} = picture} <-
|
||||
Mobilizon.Media.create_picture(%{
|
||||
"file" => %{
|
||||
"url" => url,
|
||||
@ -284,7 +269,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
},
|
||||
"actor_id" => picture.actor_id
|
||||
}) do
|
||||
make_picture_data(pic)
|
||||
Converter.Picture.model_to_as(picture)
|
||||
end
|
||||
end
|
||||
|
||||
@ -348,7 +333,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
if is_nil(metadata.options) do
|
||||
res
|
||||
else
|
||||
options = struct(Mobilizon.Events.EventOptions, metadata.options) |> Map.from_struct()
|
||||
options = Events.EventOptions |> struct(metadata.options) |> Map.from_struct()
|
||||
|
||||
Enum.reduce(options, res, fn {key, value}, acc ->
|
||||
(value && Map.put(acc, camelize(key), value)) ||
|
||||
|
@ -1,13 +1,13 @@
|
||||
defmodule Mobilizon.Service.Admin.ActionLogService do
|
||||
@moduledoc """
|
||||
Module to handle action log creations
|
||||
Module to handle action log creations.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Admin
|
||||
alias Mobilizon.Admin.ActionLog
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
@doc """
|
||||
Log an admin action
|
||||
|
@ -1,15 +1,14 @@
|
||||
defmodule Mobilizon.Service.EmailChecker do
|
||||
@moduledoc """
|
||||
Provides a function to test emails against a "not so bad" regex
|
||||
Provides a function to test emails against a "not so bad" regex.
|
||||
"""
|
||||
|
||||
# TODO: simplify me!
|
||||
@email_regex ~r/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
||||
|
||||
@doc """
|
||||
Returns whether the email is valid
|
||||
Returns whether the email is valid.
|
||||
"""
|
||||
@spec valid?(String.t()) :: boolean()
|
||||
def valid?(email) do
|
||||
email =~ @email_regex
|
||||
end
|
||||
@spec valid?(String.t()) :: boolean
|
||||
def valid?(email), do: email =~ @email_regex
|
||||
end
|
||||
|
@ -1,23 +1,24 @@
|
||||
defmodule Mobilizon.Service.Export.Feed do
|
||||
@moduledoc """
|
||||
Serve Atom Syndication Feeds
|
||||
Serve Atom Syndication Feeds.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, FeedToken}
|
||||
alias Atomex.{Feed, Entry}
|
||||
import MobilizonWeb.Gettext
|
||||
|
||||
alias Atomex.{Entry, Feed}
|
||||
|
||||
alias Mobilizon.{Actors, Events, Users}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.{Event, FeedToken}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.{Endpoint, MediaProxy}
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.MediaProxy
|
||||
|
||||
require Logger
|
||||
|
||||
@version Mix.Project.config()[:version]
|
||||
def version(), do: @version
|
||||
def version, do: @version
|
||||
|
||||
@spec create_cache(String.t()) :: {:commit, String.t()} | {:ignore, any()}
|
||||
def create_cache("actor_" <> name) do
|
||||
@ -57,7 +58,11 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
@spec build_actor_feed(Actor.t(), list(), boolean()) :: String.t()
|
||||
defp build_actor_feed(%Actor{} = actor, events, public \\ true) do
|
||||
display_name = Actor.display_name(actor)
|
||||
self_url = Routes.feed_url(Endpoint, :actor, actor.preferred_username, "atom") |> URI.decode()
|
||||
|
||||
self_url =
|
||||
Endpoint
|
||||
|> Routes.feed_url(:actor, actor.preferred_username, "atom")
|
||||
|> URI.decode()
|
||||
|
||||
title =
|
||||
if public,
|
||||
@ -66,8 +71,8 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
|
||||
# Title uses default instance language
|
||||
feed =
|
||||
Feed.new(
|
||||
self_url,
|
||||
self_url
|
||||
|> Feed.new(
|
||||
DateTime.utc_now(),
|
||||
Gettext.gettext(MobilizonWeb.Gettext, title, actor: display_name)
|
||||
)
|
||||
@ -102,7 +107,8 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
description = event.description || ""
|
||||
|
||||
entry =
|
||||
Entry.new(event.url, event.publish_at || event.inserted_at, event.title)
|
||||
event.url
|
||||
|> Entry.new(event.publish_at || event.inserted_at, event.title)
|
||||
|> Entry.link(event.url, rel: "alternate", type: "text/html")
|
||||
|> Entry.content({:cdata, description}, type: "html")
|
||||
|> Entry.published(event.publish_at || event.inserted_at)
|
||||
@ -156,14 +162,11 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
# Build an atom feed from actor and it's public events
|
||||
@spec build_user_feed(list(), User.t(), String.t()) :: String.t()
|
||||
defp build_user_feed(events, %User{email: email}, token) do
|
||||
self_url = Routes.feed_url(Endpoint, :going, token, "atom") |> URI.decode()
|
||||
self_url = Endpoint |> Routes.feed_url(:going, token, "atom") |> URI.decode()
|
||||
|
||||
# Title uses default instance language
|
||||
Feed.new(
|
||||
self_url,
|
||||
DateTime.utc_now(),
|
||||
gettext("Feed for %{email} on Mobilizon", email: email)
|
||||
)
|
||||
self_url
|
||||
|> Feed.new(DateTime.utc_now(), gettext("Feed for %{email} on Mobilizon", email: email))
|
||||
|> Feed.link(self_url, rel: "self")
|
||||
|> Feed.generator("Mobilizon", uri: "https://joinmobilizon.org", version: version())
|
||||
|> Feed.entries(Enum.map(events, &get_entry/1))
|
||||
|
@ -1,14 +1,12 @@
|
||||
defmodule Mobilizon.Service.Export.ICalendar do
|
||||
@moduledoc """
|
||||
Export an event to iCalendar format
|
||||
Export an event to iCalendar format.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Events.{Event, FeedToken}
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.{Actors, Events, Users}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Events.{Event, FeedToken}
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Users
|
||||
|
||||
@doc """
|
||||
Export a public event to iCalendar format.
|
||||
|
@ -5,10 +5,11 @@
|
||||
|
||||
defmodule Mobilizon.Service.Formatter do
|
||||
@moduledoc """
|
||||
Formats input text to structured data, extracts mentions and hashtags
|
||||
Formats input text to structured data, extracts mentions and hashtags.
|
||||
"""
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.HTML
|
||||
|
||||
@link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui
|
||||
@ -93,7 +94,8 @@ defmodule Mobilizon.Service.Formatter do
|
||||
end
|
||||
|
||||
def html_escape(text, "text/plain") do
|
||||
Regex.split(@link_regex, text, include_captures: true)
|
||||
@link_regex
|
||||
|> Regex.split(text, include_captures: true)
|
||||
|> Enum.map_every(2, fn chunk ->
|
||||
{:safe, part} = Phoenix.HTML.html_escape(chunk)
|
||||
part
|
||||
|
@ -2,9 +2,11 @@ defmodule Mobilizon.Service.Geospatial.Addok do
|
||||
@moduledoc """
|
||||
[Addok](https://github.com/addok/addok) backend.
|
||||
"""
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
require Logger
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Provider
|
||||
|
||||
@ -68,7 +70,7 @@ defmodule Mobilizon.Service.Geospatial.Addok do
|
||||
region: Map.get(properties, "state"),
|
||||
description: Map.get(properties, "name") || street_address(properties),
|
||||
floor: Map.get(properties, "floor"),
|
||||
geom: Map.get(geometry, "coordinates") |> Provider.coordinates(),
|
||||
geom: geometry |> Map.get("coordinates") |> Provider.coordinates(),
|
||||
postal_code: Map.get(properties, "postcode"),
|
||||
street: properties |> street_address()
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
defmodule Mobilizon.Service.Geospatial do
|
||||
@moduledoc """
|
||||
Module to load the service adapter defined inside the configuration
|
||||
Module to load the service adapter defined inside the configuration.
|
||||
|
||||
See `Mobilizon.Service.Geospatial.Provider`
|
||||
See `Mobilizon.Service.Geospatial.Provider`.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Returns the appropriate service adapter
|
||||
Returns the appropriate service adapter.
|
||||
|
||||
According to the config behind `config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geospatial.Module`
|
||||
According to the config behind
|
||||
`config :mobilizon, Mobilizon.Service.Geospatial,
|
||||
service: Mobilizon.Service.Geospatial.Module`
|
||||
"""
|
||||
@spec service() :: module()
|
||||
def service(), do: Application.get_env(:mobilizon, __MODULE__) |> get_in([:service])
|
||||
@spec service :: module
|
||||
def service, do: get_in(Application.get_env(:mobilizon, __MODULE__), [:service])
|
||||
end
|
||||
|
@ -1,11 +1,13 @@
|
||||
defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||
@moduledoc """
|
||||
Google Maps [Geocoding service](https://developers.google.com/maps/documentation/geocoding/intro)
|
||||
Google Maps [Geocoding service](https://developers.google.com/maps/documentation/geocoding/intro).
|
||||
|
||||
Note: Endpoint is hardcoded to Google Maps API
|
||||
Note: Endpoint is hardcoded to Google Maps API.
|
||||
"""
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Provider
|
||||
|
@ -8,8 +8,10 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
|
||||
* `:open_data` Whether to use [Open Data or Licenced Data](https://developer.mapquest.com/documentation/open/).
|
||||
Defaults to `true`
|
||||
"""
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Provider
|
||||
|
@ -2,8 +2,10 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
|
||||
@moduledoc """
|
||||
[Nominatim](https://wiki.openstreetmap.org/wiki/Nominatim) backend.
|
||||
"""
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Provider
|
||||
@ -66,23 +68,22 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
|
||||
|
||||
@spec process_data(map()) :: Address.t()
|
||||
defp process_data(%{"address" => address} = body) do
|
||||
try do
|
||||
%Address{
|
||||
country: Map.get(address, "country"),
|
||||
locality: Map.get(address, "city"),
|
||||
region: Map.get(address, "state"),
|
||||
description: description(body),
|
||||
floor: Map.get(address, "floor"),
|
||||
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
|
||||
postal_code: Map.get(address, "postcode"),
|
||||
street: street_address(address),
|
||||
origin_id: "osm:" <> to_string(Map.get(body, "osm_id"))
|
||||
}
|
||||
rescue
|
||||
e in ArgumentError ->
|
||||
Logger.warn(inspect(e))
|
||||
nil
|
||||
end
|
||||
%Address{
|
||||
country: Map.get(address, "country"),
|
||||
locality: Map.get(address, "city"),
|
||||
region: Map.get(address, "state"),
|
||||
description: description(body),
|
||||
floor: Map.get(address, "floor"),
|
||||
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
|
||||
postal_code: Map.get(address, "postcode"),
|
||||
street: street_address(address),
|
||||
origin_id: "osm:" <> to_string(Map.get(body, "osm_id"))
|
||||
}
|
||||
rescue
|
||||
error in ArgumentError ->
|
||||
Logger.warn(inspect(error))
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
@spec street_address(map()) :: String.t()
|
||||
|
@ -2,9 +2,11 @@ defmodule Mobilizon.Service.Geospatial.Photon do
|
||||
@moduledoc """
|
||||
[Photon](https://photon.komoot.de) backend.
|
||||
"""
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
require Logger
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
require Logger
|
||||
|
||||
@behaviour Provider
|
||||
|
||||
@ -70,7 +72,7 @@ defmodule Mobilizon.Service.Geospatial.Photon do
|
||||
region: Map.get(properties, "state"),
|
||||
description: Map.get(properties, "name") || street_address(properties),
|
||||
floor: Map.get(properties, "floor"),
|
||||
geom: Map.get(geometry, "coordinates") |> Provider.coordinates(),
|
||||
geom: geometry |> Map.get("coordinates") |> Provider.coordinates(),
|
||||
postal_code: Map.get(properties, "postcode"),
|
||||
street: properties |> street_address()
|
||||
}
|
||||
|
@ -14,11 +14,13 @@ defmodule Mobilizon.Service.Geospatial.Provider do
|
||||
## Shared options
|
||||
|
||||
* `:user_agent` User-Agent string to send to the backend. Defaults to `"Mobilizon"`
|
||||
* `:lang` Lang in which to prefer results. Used as a request parameter or through an `Accept-Language` HTTP header.
|
||||
Defaults to `"en"`.
|
||||
* `:limit` Maximum limit for the number of results returned by the backend. Defaults to `10`
|
||||
* `:api_key` Allows to override the API key (if the backend requires one) set inside the configuration.
|
||||
* `:endpoint` Allows to override the endpoint set inside the configuration
|
||||
* `:lang` Lang in which to prefer results. Used as a request parameter or
|
||||
through an `Accept-Language` HTTP header. Defaults to `"en"`.
|
||||
* `:limit` Maximum limit for the number of results returned by the backend.
|
||||
Defaults to `10`
|
||||
* `:api_key` Allows to override the API key (if the backend requires one) set
|
||||
inside the configuration.
|
||||
* `:endpoint` Allows to override the endpoint set inside the configuration.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
@ -35,38 +37,40 @@ defmodule Mobilizon.Service.Geospatial.Provider do
|
||||
iex> geocode(48.11, -1.77)
|
||||
%Address{}
|
||||
"""
|
||||
@callback geocode(longitude :: number(), latitude :: number(), options :: keyword()) ::
|
||||
list(Address.t())
|
||||
@callback geocode(longitude :: number, latitude :: number, options :: keyword) :: [Address.t()]
|
||||
|
||||
@doc """
|
||||
Search for an address
|
||||
|
||||
## Options
|
||||
|
||||
In addition to [the shared options](#module-shared-options), `c:search/2` also accepts the following options:
|
||||
In addition to [the shared options](#module-shared-options), `c:search/2` also
|
||||
accepts the following options:
|
||||
|
||||
* `coords` Map of coordinates (ex: `%{lon: 48.11, lat: -1.77}`) allowing to give a geographic priority to the search.
|
||||
Defaults to `nil`
|
||||
* `coords` Map of coordinates (ex: `%{lon: 48.11, lat: -1.77}`) allowing to
|
||||
give a geographic priority to the search. Defaults to `nil`.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> search("10 rue Jangot")
|
||||
%Address{}
|
||||
"""
|
||||
@callback search(address :: String.t(), options :: keyword()) :: list(Address.t())
|
||||
@callback search(address :: String.t(), options :: keyword) :: [Address.t()]
|
||||
|
||||
@doc """
|
||||
Returns a `Geo.Point` for given coordinates
|
||||
"""
|
||||
@spec coordinates(list(number()), number()) :: Geo.Point.t()
|
||||
@spec coordinates([number], number) :: Geo.Point.t()
|
||||
def coordinates(coords, srid \\ 4326)
|
||||
|
||||
def coordinates([x, y], srid) when is_number(x) and is_number(y),
|
||||
do: %Geo.Point{coordinates: {x, y}, srid: srid}
|
||||
def coordinates([x, y], srid) when is_number(x) and is_number(y) do
|
||||
%Geo.Point{coordinates: {x, y}, srid: srid}
|
||||
end
|
||||
|
||||
def coordinates([x, y], srid) when is_bitstring(x) and is_bitstring(y),
|
||||
do: %Geo.Point{coordinates: {String.to_float(x), String.to_float(y)}, srid: srid}
|
||||
def coordinates([x, y], srid) when is_bitstring(x) and is_bitstring(y) do
|
||||
%Geo.Point{coordinates: {String.to_float(x), String.to_float(y)}, srid: srid}
|
||||
end
|
||||
|
||||
@spec coordinates(any()) :: nil
|
||||
@spec coordinates(any) :: nil
|
||||
def coordinates(_, _), do: nil
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
defmodule Mobilizon.Service.Users.Activation do
|
||||
@moduledoc false
|
||||
|
||||
alias Mobilizon.Service.Users.Tools
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Service.Users.Tools
|
||||
|
||||
alias MobilizonWeb.Email
|
||||
|
||||
|
@ -6,7 +6,7 @@ defmodule Mobilizon.ActorsTest do
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.{Actors, Config, Users}
|
||||
alias Mobilizon.Actors.{Actor, Member, Follower, Bot}
|
||||
alias Mobilizon.Actors.{Actor, Bot, Follower, Member}
|
||||
alias Mobilizon.Media.File, as: FileModel
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Storage.Page
|
||||
@ -311,9 +311,6 @@ defmodule Mobilizon.ActorsTest do
|
||||
end
|
||||
|
||||
describe "groups" do
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
@valid_attrs %{
|
||||
summary: "some description",
|
||||
suspended: true,
|
||||
@ -356,11 +353,7 @@ defmodule Mobilizon.ActorsTest do
|
||||
end
|
||||
end
|
||||
|
||||
alias Mobilizon.Actors
|
||||
|
||||
describe "bots" do
|
||||
alias Mobilizon.Actors.Bot
|
||||
|
||||
@valid_attrs %{source: "some source", type: "some type"}
|
||||
@update_attrs %{source: "some updated source", type: "some updated type"}
|
||||
@invalid_attrs %{source: nil, type: nil}
|
||||
@ -419,9 +412,6 @@ defmodule Mobilizon.ActorsTest do
|
||||
end
|
||||
|
||||
describe "followers" do
|
||||
alias Mobilizon.Actors.Follower
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
@valid_attrs %{approved: true}
|
||||
@update_attrs %{approved: false}
|
||||
@invalid_attrs %{approved: nil}
|
||||
@ -529,9 +519,6 @@ defmodule Mobilizon.ActorsTest do
|
||||
end
|
||||
|
||||
describe "members" do
|
||||
alias Mobilizon.Actors.Member
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
@valid_attrs %{role: :member}
|
||||
@update_attrs %{role: :not_approved}
|
||||
@invalid_attrs %{role: nil}
|
||||
|
@ -3,7 +3,9 @@ defmodule Mobilizon.EventsTest do
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Comment, Event, Participant, Session, Tag, TagRelation, Track}
|
||||
alias Mobilizon.Storage.Page
|
||||
|
||||
@event_valid_attrs %{
|
||||
@ -17,8 +19,6 @@ defmodule Mobilizon.EventsTest do
|
||||
}
|
||||
|
||||
describe "events" do
|
||||
alias Mobilizon.Events.Event
|
||||
|
||||
setup do
|
||||
actor = insert(:actor)
|
||||
event = insert(:event, organizer_actor: actor, visibility: :public)
|
||||
@ -176,8 +176,6 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
describe "tags" do
|
||||
alias Mobilizon.Events.Tag
|
||||
|
||||
@valid_attrs %{title: "some title"}
|
||||
@update_attrs %{title: "some updated title"}
|
||||
@invalid_attrs %{title: nil}
|
||||
@ -227,9 +225,6 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
describe "tags_relations" do
|
||||
alias Mobilizon.Events.TagRelation
|
||||
alias Mobilizon.Events.Tag
|
||||
|
||||
setup do
|
||||
tag1 = insert(:tag)
|
||||
tag2 = insert(:tag)
|
||||
@ -302,9 +297,6 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
describe "participants" do
|
||||
alias Mobilizon.Events.{Participant, Event}
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
@valid_attrs %{role: :creator}
|
||||
@update_attrs %{role: :moderator}
|
||||
@invalid_attrs %{role: :no_such_role}
|
||||
@ -369,8 +361,6 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
describe "sessions" do
|
||||
alias Mobilizon.Events.Session
|
||||
|
||||
@valid_attrs %{
|
||||
audios_urls: "some audios_urls",
|
||||
language: "some language",
|
||||
@ -463,8 +453,6 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
describe "tracks" do
|
||||
alias Mobilizon.Events.Track
|
||||
|
||||
@valid_attrs %{color: "some color", description: "some description", name: "some name"}
|
||||
@update_attrs %{
|
||||
color: "some updated color",
|
||||
@ -525,8 +513,6 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
describe "comments" do
|
||||
alias Mobilizon.Events.Comment
|
||||
|
||||
@valid_attrs %{text: "some text"}
|
||||
@update_attrs %{text: "some updated text"}
|
||||
@invalid_attrs %{text: nil, url: nil}
|
||||
|
@ -4,17 +4,22 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/activity_pub_test.exs
|
||||
|
||||
defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mock
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.HTTPSignatures.Signature
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
import Mock
|
||||
alias Mobilizon.Service.ActivityPub.Converter
|
||||
alias Mobilizon.Service.HTTPSignatures.Signature
|
||||
|
||||
alias MobilizonWeb.ActivityPub.ActorView
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
@ -28,7 +33,7 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
Signature.sign(actor, %{
|
||||
host: "example.com",
|
||||
"content-length": 15,
|
||||
digest: Jason.encode!(%{id: "my_id"}) |> Signature.build_digest(),
|
||||
digest: %{id: "my_id"} |> Jason.encode!() |> Signature.build_digest(),
|
||||
"(request-target)": Signature.generate_request_target("POST", "/inbox"),
|
||||
date: Signature.generate_date_header()
|
||||
})
|
||||
@ -160,7 +165,7 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
|
||||
test "it creates an update activity with the new actor data" do
|
||||
actor = insert(:actor)
|
||||
actor_data = MobilizonWeb.ActivityPub.ActorView.render("actor.json", %{actor: actor})
|
||||
actor_data = ActorView.render("actor.json", %{actor: actor})
|
||||
actor_data = Map.put(actor_data, "summary", @updated_actor_summary)
|
||||
|
||||
{:ok, update, updated_actor} =
|
||||
@ -189,7 +194,7 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
test "it creates an update activity with the new event data" do
|
||||
actor = insert(:actor)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
event_data = Mobilizon.Service.ActivityPub.Converters.Event.model_to_as(event)
|
||||
event_data = Converter.Event.model_to_as(event)
|
||||
event_data = Map.put(event_data, "startTime", @updated_start_time)
|
||||
|
||||
{:ok, update, updated_event} =
|
||||
|
@ -1,7 +1,8 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converters.ActorTest do
|
||||
defmodule Mobilizon.Service.ActivityPub.Converter.ActorTest do
|
||||
use Mobilizon.DataCase
|
||||
alias Mobilizon.Service.ActivityPub.Converters.Actor, as: ActorConverter
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub.Converter.Actor, as: ActorConverter
|
||||
|
||||
describe "actor to AS" do
|
||||
test "valid actor to as" do
|
@ -4,6 +4,8 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/activity_pub/transmogrifier_test.exs
|
||||
|
||||
defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
@ -13,9 +15,10 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.{Utils, Activity}
|
||||
alias Mobilizon.Service.ActivityPub.{Activity, Utils}
|
||||
alias Mobilizon.Service.ActivityPub.Transmogrifier
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
alias MobilizonWeb.API
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
@ -784,7 +787,9 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
assert :error == Transmogrifier.handle_incoming(reject_data)
|
||||
|
||||
# Organiser is not present since we use factories directly
|
||||
assert Events.list_participants_for_event(event.id) |> Enum.map(& &1.id) ==
|
||||
assert event.id
|
||||
|> Events.list_participants_for_event()
|
||||
|> Enum.map(& &1.id) ==
|
||||
[]
|
||||
end
|
||||
|
||||
@ -812,9 +817,10 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
assert activity.data["actor"] == participant_url
|
||||
|
||||
# The only participant left is the organizer
|
||||
assert Events.list_participants_for_event(event.id) |> Enum.map(& &1.id) == [
|
||||
organizer_participation.id
|
||||
]
|
||||
assert event.id
|
||||
|> Events.list_participants_for_event()
|
||||
|> Enum.map(& &1.id) ==
|
||||
[organizer_participation.id]
|
||||
end
|
||||
|
||||
test "it refuses Leave activities when actor is the only organizer" do
|
||||
@ -841,7 +847,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
other_actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} =
|
||||
MobilizonWeb.API.Comments.create_comment(
|
||||
API.Comments.create_comment(
|
||||
actor.preferred_username,
|
||||
"hey, @#{other_actor.preferred_username}, how are ya? #2hu"
|
||||
)
|
||||
@ -877,8 +883,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
test "it adds the json-ld context and the conversation property" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} =
|
||||
MobilizonWeb.API.Comments.create_comment(actor.preferred_username, "hey")
|
||||
{:ok, activity, _} = API.Comments.create_comment(actor.preferred_username, "hey")
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
@ -888,8 +893,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} =
|
||||
MobilizonWeb.API.Comments.create_comment(actor.preferred_username, "hey")
|
||||
{:ok, activity, _} = API.Comments.create_comment(actor.preferred_username, "hey")
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
@ -899,8 +903,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
test "it strips internal hashtag data" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} =
|
||||
MobilizonWeb.API.Comments.create_comment(actor.preferred_username, "#2hu")
|
||||
{:ok, activity, _} = API.Comments.create_comment(actor.preferred_username, "#2hu")
|
||||
|
||||
expected_tag = %{
|
||||
"href" => MobilizonWeb.Endpoint.url() <> "/tags/2hu",
|
||||
@ -916,8 +919,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
test "it strips internal fields" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} =
|
||||
MobilizonWeb.API.Comments.create_comment(actor.preferred_username, "#2hu")
|
||||
{:ok, activity, _} = API.Comments.create_comment(actor.preferred_username, "#2hu")
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
|
@ -1,10 +1,14 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.UtilsTest do
|
||||
use Mobilizon.DataCase
|
||||
import Mobilizon.Factory
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Service.ActivityPub.{Converter, Utils}
|
||||
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
@ -24,7 +28,7 @@ defmodule Mobilizon.Service.ActivityPub.UtilsTest do
|
||||
"id" => Routes.page_url(Endpoint, :comment, reply.uuid),
|
||||
"inReplyTo" => comment.url,
|
||||
"attributedTo" => reply.actor.url
|
||||
} == Mobilizon.Service.ActivityPub.Converters.Comment.model_to_as(reply)
|
||||
} == Converter.Comment.model_to_as(reply)
|
||||
end
|
||||
|
||||
test "comment data from map" do
|
||||
|
@ -1,12 +1,15 @@
|
||||
defmodule Mobilizon.Service.Admin.ActionLogServiceTest do
|
||||
@moduledoc """
|
||||
Test the ActionLogService module
|
||||
Test the ActionLogService module.
|
||||
"""
|
||||
|
||||
use Mobilizon.DataCase
|
||||
import Mobilizon.Service.Admin.ActionLogService
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
alias Mobilizon.Admin.ActionLog
|
||||
|
||||
import Mobilizon.Factory
|
||||
import Mobilizon.Service.Admin.ActionLogService
|
||||
|
||||
alias Mobilizon.Admin.ActionLog
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
|
||||
setup do
|
||||
moderator_user = insert(:user, role: :moderator)
|
||||
|
@ -1,13 +1,14 @@
|
||||
defmodule Mobilizon.Service.Geospatial.AddokTest do
|
||||
use Mobilizon.DataCase, async: false
|
||||
alias Mobilizon.Service.Geospatial.Addok
|
||||
alias Mobilizon.Addresses.Address
|
||||
|
||||
import Mock
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
@endpoint Application.get_env(:mobilizon, Mobilizon.Service.Geospatial.Addok)
|
||||
|> get_in([:endpoint])
|
||||
use Mobilizon.DataCase, async: false
|
||||
|
||||
import Mock
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Addok
|
||||
|
||||
@endpoint get_in(Application.get_env(:mobilizon, Addok), [:endpoint])
|
||||
@fake_endpoint "https://domain.tld"
|
||||
|
||||
describe "search address" do
|
||||
|
@ -1,10 +1,12 @@
|
||||
defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase, async: false
|
||||
alias Mobilizon.Service.Geospatial.GoogleMaps
|
||||
alias Mobilizon.Addresses.Address
|
||||
|
||||
import Mock
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.GoogleMaps
|
||||
|
||||
describe "search address" do
|
||||
test "without API Key triggers an error" do
|
||||
|
@ -1,10 +1,12 @@
|
||||
defmodule Mobilizon.Service.Geospatial.MapQuestTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase, async: false
|
||||
alias Mobilizon.Service.Geospatial.MapQuest
|
||||
alias Mobilizon.Addresses.Address
|
||||
|
||||
import Mock
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.MapQuest
|
||||
|
||||
describe "search address" do
|
||||
test "without API Key triggers an error" do
|
||||
|
@ -1,10 +1,12 @@
|
||||
defmodule Mobilizon.Service.Geospatial.NominatimTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase, async: false
|
||||
alias Mobilizon.Service.Geospatial.Nominatim
|
||||
alias Mobilizon.Addresses.Address
|
||||
|
||||
import Mock
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Nominatim
|
||||
|
||||
describe "search address" do
|
||||
test "produces a valid search address with options" do
|
||||
|
@ -1,10 +1,12 @@
|
||||
defmodule Mobilizon.Service.Geospatial.PhotonTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase, async: false
|
||||
alias Mobilizon.Service.Geospatial.Photon
|
||||
alias Mobilizon.Addresses.Address
|
||||
|
||||
import Mock
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Photon
|
||||
|
||||
describe "search address" do
|
||||
test "produces a valid search address with options" do
|
||||
|
@ -5,10 +5,11 @@ defmodule MobilizonWeb.API.ReportTest do
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.{Comment, Event}
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
alias Mobilizon.Service.Formatter
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Service.ActivityPub.Activity
|
||||
|
||||
alias MobilizonWeb.API.Reports
|
||||
|
||||
@ -86,7 +87,7 @@ defmodule MobilizonWeb.API.ReportTest do
|
||||
_comment_2 = insert(:comment, actor: reported)
|
||||
|
||||
comment = "This is really not acceptable, remote admin I don't know"
|
||||
encoded_comment = Mobilizon.Service.Formatter.html_escape(comment, "text/plain")
|
||||
encoded_comment = Formatter.html_escape(comment, "text/plain")
|
||||
|
||||
assert {:ok, %Activity{} = flag_activity, _} =
|
||||
Reports.report(%{
|
||||
|
@ -1,17 +1,17 @@
|
||||
defmodule MobilizonWeb.API.SearchTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
import Mock
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Storage.Page
|
||||
|
||||
alias MobilizonWeb.API.Search
|
||||
|
||||
import Mock
|
||||
|
||||
test "search an user by username" do
|
||||
with_mock ActivityPub,
|
||||
find_or_make_actor_from_nickname: fn "toto@domain.tld" -> {:ok, %Actor{id: 42}} end do
|
||||
|
@ -4,16 +4,20 @@
|
||||
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/test/web/web_finger/web_finger_controller_test.exs
|
||||
|
||||
defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
alias MobilizonWeb.ActivityPub.ActorView
|
||||
alias MobilizonWeb.PageView
|
||||
|
||||
alias Mobilizon.{Actors, Config}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
alias MobilizonWeb.ActivityPub.ActorView
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.PageView
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
setup do
|
||||
conn = build_conn() |> put_req_header("accept", "application/activity+json")
|
||||
|
@ -1,8 +1,10 @@
|
||||
defmodule MobilizonWeb.FeedControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
describe "/@:preferred_username/feed/atom" do
|
||||
test "it returns an RSS representation of the actor's public events if the actor is publicly visible",
|
||||
@ -16,7 +18,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :actor, actor.preferred_username, "atom")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:actor, actor.preferred_username, "atom")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -48,7 +51,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :actor, actor.preferred_username, "atom")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:actor, actor.preferred_username, "atom")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -63,7 +67,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :actor, actor.preferred_username, "atom")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:actor, actor.preferred_username, "atom")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -93,7 +98,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :actor, actor.preferred_username, "ics")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:actor, actor.preferred_username, "ics")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -121,7 +127,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :actor, actor.preferred_username, "ics")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:actor, actor.preferred_username, "ics")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -136,7 +143,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn
|
||||
|> put_req_header("accept", "text/calendar")
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :actor, actor.preferred_username, "ics")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:actor, actor.preferred_username, "ics")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -163,7 +171,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :event, event1.uuid, "ics")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:event, event1.uuid, "ics")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -194,7 +203,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :going, feed_token.token, "atom")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:going, feed_token.token, "atom")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -228,7 +238,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :going, feed_token.token, "atom")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:going, feed_token.token, "atom")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -247,7 +258,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :going, "not existing", "atom")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:going, "not existing", "atom")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -272,7 +284,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn
|
||||
|> put_req_header("accept", "text/calendar")
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :going, feed_token.token, "ics")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:going, feed_token.token, "ics")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -302,7 +315,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn
|
||||
|> put_req_header("accept", "text/calendar")
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :going, feed_token.token, "ics")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:going, feed_token.token, "ics")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
@ -318,7 +332,8 @@ defmodule MobilizonWeb.FeedControllerTest do
|
||||
conn =
|
||||
conn
|
||||
|> get(
|
||||
Routes.feed_url(Endpoint, :going, "not existing", "ics")
|
||||
Endpoint
|
||||
|> Routes.feed_url(:going, "not existing", "ics")
|
||||
|> URI.decode()
|
||||
)
|
||||
|
||||
|
@ -3,27 +3,20 @@ defmodule MobilizonWeb.NodeInfoControllerTest do
|
||||
|
||||
alias Mobilizon.Config
|
||||
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
test "Get node info schemas", %{conn: conn} do
|
||||
conn = get(conn, node_info_path(conn, :schemas))
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"links" => [
|
||||
%{
|
||||
"href" =>
|
||||
MobilizonWeb.Router.Helpers.node_info_url(
|
||||
MobilizonWeb.Endpoint,
|
||||
:nodeinfo,
|
||||
"2.0"
|
||||
),
|
||||
"href" => Routes.node_info_url(Endpoint, :nodeinfo, "2.0"),
|
||||
"rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0"
|
||||
},
|
||||
%{
|
||||
"href" =>
|
||||
MobilizonWeb.Router.Helpers.node_info_url(
|
||||
MobilizonWeb.Endpoint,
|
||||
:nodeinfo,
|
||||
"2.1"
|
||||
),
|
||||
"href" => Routes.node_info_url(Endpoint, :nodeinfo, "2.1"),
|
||||
"rel" => "http://nodeinfo.diaspora.software/ns/schema/2.1"
|
||||
}
|
||||
]
|
||||
|
@ -1,9 +1,12 @@
|
||||
defmodule MobilizonWeb.PageControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
|
||||
setup do
|
||||
conn = build_conn() |> put_req_header("accept", "text/html")
|
||||
|
@ -1,12 +1,15 @@
|
||||
defmodule MobilizonWeb.Resolvers.AdminResolverTest do
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
alias MobilizonWeb.API
|
||||
|
||||
describe "Resolver: List the action logs" do
|
||||
@note_content "This a note on a report"
|
||||
@ -18,12 +21,11 @@ defmodule MobilizonWeb.Resolvers.AdminResolverTest do
|
||||
%Actor{} = moderator_2 = insert(:actor, user: user_moderator_2)
|
||||
|
||||
%Report{} = report = insert(:report)
|
||||
MobilizonWeb.API.Reports.update_report_status(moderator, report, "resolved")
|
||||
API.Reports.update_report_status(moderator, report, "resolved")
|
||||
|
||||
{:ok, %Note{} = note} =
|
||||
MobilizonWeb.API.Reports.create_report_note(report, moderator_2, @note_content)
|
||||
{:ok, %Note{} = note} = API.Reports.create_report_note(report, moderator_2, @note_content)
|
||||
|
||||
MobilizonWeb.API.Reports.delete_report_note(note, moderator_2)
|
||||
API.Reports.delete_report_note(note, moderator_2)
|
||||
|
||||
query = """
|
||||
{
|
||||
|
@ -1,12 +1,14 @@
|
||||
defmodule MobilizonWeb.Resolvers.ReportResolverTest do
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
use MobilizonWeb.ConnCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
|
||||
describe "Resolver: Report a content" do
|
||||
test "create_report/3 creates a report", %{conn: conn} do
|
||||
|
@ -33,7 +33,8 @@ defmodule MobilizonWeb.Resolvers.TagResolverTest do
|
||||
tags = json_response(res, 200)["data"]["tags"]
|
||||
assert tags |> length == 3
|
||||
|
||||
assert Enum.filter(tags, fn tag -> tag["slug"] == tag1.slug end)
|
||||
assert tags
|
||||
|> Enum.filter(fn tag -> tag["slug"] == tag1.slug end)
|
||||
|> hd
|
||||
|> Map.get("related")
|
||||
|> Enum.map(fn tag -> tag["slug"] end)
|
||||
|
@ -9,8 +9,8 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||
alias Mobilizon.{Actors, Config, Users}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Users.ResetPassword
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.{AbsintheHelpers, Email}
|
||||
|
||||
|
@ -198,7 +198,7 @@ defmodule Mobilizon.UploadTest do
|
||||
end
|
||||
end
|
||||
|
||||
defp upload() do
|
||||
defp upload do
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
file = %Plug.Upload{
|
||||
|
@ -15,6 +15,10 @@ defmodule MobilizonWeb.ChannelCase do
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
alias Ecto.Adapters.SQL.Sandbox, as: Adapter
|
||||
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
using do
|
||||
quote do
|
||||
# Import conveniences for testing with channels
|
||||
@ -26,11 +30,9 @@ defmodule MobilizonWeb.ChannelCase do
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Storage.Repo)
|
||||
:ok = Adapter.checkout(Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Storage.Repo, {:shared, self()})
|
||||
end
|
||||
unless tags[:async], do: Adapter.mode(Repo, {:shared, self()})
|
||||
|
||||
:ok
|
||||
end
|
||||
|
@ -15,6 +15,11 @@ defmodule MobilizonWeb.ConnCase do
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
alias Ecto.Adapters.SQL.Sandbox, as: Adapter
|
||||
|
||||
alias Mobilizon.Storage.Repo
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
using do
|
||||
quote do
|
||||
# Import conveniences for testing with connections
|
||||
@ -24,7 +29,7 @@ defmodule MobilizonWeb.ConnCase do
|
||||
# The default endpoint for testing
|
||||
@endpoint MobilizonWeb.Endpoint
|
||||
|
||||
def auth_conn(%Plug.Conn{} = conn, %Mobilizon.Users.User{} = user) do
|
||||
def auth_conn(%Plug.Conn{} = conn, %User{} = user) do
|
||||
{:ok, token, _claims} = MobilizonWeb.Guardian.encode_and_sign(user)
|
||||
|
||||
conn
|
||||
@ -35,11 +40,9 @@ defmodule MobilizonWeb.ConnCase do
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Storage.Repo)
|
||||
:ok = Adapter.checkout(Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Storage.Repo, {:shared, self()})
|
||||
end
|
||||
unless tags[:async], do: Adapter.mode(Repo, {:shared, self()})
|
||||
|
||||
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
||||
end
|
||||
|
@ -14,7 +14,10 @@ defmodule Mobilizon.DataCase do
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
alias Ecto.Adapters.SQL.Sandbox, as: Adapter
|
||||
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
using do
|
||||
quote do
|
||||
@ -28,11 +31,9 @@ defmodule Mobilizon.DataCase do
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Storage.Repo)
|
||||
:ok = Adapter.checkout(Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Storage.Repo, {:shared, self()})
|
||||
end
|
||||
unless tags[:async], do: Adapter.mode(Repo, {:shared, self()})
|
||||
|
||||
:ok
|
||||
end
|
||||
|
@ -8,8 +8,8 @@ defmodule Mobilizon.Factory do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Crypto
|
||||
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Endpoint
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Upload
|
||||
|
||||
def user_factory do
|
||||
|
@ -1,9 +1,10 @@
|
||||
defmodule Mobilizon.Service.Geospatial.Mock do
|
||||
@moduledoc """
|
||||
Mock for Geospatial Provider implementations
|
||||
Mock for Geospatial Provider implementations.
|
||||
"""
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Service.Geospatial.Provider
|
||||
|
||||
@behaviour Provider
|
||||
|
||||
|
@ -3,12 +3,14 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Mobilizon.RelayTest do
|
||||
alias Mobilizon.Actors.{Actor, Follower}
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Service.ActivityPub.Relay
|
||||
use Mobilizon.DataCase
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
use Mobilizon.DataCase
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{Actor, Follower}
|
||||
alias Mobilizon.Service.ActivityPub.Relay
|
||||
|
||||
describe "running follow" do
|
||||
test "relay is followed" do
|
||||
use_cassette "relay/fetch_relay_follow" do
|
||||
|
Loading…
Reference in New Issue
Block a user