Fix various issues reported by Dializer

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-01-06 18:48:48 +01:00 committed by tykayn
parent 19005d3199
commit d5545e01b0
12 changed files with 27 additions and 25 deletions

View File

@ -108,15 +108,15 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do
@doc """
Create an actor inside our database from username, using WebFinger to find out its AP ID and then fetch it
"""
@spec make_actor_from_nickname(nickname :: String.t(), preload :: boolean) ::
@spec make_actor_from_nickname(nickname :: String.t(), options :: Keyword.t()) ::
{:ok, Actor.t()} | {:error, make_actor_errors | WebFinger.finger_errors()}
def make_actor_from_nickname(nickname, preload \\ false) do
def make_actor_from_nickname(nickname, options \\ []) do
Logger.debug("Fingering actor from nickname #{nickname}")
case WebFinger.finger(nickname) do
{:ok, url} when is_binary(url) ->
Logger.debug("Matched #{nickname} to URL #{url}, now making actor")
make_actor_from_url(url, preload: preload)
make_actor_from_url(url, options)
{:error, e} ->
{:error, e}

View File

@ -20,7 +20,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
@doc """
Get audience for an entity
"""
@spec get_audience(Entity.t()) :: audience()
@spec get_audience(Entity.t() | Participant.t()) :: audience()
def get_audience(%Event{} = event) do
extract_actors_from_event(event)
end

View File

@ -190,7 +190,7 @@ defmodule Mobilizon.Federation.ActivityPub.Refresher do
# If we're handling an activity
@spec handling_element(map()) :: {:ok, any, struct} | :error
@spec handling_element(String.t()) :: {:ok, struct} | {:error, any()}
@spec handling_element(String.t()) :: {:ok, struct} | {:ok, atom, struct} | {:error, any()}
defp handling_element(%{"type" => activity_type} = data)
when activity_type in ["Create", "Update", "Delete"] do
object = get_in(data, ["object"])

View File

@ -69,7 +69,8 @@ defmodule Mobilizon.GraphQL.API.Follows do
)
case Actors.check_follow(follower, followed) do
%Follower{approved: false} ->
%Follower{approved: false} = follow ->
Actors.delete_follower(follow)
{:error, "Follow already rejected"}
%Follower{} = follow ->

View File

@ -130,7 +130,7 @@ defmodule Mix.Tasks.Mobilizon.Instance do
options,
:listen_port,
"What port will the app listen to (leave it if you are using the default setup with nginx)?",
4000
"4000"
)
instance_secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)

View File

@ -67,10 +67,6 @@ defmodule Mix.Tasks.Mobilizon.Users.New do
{:error, %Ecto.Changeset{errors: errors}} ->
shell_error(inspect(errors))
shell_error("User has not been created because of the above reason.")
err ->
shell_error(inspect(err))
shell_error("User has not been created because of an unknown reason.")
end
end

View File

@ -1475,7 +1475,7 @@ defmodule Mobilizon.Actors do
|> where([_q, ..., a], like(a.name, ^"%#{name}%") or like(a.preferred_username, ^"%#{name}%"))
end
@spec join_members_actor(Ecto.Query.t()) :: Ecto.Query.t()
@spec join_members_actor(Ecto.Queryable.t()) :: Ecto.Query.t()
defp join_members_actor(query) do
join(query, :inner, [q], a in Actor, on: q.actor_id == a.id)
end

View File

@ -8,7 +8,12 @@ defmodule Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker do
@impl Oban.Worker
def perform(%Job{}) do
if Mobilizon.Config.get!([:instance, :remove_unconfirmed_users]) and should_perform?() do
remove_unconfirmed_users =
:mobilizon
|> Application.get_env(:instance)
|> Keyword.get(:remove_unconfirmed_users, false)
if remove_unconfirmed_users and should_perform?() do
CleanUnconfirmedUsers.clean()
end
end

View File

@ -41,7 +41,7 @@ defmodule Mobilizon.Service.Workers.Helper do
alias Oban.Job
@spec enqueue(String.t(), map(), Keyword.t()) ::
@spec enqueue(String.t() | :atom, map(), Keyword.t()) ::
{:ok, Job.t()} | {:error, Ecto.Changeset.t()}
def enqueue(operation, params, worker_args \\ []) do
params = Map.merge(%{"op" => operation}, params)

