Spec fixes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-10-05 17:43:45 +02:00
parent 76bc409f68
commit dee7c58449
33 changed files with 193 additions and 234 deletions

View File

@@ -48,20 +48,18 @@ defmodule Mobilizon.Admin do
@spec log_action(Actor.t(), String.t(), struct()) ::
{:ok, ActionLog.t()} | {:error, Ecto.Changeset.t() | :user_not_moderator}
def log_action(%Actor{user_id: user_id, id: actor_id}, action, target) do
with %User{role: role} <- Users.get_user!(user_id),
{:role, true} <- {:role, role in [:administrator, :moderator]},
{:ok, %ActionLog{} = create_action_log} <-
Admin.create_action_log(%{
"actor_id" => actor_id,
"target_type" => to_string(target.__struct__),
"target_id" => target.id,
"action" => action,
"changes" => stringify_struct(target)
}) do
{:ok, create_action_log}
%User{role: role} = Users.get_user!(user_id)
if role in [:administrator, :moderator] do
Admin.create_action_log(%{
"actor_id" => actor_id,
"target_type" => to_string(target.__struct__),
"target_id" => target.id,
"action" => action,
"changes" => stringify_struct(target)
})
else
{:role, false} ->
{:error, :user_not_moderator}
{:error, :user_not_moderator}
end
end

View File

@@ -115,13 +115,13 @@ defmodule Mobilizon.Discussions.Comment do
@doc """
Checks whether an comment can be managed.
"""
@spec can_be_managed_by(t, integer | String.t()) :: boolean
def can_be_managed_by(%__MODULE__{actor_id: creator_actor_id}, actor_id)
@spec can_be_managed_by?(t, integer | String.t()) :: boolean()
def can_be_managed_by?(%__MODULE__{actor_id: creator_actor_id}, actor_id)
when creator_actor_id == actor_id do
{:comment_can_be_managed, true}
creator_actor_id == actor_id
end
def can_be_managed_by(_comment, _actor), do: {:comment_can_be_managed, false}
def can_be_managed_by?(_comment, _actor), do: false
defp common_changeset(%__MODULE__{} = comment, attrs) do
comment

View File

@@ -572,7 +572,7 @@ defmodule Mobilizon.Events do
@doc """
Returns the list of tags.
"""
@spec list_tags(String.t() | nil, integer | nil, integer | nil) :: [Tag.t()]
@spec list_tags(String.t() | nil, integer | nil, integer | nil) :: Page.t(Tag.t())
def list_tags(filter \\ nil, page \\ nil, limit \\ nil) do
Tag
|> tag_filter(filter)
@@ -608,7 +608,7 @@ defmodule Mobilizon.Events do
Creates a relation between two tags.
"""
@spec create_tag_relation(map) :: {:ok, TagRelation.t()} | {:error, Changeset.t()}
def create_tag_relation(attrs \\ {}) do
def create_tag_relation(attrs) do
%TagRelation{}
|> TagRelation.changeset(attrs)
|> Repo.insert(

View File

@@ -131,7 +131,7 @@ defmodule Mobilizon.Posts do
|> Repo.all()
end
@spec tags_for_post_query(integer) :: Ecto.Query.t()
@spec tags_for_post_query(String.t()) :: Ecto.Query.t()
defp tags_for_post_query(post_id) do
from(
t in Tag,

View File

@@ -49,7 +49,8 @@ defmodule Mobilizon.Reports do
@doc """
Returns the list of reports.
"""
@spec list_reports(integer | nil, integer | nil, atom, atom, ReportStatus) :: Page.t()
@spec list_reports(integer | nil, integer | nil, atom, atom, ReportStatus.t()) ::
Page.t(Report.t())
def list_reports(
page \\ nil,
limit \\ nil,

View File

@@ -10,7 +10,7 @@ defmodule Mobilizon.Storage.Repo do
@doc """
Dynamically loads the repository url from the DATABASE_URL environment variable.
"""
@spec init(any(), any()) :: any()
@spec init(any(), any()) :: {:ok, Keyword.t()}
def init(_, opts) do
{:ok, opts}
end

View File

@@ -31,8 +31,8 @@ defmodule Mobilizon.Users.User do
feed_tokens: [FeedToken.t()],
last_sign_in_at: DateTime.t(),
last_sign_in_ip: String.t(),
current_sign_in_ip: String.t(),
current_sign_in_at: DateTime.t(),
current_sign_in_ip: String.t() | nil,
current_sign_in_at: DateTime.t() | nil,
activity_settings: [ActivitySetting.t()],
settings: Setting.t(),
unconfirmed_email: String.t() | nil