Merge branch 'dialyzer-fixes' into 'develop'

Dialyzer fixes, some reverts

See merge request pleroma/pleroma!4049
This commit is contained in:
feld 2024-01-30 20:32:32 +00:00
commit 1bba02863d
51 changed files with 217 additions and 182 deletions

View File

@ -51,7 +51,6 @@ defmodule Pleroma.Upload do
| {:size_limit, nil | non_neg_integer()} | {:size_limit, nil | non_neg_integer()}
| {:uploader, module()} | {:uploader, module()}
| {:filters, [module()]} | {:filters, [module()]}
| {:actor, String.t()}
@type t :: %__MODULE__{ @type t :: %__MODULE__{
id: String.t(), id: String.t(),

View File

@ -2559,9 +2559,9 @@ def confirmation_changeset(user, set_confirmation: confirmed?) do
cast(user, params, [:is_confirmed, :confirmation_token]) cast(user, params, [:is_confirmed, :confirmation_token])
end end
@spec approval_changeset(User.t(), keyword()) :: Ecto.Changeset.t() @spec approval_changeset(Ecto.Changeset.t(), keyword()) :: Ecto.Changeset.t()
def approval_changeset(user, set_approval: approved?) do def approval_changeset(changeset, set_approval: approved?) do
cast(user, %{is_approved: approved?}, [:is_approved]) cast(changeset, %{is_approved: approved?}, [:is_approved])
end end
@spec add_pinned_object_id(User.t(), String.t()) :: {:ok, User.t()} | {:error, term()} @spec add_pinned_object_id(User.t(), String.t()) :: {:ok, User.t()} | {:error, term()}

View File

@ -128,7 +128,7 @@ def show(conn, _params) do
end end
end end
def update(%{body_params: %{"configs" => configs}} = conn, _) do def update(%{body_params: %{configs: configs}} = conn, _) do
with :ok <- configurable_from_database() do with :ok <- configurable_from_database() do
results = results =
configs configs

View File

@ -27,7 +27,7 @@ def show(conn, %{name: document_name}) do
end end
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 with {:ok, url} <- InstanceDocument.put(document_name, file.path) do
json(conn, %{"url" => url}) json(conn, %{"url" => url})
end end

View File

@ -40,7 +40,7 @@ def create(%{body_params: params} = conn, _) do
end end
@doc "Revokes invite by token" @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), with {:ok, invite} <- UserInviteToken.find_by_token(token),
{:ok, updated_invite} = UserInviteToken.update_invite(invite, %{used: true}) do {:ok, updated_invite} = UserInviteToken.update_invite(invite, %{used: true}) do
render(conn, "show.json", invite: updated_invite) render(conn, "show.json", invite: updated_invite)
@ -51,7 +51,7 @@ def revoke(%{body_params: %{"token" => token}} = conn, _) do
end end
@doc "Sends registration invite via email" @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])}, with {_, false} <- {:registrations_open, Config.get([:instance, :registrations_open])},
{_, true} <- {:invites_enabled, Config.get([:instance, :invites_enabled])}, {_, true} <- {:invites_enabled, Config.get([:instance, :invites_enabled])},
{:ok, invite_token} <- UserInviteToken.create_invite(), {:ok, invite_token} <- UserInviteToken.create_invite(),
@ -60,7 +60,7 @@ def email(%{assigns: %{user: user}, body_params: %{"email" => email} = params} =
|> Pleroma.Emails.UserEmail.user_invitation_email( |> Pleroma.Emails.UserEmail.user_invitation_email(
invite_token, invite_token,
email, email,
params["name"] params[:name]
) )
|> Pleroma.Emails.Mailer.deliver() do |> Pleroma.Emails.Mailer.deliver() do
json_response(conn, :no_content, "") json_response(conn, :no_content, "")

View File

@ -59,12 +59,12 @@ defp paginate_entries(entries, page, page_size) do
Enum.slice(entries, offset, page_size) Enum.slice(entries, offset, page_size)
end 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) MediaProxy.remove_from_banned_urls(urls)
json(conn, %{}) json(conn, %{})
end 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) MediaProxy.Invalidation.purge(urls)
if ban do if ban do

View File

@ -31,7 +31,7 @@ def index(conn, _params) do
end end
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 with {:ok, _message} <- Relay.follow(target) do
ModerationLog.insert_log(%{action: "relay_follow", actor: admin, target: target}) ModerationLog.insert_log(%{action: "relay_follow", actor: admin, target: target})
@ -44,11 +44,8 @@ def follow(%{assigns: %{user: admin}, body_params: %{"relay_url" => target}} = c
end end
end end
def unfollow( def unfollow(%{assigns: %{user: admin}, body_params: %{relay_url: target} = params} = conn, _) do
%{assigns: %{user: admin}, body_params: %{"relay_url" => target} = params} = conn, with {:ok, _message} <- Relay.unfollow(target, %{force: params[:force]}) do
_
) do
with {:ok, _message} <- Relay.unfollow(target, %{force: params["force"]}) do
ModerationLog.insert_log(%{action: "relay_unfollow", actor: admin, target: target}) ModerationLog.insert_log(%{action: "relay_unfollow", actor: admin, target: target})
json(conn, target) json(conn, target)

View File

@ -45,7 +45,7 @@ def show(conn, %{id: id}) do
end end
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 = result =
Enum.map(reports, fn report -> Enum.map(reports, fn report ->
case CommonAPI.update_report_state(report.id, report.state) do case CommonAPI.update_report_state(report.id, report.state) do
@ -73,7 +73,7 @@ def update(%{assigns: %{user: admin}, body_params: %{"reports" => reports}} = co
end end
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 id: report_id
}) do }) do
with {:ok, _} <- ReportNote.create(user.id, report_id, content), with {:ok, _} <- ReportNote.create(user.id, report_id, content),

View File