View File

@ -30,7 +30,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActorTest do
HostMetaClientMock
|> expect(:call, fn
%{method: :get, url: "http://framapiaf.org/.well-known/host-meta"}, _opts ->
%{method: :get, url: "https://framapiaf.org/.well-known/host-meta"}, _opts ->
{:ok, %Tesla.Env{status: 404, body: ""}}
end)
@ -43,7 +43,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActorTest do
|> expect(:call, fn
%{
method: :get,
url: "http://framapiaf.org/.well-known/webfinger?resource=acct:tcit@framapiaf.org"
url: "https://framapiaf.org/.well-known/webfinger?resource=acct:tcit@framapiaf.org"
},
_opts ->
{:ok, %Tesla.Env{status: 200, body: webfinger_data}}
@ -69,7 +69,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActorTest do
HostMetaClientMock
|> expect(:call, fn
%{method: :get, url: "http://framapiaf.org/.well-known/host-meta"}, _opts ->
%{method: :get, url: "https://framapiaf.org/.well-known/host-meta"}, _opts ->
{:ok, %Tesla.Env{status: 404, body: ""}}
end)
@ -82,7 +82,7 @@ defmodule Mobilizon.Federation.ActivityPub.ActorTest do
|> expect(:call, fn
%{
method: :get,
url: "http://framapiaf.org/.well-known/webfinger?resource=acct:tcit@framapiaf.org"
url: "https://framapiaf.org/.well-known/webfinger?resource=acct:tcit@framapiaf.org"
},
_opts ->
{:ok, %Tesla.Env{status: 200, body: webfinger_data}}

View File

@ -72,7 +72,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
HostMetaClientMock
|> expect(:call, fn
%{method: :get, url: "http://social.tcit.fr/.well-known/host-meta"}, _opts ->
%{method: :get, url: "https://social.tcit.fr/.well-known/host-meta"}, _opts ->
{:ok, %Tesla.Env{status: 200, body: host_meta_xml}}
end)
@ -100,7 +100,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
HostMetaClientMock
|> expect(:call, fn
%{method: :get, url: "http://pleroma.soykaf.com/.well-known/host-meta"}, _opts ->
%{method: :get, url: "https://pleroma.soykaf.com/.well-known/host-meta"}, _opts ->
{:ok, %Tesla.Env{status: 200, body: host_meta_xml}}
end)
@ -127,7 +127,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
HostMetaClientMock
|> expect(:call, fn
%{method: :get, url: "http://framatube.org/.well-known/host-meta"}, _opts ->
%{method: :get, url: "https://framatube.org/.well-known/host-meta"}, _opts ->
{:ok, %Tesla.Env{status: 200, body: host_meta_xml}}
end)
@ -154,7 +154,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
HostMetaClientMock
|> expect(:call, fn
%{method: :get, url: "http://squeet.me/.well-known/host-meta"}, _opts ->
%{method: :get, url: "https://squeet.me/.well-known/host-meta"}, _opts ->
{:ok, %Tesla.Env{status: 200, body: host_meta_xml}}
end)
@ -182,7 +182,7 @@ defmodule Mobilizon.Federation.WebFingerTest do
HostMetaClientMock
|> expect(:call, fn
%{method: :get, url: "http://demo.gancio.org/.well-known/host-meta"}, _opts ->
%{method: :get, url: "https://demo.gancio.org/.well-known/host-meta"}, _opts ->
{:ok, %Tesla.Env{status: 200, body: host_meta_xml}}
end)

View File

@ -301,7 +301,7 @@ defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
HostMetaClientMock
|> expect(:call, fn
%{method: :get, url: "http://nowhere.absolute/.well-known/host-meta"}, _opts ->
%{method: :get, url: "https://nowhere.absolute/.well-known/host-meta"}, _opts ->
{:ok, %Tesla.Env{status: 404, body: ""}}
end)
@ -310,7 +310,7 @@ defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
%{
method: :get,
url:
"http://nowhere.absolute/.well-known/webfinger?resource=acct:not_existing@nowhere.absolute"
"https://nowhere.absolute/.well-known/webfinger?resource=acct:not_existing@nowhere.absolute"
},
_opts ->
{:ok, %Tesla.Env{status: 404, body: ""}}