Fix some typespecs

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-04-18 14:38:57 +02:00
parent 714e9216c1
commit 83f2880dd9
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
33 changed files with 76 additions and 60 deletions

View file

@ -1,7 +1,7 @@
defmodule Mobilizon.Federation.ActivityPub.Types.Actors do
@moduledoc false
alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, Follower, Member, MemberRole}
alias Mobilizon.Actors.{Actor, Follower, Member}
alias Mobilizon.Federation.ActivityPub.{Actions, Audience, Permission, Relay}
alias Mobilizon.Federation.ActivityPub.Types.Entity
alias Mobilizon.Federation.ActivityStream
@ -244,7 +244,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Actors do
Actor.t(),
ActivityStreams.t(),
Member.t(),
MemberRole.t()
atom()
) ::
{:ok, ActivityStreams.t(), Member.t()}
defp approve_if_default_role_is_member(

View file

@ -3,7 +3,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Events, as: EventsManager
alias Mobilizon.Events.{Event, Participant, ParticipantRole}
alias Mobilizon.Events.{Event, Participant}
alias Mobilizon.Federation.ActivityPub.{Actions, Audience, Permission}
alias Mobilizon.Federation.ActivityPub.Types.Entity
alias Mobilizon.Federation.ActivityStream
@ -191,7 +191,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
Event.t(),
ActivityStreams.t(),
Participant.t(),
ParticipantRole.t()
atom()
) :: {:ok, ActivityStreams.t(), Participant.t()} | {:accept, any()}
defp approve_if_default_role_is_participant(event, activity_data, participant, role) do
case event do
@ -217,7 +217,7 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
end
end
@spec do_approve(Event.t(), ActivityStreams.t(), Particpant.t(), ParticipantRole.t(), map()) ::
@spec do_approve(Event.t(), ActivityStreams.t(), Particpant.t(), atom(), map()) ::
{:accept, any} | {:ok, ActivityStreams.t(), Participant.t()}
defp do_approve(event, activity_data, participant, role, additionnal) do
cond do

View file

@ -1,7 +1,7 @@
defmodule Mobilizon.Federation.ActivityPub.Types.Members do
@moduledoc false
alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, Member, MemberRole}
alias Mobilizon.Actors.{Actor, Member}
alias Mobilizon.Federation.ActivityPub.Actions
alias Mobilizon.Federation.ActivityStream
alias Mobilizon.Federation.ActivityStream.Convertible
@ -89,8 +89,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Members do
@spec check_admins_left?(
String.t() | integer,
String.t() | integer,
MemberRole.t(),
MemberRole.t()
atom(),
atom()
) :: boolean
defp check_admins_left?(member_id, group_id, current_role, updated_role) do
Actors.is_only_administrator?(member_id, group_id) && current_role == :administrator &&

View file

@ -22,7 +22,7 @@ defmodule Mobilizon.GraphQL.API.Reports do
@doc """
Update the state of a report
"""
@spec update_report_status(Actor.t(), Report.t(), ReportStatus.t()) ::
@spec update_report_status(Actor.t(), Report.t(), atom()) ::
{:ok, Report.t()} | {:error, Ecto.Changeset.t() | String.t()}
def update_report_status(%Actor{} = actor, %Report{} = report, state) do
if ReportStatus.valid_value?(state) do

View file