@ -53,11 +53,11 @@ defmodule Pleroma.Web.AdminAPI.UserController do
def delete(conn, %{nickname: nickname}) do def delete(conn, %{nickname: nickname}) do
conn conn
|> Map.put(:body_params, %{"nicknames" => [nickname]}) |> Map.put(:body_params, %{nicknames: [nickname]})
|> delete(%{}) |> delete(%{})
end 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) users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
Enum.each(users, fn user -> Enum.each(users, fn user ->
@ -78,8 +78,8 @@ def follow(
%{ %{
assigns: %{user: admin}, assigns: %{user: admin},
body_params: %{ body_params: %{
"follower" => follower_nick, follower: follower_nick,
"followed" => followed_nick followed: followed_nick
} }
} = conn, } = conn,
_ _
@ -103,8 +103,8 @@ def unfollow(
%{ %{
assigns: %{user: admin}, assigns: %{user: admin},
body_params: %{ body_params: %{
"follower" => follower_nick, follower: follower_nick,
"followed" => followed_nick followed: followed_nick
} }
} = conn, } = conn,
_ _
@ -124,7 +124,7 @@ def unfollow(
json(conn, "ok") json(conn, "ok")
end end
def create(%{assigns: %{user: admin}, body_params: %{"users" => users}} = conn, _) do def create(%{assigns: %{user: admin}, body_params: %{users: users}} = conn, _) do
changesets = changesets =
users users
|> Enum.map(fn %{nickname: nickname, email: email, password: password} -> |> Enum.map(fn %{nickname: nickname, email: email, password: password} ->
@ -202,7 +202,7 @@ def toggle_activation(%{assigns: %{user: admin}} = conn, %{nickname: nickname})
render(conn, "show.json", user: updated_user) render(conn, "show.json", user: updated_user)
end 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) users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.set_activation(users, true) {:ok, updated_users} = User.set_activation(users, true)
@ -215,7 +215,7 @@ def activate(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}
render(conn, "index.json", users: updated_users) render(conn, "index.json", users: updated_users)
end 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) users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.set_activation(users, false) {:ok, updated_users} = User.set_activation(users, false)
@ -228,7 +228,7 @@ def deactivate(%{assigns: %{user: admin}, body_params: %{"nicknames" => nickname
render(conn, "index.json", users: updated_users) render(conn, "index.json", users: updated_users)
end 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) users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.approve(users) {:ok, updated_users} = User.approve(users)
@ -241,7 +241,7 @@ def approve(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}}
render(conn, "index.json", users: updated_users) render(conn, "index.json", users: updated_users)
end 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) users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.set_suggestion(users, true) {:ok, updated_users} = User.set_suggestion(users, true)
@ -254,7 +254,7 @@ def suggest(%{assigns: %{user: admin}, body_params: %{"nicknames" => nicknames}}
render(conn, "index.json", users: updated_users) render(conn, "index.json", users: updated_users)
end 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) users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
{:ok, updated_users} = User.set_suggestion(users, false) {:ok, updated_users} = User.set_suggestion(users, false)

View File

@ -27,10 +27,12 @@ def init(opts) do
@impl Plug @impl Plug
def call(conn, %{operation_id: operation_id, render_error: render_error}) do def call(conn, %{operation_id: operation_id, render_error: render_error} = opts) do
{spec, operation_lookup} = PutApiSpec.get_spec_and_operation_lookup(conn) {spec, operation_lookup} = PutApiSpec.get_spec_and_operation_lookup(conn)
operation = operation_lookup[operation_id] operation = operation_lookup[operation_id]
cast_opts = opts |> Map.take([:replace_params]) |> Map.to_list()
content_type = content_type =
case Conn.get_req_header(conn, "content-type") do case Conn.get_req_header(conn, "content-type") do
[header_value | _] -> [header_value | _] ->
@ -44,7 +46,7 @@ def call(conn, %{operation_id: operation_id, render_error: render_error}) do
conn = Conn.put_private(conn, :operation_id, operation_id) conn = Conn.put_private(conn, :operation_id, operation_id)
case cast_and_validate(spec, operation, conn, content_type, strict?()) do case cast_and_validate(spec, operation, conn, content_type, strict?(), cast_opts) do
{:ok, conn} -> {:ok, conn} ->
conn conn
@ -94,11 +96,11 @@ def call(
def call(conn, opts), do: OpenApiSpex.Plug.CastAndValidate.call(conn, opts) def call(conn, opts), do: OpenApiSpex.Plug.CastAndValidate.call(conn, opts)
defp cast_and_validate(spec, operation, conn, content_type, true = _strict) do defp cast_and_validate(spec, operation, conn, content_type, true = _strict, cast_opts) do
OpenApiSpex.cast_and_validate(spec, operation, conn, content_type) OpenApiSpex.cast_and_validate(spec, operation, conn, content_type, cast_opts)
end end
defp cast_and_validate(spec, operation, conn, content_type, false = _strict) do defp cast_and_validate(spec, operation, conn, content_type, false = _strict, cast_opts) do
case OpenApiSpex.cast_and_validate(spec, operation, conn, content_type) do case OpenApiSpex.cast_and_validate(spec, operation, conn, content_type) do
{:ok, conn} -> {:ok, conn} ->
{:ok, conn} {:ok, conn}
@ -123,7 +125,7 @@ defp cast_and_validate(spec, operation, conn, content_type, false = _strict) do
end) end)
conn = %Conn{conn | query_params: query_params} conn = %Conn{conn | query_params: query_params}
OpenApiSpex.cast_and_validate(spec, operation, conn, content_type) OpenApiSpex.cast_and_validate(spec, operation, conn, content_type, cast_opts)
end end
end end

View File

@ -62,7 +62,7 @@ def with_relationships_param do
Operation.parameter( Operation.parameter(
:with_relationships, :with_relationships,
:query, :query,
BooleanLike, BooleanLike.schema(),
"Embed relationships into accounts. **If this parameter is not set account's `pleroma.relationship` is going to be `null`.**" "Embed relationships into accounts. **If this parameter is not set account's `pleroma.relationship` is going to be `null`.**"
) )
end end

View File

@ -122,22 +122,27 @@ def statuses_operation do
parameters: parameters:
[ [
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}, %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
Operation.parameter(:pinned, :query, BooleanLike, "Include only pinned statuses"), Operation.parameter(
:pinned,
:query,
BooleanLike.schema(),
"Include only pinned statuses"
),
Operation.parameter(:tagged, :query, :string, "With tag"), Operation.parameter(:tagged, :query, :string, "With tag"),
Operation.parameter( Operation.parameter(
:only_media, :only_media,
:query, :query,
BooleanLike, BooleanLike.schema(),
"Include only statuses with media attached" "Include only statuses with media attached"
), ),
Operation.parameter( Operation.parameter(
:with_muted, :with_muted,
:query, :query,
BooleanLike, BooleanLike.schema(),
"Include statuses from muted accounts." "Include statuses from muted accounts."
), ),
Operation.parameter(:exclude_reblogs, :query, BooleanLike, "Exclude reblogs"), Operation.parameter(:exclude_reblogs, :query, BooleanLike.schema(), "Exclude reblogs"),
Operation.parameter(:exclude_replies, :query, BooleanLike, "Exclude replies"), Operation.parameter(:exclude_replies, :query, BooleanLike.schema(), "Exclude replies"),
Operation.parameter( Operation.parameter(
:exclude_visibilities, :exclude_visibilities,
:query, :query,
@ -147,7 +152,7 @@ def statuses_operation do
Operation.parameter( Operation.parameter(
:with_muted, :with_muted,
:query, :query,
BooleanLike, BooleanLike.schema(),
"Include reactions from muted accounts." "Include reactions from muted accounts."
) )
] ++ pagination_params(), ] ++ pagination_params(),
@ -882,9 +887,9 @@ defp follow_by_uri_request do
description: "POST body for muting an account", description: "POST body for muting an account",
type: :object, type: :object,
properties: %{ properties: %{
"uri" => %Schema{type: :string, nullable: true, format: :uri} uri: %Schema{type: :string, nullable: true, format: :uri}
}, },
required: ["uri"] required: [:uri]
} }
end end
@ -925,7 +930,7 @@ defp note_request do
description: "POST body for adding a note for an account", description: "POST body for adding a note for an account",
type: :object, type: :object,
properties: %{ properties: %{
"comment" => %Schema{ comment: %Schema{
type: :string, type: :string,
description: "Account note body" description: "Account note body"
} }

View File

@ -47,7 +47,7 @@ def update_operation do
request_body("Parameters", %Schema{ request_body("Parameters", %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"configs" => %Schema{ configs: %Schema{
type: :array, type: :array,
items: %Schema{ items: %Schema{
type: :object, type: :object,

View File

@ -61,9 +61,9 @@ defp update_request do
title: "UpdateRequest", title: "UpdateRequest",
description: "POST body for uploading the file", description: "POST body for uploading the file",
type: :object, type: :object,
required: ["file"], required: [:file],
properties: %{ properties: %{
"file" => %Schema{ file: %Schema{
type: :string, type: :string,
format: :binary, format: :binary,
description: "The file to be uploaded, using multipart form data." description: "The file to be uploaded, using multipart form data."

View File

@ -79,9 +79,9 @@ def revoke_operation do
"Parameters", "Parameters",
%Schema{ %Schema{
type: :object, type: :object,
required: ["token"], required: [:token],
properties: %{ properties: %{
"token" => %Schema{type: :string} token: %Schema{type: :string}
} }
}, },
required: true required: true
@ -106,10 +106,10 @@ def email_operation do
"Parameters", "Parameters",
%Schema{ %Schema{
type: :object, type: :object,
required: ["email"], required: [:email],
properties: %{ properties: %{
"email" => %Schema{type: :string, format: :email}, email: %Schema{type: :string, format: :email},
"name" => %Schema{type: :string} name: %Schema{type: :string}
} }
}, },
required: true required: true

View File

@ -78,9 +78,9 @@ def delete_operation do
"Parameters", "Parameters",
%Schema{ %Schema{
type: :object, type: :object,
required: ["urls"], required: [:urls],
properties: %{ properties: %{
"urls" => %Schema{type: :array, items: %Schema{type: :string, format: :uri}} urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}}
} }
}, },
required: true required: true
@ -104,10 +104,10 @@ def purge_operation do
"Parameters", "Parameters",
%Schema{ %Schema{
type: :object, type: :object,
required: ["urls"], required: [:urls],
properties: %{ properties: %{
"urls" => %Schema{type: :array, items: %Schema{type: :string, format: :uri}}, urls: %Schema{type: :array, items: %Schema{type: :string, format: :uri}},
"ban" => %Schema{type: :boolean, default: true} ban: %Schema{type: :boolean, default: true}
} }
}, },
required: true required: true

View File

@ -87,7 +87,7 @@ defp relay_url do
%Schema{ %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"relay_url" => %Schema{type: :string, format: :uri} relay_url: %Schema{type: :string, format: :uri}
} }
} }
end end
@ -96,8 +96,8 @@ defp relay_unfollow do
%Schema{ %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"relay_url" => %Schema{type: :string, format: :uri}, relay_url: %Schema{type: :string, format: :uri},
"force" => %Schema{type: :boolean, default: false} force: %Schema{type: :boolean, default: false}
} }
} }
end end

View File

@ -107,7 +107,7 @@ def notes_create_operation do
request_body("Parameters", %Schema{ request_body("Parameters", %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"content" => %Schema{type: :string, description: "The message"} content: %Schema{type: :string, description: "The message"}
} }
}), }),
security: [%{"oAuth" => ["admin:write:reports"]}], security: [%{"oAuth" => ["admin:write:reports"]}],
@ -141,7 +141,7 @@ def report_state do
end end
def id_param do def id_param do
Operation.parameter(:id, :path, FlakeID, "Report ID", Operation.parameter(:id, :path, FlakeID.schema(), "Report ID",
example: "9umDrYheeY451cQnEe", example: "9umDrYheeY451cQnEe",
required: true required: true
) )
@ -199,9 +199,9 @@ defp account_admin do
defp update_request do defp update_request do
%Schema{ %Schema{
type: :object, type: :object,
required: ["reports"], required: [:reports],
properties: %{ properties: %{
"reports" => %Schema{ reports: %Schema{
type: :array, type: :array,
items: %Schema{ items: %Schema{
type: :object, type: :object,

View File

@ -50,7 +50,7 @@ def index_operation do
%Schema{ %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"users" => %Schema{type: :array, items: user()}, users: %Schema{type: :array, items: user()},
count: %Schema{type: :integer}, count: %Schema{type: :integer},
page_size: %Schema{type: :integer} page_size: %Schema{type: :integer}
} }
@ -75,7 +75,7 @@ def create_operation do
description: "POST body for creating users", description: "POST body for creating users",
type: :object, type: :object,
properties: %{ properties: %{
"users" => %Schema{ users: %Schema{
type: :array, type: :array,
items: %Schema{ items: %Schema{
type: :object, type: :object,
@ -168,8 +168,8 @@ def follow_operation do
%Schema{ %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"follower" => %Schema{type: :string, description: "Follower nickname"}, follower: %Schema{type: :string, description: "Follower nickname"},
"followed" => %Schema{type: :string, description: "Followed nickname"} followed: %Schema{type: :string, description: "Followed nickname"}
} }
} }
), ),
@ -193,8 +193,8 @@ def unfollow_operation do
%Schema{ %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"follower" => %Schema{type: :string, description: "Follower nickname"}, follower: %Schema{type: :string, description: "Follower nickname"},
"followed" => %Schema{type: :string, description: "Followed nickname"} followed: %Schema{type: :string, description: "Followed nickname"}
} }
} }
), ),
@ -219,7 +219,7 @@ def approve_operation do
description: "POST body for approving multiple users", description: "POST body for approving multiple users",
type: :object, type: :object,
properties: %{ properties: %{
"nicknames" => %Schema{ nicknames: %Schema{
type: :array, type: :array,
items: %Schema{type: :string} items: %Schema{type: :string}
} }
@ -251,7 +251,7 @@ def suggest_operation do
description: "POST body for adding multiple suggested users", description: "POST body for adding multiple suggested users",
type: :object, type: :object,
properties: %{ properties: %{
"nicknames" => %Schema{ nicknames: %Schema{
type: :array, type: :array,
items: %Schema{type: :string} items: %Schema{type: :string}
} }
@ -283,7 +283,7 @@ def unsuggest_operation do
description: "POST body for removing multiple suggested users", description: "POST body for removing multiple suggested users",
type: :object, type: :object,
properties: %{ properties: %{
"nicknames" => %Schema{ nicknames: %Schema{
type: :array, type: :array,
items: %Schema{type: :string} items: %Schema{type: :string}
} }
@ -332,7 +332,7 @@ def activate_operation do
description: "POST body for deleting multiple users", description: "POST body for deleting multiple users",
type: :object, type: :object,
properties: %{ properties: %{
"nicknames" => %Schema{ nicknames: %Schema{
type: :array, type: :array,
items: %Schema{type: :string} items: %Schema{type: :string}
} }
@ -364,7 +364,7 @@ def deactivate_operation do
description: "POST body for deleting multiple users", description: "POST body for deleting multiple users",
type: :object, type: :object,
properties: %{ properties: %{
"nicknames" => %Schema{ nicknames: %Schema{
type: :array, type: :array,
items: %Schema{type: :string} items: %Schema{type: :string}
} }
@ -404,7 +404,7 @@ def delete_operation do
description: "POST body for deleting multiple users", description: "POST body for deleting multiple users",
type: :object, type: :object,
properties: %{ properties: %{
"nicknames" => %Schema{ nicknames: %Schema{
type: :array, type: :array,
items: %Schema{type: :string} items: %Schema{type: :string}
} }

View File

@ -137,7 +137,12 @@ def index_operation do
"Deprecated due to no support for pagination. Using [/api/v2/pleroma/chats](#operation/ChatController.index2) instead is recommended.", "Deprecated due to no support for pagination. Using [/api/v2/pleroma/chats](#operation/ChatController.index2) instead is recommended.",
operationId: "ChatController.index", operationId: "ChatController.index",
parameters: [ parameters: [
Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users") Operation.parameter(
:with_muted,
:query,
BooleanLike.schema(),
"Include chats from muted users"
)
], ],
responses: %{ responses: %{
200 => Operation.response("The chats of the user", "application/json", chats_response()) 200 => Operation.response("The chats of the user", "application/json", chats_response())
@ -156,7 +161,12 @@ def index2_operation do
summary: "Retrieve list of chats", summary: "Retrieve list of chats",
operationId: "ChatController.index2", operationId: "ChatController.index2",
parameters: [ parameters: [
Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users") Operation.parameter(
:with_muted,
:query,
BooleanLike.schema(),
"Include chats from muted users"
)
| pagination_params() | pagination_params()
], ],
responses: %{ responses: %{
@ -368,9 +378,9 @@ def mark_as_read do
title: "MarkAsReadRequest", title: "MarkAsReadRequest",
description: "POST body for marking a number of chat messages as read", description: "POST body for marking a number of chat messages as read",
type: :object, type: :object,
required: ["last_read_id"], required: [:last_read_id],
properties: %{ properties: %{
"last_read_id" => %Schema{ last_read_id: %Schema{
type: :string, type: :string,
description: "The content of your message." description: "The content of your message."
} }

View File

@ -29,7 +29,7 @@ def index_operation do
"Order by recent activity or account creation", "Order by recent activity or account creation",
required: nil required: nil
), ),
Operation.parameter(:local, :query, BooleanLike, "Include local users only") Operation.parameter(:local, :query, BooleanLike.schema(), "Include local users only")
] ++ pagination_params(), ] ++ pagination_params(),
responses: %{ responses: %{
200 => 200 =>

View File

@ -21,7 +21,7 @@ def index_operation do
summary: summary:
"Get an object of emoji to account mappings with accounts that reacted to the post", "Get an object of emoji to account mappings with accounts that reacted to the post",
parameters: [ parameters: [
Operation.parameter(:id, :path, FlakeID, "Status ID", required: true), Operation.parameter(:id, :path, FlakeID.schema(), "Status ID", required: true),
Operation.parameter(:emoji, :path, :string, "Filter by a single unicode emoji", Operation.parameter(:emoji, :path, :string, "Filter by a single unicode emoji",
required: nil required: nil
), ),
@ -45,7 +45,7 @@ def create_operation do
tags: ["Emoji reactions"], tags: ["Emoji reactions"],
summary: "React to a post with a unicode emoji", summary: "React to a post with a unicode emoji",
parameters: [ parameters: [
Operation.parameter(:id, :path, FlakeID, "Status ID", required: true), Operation.parameter(:id, :path, FlakeID.schema(), "Status ID", required: true),
Operation.parameter(:emoji, :path, :string, "A single character unicode emoji", Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
required: true required: true
) )
@ -64,7 +64,7 @@ def delete_operation do
tags: ["Emoji reactions"], tags: ["Emoji reactions"],
summary: "Remove a reaction to a post with a unicode emoji", summary: "Remove a reaction to a post with a unicode emoji",
parameters: [ parameters: [
Operation.parameter(:id, :path, FlakeID, "Status ID", required: true), Operation.parameter(:id, :path, FlakeID.schema(), "Status ID", required: true),
Operation.parameter(:emoji, :path, :string, "A single character unicode emoji", Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
required: true required: true
) )

View File

@ -62,7 +62,7 @@ def index_operation do
Operation.parameter( Operation.parameter(
:with_muted, :with_muted,
:query, :query,
BooleanLike, BooleanLike.schema(),
"Include the notifications from muted users" "Include the notifications from muted users"
) )
] ++ pagination_params(), ] ++ pagination_params(),

View File

@ -142,7 +142,7 @@ def birthdays_operation do
end end
defp id_param do defp id_param do
Operation.parameter(:id, :path, FlakeID, "Account ID", Operation.parameter(:id, :path, FlakeID.schema(), "Account ID",
example: "9umDrYheeY451cQnEe", example: "9umDrYheeY451cQnEe",
required: true required: true
) )

View File

@ -36,9 +36,9 @@ def create_operation do
defp create_request do defp create_request do
%Schema{ %Schema{
type: :object, type: :object,
required: ["file"], required: [:file],
properties: %{ properties: %{
"file" => %Schema{ file: %Schema{
description: description:
"File needs to be uploaded with the multipart request or link to remote file", "File needs to be uploaded with the multipart request or link to remote file",
anyOf: [ anyOf: [
@ -46,12 +46,12 @@ defp create_request do
%Schema{type: :string, format: :uri} %Schema{type: :string, format: :uri}
] ]
}, },
"shortcode" => %Schema{ shortcode: %Schema{
type: :string, type: :string,
description: description:
"Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename." "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, type: :string,
description: description:
"New emoji file name. If not specified will be taken from original filename." "New emoji file name. If not specified will be taken from original filename."
@ -81,21 +81,21 @@ def update_operation do
defp update_request do defp update_request do
%Schema{ %Schema{
type: :object, type: :object,
required: ["shortcode", "new_shortcode", "new_filename"], required: [:shortcode, :new_shortcode, :new_filename],
properties: %{ properties: %{
"shortcode" => %Schema{ shortcode: %Schema{
type: :string, type: :string,
description: "Emoji file shortcode" description: "Emoji file shortcode"
}, },
"new_shortcode" => %Schema{ new_shortcode: %Schema{
type: :string, type: :string,
description: "New emoji file shortcode" description: "New emoji file shortcode"
}, },
"new_filename" => %Schema{ new_filename: %Schema{
type: :string, type: :string,
description: "New filename for emoji file" description: "New filename for emoji file"
}, },
"force" => %Schema{ force: %Schema{
type: :boolean, type: :boolean,
description: "With true value to overwrite existing emoji with new shortcode", description: "With true value to overwrite existing emoji with new shortcode",
default: false default: false

View File

@ -130,15 +130,15 @@ def download_operation do
defp download_request do defp download_request do
%Schema{ %Schema{
type: :object, type: :object,
required: ["url", "name"], required: [:url, :name],
properties: %{ properties: %{
"url" => %Schema{ url: %Schema{
type: :string, type: :string,
format: :uri, format: :uri,
description: "URL of the instance to download from" description: "URL of the instance to download from"
}, },
"name" => %Schema{type: :string, format: :uri, description: "Pack Name"}, name: %Schema{type: :string, format: :uri, description: "Pack Name"},
"as" => %Schema{type: :string, format: :uri, description: "Save as"} as: %Schema{type: :string, format: :uri, description: "Save as"}
} }
} }
end end
@ -302,7 +302,27 @@ defp files_object do
defp update_request do defp update_request do
%Schema{ %Schema{
type: :object, type: :object,
properties: %{"metadata" => metadata()} 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?"}
}
}
}
} }
end end

View File

@ -39,7 +39,7 @@ def update_operation do
%Schema{ %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"file" => %Schema{type: :string, format: :binary} file: %Schema{type: :string, format: :binary}
} }
}, },
required: true required: true

View File

@ -24,11 +24,8 @@ def mark_as_read_operation do
request_body("Parameters", %Schema{ request_body("Parameters", %Schema{
type: :object, type: :object,
properties: %{ properties: %{
"id" => %Schema{type: :integer, description: "A single notification ID to read"}, id: %Schema{type: :integer, description: "A single notification ID to read"},
"max_id" => %Schema{ max_id: %Schema{type: :integer, description: "Read all notifications up to this ID"}
type: :integer,
description: "Read all notifications up to this ID"
}
} }
}), }),
security: [%{"oAuth" => ["write:notifications"]}], security: [%{"oAuth" => ["write:notifications"]}],

View File

@ -37,7 +37,7 @@ def quotes_operation do
end end
def id_param do def id_param do
Operation.parameter(:id, :path, FlakeID, "Status ID", Operation.parameter(:id, :path, FlakeID.schema(), "Status ID",
example: "9umDrYheeY451cQnEe", example: "9umDrYheeY451cQnEe",
required: true required: true
) )

View File

@ -47,7 +47,7 @@ def vote_operation do
end end
defp id_param do defp id_param do
Operation.parameter(:id, :path, FlakeID, "Poll ID", Operation.parameter(:id, :path, FlakeID.schema(), "Poll ID",
example: "123", example: "123",
required: true required: true
) )

View File

@ -88,7 +88,7 @@ def delete_operation do
end end
defp id_param do defp id_param do
Operation.parameter(:id, :path, FlakeID, "Poll ID", Operation.parameter(:id, :path, FlakeID.schema(), "Poll ID",
example: "123", example: "123",
required: true required: true
) )

View File

@ -70,7 +70,7 @@ def search_operation do
Operation.parameter( Operation.parameter(
:account_id, :account_id,
:query, :query,
FlakeID, FlakeID.schema(),
"If provided, statuses returned will be authored only by this account" "If provided, statuses returned will be authored only by this account"
), ),
Operation.parameter( Operation.parameter(
@ -116,7 +116,7 @@ def search2_operation do
Operation.parameter( Operation.parameter(
:account_id, :account_id,
:query, :query,
FlakeID, FlakeID.schema(),
"If provided, statuses returned will be authored only by this account" "If provided, statuses returned will be authored only by this account"
), ),
Operation.parameter( Operation.parameter(

View File

@ -39,7 +39,7 @@ def index_operation do
Operation.parameter( Operation.parameter(
:with_muted, :with_muted,
:query, :query,
BooleanLike, BooleanLike.schema(),
"Include reactions from muted acccounts." "Include reactions from muted acccounts."
) )
], ],
@ -82,7 +82,7 @@ def show_operation do
Operation.parameter( Operation.parameter(
:with_muted, :with_muted,
:query, :query,
BooleanLike, BooleanLike.schema(),
"Include reactions from muted acccounts." "Include reactions from muted acccounts."
) )
], ],
@ -685,7 +685,7 @@ def poll_params do
end end
def id_param do def id_param do
Operation.parameter(:id, :path, FlakeID, "Status ID", Operation.parameter(:id, :path, FlakeID.schema(), "Status ID",
example: "9umDrYheeY451cQnEe", example: "9umDrYheeY451cQnEe",
required: true required: true
) )

View File

@ -176,7 +176,12 @@ defp instance_param do
end end
defp with_muted_param do defp with_muted_param do
Operation.parameter(:with_muted, :query, BooleanLike, "Include activities by muted users") Operation.parameter(
:with_muted,
:query,
BooleanLike.schema(),
"Include activities by muted users"
)
end end
defp exclude_visibilities_param do defp exclude_visibilities_param do

View File

@ -146,13 +146,13 @@ def update_notification_settings_operation do
Operation.parameter( Operation.parameter(
:block_from_strangers, :block_from_strangers,
:query, :query,
BooleanLike, BooleanLike.schema(),
"blocks notifications from accounts you do not follow" "blocks notifications from accounts you do not follow"
), ),
Operation.parameter( Operation.parameter(
:hide_notification_contents, :hide_notification_contents,
:query, :query,
BooleanLike, BooleanLike.schema(),
"removes the contents of a message from the push notification" "removes the contents of a message from the push notification"
) )
], ],
@ -404,10 +404,10 @@ defp remote_interaction_request do
title: "RemoteInteractionRequest", title: "RemoteInteractionRequest",
description: "POST body for remote interaction", description: "POST body for remote interaction",
type: :object, type: :object,
required: ["ap_id", "profile"], required: [:ap_id, :profile],
properties: %{ properties: %{
"ap_id" => %Schema{type: :string, description: "Profile or status ActivityPub ID"}, ap_id: %Schema{type: :string, description: "Profile or status ActivityPub ID"},
"profile" => %Schema{type: :string, description: "Remote profile webfinger"} profile: %Schema{type: :string, description: "Remote profile webfinger"}
} }
} }
end end

View File

@ -61,9 +61,9 @@ def mutes_operation do
defp import_request do defp import_request do
%Schema{ %Schema{
type: :object, type: :object,
required: ["list"], required: [:list],
properties: %{ properties: %{
"list" => %Schema{ list: %Schema{
description: description:
"STRING or FILE containing a whitespace-separated list of accounts to import.", "STRING or FILE containing a whitespace-separated list of accounts to import.",
anyOf: [ anyOf: [

View File

@ -93,10 +93,7 @@ def assign_account_by_id(conn, _) do
end end
def try_render(conn, target, params) when is_binary(target) do def try_render(conn, target, params) when is_binary(target) do
case render(conn, target, params) do render(conn, target, params)
nil -> render_error(conn, :not_implemented, "Can't display this activity")
res -> res
end
end end
def try_render(conn, _, _) do def try_render(conn, _, _) do

View File

@ -472,7 +472,7 @@ def unblock(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
@doc "POST /api/v1/accounts/:id/note" @doc "POST /api/v1/accounts/:id/note"
def note( def note(
%{assigns: %{user: noter, account: target}, body_params: %{"comment" => comment}} = conn, %{assigns: %{user: noter, account: target}, body_params: %{comment: comment}} = conn,
_params _params
) do ) do
with {:ok, _user_note} <- UserNote.create(noter, target, comment) do with {:ok, _user_note} <- UserNote.create(noter, target, comment) do
@ -513,7 +513,7 @@ def remove_from_followers(%{assigns: %{user: followed, account: follower}} = con
end end
@doc "POST /api/v1/follows" @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 case User.get_cached_by_nickname(uri) do
%User{} = user -> %User{} = user ->
conn conn

View File

@ -8,7 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.DomainBlockOperation defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.DomainBlockOperation
plug( plug(
@ -27,23 +27,31 @@ def index(%{assigns: %{user: user}} = conn, _) do
end end
@doc "POST /api/v1/domain_blocks" @doc "POST /api/v1/domain_blocks"
def create(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do def create(
%{assigns: %{user: blocker}, private: %{open_api_spex: %{body_params: %{domain: domain}}}} =
conn,
_params
) do
User.block_domain(blocker, domain) User.block_domain(blocker, domain)
json(conn, %{}) json(conn, %{})
end end
def create(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do def create(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
User.block_domain(blocker, domain) User.block_domain(blocker, domain)
json(conn, %{}) json(conn, %{})
end end
@doc "DELETE /api/v1/domain_blocks" @doc "DELETE /api/v1/domain_blocks"
def delete(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do def delete(
%{assigns: %{user: blocker}, private: %{open_api_spex: %{body_params: %{domain: domain}}}} =
conn,
_params
) do
User.unblock_domain(blocker, domain) User.unblock_domain(blocker, domain)
json(conn, %{}) json(conn, %{})
end end
def delete(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do def delete(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
User.unblock_domain(blocker, domain) User.unblock_domain(blocker, domain)
json(conn, %{}) json(conn, %{})
end end

View File

@ -796,8 +796,6 @@ defp build_image_url(%URI{} = image_url_data, %URI{} = page_url_data) do
URI.merge(page_url_data, image_url_data) |> to_string URI.merge(page_url_data, image_url_data) |> to_string
end end
defp build_image_url(_, _), do: nil
defp get_source_text(%{"content" => content} = _source) do defp get_source_text(%{"content" => content} = _source) do
content content
end end

View File

@ -56,7 +56,7 @@ defp handle_preview(conn, url) do
media_proxy_url = MediaProxy.url(url) media_proxy_url = MediaProxy.url(url)
with {:ok, %{status: status} = head_response} when status in 200..299 <- with {:ok, %{status: status} = head_response} when status in 200..299 <-
Pleroma.HTTP.request("HEAD", media_proxy_url, [], [], pool: :media) do Pleroma.HTTP.request(:head, media_proxy_url, "", [], pool: :media) do
content_type = Tesla.get_header(head_response, "content-type") content_type = Tesla.get_header(head_response, "content-type")
content_length = Tesla.get_header(head_response, "content-length") content_length = Tesla.get_header(head_response, "content-length")
content_length = content_length && String.to_integer(content_length) content_length = content_length && String.to_integer(content_length)

View File

@ -120,7 +120,7 @@ def mark_message_as_read(
end end
def mark_as_read( 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} %{id: id}
) do ) do
with {:ok, chat} <- Chat.get_by_user_and_id(user, id), with {:ok, chat} <- Chat.get_by_user_and_id(user, id),

View File

@ -23,11 +23,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
defdelegate open_api_operation(action), to: ApiSpec.PleromaEmojiFileOperation defdelegate open_api_operation(action), to: ApiSpec.PleromaEmojiFileOperation
def create(%{body_params: params} = conn, %{name: pack_name}) do def create(%{body_params: params} = conn, %{name: pack_name}) do
filename = params["filename"] || get_filename(params["file"]) filename = params[:filename] || get_filename(params[:file])
shortcode = params["shortcode"] || Path.basename(filename, Path.extname(filename)) shortcode = params[:shortcode] || Path.basename(filename, Path.extname(filename))
with {:ok, pack} <- Pack.load_pack(pack_name), 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 {:ok, pack} <- Pack.add_file(pack, shortcode, filename, file) do
json(conn, pack.files) json(conn, pack.files)
else else
@ -49,10 +49,10 @@ def create(%{body_params: params} = conn, %{name: pack_name}) do
end end
end end
def update(%{body_params: %{"shortcode" => shortcode} = params} = conn, %{name: pack_name}) do def update(%{body_params: %{shortcode: shortcode} = params} = conn, %{name: pack_name}) do
new_shortcode = params["new_shortcode"] new_shortcode = params[:new_shortcode]
new_filename = params["new_filename"] new_filename = params[:new_filename]
force = params["force"] force = params[:force]
with {:ok, pack} <- Pack.load_pack(pack_name), with {:ok, pack} <- Pack.load_pack(pack_name),
{:ok, pack} <- Pack.update_file(pack, shortcode, new_shortcode, new_filename, force) do {:ok, pack} <- Pack.update_file(pack, shortcode, new_shortcode, new_filename, force) do
@ -128,9 +128,9 @@ defp handle_error(conn, {:error, error}, opts) do
defp get_filename(%Plug.Upload{filename: filename}), do: filename defp get_filename(%Plug.Upload{filename: filename}), do: filename
defp get_filename(url) when is_binary(url), do: Path.basename(url) defp get_filename(url) when is_binary(url), do: Path.basename(url)
defp get_file(%Plug.Upload{} = file), do: {:ok, file} def get_file(%Plug.Upload{} = file), do: {:ok, file}
defp get_file(url) when is_binary(url) do def get_file(url) when is_binary(url) do
with {:ok, %Tesla.Env{body: body, status: code, headers: headers}} with {:ok, %Tesla.Env{body: body, status: code, headers: headers}}
when code in 200..299 <- Pleroma.HTTP.get(url) do when code in 200..299 <- Pleroma.HTTP.get(url) do
path = Plug.Upload.random_file!("emoji") path = Plug.Upload.random_file!("emoji")

View File

@ -109,8 +109,8 @@ def archive(conn, %{name: name}) do
end end
end end
def download(%{body_params: %{"url" => url, "name" => name} = params} = conn, _) do def download(%{body_params: %{url: url, name: name} = params} = conn, _) do
with {:ok, _pack} <- Pack.download(name, url, params["as"]) do with {:ok, _pack} <- Pack.download(name, url, params[:as]) do
json(conn, "ok") json(conn, "ok")
else else
{:error, :not_shareable} -> {:error, :not_shareable} ->
@ -184,7 +184,7 @@ def delete(conn, %{name: name}) do
end end
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 with {:ok, pack} <- Pack.update_metadata(name, metadata) do
json(conn, pack.pack) json(conn, pack.pack)
else else

View File

@ -22,9 +22,9 @@ def show(%{assigns: %{user: user}} = conn, _params) do
end end
@doc "PUT /api/v1/pleroma/mascot" @doc "PUT /api/v1/pleroma/mascot"
def update(%{assigns: %{user: user}, body_params: %{"file" => file}} = conn, _) do def update(%{assigns: %{user: user}, body_params: %{file: file}} = conn, _) do
with {_, "image" <> _} <- {:content_type, file.content_type}, with {:content_type, "image" <> _} <- {:content_type, file.content_type},
{_, {:ok, object}} <- {:upload, ActivityPub.upload(file, actor: User.ap_id(user))} do {:ok, object} <- ActivityPub.upload(file, actor: User.ap_id(user)) do
attachment = render_attachment(object) attachment = render_attachment(object)
{:ok, _user} = User.mascot_update(user, attachment) {:ok, _user} = User.mascot_update(user, attachment)

View File

@ -16,7 +16,7 @@ defmodule Pleroma.Web.PleromaAPI.NotificationController do
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaNotificationOperation 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 with {:ok, notification} <- Notification.read_one(user, notification_id) do
render(conn, "show.json", notification: notification, for: user) render(conn, "show.json", notification: notification, for: user)
else else
@ -27,7 +27,7 @@ def mark_as_read(%{assigns: %{user: user}, body_params: %{"id" => notification_i
end end
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 = notifications =
user user
|> Notification.set_read_up_to(max_id) |> Notification.set_read_up_to(max_id)

View File

@ -18,11 +18,11 @@ defmodule Pleroma.Web.PleromaAPI.UserImportController do
plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)
defdelegate open_api_operation(action), to: ApiSpec.UserImportOperation defdelegate open_api_operation(action), to: ApiSpec.UserImportOperation
def follow(%{body_params: %{"list" => %Plug.Upload{path: path}}} = conn, _) do def follow(%{body_params: %{list: %Plug.Upload{path: path}}} = conn, _) do
follow(%Plug.Conn{conn | body_params: %{"list" => File.read!(path)}}, %{}) follow(%Plug.Conn{conn | body_params: %{list: File.read!(path)}}, %{})
end end
def follow(%{assigns: %{user: follower}, body_params: %{"list" => list}} = conn, _) do def follow(%{assigns: %{user: follower}, body_params: %{list: list}} = conn, _) do
identifiers = identifiers =
list list
|> String.split("\n") |> String.split("\n")
@ -35,20 +35,20 @@ def follow(%{assigns: %{user: follower}, body_params: %{"list" => list}} = conn,
json(conn, "job started") json(conn, "job started")
end end
def blocks(%{body_params: %{"list" => %Plug.Upload{path: path}}} = conn, _) do def blocks(%{body_params: %{list: %Plug.Upload{path: path}}} = conn, _) do
blocks(%Plug.Conn{conn | body_params: %{"list" => File.read!(path)}}, %{}) blocks(%Plug.Conn{conn | body_params: %{list: File.read!(path)}}, %{})
end 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)) User.Import.blocks_import(blocker, prepare_user_identifiers(list))
json(conn, "job started") json(conn, "job started")
end end
def mutes(%{body_params: %{"list" => %Plug.Upload{path: path}}} = conn, _) do def mutes(%{body_params: %{list: %Plug.Upload{path: path}}} = conn, _) do
mutes(%Plug.Conn{conn | body_params: %{"list" => File.read!(path)}}, %{}) mutes(%Plug.Conn{conn | body_params: %{list: File.read!(path)}}, %{})
end 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)) User.Import.mutes_import(user, prepare_user_identifiers(list))
json(conn, "job started") json(conn, "job started")
end end

View File

@ -150,10 +150,7 @@ def remote_subscribe(conn, %{"status" => %{"status_id" => id, "profile" => profi
end end
end end
def remote_interaction( def remote_interaction(%{body_params: %{ap_id: ap_id, profile: profile}} = conn, _params) do
%{body_params: %{"ap_id" => ap_id, "profile" => profile}} = conn,
_params
) do
with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile) do with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile) do
conn conn
|> json(%{url: String.replace(template, "{uri}", ap_id)}) |> json(%{url: String.replace(template, "{uri}", ap_id)})

View File

@ -88,7 +88,7 @@
"nodex": {:git, "https://git.pleroma.social/pleroma/nodex", "cb6730f943cfc6aad674c92161be23a8411f15d1", [ref: "cb6730f943cfc6aad674c92161be23a8411f15d1"]}, "nodex": {:git, "https://git.pleroma.social/pleroma/nodex", "cb6730f943cfc6aad674c92161be23a8411f15d1", [ref: "cb6730f943cfc6aad674c92161be23a8411f15d1"]},
"oban": {:hex, :oban, "2.13.6", "a0cb1bce3bd393770512231fb5a3695fa19fd3af10d7575bf73f837aee7abf43", [:mix], [{:ecto_sql, "~> 3.6", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c1c5eb16f377b3cbbf2ea14be24d20e3d91285af9d1ac86260b7c2af5464887"}, "oban": {:hex, :oban, "2.13.6", "a0cb1bce3bd393770512231fb5a3695fa19fd3af10d7575bf73f837aee7abf43", [:mix], [{:ecto_sql, "~> 3.6", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c1c5eb16f377b3cbbf2ea14be24d20e3d91285af9d1ac86260b7c2af5464887"},
"octo_fetch": {:hex, :octo_fetch, "0.4.0", "074b5ecbc08be10b05b27e9db08bc20a3060142769436242702931c418695b19", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "cf8be6f40cd519d7000bb4e84adcf661c32e59369ca2827c4e20042eda7a7fc6"}, "octo_fetch": {:hex, :octo_fetch, "0.4.0", "074b5ecbc08be10b05b27e9db08bc20a3060142769436242702931c418695b19", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "cf8be6f40cd519d7000bb4e84adcf661c32e59369ca2827c4e20042eda7a7fc6"},
"open_api_spex": {:hex, :open_api_spex, "3.18.1", "0a73cd5dbcba7d32952dd9738c6819892933d9bae1642f04c9f200281524dd31", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}, {:ymlr, "~> 2.0 or ~> 3.0 or ~> 4.0", [hex: :ymlr, repo: "hexpm", optional: true]}], "hexpm", "f52933cddecca675e42ead660379ae2d3853f57f5a35d201eaed85e2e81517d1"}, "open_api_spex": {:hex, :open_api_spex, "3.18.2", "8c855e83bfe8bf81603d919d6e892541eafece3720f34d1700b58024dadde247", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}, {:ymlr, "~> 2.0 or ~> 3.0 or ~> 4.0", [hex: :ymlr, repo: "hexpm", optional: true]}], "hexpm", "aa3e6dcfc0ad6a02596b2172662da21c9dd848dac145ea9e603f54e3d81b8d2b"},
"parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
"pbkdf2_elixir": {:hex, :pbkdf2_elixir, "1.2.1", "9cbe354b58121075bd20eb83076900a3832324b7dd171a6895fab57b6bb2752c", [:mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}], "hexpm", "d3b40a4a4630f0b442f19eca891fcfeeee4c40871936fed2f68e1c4faa30481f"}, "pbkdf2_elixir": {:hex, :pbkdf2_elixir, "1.2.1", "9cbe354b58121075bd20eb83076900a3832324b7dd171a6895fab57b6bb2752c", [:mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}], "hexpm", "d3b40a4a4630f0b442f19eca891fcfeeee4c40871936fed2f68e1c4faa30481f"},
"phoenix": {:hex, :phoenix, "1.7.10", "02189140a61b2ce85bb633a9b6fd02dff705a5f1596869547aeb2b2b95edd729", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "cf784932e010fd736d656d7fead6a584a4498efefe5b8227e9f383bf15bb79d0"}, "phoenix": {:hex, :phoenix, "1.7.10", "02189140a61b2ce85bb633a9b6fd02dff705a5f1596869547aeb2b2b95edd729", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "cf784932e010fd736d656d7fead6a584a4498efefe5b8227e9f383bf15bb79d0"},

View File

@ -873,7 +873,7 @@ test "tuples with more than two values", %{conn: conn} do
%{ %{
"tuple" => [ "tuple" => [
":_", ":_",
"Plug.Cowboy.Handler", "Phoenix.Endpoint.Cowboy2Handler",
%{"tuple" => ["Pleroma.Web.Endpoint", []]} %{"tuple" => ["Pleroma.Web.Endpoint", []]}
] ]
} }
@ -937,7 +937,7 @@ test "tuples with more than two values", %{conn: conn} do
%{ %{
"tuple" => [ "tuple" => [
":_", ":_",
"Plug.Cowboy.Handler", "Phoenix.Endpoint.Cowboy2Handler",
%{"tuple" => ["Pleroma.Web.Endpoint", []]} %{"tuple" => ["Pleroma.Web.Endpoint", []]}
] ]
} }

View File

@ -182,7 +182,7 @@ test "responds with 424 Failed Dependency if HEAD request to media proxy fails",
media_proxy_url: media_proxy_url media_proxy_url: media_proxy_url
} do } do
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{status: 500, body: ""} %Tesla.Env{status: 500, body: ""}
end) end)
@ -197,7 +197,7 @@ test "redirects to media proxy URI on unsupported content type", %{
media_proxy_url: media_proxy_url media_proxy_url: media_proxy_url
} do } do
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/pdf"}]} %Tesla.Env{status: 200, body: "", headers: [{"content-type", "application/pdf"}]}
end) end)
@ -217,7 +217,7 @@ test "with `static=true` and GIF image preview requested, responds with JPEG ima
clear_config([:media_preview_proxy, :min_content_length], 1_000_000_000) clear_config([:media_preview_proxy, :min_content_length], 1_000_000_000)
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
body: "", body: "",
@ -242,7 +242,7 @@ test "with GIF image preview requested and no `static` param, redirects to media
media_proxy_url: media_proxy_url media_proxy_url: media_proxy_url
} do } do
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/gif"}]} %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/gif"}]}
end) end)
@ -260,7 +260,7 @@ test "with `static` param and non-GIF image preview requested, " <>
media_proxy_url: media_proxy_url media_proxy_url: media_proxy_url
} do } do
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]} %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
end) end)
@ -280,7 +280,7 @@ test "with :min_content_length setting not matched by Content-Length header, " <
clear_config([:media_preview_proxy, :min_content_length], 100_000) clear_config([:media_preview_proxy, :min_content_length], 100_000)
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{ %Tesla.Env{
status: 200, status: 200,
body: "", body: "",
@ -302,7 +302,7 @@ test "thumbnails PNG images into PNG", %{
assert_dependencies_installed() assert_dependencies_installed()
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/png"}]} %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/png"}]}
%{method: :get, url: ^media_proxy_url} -> %{method: :get, url: ^media_proxy_url} ->
@ -324,7 +324,7 @@ test "thumbnails JPEG images into JPEG", %{
assert_dependencies_installed() assert_dependencies_installed()
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]} %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
%{method: :get, url: ^media_proxy_url} -> %{method: :get, url: ^media_proxy_url} ->
@ -344,7 +344,7 @@ test "redirects to media proxy URI in case of thumbnailing error", %{
media_proxy_url: media_proxy_url media_proxy_url: media_proxy_url
} do } do
Tesla.Mock.mock(fn Tesla.Mock.mock(fn
%{method: "HEAD", url: ^media_proxy_url} -> %{method: :head, url: ^media_proxy_url} ->
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]} %Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
%{method: :get, url: ^media_proxy_url} -> %{method: :get, url: ^media_proxy_url} ->