Fix invalid typespec references to Ecto.Changeset.t()

This commit is contained in:
Mark Felder 2024-01-20 16:47:50 -05:00
parent dc8045d766
commit 0b7d214211
7 changed files with 22 additions and 22 deletions

View File

@ -23,7 +23,7 @@ defmodule Pleroma.Bookmark do
end end
@spec create(Ecto.UUID.t(), Ecto.UUID.t()) :: @spec create(Ecto.UUID.t(), Ecto.UUID.t()) ::
{:ok, Bookmark.t()} | {:error, Changeset.t()} {:ok, Bookmark.t()} | {:error, Ecto.Changeset.t()}
def create(user_id, activity_id) do def create(user_id, activity_id) do
attrs = %{ attrs = %{
user_id: user_id, user_id: user_id,
@ -53,7 +53,7 @@ defmodule Pleroma.Bookmark do
end end
@spec destroy(Ecto.UUID.t(), Ecto.UUID.t()) :: @spec destroy(Ecto.UUID.t(), Ecto.UUID.t()) ::
{:ok, Bookmark.t()} | {:error, Changeset.t()} {:ok, Bookmark.t()} | {:error, Ecto.Changeset.t()}
def destroy(user_id, activity_id) do def destroy(user_id, activity_id) do
from(b in Bookmark, from(b in Bookmark,
where: b.user_id == ^user_id, where: b.user_id == ^user_id,

View File

@ -54,7 +54,7 @@ defmodule Pleroma.ConfigDB do
@spec get_by_params(map()) :: ConfigDB.t() | nil @spec get_by_params(map()) :: ConfigDB.t() | nil
def get_by_params(%{group: _, key: _} = params), do: Repo.get_by(ConfigDB, params) def get_by_params(%{group: _, key: _} = params), do: Repo.get_by(ConfigDB, params)
@spec changeset(ConfigDB.t(), map()) :: Changeset.t() @spec changeset(ConfigDB.t(), map()) :: Ecto.Changeset.t()
def changeset(config, params \\ %{}) do def changeset(config, params \\ %{}) do
config config
|> cast(params, [:key, :group, :value]) |> cast(params, [:key, :group, :value])
@ -138,7 +138,7 @@ defmodule Pleroma.ConfigDB do
end end
end end
@spec update_or_create(map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()} @spec update_or_create(map()) :: {:ok, ConfigDB.t()} | {:error, Ecto.Changeset.t()}
def update_or_create(params) do def update_or_create(params) do
params = Map.put(params, :value, to_elixir_types(params[:value])) params = Map.put(params, :value, to_elixir_types(params[:value]))
search_opts = Map.take(params, [:group, :key]) search_opts = Map.take(params, [:group, :key])
@ -175,7 +175,7 @@ defmodule Pleroma.ConfigDB do
end) end)
end end
@spec delete(ConfigDB.t() | map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()} @spec delete(ConfigDB.t() | map()) :: {:ok, ConfigDB.t()} | {:error, Ecto.Changeset.t()}
def delete(%ConfigDB{} = config), do: Repo.delete(config) def delete(%ConfigDB{} = config), do: Repo.delete(config)
def delete(params) do def delete(params) do

View File

@ -24,7 +24,7 @@ defmodule Pleroma.ReportNote do
end end
@spec create(Ecto.UUID.t(), Ecto.UUID.t(), String.t()) :: @spec create(Ecto.UUID.t(), Ecto.UUID.t(), String.t()) ::
{:ok, ReportNote.t()} | {:error, Changeset.t()} {:ok, ReportNote.t()} | {:error, Ecto.Changeset.t()}
def create(user_id, activity_id, content) do def create(user_id, activity_id, content) do
attrs = %{ attrs = %{
user_id: user_id, user_id: user_id,
@ -39,7 +39,7 @@ defmodule Pleroma.ReportNote do
end end
@spec destroy(Ecto.UUID.t()) :: @spec destroy(Ecto.UUID.t()) ::
{:ok, ReportNote.t()} | {:error, Changeset.t()} {:ok, ReportNote.t()} | {:error, Ecto.Changeset.t()}
def destroy(id) do def destroy(id) do
from(r in ReportNote, where: r.id == ^id) from(r in ReportNote, where: r.id == ^id)
|> Repo.one() |> Repo.one()

View File

@ -672,7 +672,7 @@ defmodule Pleroma.User do
|> validate_inclusion(:actor_type, ["Person", "Service"]) |> validate_inclusion(:actor_type, ["Person", "Service"])
end end
@spec update_as_admin(User.t(), map()) :: {:ok, User.t()} | {:error, Changeset.t()} @spec update_as_admin(User.t(), map()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
def update_as_admin(user, params) do def update_as_admin(user, params) do
params = Map.put(params, "password_confirmation", params["password"]) params = Map.put(params, "password_confirmation", params["password"])
changeset = update_as_admin_changeset(user, params) changeset = update_as_admin_changeset(user, params)
@ -693,7 +693,7 @@ defmodule Pleroma.User do
|> put_change(:password_reset_pending, false) |> put_change(:password_reset_pending, false)
end end
@spec reset_password(User.t(), map()) :: {:ok, User.t()} | {:error, Changeset.t()} @spec reset_password(User.t(), map()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
def reset_password(%User{} = user, params) do def reset_password(%User{} = user, params) do
reset_password(user, user, params) reset_password(user, user, params)
end end
@ -1783,14 +1783,14 @@ defmodule Pleroma.User do
BackgroundWorker.enqueue("user_activation", %{"user_id" => user.id, "status" => status}) BackgroundWorker.enqueue("user_activation", %{"user_id" => user.id, "status" => status})
end end
@spec set_activation([User.t()], boolean()) :: {:ok, User.t()} | {:error, Changeset.t()} @spec set_activation([User.t()], boolean()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
def set_activation(users, status) when is_list(users) do def set_activation(users, status) when is_list(users) do
Repo.transaction(fn -> Repo.transaction(fn ->
for user <- users, do: set_activation(user, status) for user <- users, do: set_activation(user, status)
end) end)
end end
@spec set_activation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()} @spec set_activation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
def set_activation(%User{} = user, status) do def set_activation(%User{} = user, status) do
with {:ok, user} <- set_activation_status(user, status) do with {:ok, user} <- set_activation_status(user, status) do
user user
@ -1868,7 +1868,7 @@ defmodule Pleroma.User do
|> update_and_set_cache() |> update_and_set_cache()
end end
@spec purge_user_changeset(User.t()) :: Changeset.t() @spec purge_user_changeset(User.t()) :: Ecto.Changeset.t()
def purge_user_changeset(user) do def purge_user_changeset(user) do
# "Right to be forgotten" # "Right to be forgotten"
# https://gdpr.eu/right-to-be-forgotten/ # https://gdpr.eu/right-to-be-forgotten/
@ -2359,7 +2359,7 @@ defmodule Pleroma.User do
updated_user updated_user
end end
@spec set_confirmation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()} @spec set_confirmation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
def set_confirmation(%User{} = user, bool) do def set_confirmation(%User{} = user, bool) do
user user
|> confirmation_changeset(set_confirmation: bool) |> confirmation_changeset(set_confirmation: bool)
@ -2537,7 +2537,7 @@ defmodule Pleroma.User do
|> update_and_set_cache() |> update_and_set_cache()
end end
@spec confirmation_changeset(User.t(), keyword()) :: Changeset.t() @spec confirmation_changeset(User.t(), keyword()) :: Ecto.Changeset.t()
def confirmation_changeset(user, set_confirmation: confirmed?) do def confirmation_changeset(user, set_confirmation: confirmed?) do
params = params =
if confirmed? do if confirmed? do
@ -2555,7 +2555,7 @@ defmodule Pleroma.User do
cast(user, params, [:is_confirmed, :confirmation_token]) cast(user, params, [:is_confirmed, :confirmation_token])
end end
@spec approval_changeset(User.t(), keyword()) :: Changeset.t() @spec approval_changeset(User.t(), keyword()) :: Ecto.Changeset.t()
def approval_changeset(user, set_approval: approved?) do def approval_changeset(user, set_approval: approved?) do
cast(user, %{is_approved: approved?}, [:is_approved]) cast(user, %{is_approved: approved?}, [:is_approved])
end end

View File

@ -64,7 +64,7 @@ defmodule Pleroma.UserInviteToken do
end end
@spec update_invite(UserInviteToken.t(), map()) :: @spec update_invite(UserInviteToken.t(), map()) ::
{:ok, UserInviteToken.t()} | {:error, Changeset.t()} {:ok, UserInviteToken.t()} | {:error, Ecto.Changeset.t()}
def update_invite(invite, changes) do def update_invite(invite, changes) do
change(invite, changes) |> Repo.update() change(invite, changes) |> Repo.update()
end end

View File

@ -28,7 +28,7 @@ defmodule Pleroma.Web.OAuth.Authorization do
end end
@spec create_authorization(App.t(), User.t() | %{}, [String.t()] | nil) :: @spec create_authorization(App.t(), User.t() | %{}, [String.t()] | nil) ::
{:ok, Authorization.t()} | {:error, Changeset.t()} {:ok, Authorization.t()} | {:error, Ecto.Changeset.t()}
def create_authorization(%App{} = app, %User{} = user, scopes \\ nil) do def create_authorization(%App{} = app, %User{} = user, scopes \\ nil) do
%{ %{
scopes: scopes || app.scopes, scopes: scopes || app.scopes,
@ -39,7 +39,7 @@ defmodule Pleroma.Web.OAuth.Authorization do
|> Repo.insert() |> Repo.insert()
end end
@spec create_changeset(map()) :: Changeset.t() @spec create_changeset(map()) :: Ecto.Changeset.t()
def create_changeset(attrs \\ %{}) do def create_changeset(attrs \\ %{}) do
%Authorization{} %Authorization{}
|> cast(attrs, [:user_id, :app_id, :scopes, :valid_until]) |> cast(attrs, [:user_id, :app_id, :scopes, :valid_until])
@ -58,7 +58,7 @@ defmodule Pleroma.Web.OAuth.Authorization do
put_change(changeset, :valid_until, NaiveDateTime.add(NaiveDateTime.utc_now(), lifespan)) put_change(changeset, :valid_until, NaiveDateTime.add(NaiveDateTime.utc_now(), lifespan))
end end
@spec use_changeset(Authtorizatiton.t(), map()) :: Changeset.t() @spec use_changeset(Authtorizatiton.t(), map()) :: Ecto.Changeset.t()
def use_changeset(%Authorization{} = auth, params) do def use_changeset(%Authorization{} = auth, params) do
auth auth
|> cast(params, [:used]) |> cast(params, [:used])
@ -66,7 +66,7 @@ defmodule Pleroma.Web.OAuth.Authorization do
end end
@spec use_token(Authorization.t()) :: @spec use_token(Authorization.t()) ::
{:ok, Authorization.t()} | {:error, Changeset.t()} | {:error, String.t()} {:ok, Authorization.t()} | {:error, Ecto.Changeset.t()} | {:error, String.t()}
def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do
if NaiveDateTime.diff(NaiveDateTime.utc_now(), valid_until) < 0 do if NaiveDateTime.diff(NaiveDateTime.utc_now(), valid_until) < 0 do
Repo.update(use_changeset(auth, %{used: true})) Repo.update(use_changeset(auth, %{used: true}))

View File

@ -56,7 +56,7 @@ defmodule Pleroma.Web.OAuth.Token do
|> Repo.find_resource() |> Repo.find_resource()
end end
@spec exchange_token(App.t(), Authorization.t()) :: {:ok, Token.t()} | {:error, Changeset.t()} @spec exchange_token(App.t(), Authorization.t()) :: {:ok, Token.t()} | {:error, Ecto.Changeset.t()}
def exchange_token(app, auth) do def exchange_token(app, auth) do
with {:ok, auth} <- Authorization.use_token(auth), with {:ok, auth} <- Authorization.use_token(auth),
true <- auth.app_id == app.id do true <- auth.app_id == app.id do
@ -95,7 +95,7 @@ defmodule Pleroma.Web.OAuth.Token do
|> validate_required([:valid_until]) |> validate_required([:valid_until])
end end
@spec create(App.t(), User.t(), map()) :: {:ok, Token} | {:error, Changeset.t()} @spec create(App.t(), User.t(), map()) :: {:ok, Token} | {:error, Ecto.Changeset.t()}
def create(%App{} = app, %User{} = user, attrs \\ %{}) do def create(%App{} = app, %User{} = user, attrs \\ %{}) do
with {:ok, token} <- do_create(app, user, attrs) do with {:ok, token} <- do_create(app, user, attrs) do
if Pleroma.Config.get([:oauth2, :clean_expired_tokens]) do if Pleroma.Config.get([:oauth2, :clean_expired_tokens]) do