@ -4,7 +4,7 @@ defmodule Mobilizon.GraphQL.API.Search do
"""
alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, ActorType}
alias Mobilizon.Actors.Actor
alias Mobilizon.Events
alias Mobilizon.Events.Event
alias Mobilizon.Storage.Page
@ -18,7 +18,7 @@ defmodule Mobilizon.GraphQL.API.Search do
@doc """
Searches actors.
"""
@spec search_actors(map(), integer | nil, integer | nil, ActorType.t()) ::
@spec search_actors(map(), integer | nil, integer | nil, atom()) ::
{:ok, Page.t(Actor.t())} | {:error, String.t()}
def search_actors(%{term: term} = args, page \\ 1, limit \\ 10, result_type) do
term = String.trim(term)

View file

@ -5,7 +5,7 @@ defmodule Mobilizon.GraphQL.Middleware.ErrorHandler do
alias Mobilizon.GraphQL.Error
@behaviour Absinthe.Middleware
@impl true
@impl Absinthe.Middleware
def call(resolution, _config) do
errors =
resolution.errors

View file

@ -345,7 +345,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
end
end
@spec change_role(User.t(), Mobilizon.Users.UserRole.t(), boolean()) ::
@spec change_role(User.t(), atom(), boolean()) ::
{:ok, User.t()} | {:error, String.t() | Ecto.Changeset.t()}
defp change_role(%User{role: old_role} = user, new_role, notify) do
if old_role != new_role do

View file

@ -10,7 +10,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
alias Mobilizon.Federation.ActivityPub.Actions
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
alias Mobilizon.GraphQL.API
alias Mobilizon.Users.{User, UserRole}
alias Mobilizon.Users.User
alias Mobilizon.Web.Upload
import Mobilizon.Web.Gettext
@ -192,7 +192,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
{:error, "You need to be logged-in to create a group"}
end
@spec can_create_group?(UserRole.t()) :: boolean()
@spec can_create_group?(atom()) :: boolean()
defp can_create_group?(role) do
if Config.only_admin_can_create_groups?() do
is_admin(role)

View file

@ -21,13 +21,13 @@ defmodule Mobilizon.Activities.Activity do
@attrs @required_attrs ++ @optional_attrs
@type t :: %__MODULE__{
priority: Priority.t(),
type: Type.t(),
subject: Subject.t(),
priority: pos_integer(),
type: String.t(),
subject: String.t(),
subject_params: map(),
message: String.t(),
message_params: map(),
object_type: ObjectType.t(),
object_type: String.t(),
object_id: String.t(),
object: map(),
author: Actor.t(),

View file

@ -33,15 +33,15 @@ defmodule Mobilizon.Actors.Actor do
resources_url: String.t(),
posts_url: String.t(),
events_url: String.t(),
type: ActorType.t(),
type: atom(),
name: String.t() | nil,
domain: String.t() | nil,
summary: String.t(),
preferred_username: String.t(),
keys: String.t(),
manually_approves_followers: boolean,
openness: ActorOpenness.t(),
visibility: ActorVisibility.t(),
openness: atom(),
visibility: atom(),
suspended: boolean,
avatar: File.t() | nil,
banner: File.t() | nil,
@ -358,7 +358,7 @@ defmodule Mobilizon.Actors.Actor do
# When we don't even have any preferred_username, don't even try validating preferred_username
defp unique_username_validator(changeset), do: changeset
@spec build_urls(Ecto.Changeset.t(), ActorType.t()) :: Ecto.Changeset.t()
@spec build_urls(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
defp build_urls(changeset, type \\ :Person)
defp build_urls(%Ecto.Changeset{changes: %{preferred_username: username}} = changeset, type) do

View file

@ -145,7 +145,7 @@ defmodule Mobilizon.Actors do
@doc """
Gets an actor by name.
"""
@spec get_actor_by_name(String.t(), ActorType.t() | nil) :: Actor.t() | nil
@spec get_actor_by_name(String.t(), atom() | nil) :: Actor.t() | nil
def get_actor_by_name(name, type \\ nil) do
Actor
|> filter_by_type(type)
@ -1635,7 +1635,7 @@ defmodule Mobilizon.Actors do
|> preload([f, a], [:target_actor, :actor])
end
@spec filter_by_type(Ecto.Queryable.t(), ActorType.t() | nil) :: Ecto.Queryable.t()
@spec filter_by_type(Ecto.Queryable.t(), atom() | nil) :: Ecto.Queryable.t()
defp filter_by_type(query, type)
when type in [:Person, :Group, :Application, :Service, :Organisation] do
from(a in query, where: a.type == ^type)

View file

@ -14,7 +14,7 @@ defmodule Mobilizon.Actors.Member do
@type t :: %__MODULE__{
id: String.t(),
url: String.t(),
role: MemberRole.t(),
role: atom(),
parent: Actor.t(),
actor: Actor.t(),
metadata: Metadata.t()

View file

@ -22,7 +22,7 @@ defmodule Mobilizon.Discussions.Comment do
url: String.t(),
id: integer(),
local: boolean,
visibility: CommentVisibility.t(),
visibility: atom(),
uuid: Ecto.UUID.t(),
actor: Actor.t(),
attributed_to: Actor.t(),

View file

@ -43,10 +43,10 @@ defmodule Mobilizon.Events.Event do
description: String.t(),
ends_on: DateTime.t(),
title: String.t(),
status: EventStatus.t(),
status: atom(),
draft: boolean,
visibility: EventVisibility.t(),
join_options: JoinOptions.t(),
visibility: atom(),
join_options: atom(),
publish_at: DateTime.t() | nil,
uuid: Ecto.UUID.t(),
online_address: String.t() | nil,

View file

@ -442,7 +442,7 @@ defmodule Mobilizon.Events do
@spec list_organized_events_for_group(
Actor.t(),
EventVisibility.t() | :all,
atom(),
DateTime.t() | nil,
DateTime.t() | nil,
integer | nil,

View file

@ -16,7 +16,7 @@ defmodule Mobilizon.Events.Participant do
@type t :: %__MODULE__{
id: String.t(),
role: ParticipantRole.t(),
role: atom(),
code: String.t(),
url: String.t(),
event: Event.t(),

View file

@ -39,7 +39,7 @@ defmodule Mobilizon.Posts.Post do
body: String.t(),
title: String.t(),
draft: boolean,
visibility: PostVisibility.t(),
visibility: atom(),
publish_at: DateTime.t(),
author: Actor.t(),
attributed_to: Actor.t(),

View file

@ -17,7 +17,7 @@ defmodule Mobilizon.Reports.Report do
@type t :: %__MODULE__{
id: integer(),
content: String.t(),
status: ReportStatus.t(),
status: atom(),
url: String.t(),
reported: Actor.t(),
reporter: Actor.t(),

View file

@ -99,7 +99,7 @@ defmodule Mobilizon.Reports do
@spec delete_note(Note.t()) :: {:ok, Note.t()} | {:error, Ecto.Changeset.t()}
def delete_note(%Note{} = note), do: Repo.delete(note)
@spec list_reports_query(ReportStatus.t()) :: Ecto.Query.t()
@spec list_reports_query(atom()) :: Ecto.Query.t()
defp list_reports_query(status) do
Report
|> preload([:reported, :reporter, :manager, :event, :comments, :notes])

View file

@ -13,9 +13,9 @@ defmodule Mobilizon.Users.Setting do
notification_on_day: boolean,
notification_each_week: boolean,
notification_before_event: boolean,
notification_pending_participation: NotificationPendingNotificationDelay.t(),
notification_pending_membership: NotificationPendingNotificationDelay.t(),
group_notifications: NotificationPendingNotificationDelay.t(),
notification_pending_participation: non_neg_integer(),
notification_pending_membership: non_neg_integer(),
group_notifications: non_neg_integer(),
last_notification_sent: DateTime.t(),
user: User.t()
}

View file

@ -18,7 +18,7 @@ defmodule Mobilizon.Users.User do
email: String.t(),
password_hash: String.t(),
password: String.t(),
role: UserRole.t(),
role: atom(),
confirmed_at: DateTime.t() | nil,
confirmation_sent_at: DateTime.t(),
confirmation_token: String.t(),

View file

@ -1,6 +1,6 @@
defmodule Mobilizon.Service.ErrorReporting do
@moduledoc """
Mpdule to load and configure error reporting adapters
Module to load and configure error reporting adapters
"""
@callback enabled? :: boolean()

View file

@ -30,7 +30,7 @@ defmodule Mobilizon.Service.Export.Participants.Common do
@doc """
Match a participant role to it's translated version
"""
@spec translate_role(Mobilizon.Events.ParticipantRole.t()) :: String.t()
@spec translate_role(atom()) :: String.t()
def translate_role(role) do
case role do
:not_approved ->

View file

@ -93,7 +93,7 @@ defmodule Mobilizon.Service.Notifier.Email do
end
@spec match_group_notifications_setting(
NotificationPendingNotificationDelay.t(),
non_neg_integer(),
String.t(),
DateTime.t() | nil,
Keyword.t()

View file

@ -7,11 +7,12 @@ defmodule Mobilizon.Web.Upload.Filter.AnalyzeMetadata do
@moduledoc """
Extracts metadata about the upload, such as width/height
"""
require Logger
alias Mobilizon.Web.Upload
alias Mobilizon.Web.Upload.Filter
@behaviour Mobilizon.Web.Upload.Filter
@behaviour Filter
@impl Filter
@spec filter(Upload.t()) ::
{:ok, :filtered, Upload.t()} | {:ok, :noop}
def filter(%Upload{tempfile: file, content_type: "image" <> _} = upload) do
@ -23,6 +24,7 @@ defmodule Mobilizon.Web.Upload.Filter.AnalyzeMetadata do
{:ok, :filtered, %Upload{upload | width: image.width, height: image.height}}
rescue
e in ErlangError ->
require Logger
Logger.warn("#{__MODULE__}: #{inspect(e)}")
{:ok, :noop}
end

View file

@ -4,9 +4,11 @@ defmodule Mobilizon.Web.Upload.Filter.BlurHash do
"""
require Logger
alias Mobilizon.Web.Upload
alias Mobilizon.Web.Upload.Filter
@behaviour Mobilizon.Web.Upload.Filter
@behaviour Filter
@impl Filter
@spec filter(Upload.t()) ::
{:ok, :filtered, Upload.t()} | {:ok, :noop}
def filter(%Upload{tempfile: file, content_type: "image" <> _} = upload) do

