commit: c9dc881747ee04498ae19311b5525b4bfc660eee
parent b1659b77554000b582041ab053708c8c52720f35
Author: feld <feld@feld.me>
Date: Sun, 28 Jan 2024 23:20:25 +0000
Merge branch 'dialyzer-fixes' into 'develop'
More dialyzer fixes
See merge request pleroma/pleroma!4048
Diffstat:
44 files changed, 178 insertions(+), 163 deletions(-)
diff --git a/.dialyzer_ignore.exs b/.dialyzer_ignore.exs
@@ -0,0 +1,6 @@
+[
+{"lib/cachex.ex", "Unknown type: Spec.cache/0."},
+{"lib/pleroma/web/plugs/rate_limiter.ex", "The pattern can never match the type {:commit, _} | {:ignore, _}."},
+{"lib/pleroma/web/plugs/rate_limiter.ex", "Function get_scale/2 will never be called."},
+{"lib/pleroma/web/plugs/rate_limiter.ex", "Function initialize_buckets!/1 will never be called."}
+]
diff --git a/changelog.d/mastodon_directory.fix b/changelog.d/mastodon_directory.fix
@@ -0,0 +1 @@
+Mastodon API /api/v1/directory: Fix listing directory contents when not authenticated
diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex
@@ -51,12 +51,12 @@ defmodule Pleroma.Emoji do
end
@doc "Returns the path of the emoji `name`."
- @spec get(String.t()) :: String.t() | nil
+ @spec get(String.t()) :: Pleroma.Emoji.t() | nil
def get(name) do
name = maybe_strip_name(name)
case :ets.lookup(@ets, name) do
- [{_, path}] -> path
+ [{_, emoji}] -> emoji
_ -> nil
end
end
diff --git a/lib/pleroma/gun/connection_pool/reclaimer.ex b/lib/pleroma/gun/connection_pool/reclaimer.ex
@@ -9,7 +9,7 @@ defmodule Pleroma.Gun.ConnectionPool.Reclaimer do
def start_monitor do
pid =
- case :gen_server.start(__MODULE__, [], name: {:via, Registry, {registry(), "reclaimer"}}) do
+ case GenServer.start_link(__MODULE__, [], name: {:via, Registry, {registry(), "reclaimer"}}) do
{:ok, pid} ->
pid
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex
@@ -242,17 +242,17 @@ defmodule Pleroma.Object do
{:ok, _} <- invalid_object_cache(object) do
cleanup_attachments(
Config.get([:instance, :cleanup_attachments]),
- %{"object" => object}
+ object
)
{:ok, object, deleted_activity}
end
end
- @spec cleanup_attachments(boolean(), %{required(:object) => map()}) ::
+ @spec cleanup_attachments(boolean(), Object.t()) ::
{:ok, Oban.Job.t() | nil}
- def cleanup_attachments(true, %{"object" => _} = params) do
- AttachmentsCleanupWorker.enqueue("cleanup_attachments", params)
+ def cleanup_attachments(true, %Object{} = object) do
+ AttachmentsCleanupWorker.enqueue("cleanup_attachments", %{"object" => object})
end
def cleanup_attachments(_, _), do: {:ok, nil}
diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex
@@ -84,13 +84,13 @@ defmodule Pleroma.ReverseProxy do
{:max_read_duration, non_neg_integer() | :infinity}
| {:max_body_length, non_neg_integer() | :infinity}
| {:failed_request_ttl, non_neg_integer() | :infinity}
- | {:http, []}
+ | {:http, keyword()}
| {:req_headers, [{String.t(), String.t()}]}
| {:resp_headers, [{String.t(), String.t()}]}
- | {:inline_content_types, boolean() | [String.t()]}
+ | {:inline_content_types, boolean() | list(String.t())}
| {:redirect_on_failure, boolean()}
- @spec call(Plug.Conn.t(), url :: String.t(), [option()]) :: Plug.Conn.t()
+ @spec call(Plug.Conn.t(), String.t(), list(option())) :: Plug.Conn.t()
def call(_conn, _url, _opts \\ [])
def call(conn = %{method: method}, url, opts) when method in @methods do
@@ -388,8 +388,6 @@ defmodule Pleroma.ReverseProxy do
defp body_size_constraint(_, _), do: :ok
- defp check_read_duration(nil = _duration, max), do: check_read_duration(@max_read_duration, max)
-
defp check_read_duration(duration, max)
when is_integer(duration) and is_integer(max) and max > 0 do
if duration > max do
@@ -407,10 +405,6 @@ defmodule Pleroma.ReverseProxy do
{:ok, previous_duration + duration}
end
- defp increase_read_duration(_) do
- {:ok, :no_duration_limit, :no_duration_limit}
- end
-
defp client, do: Pleroma.ReverseProxy.Client.Wrapper
defp track_failed_url(url, error, opts) do
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
@@ -51,6 +51,7 @@ defmodule Pleroma.Upload do
| {:size_limit, nil | non_neg_integer()}
| {:uploader, module()}
| {:filters, [module()]}
+ | {:actor, String.t()}
@type t :: %__MODULE__{
id: String.t(),
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
@@ -1787,7 +1787,10 @@ defmodule Pleroma.User do
@spec set_activation([User.t()], boolean()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
def set_activation(users, status) when is_list(users) do
Repo.transaction(fn ->
- for user <- users, do: set_activation(user, status)
+ for user <- users do
+ {:ok, user} = set_activation(user, status)
+ user
+ end
end)
end
diff --git a/lib/pleroma/web/activity_pub/object_validator.ex b/lib/pleroma/web/activity_pub/object_validator.ex
@@ -173,6 +173,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
{:object_validation, e} ->
e
+
+ {:error, %Ecto.Changeset{} = e} ->
+ {:error, e}
end
end
diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex
@@ -304,9 +304,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
result =
case deleted_object do
%Object{} ->
- with {:ok, deleted_object, _activity} <- Object.delete(deleted_object),
+ with {_, {:ok, deleted_object, _activity}} <- {:object, Object.delete(deleted_object)},
{_, actor} when is_binary(actor) <- {:actor, deleted_object.data["actor"]},
- %User{} = user <- User.get_cached_by_ap_id(actor) do
+ {_, %User{} = user} <- {:user, User.get_cached_by_ap_id(actor)} do
User.remove_pinned_object_id(user, deleted_object.data["id"])
{:ok, user} = ActivityPub.decrease_note_count_if_public(user, deleted_object)
@@ -328,6 +328,17 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
{:actor, _} ->
@logger.error("The object doesn't have an actor: #{inspect(deleted_object)}")
:no_object_actor
+
+ {:user, _} ->
+ @logger.error(
+ "The object's actor could not be resolved to a user: #{inspect(deleted_object)}"
+ )
+
+ :no_object_user
+
+ {:object, _} ->
+ @logger.error("The object could not be deleted: #{inspect(deleted_object)}")
+ {:error, object}
end
%User{} ->
@@ -569,7 +580,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
def handle_undoing(object), do: {:error, ["don't know how to handle", object]}
- @spec delete_object(Object.t()) :: :ok | {:error, Ecto.Changeset.t()}
+ @spec delete_object(Activity.t()) :: :ok | {:error, Ecto.Changeset.t()}
defp delete_object(object) do
with {:ok, _} <- Repo.delete(object), do: :ok
end
diff --git a/lib/pleroma/web/activity_pub/side_effects/handling.ex b/lib/pleroma/web/activity_pub/side_effects/handling.ex
@@ -4,5 +4,5 @@
defmodule Pleroma.Web.ActivityPub.SideEffects.Handling do
@callback handle(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()}
- @callback handle_after_transaction(map()) :: map()
+ @callback handle_after_transaction(keyword()) :: keyword()
end
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
@@ -776,10 +776,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do
build_flag_object(object)
nil ->
- if %Object{} = object = Object.get_by_ap_id(id) do
- build_flag_object(object)
- else
- %{"id" => id, "deleted" => true}
+ case Object.get_by_ap_id(id) do
+ %Object{} = object -> build_flag_object(object)
+ _ -> %{"id" => id, "deleted" => true}
end
end
end
diff --git a/lib/pleroma/web/admin_api/controllers/config_controller.ex b/lib/pleroma/web/admin_api/controllers/config_controller.ex
@@ -128,7 +128,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
end
end
- def update(%{body_params: %{configs: configs}} = conn, _) do
+ def update(%{body_params: %{"configs" => configs}} = conn, _) do
with :ok <- configurable_from_database() do
results =
configs
diff --git a/lib/pleroma/web/admin_api/controllers/instance_document_controller.ex b/lib/pleroma/web/admin_api/controllers/instance_document_controller.ex
@@ -27,7 +27,7 @@ defmodule Pleroma.Web.AdminAPI.InstanceDocumentController do
end
end
- def update(%{body_params: %{file: file}} = conn, %{name: document_name}) do
+ def update(%{body_params: %{"file" => file}} = conn, %{name: document_name}) do
with {:ok, url} <- InstanceDocument.put(document_name, file.path) do
json(conn, %{"url" => url})
end
diff --git a/lib/pleroma/web/admin_api/controllers/invite_controller.ex b/lib/pleroma/web/admin_api/controllers/invite_controller.ex
@@ -40,7 +40,7 @@ defmodule Pleroma.Web.AdminAPI.InviteController do
end
@doc "Revokes invite by token"
- def revoke(%{body_params: %{token: token}} = conn, _) do
+ def revoke(%{body_params: %{"token" => token}} = conn, _) do
with {:ok, invite} <- UserInviteToken.find_by_token(token),
{:ok, updated_invite} = UserInviteToken.update_invite(invite, %{used: true}) do
render(conn, "show.json", invite: updated_invite)
@@ -51,7 +51,7 @@ defmodule Pleroma.Web.AdminAPI.InviteController do
end
@doc "Sends registration invite via email"
- def email(%{assigns: %{user: user}, body_params: %{email: email} = params} = conn, _) do
+ def email(%{assigns: %{user: user}, body_params: %{"email" => email} = params} = conn, _) do
with {_, false} <- {:registrations_open, Config.get([:instance, :registrations_open])},
{_, true} <- {:invites_enabled, Config.get([:instance, :invites_enabled])},
{:ok, invite_token} <- UserInviteToken.create_invite(),
@@ -60,7 +60,7 @@ defmodule Pleroma.Web.AdminAPI.InviteController do
|> Pleroma.Emails.UserEmail.user_invitation_email(
invite_token,
email,
- params[:name]
+ params["name"]
)
|> Pleroma.Emails.Mailer.deliver() do
json_response(conn, :no_content, "")
diff --git a/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex b/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex
@@ -59,12 +59,12 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheController do
Enum.slice(entries, offset, page_size)
end
- def delete(%{assigns: %{user: _}, body_params: %{urls: urls}} = conn, _) do
+ def delete(%{assigns: %{user: _}, body_params: %{"urls" => urls}} = conn, _) do
MediaProxy.remove_from_banned_urls(urls)
json(conn, %{})
end
- def purge(%{assigns: %{user: _}, body_params: %{urls: urls, ban: ban}} = conn, _) do
+ def purge(%{assigns: %{user: _}, body_params: %{"urls" => urls, "ban" => ban}} = conn, _) do
MediaProxy.Invalidation.purge(urls)
if ban do
diff --git a/lib/pleroma/web/admin_api/controllers/relay_controller.ex b/lib/pleroma/web/admin_api/controllers/relay_controller.ex
@@ -31,7 +31,7 @@ defmodule Pleroma.Web.AdminAPI.RelayController do
end
end
- def follow(%{assigns: %{user: admin}, body_params: %{relay_url: target}} = conn, _) do
+ def follow(%{assigns: %{user: admin}, body_params: %{"relay_url" => target}} = conn, _) do
with {:ok, _message} <- Relay.follow(target) do
ModerationLog.insert_log(%{action: "relay_follow", actor: admin, target: target})
@@ -44,8 +44,11 @@ defmodule Pleroma.Web.AdminAPI.RelayController do
end
end
- def unfollow(%{assigns: %{user: admin}, body_params: %{relay_url: target} = params} = conn, _) do
- with {:ok, _message} <- Relay.unfollow(target, %{force: params[:force]}) do
+ def unfollow(
+ %{assigns: %{user: admin}, body_params: %{"relay_url" => target} = params} = conn,
+ _
+ ) do
+ with {:ok, _message} <- Relay.unfollow(target, %{force: params["force"]}) do
ModerationLog.insert_log(%{action: "relay_unfollow", actor: admin, target: target})
json(conn, target)
diff --git a/lib/pleroma/web/admin_api/controllers/report_controller.ex b/lib/pleroma/web/admin_api/controllers/report_controller.ex
@@ -45,7 +45,7 @@ defmodule Pleroma.Web.AdminAPI.ReportController do
end
end
- def update(%{assigns: %{user: admin}, body_params: %{reports: reports}} = conn, _) do
+ def update(%{assigns: %{user: admin}, body_params: %{"reports" => reports}} = conn, _) do
result =
Enum.map(reports, fn report ->
case CommonAPI.update_report_state(report.id, report.state) do
@@ -73,7 +73,7 @@ defmodule Pleroma.Web.AdminAPI.ReportController do
end
end
- def notes_create(%{assigns: %{user: user}, body_params: %{content: content}} = conn, %{
+ def notes_create(%{assigns: %{user: user}, body_params: %{"content" => content}} = conn, %{
id: report_id
}) do
with {:ok, _} <- ReportNote.create(user.id, report_id, content),
diff --git a/lib/pleroma/web/admin_api/controllers/user_controller.ex b/lib/pleroma/web/admin_api/controllers/user_controller.ex
@@ -53,11 +53,11 @@ defmodule Pleroma.Web.AdminAPI.UserController do
def delete(conn, %{nickname: nickname}) do
conn
- |> Map.put(:body_params, %{nicknames: [nickname]})
+ |> Map.put(:body_params, %{"nicknames" => [nickname]})
|> delete(%{})
end
- def delete(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
+ def delete(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}} = conn, _) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
Enum.each(users, fn user ->
@@ -78,8 +78,8 @@ defmodule Pleroma.Web.AdminAPI.UserController do
%{
assigns: %{user: admin},
body_params: %{
- follower: follower_nick,
- followed: followed_nick
+ "follower" => follower_nick,
+ "followed" => followed_nick
}
} = conn,
_
@@ -103,8 +103,8 @@ defmodule Pleroma.Web.AdminAPI.UserController do
%{
assigns: %{user: admin},
body_params: %{
- follower: follower_nick,
- followed: followed_nick
+ "follower" => follower_nick,
+ "followed" => followed_nick
}
} = conn,
_
@@ -124,7 +124,7 @@ defmodule Pleroma.Web.AdminAPI.UserController do
json(conn, "ok")
end
- def create(%{assigns: %{user: admin}, body_params: %{users: users}} = conn, _) do
+ def create(%{assigns: %{user: admin}, body_params: %{"users" => users}} = conn, _) do
changesets =
users
|> Enum.map(fn %{nickname: nickname, email: email, password: password} ->
@@ -202,7 +202,7 @@ defmodule Pleroma.Web.AdminAPI.UserController do
render(conn, "show.json", user: updated_user)
end
- def activate(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
+ def activate(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}} = conn, _) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.set_activation(users, true)
@@ -212,10 +212,10 @@ defmodule Pleroma.Web.AdminAPI.UserController do
action: "activate"
})
- render(conn, "index.json", users: Keyword.values(updated_users))
+ render(conn, "index.json", users: updated_users)
end
- def deactivate(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
+ def deactivate(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}} = conn, _) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.set_activation(users, false)
@@ -225,10 +225,10 @@ defmodule Pleroma.Web.AdminAPI.UserController do
action: "deactivate"
})
- render(conn, "index.json", users: Keyword.values(updated_users))
+ render(conn, "index.json", users: updated_users)
end
- def approve(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
+ def approve(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}} = conn, _) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.approve(users)
@@ -241,7 +241,7 @@ defmodule Pleroma.Web.AdminAPI.UserController do
render(conn, "index.json", users: updated_users)
end
- def suggest(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
+ def suggest(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}} = conn, _) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.set_suggestion(users, true)
@@ -254,7 +254,7 @@ defmodule Pleroma.Web.AdminAPI.UserController do
render(conn, "index.json", users: updated_users)
end
- def unsuggest(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
+ def unsuggest(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}} = conn, _) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.set_suggestion(users, false)
diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex
@@ -882,9 +882,9 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
description: "POST body for muting an account",
type: :object,
properties: %{
- uri: %Schema{type: :string, nullable: true, format: :uri}
+ "uri" => %Schema{type: :string, nullable: true, format: :uri}
},
- required: [:uri]
+ required: ["uri"]
}
end
@@ -925,7 +925,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
description: "POST body for adding a note for an account",
type: :object,
properties: %{
- comment: %Schema{
+ "comment" => %Schema{
type: :string,
description: "Account note body"
}
diff --git a/lib/pleroma/web/api_spec/operations/admin/config_operation.ex b/lib/pleroma/web/api_spec/operations/admin/config_operation.ex
@@ -47,7 +47,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.ConfigOperation do
request_body("Parameters", %Schema{
type: :object,
properties: %{
- configs: %Schema{
+ "configs" => %Schema{
type: :array,
items: %Schema{
type: :object,
diff --git a/lib/pleroma/web/api_spec/operations/admin/instance_document_operation.ex b/lib/pleroma/web/api_spec/operations/admin/instance_document_operation.ex
@@ -61,9 +61,9 @@ defmodule Pleroma.Web.ApiSpec.Admin.InstanceDocumentOperation do
title: "UpdateRequest",
description: "POST body for uploading the file",
type: :object,
- required: [:file],
+ required: ["file"],
properties: %{
- file: %Schema{
+ "file" => %Schema{
type: :string,
format: :binary,
description: "The file to be uploaded, using multipart form data."
diff --git a/lib/pleroma/web/api_spec/operations/admin/invite_operation.ex b/lib/pleroma/web/api_spec/operations/admin/invite_operation.ex
@@ -79,9 +79,9 @@ defmodule Pleroma.Web.ApiSpec.Admin.InviteOperation do
"Parameters",
%Schema{
type: :object,
- required: [:token],
+ required: ["token"],
properties: %{
- token: %Schema{type: :string}
+ "token" => %Schema{type: :string}
}
},
required: true
@@ -106,10 +106,10 @@ defmodule Pleroma.Web.ApiSpec.Admin.InviteOperation do
"Parameters",
%Schema{
type: :object,
- required: [:email],
+ required: ["email"],
properties: %{
- email: %Schema{type: :string, format: :email},
- name: %Schema{type: :string}
+ "email" => %Schema{type: :string, format: :email},
+ "name" => %Schema{type: :string}
}
},
required: true
diff --git a/lib/pleroma/web/api_spec/operations/admin/media_proxy_cache_operation.ex b/lib/pleroma/web/api_spec/operations/admin/media_proxy_cache_operation.ex
@@ -78,9 +78,9 @@ defmodule Pleroma.Web.ApiSpec.Admin.MediaProxyCacheOperation do
"Parameters",
%Schema{
type: :object,
- required: [:urls],
+ required: ["urls"],
properties: %{
- urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}}
+ "urls" => %Schema{type: :array, items: %Schema{type: :string, format: :uri}}
}
},
required: true
@@ -104,10 +104,10 @@ defmodule Pleroma.Web.ApiSpec.Admin.MediaProxyCacheOperation do
"Parameters",
%Schema{
type: :object,
- required: [:urls],
+ required: ["urls"],
properties: %{
- urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}},
- ban: %Schema{type: :boolean, default: true}
+ "urls" => %Schema{type: :array, items: %Schema{type: :string, format: :uri}},
+ "ban" => %Schema{type: :boolean, default: true}
}
},
required: true
diff --git a/lib/pleroma/web/api_spec/operations/admin/relay_operation.ex b/lib/pleroma/web/api_spec/operations/admin/relay_operation.ex
@@ -87,7 +87,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.RelayOperation do
%Schema{
type: :object,
properties: %{
- relay_url: %Schema{type: :string, format: :uri}
+ "relay_url" => %Schema{type: :string, format: :uri}
}
}
end
@@ -96,8 +96,8 @@ defmodule Pleroma.Web.ApiSpec.Admin.RelayOperation do
%Schema{
type: :object,
properties: %{
- relay_url: %Schema{type: :string, format: :uri},
- force: %Schema{type: :boolean, default: false}
+ "relay_url" => %Schema{type: :string, format: :uri},
+ "force" => %Schema{type: :boolean, default: false}
}
}
end
diff --git a/lib/pleroma/web/api_spec/operations/admin/report_operation.ex b/lib/pleroma/web/api_spec/operations/admin/report_operation.ex
@@ -107,7 +107,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do
request_body("Parameters", %Schema{
type: :object,
properties: %{
- content: %Schema{type: :string, description: "The message"}
+ "content" => %Schema{type: :string, description: "The message"}
}
}),
security: [%{"oAuth" => ["admin:write:reports"]}],
@@ -199,9 +199,9 @@ defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do
defp update_request do
%Schema{
type: :object,
- required: [:reports],
+ required: ["reports"],
properties: %{
- reports: %Schema{
+ "reports" => %Schema{
type: :array,
items: %Schema{
type: :object,
diff --git a/lib/pleroma/web/api_spec/operations/admin/user_operation.ex b/lib/pleroma/web/api_spec/operations/admin/user_operation.ex
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
%Schema{
type: :object,
properties: %{
- users: %Schema{type: :array, items: user()},
+ "users" => %Schema{type: :array, items: user()},
count: %Schema{type: :integer},
page_size: %Schema{type: :integer}
}
@@ -75,7 +75,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
description: "POST body for creating users",
type: :object,
properties: %{
- users: %Schema{
+ "users" => %Schema{
type: :array,
items: %Schema{
type: :object,
@@ -168,8 +168,8 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
%Schema{
type: :object,
properties: %{
- follower: %Schema{type: :string, description: "Follower nickname"},
- followed: %Schema{type: :string, description: "Followed nickname"}
+ "follower" => %Schema{type: :string, description: "Follower nickname"},
+ "followed" => %Schema{type: :string, description: "Followed nickname"}
}
}
),
@@ -193,8 +193,8 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
%Schema{
type: :object,
properties: %{
- follower: %Schema{type: :string, description: "Follower nickname"},
- followed: %Schema{type: :string, description: "Followed nickname"}
+ "follower" => %Schema{type: :string, description: "Follower nickname"},
+ "followed" => %Schema{type: :string, description: "Followed nickname"}
}
}
),
@@ -219,7 +219,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
description: "POST body for approving multiple users",
type: :object,
properties: %{
- nicknames: %Schema{
+ "nicknames" => %Schema{
type: :array,
items: %Schema{type: :string}
}
@@ -251,7 +251,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
description: "POST body for adding multiple suggested users",
type: :object,
properties: %{
- nicknames: %Schema{
+ "nicknames" => %Schema{
type: :array,
items: %Schema{type: :string}
}
@@ -283,7 +283,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
description: "POST body for removing multiple suggested users",
type: :object,
properties: %{
- nicknames: %Schema{
+ "nicknames" => %Schema{
type: :array,
items: %Schema{type: :string}
}
@@ -332,7 +332,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
description: "POST body for deleting multiple users",
type: :object,
properties: %{
- nicknames: %Schema{
+ "nicknames" => %Schema{
type: :array,
items: %Schema{type: :string}
}
@@ -364,7 +364,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
description: "POST body for deleting multiple users",
type: :object,
properties: %{
- nicknames: %Schema{
+ "nicknames" => %Schema{
type: :array,
items: %Schema{type: :string}
}
@@ -404,7 +404,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.UserOperation do
description: "POST body for deleting multiple users",
type: :object,
properties: %{
- nicknames: %Schema{
+ "nicknames" => %Schema{
type: :array,
items: %Schema{type: :string}
}
diff --git a/lib/pleroma/web/api_spec/operations/chat_operation.ex b/lib/pleroma/web/api_spec/operations/chat_operation.ex
@@ -368,9 +368,9 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
title: "MarkAsReadRequest",
description: "POST body for marking a number of chat messages as read",
type: :object,
- required: [:last_read_id],
+ required: ["last_read_id"],
properties: %{
- last_read_id: %Schema{
+ "last_read_id" => %Schema{
type: :string,
description: "The content of your message."
}
diff --git a/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex
@@ -36,9 +36,9 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
defp create_request do
%Schema{
type: :object,
- required: [:file],
+ required: ["file"],
properties: %{
- file: %Schema{
+ "file" => %Schema{
description:
"File needs to be uploaded with the multipart request or link to remote file",
anyOf: [
@@ -46,12 +46,12 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
%Schema{type: :string, format: :uri}
]
},
- shortcode: %Schema{
+ "shortcode" => %Schema{
type: :string,
description:
"Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
},
- filename: %Schema{
+ "filename" => %Schema{
type: :string,
description:
"New emoji file name. If not specified will be taken from original filename."
@@ -81,21 +81,21 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
defp update_request do
%Schema{
type: :object,
- required: [:shortcode, :new_shortcode, :new_filename],
+ required: ["shortcode", "new_shortcode", "new_filename"],
properties: %{
- shortcode: %Schema{
+ "shortcode" => %Schema{
type: :string,
description: "Emoji file shortcode"
},
- new_shortcode: %Schema{
+ "new_shortcode" => %Schema{
type: :string,
description: "New emoji file shortcode"
},
- new_filename: %Schema{
+ "new_filename" => %Schema{
type: :string,
description: "New filename for emoji file"
},
- force: %Schema{
+ "force" => %Schema{
type: :boolean,
description: "With true value to overwrite existing emoji with new shortcode",
default: false
diff --git a/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex
@@ -130,15 +130,15 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do
defp download_request do
%Schema{
type: :object,
- required: [:url, :name],
+ required: ["url", "name"],
properties: %{
- url: %Schema{
+ "url" => %Schema{
type: :string,
format: :uri,
description: "URL of the instance to download from"
},
- name: %Schema{type: :string, format: :uri, description: "Pack Name"},
- as: %Schema{type: :string, format: :uri, description: "Save as"}
+ "name" => %Schema{type: :string, format: :uri, description: "Pack Name"},
+ "as" => %Schema{type: :string, format: :uri, description: "Save as"}
}
}
end
@@ -302,27 +302,7 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do
defp update_request do
%Schema{
type: :object,
- properties: %{
- metadata: %Schema{
- type: :object,
- description: "Metadata to replace the old one",
- properties: %{
- license: %Schema{type: :string},
- homepage: %Schema{type: :string, format: :uri},
- description: %Schema{type: :string},
- "fallback-src": %Schema{
- type: :string,
- format: :uri,
- description: "Fallback url to download pack from"
- },
- "fallback-src-sha256": %Schema{
- type: :string,
- description: "SHA256 encoded for fallback pack archive"
- },
- "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}
- }
- }
- }
+ properties: %{"metadata" => metadata()}
}
end
diff --git a/lib/pleroma/web/api_spec/operations/pleroma_mascot_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_mascot_operation.ex
@@ -39,7 +39,7 @@ defmodule Pleroma.Web.ApiSpec.PleromaMascotOperation do
%Schema{
type: :object,
properties: %{
- file: %Schema{type: :string, format: :binary}
+ "file" => %Schema{type: :string, format: :binary}
}
},
required: true
diff --git a/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex
@@ -24,8 +24,11 @@ defmodule Pleroma.Web.ApiSpec.PleromaNotificationOperation do
request_body("Parameters", %Schema{
type: :object,
properties: %{
- id: %Schema{type: :integer, description: "A single notification ID to read"},
- max_id: %Schema{type: :integer, description: "Read all notifications up to this ID"}
+ "id" => %Schema{type: :integer, description: "A single notification ID to read"},
+ "max_id" => %Schema{
+ type: :integer,
+ description: "Read all notifications up to this ID"
+ }
}
}),
security: [%{"oAuth" => ["write:notifications"]}],
diff --git a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex
@@ -404,10 +404,10 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do
title: "RemoteInteractionRequest",
description: "POST body for remote interaction",
type: :object,
- required: [:ap_id, :profile],
+ required: ["ap_id", "profile"],
properties: %{
- ap_id: %Schema{type: :string, description: "Profile or status ActivityPub ID"},
- profile: %Schema{type: :string, description: "Remote profile webfinger"}
+ "ap_id" => %Schema{type: :string, description: "Profile or status ActivityPub ID"},
+ "profile" => %Schema{type: :string, description: "Remote profile webfinger"}
}
}
end
diff --git a/lib/pleroma/web/api_spec/operations/user_import_operation.ex b/lib/pleroma/web/api_spec/operations/user_import_operation.ex
@@ -61,9 +61,9 @@ defmodule Pleroma.Web.ApiSpec.UserImportOperation do
defp import_request do
%Schema{
type: :object,
- required: [:list],
+ required: ["list"],
properties: %{
- list: %Schema{
+ "list" => %Schema{
description:
"STRING or FILE containing a whitespace-separated list of accounts to import.",
anyOf: [
diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
@@ -472,7 +472,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
@doc "POST /api/v1/accounts/:id/note"
def note(
- %{assigns: %{user: noter, account: target}, body_params: %{comment: comment}} = conn,
+ %{assigns: %{user: noter, account: target}, body_params: %{"comment" => comment}} = conn,
_params
) do
with {:ok, _user_note} <- UserNote.create(noter, target, comment) do
@@ -513,7 +513,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
end
@doc "POST /api/v1/follows"
- def follow_by_uri(%{body_params: %{uri: uri}} = conn, _) do
+ def follow_by_uri(%{body_params: %{"uri" => uri}} = conn, _) do
case User.get_cached_by_nickname(uri) do
%User{} = user ->
conn
diff --git a/lib/pleroma/web/mastodon_api/controllers/directory_controller.ex b/lib/pleroma/web/mastodon_api/controllers/directory_controller.ex
@@ -15,7 +15,7 @@ defmodule Pleroma.Web.MastodonAPI.DirectoryController do
plug(Pleroma.Web.ApiSpec.CastAndValidate)
- plug(:skip_auth when action == "index")
+ plug(:skip_auth when action == :index)
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.DirectoryOperation
diff --git a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
@@ -76,7 +76,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
%{id: id}
) do
with {:ok, chat} <- Chat.get_by_user_and_id(user, id),
- %User{} = recipient <- User.get_cached_by_ap_id(chat.recipient),
+ {_, %User{} = recipient} <- {:user, User.get_cached_by_ap_id(chat.recipient)},
{:ok, activity} <-
CommonAPI.post_chat_message(user, recipient, params[:content],
media_id: params[:media_id],
@@ -97,6 +97,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
conn
|> put_status(:bad_request)
|> json(%{error: message})
+
+ {:user, nil} ->
+ conn
+ |> put_status(:bad_request)
+ |> json(%{error: "Recipient does not exist"})
end
end
@@ -115,7 +120,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
end
def mark_as_read(
- %{body_params: %{last_read_id: last_read_id}, assigns: %{user: user}} = conn,
+ %{body_params: %{"last_read_id" => last_read_id}, assigns: %{user: user}} = conn,
%{id: id}
) do
with {:ok, chat} <- Chat.get_by_user_and_id(user, id),
diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex
@@ -23,11 +23,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
defdelegate open_api_operation(action), to: ApiSpec.PleromaEmojiFileOperation
def create(%{body_params: params} = conn, %{name: pack_name}) do
- filename = params[:filename] || get_filename(params[:file])
- shortcode = params[:shortcode] || Path.basename(filename, Path.extname(filename))
+ filename = params["filename"] || get_filename(params["file"])
+ shortcode = params["shortcode"] || Path.basename(filename, Path.extname(filename))
with {:ok, pack} <- Pack.load_pack(pack_name),
- {:ok, file} <- get_file(params[:file]),
+ {:ok, file} <- get_file(params["file"]),
{:ok, pack} <- Pack.add_file(pack, shortcode, filename, file) do
json(conn, pack.files)
else
@@ -49,10 +49,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
end
end
- def update(%{body_params: %{shortcode: shortcode} = params} = conn, %{name: pack_name}) do
- new_shortcode = params[:new_shortcode]
- new_filename = params[:new_filename]
- force = params[:force]
+ def update(%{body_params: %{"shortcode" => shortcode} = params} = conn, %{name: pack_name}) do
+ new_shortcode = params["new_shortcode"]
+ new_filename = params["new_filename"]
+ force = params["force"]
with {:ok, pack} <- Pack.load_pack(pack_name),
{:ok, pack} <- Pack.update_file(pack, shortcode, new_shortcode, new_filename, force) do
@@ -128,9 +128,9 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
defp get_filename(%Plug.Upload{filename: filename}), do: filename
defp get_filename(url) when is_binary(url), do: Path.basename(url)
- def get_file(%Plug.Upload{} = file), do: {:ok, file}
+ defp get_file(%Plug.Upload{} = file), do: {:ok, file}
- def get_file(url) when is_binary(url) do
+ defp get_file(url) when is_binary(url) do
with {:ok, %Tesla.Env{body: body, status: code, headers: headers}}
when code in 200..299 <- Pleroma.HTTP.get(url) do
path = Plug.Upload.random_file!("emoji")
diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex
@@ -109,8 +109,8 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackController do
end
end
- def download(%{body_params: %{url: url, name: name} = params} = conn, _) do
- with {:ok, _pack} <- Pack.download(name, url, params[:as]) do
+ def download(%{body_params: %{"url" => url, "name" => name} = params} = conn, _) do
+ with {:ok, _pack} <- Pack.download(name, url, params["as"]) do
json(conn, "ok")
else
{:error, :not_shareable} ->
@@ -184,7 +184,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackController do
end
end
- def update(%{body_params: %{metadata: metadata}} = conn, %{name: name}) do
+ def update(%{body_params: %{"metadata" => metadata}} = conn, %{name: name}) do
with {:ok, pack} <- Pack.update_metadata(name, metadata) do
json(conn, pack.pack)
else
diff --git a/lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex b/lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex
@@ -22,9 +22,9 @@ defmodule Pleroma.Web.PleromaAPI.MascotController do
end
@doc "PUT /api/v1/pleroma/mascot"
- def update(%{assigns: %{user: user}, body_params: %{file: file}} = conn, _) do
- with {:content_type, "image" <> _} <- {:content_type, file.content_type},
- {:ok, object} <- ActivityPub.upload(file, actor: User.ap_id(user)) do
+ def update(%{assigns: %{user: user}, body_params: %{"file" => file}} = conn, _) do
+ with {_, "image" <> _} <- {:content_type, file.content_type},
+ {_, {:ok, object}} <- {:upload, ActivityPub.upload(file, actor: User.ap_id(user))} do
attachment = render_attachment(object)
{:ok, _user} = User.mascot_update(user, attachment)
@@ -32,6 +32,9 @@ defmodule Pleroma.Web.PleromaAPI.MascotController do
else
{:content_type, _} ->
render_error(conn, :unsupported_media_type, "mascots can only be images")
+
+ {:upload, {:error, _}} ->
+ render_error(conn, :error, "error uploading file")
end
end
diff --git a/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex b/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.PleromaAPI.NotificationController do
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaNotificationOperation
- def mark_as_read(%{assigns: %{user: user}, body_params: %{id: notification_id}} = conn, _) do
+ def mark_as_read(%{assigns: %{user: user}, body_params: %{"id" => notification_id}} = conn, _) do
with {:ok, notification} <- Notification.read_one(user, notification_id) do
render(conn, "show.json", notification: notification, for: user)
else
@@ -27,7 +27,7 @@ defmodule Pleroma.Web.PleromaAPI.NotificationController do
end
end
- def mark_as_read(%{assigns: %{user: user}, body_params: %{max_id: max_id}} = conn, _) do
+ def mark_as_read(%{assigns: %{user: user}, body_params: %{"max_id" => max_id}} = conn, _) do
notifications =
user
|> Notification.set_read_up_to(max_id)
diff --git a/lib/pleroma/web/pleroma_api/controllers/user_import_controller.ex b/lib/pleroma/web/pleroma_api/controllers/user_import_controller.ex
@@ -18,11 +18,11 @@ defmodule Pleroma.Web.PleromaAPI.UserImportController do
plug(Pleroma.Web.ApiSpec.CastAndValidate)
defdelegate open_api_operation(action), to: ApiSpec.UserImportOperation
- def follow(%{body_params: %{list: %Plug.Upload{path: path}}} = conn, _) do
- follow(%Plug.Conn{conn | body_params: %{list: File.read!(path)}}, %{})
+ def follow(%{body_params: %{"list" => %Plug.Upload{path: path}}} = conn, _) do
+ follow(%Plug.Conn{conn | body_params: %{"list" => File.read!(path)}}, %{})
end
- def follow(%{assigns: %{user: follower}, body_params: %{list: list}} = conn, _) do
+ def follow(%{assigns: %{user: follower}, body_params: %{"list" => list}} = conn, _) do
identifiers =
list
|> String.split("\n")
@@ -35,20 +35,20 @@ defmodule Pleroma.Web.PleromaAPI.UserImportController do
json(conn, "job started")
end
- def blocks(%{body_params: %{list: %Plug.Upload{path: path}}} = conn, _) do
- blocks(%Plug.Conn{conn | body_params: %{list: File.read!(path)}}, %{})
+ def blocks(%{body_params: %{"list" => %Plug.Upload{path: path}}} = conn, _) do
+ blocks(%Plug.Conn{conn | body_params: %{"list" => File.read!(path)}}, %{})
end
- def blocks(%{assigns: %{user: blocker}, body_params: %{list: list}} = conn, _) do
+ def blocks(%{assigns: %{user: blocker}, body_params: %{"list" => list}} = conn, _) do
User.Import.blocks_import(blocker, prepare_user_identifiers(list))
json(conn, "job started")
end
- def mutes(%{body_params: %{list: %Plug.Upload{path: path}}} = conn, _) do
- mutes(%Plug.Conn{conn | body_params: %{list: File.read!(path)}}, %{})
+ def mutes(%{body_params: %{"list" => %Plug.Upload{path: path}}} = conn, _) do
+ mutes(%Plug.Conn{conn | body_params: %{"list" => File.read!(path)}}, %{})
end
- def mutes(%{assigns: %{user: user}, body_params: %{list: list}} = conn, _) do
+ def mutes(%{assigns: %{user: user}, body_params: %{"list" => list}} = conn, _) do
User.Import.mutes_import(user, prepare_user_identifiers(list))
json(conn, "job started")
end
diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex
@@ -150,7 +150,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
end
end
- def remote_interaction(%{body_params: %{ap_id: ap_id, profile: profile}} = conn, _params) do
+ def remote_interaction(
+ %{body_params: %{"ap_id" => ap_id, "profile" => profile}} = conn,
+ _params
+ ) do
with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile) do
conn
|> json(%{url: String.replace(template, "{uri}", ap_id)})
diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs
@@ -873,7 +873,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
%{
"tuple" => [
":_",
- "Phoenix.Endpoint.Cowboy2Handler",
+ "Plug.Cowboy.Handler",
%{"tuple" => ["Pleroma.Web.Endpoint", []]}
]
}
@@ -937,7 +937,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
%{
"tuple" => [
":_",
- "Phoenix.Endpoint.Cowboy2Handler",
+ "Plug.Cowboy.Handler",
%{"tuple" => ["Pleroma.Web.Endpoint", []]}
]
}