View file

@ -7,9 +7,12 @@ defmodule Mobilizon.Web.Upload.Filter.Dedupe do
@moduledoc """
Names the file after its hash to avoid dedupes
"""
@behaviour Mobilizon.Web.Upload.Filter
alias Mobilizon.Web.Upload
alias Mobilizon.Web.Upload.Filter
@behaviour Filter
@impl Filter
@spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop}
def filter(%Upload{name: name, tempfile: tempfile} = upload) do
extension = name |> String.split(".") |> List.last()

View file

@ -8,12 +8,14 @@ defmodule Mobilizon.Web.Upload.Filter.Exiftool do
Also strips or replaces filesystem metadata e.g., timestamps.
"""
alias Mobilizon.Web.Upload
alias Mobilizon.Web.Upload.Filter
@behaviour Mobilizon.Web.Upload.Filter
@behaviour Filter
@spec filter(Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()}
# webp is not compatible with exiftool at this time
@impl Filter
def filter(%Upload{content_type: "image/webp"}), do: {:ok, :noop}
def filter(%Upload{tempfile: file, content_type: "image" <> _}) do

View file

@ -8,13 +8,15 @@ defmodule Mobilizon.Web.Upload.Filter.Mogrify do
Handle mogrify transformations
"""
@behaviour Mobilizon.Web.Upload.Filter
alias Mobilizon.Config
alias Mobilizon.Web.Upload.Filter
@behaviour Filter
@type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
@type conversions :: conversion() | [conversion()]
@impl Filter
@spec filter(Mobilizon.Web.Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()}
def filter(%Mobilizon.Web.Upload{tempfile: file, content_type: "image" <> _}) do
do_filter(file, Config.get!([__MODULE__, :args]))

View file

@ -2,13 +2,13 @@ defmodule Mobilizon.Web.Upload.Filter.Optimize do
@moduledoc """
Handle media optimizations
"""
@behaviour Mobilizon.Web.Upload.Filter
alias Mobilizon.Config
alias Mobilizon.Web.Upload
alias Mobilizon.Web.Upload.Filter
require Logger
@behaviour Filter
@default_optimizers [
JpegOptim,
PngQuant,
@ -18,6 +18,7 @@ defmodule Mobilizon.Web.Upload.Filter.Optimize do
Cwebp
]
@impl Filter
@spec filter(Upload.t()) :: {:ok, :filtered | :noop} | {:error, :file_not_found}
def filter(%Upload{tempfile: file, content_type: "image" <> _}) do
optimizers = Config.get([__MODULE__, :optimizers], @default_optimizers)

View file

@ -5,12 +5,15 @@ defmodule Mobilizon.Web.Upload.Filter.Resize do
This filter requires `Mobilizon.Web.Upload.Filter.AnalyzeMetadata` to be performed before.
"""
@behaviour Mobilizon.Web.Upload.Filter
alias Mobilizon.Web.Upload
alias Mobilizon.Web.Upload.Filter
@behaviour Filter
@maximum_width 1_920
@maximum_height 1_080
@impl Filter
@spec filter(Upload.t()) :: {:ok, :filtered, Upload.t()} | {:ok, :noop}
def filter(
%Upload{

View file

@ -8,17 +8,18 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do
Local uploader for files
"""
@behaviour Mobilizon.Web.Upload.Uploader
alias Mobilizon.Config
alias Mobilizon.Web.Upload
alias Mobilizon.Web.Upload.Uploader
@impl true
@behaviour Uploader
@impl Uploader
def get_file(_) do
{:ok, {:static_dir, upload_path()}}
end
@impl true
@impl Uploader
@spec put_file(Upload.t()) ::
:ok | {:ok, {:file, String.t()}} | {:error, :tempfile_no_longer_exists}
def put_file(%Upload{path: initial_path, tempfile: tempfile}) do
@ -38,7 +39,7 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do
end
end
@impl true
@impl Uploader
@spec remove_file(String.t()) ::
{:ok, {:file, String.t()}}
| {:error, :folder_not_empty}

View file

@ -3,7 +3,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.{Event, EventOptions, Participant, ParticipantRole}
alias Mobilizon.Events.{Event, EventOptions, Participant}
alias Mobilizon.Posts.Post
alias Mobilizon.Web.Endpoint
alias Mobilizon.Web.JsonLD.ObjectView
@ -166,7 +166,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
end
end
@spec reservation_status(ParticipantRole.t()) :: String.t()
@spec reservation_status(atom()) :: String.t()
defp reservation_status(:rejected), do: "https://schema.org/ReservationCancelled"
defp reservation_status(:not_confirmed), do: "https://schema.org/ReservationPending"
defp reservation_status(:not_approved), do: "https://schema.org/ReservationHold"