From 4fc177eb460c14dc1e8f4eedcbce95c242eef60d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 29 Jan 2024 16:42:48 -0500 Subject: [PATCH 01/27] Pleroma.Web.ControllerHelper: dialyzer error lib/pleroma/web/controller_helper.ex:97:pattern_match The pattern can never match the type. Pattern: nil Type: %Plug.Conn{ :adapter => {atom(), _}, :assigns => %{atom() => _}, :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :halted => boolean(), :host => binary(), :method => binary(), :owner => pid(), :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :path_info => [binary()], :path_params => %{ binary() => binary() | [binary() | [any()] | %{binary() => _}] | %{binary() => binary() | [any()] | %{binary() => _}} }, :port => char(), :private => %{atom() => _}, :query_params => %Plug.Conn.Unfetched{ :aspect => atom(), binary() => binary() | [binary() | [any()] | %{binary() => _}] | %{binary() => binary() | [any()] | %{binary() => _}} }, :query_string => binary(), :remote_ip => {byte(), byte(), byte(), byte()} | {char(), char(), char(), char(), char(), char(), char(), char()}, :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()}, :req_headers => [{binary(), binary()}], :request_path => binary(), :resp_body => nil | binary() | maybe_improper_list( binary() | maybe_improper_list(any(), binary() | []) | byte(), binary() | [] ), :resp_cookies => %{binary() => map()}, :resp_headers => [{binary(), binary()}], :scheme => :http | :https, :script_name => [binary()], :secret_key_base => nil | binary(), :state => :sent, :status => nil | non_neg_integer() } --- lib/pleroma/web/controller_helper.ex | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index 0c7fc17f4..36f7442b3 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -93,10 +93,7 @@ defmodule Pleroma.Web.ControllerHelper do end def try_render(conn, target, params) when is_binary(target) do - case render(conn, target, params) do - nil -> render_error(conn, :not_implemented, "Can't display this activity") - res -> res - end + render(conn, target, params) end def try_render(conn, _, _) do From 2de84e2e3beb5fe74760a3af083109eed00262f0 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 29 Jan 2024 17:10:28 -0500 Subject: [PATCH 02/27] API Specs: many dialyzer errors Too many to include in a commit log Module instead of schema was being passed --- lib/pleroma/web/api_spec/helpers.ex | 2 +- .../api_spec/operations/account_operation.ex | 17 +++++++++++------ .../operations/admin/report_operation.ex | 2 +- .../web/api_spec/operations/chat_operation.ex | 14 ++++++++++++-- .../api_spec/operations/directory_operation.ex | 2 +- .../operations/emoji_reaction_operation.ex | 6 +++--- .../operations/notification_operation.ex | 2 +- .../operations/pleroma_account_operation.ex | 2 +- .../operations/pleroma_status_operation.ex | 2 +- .../web/api_spec/operations/poll_operation.ex | 2 +- .../operations/scheduled_activity_operation.ex | 2 +- .../web/api_spec/operations/search_operation.ex | 4 ++-- .../web/api_spec/operations/status_operation.ex | 6 +++--- .../api_spec/operations/timeline_operation.ex | 7 ++++++- .../operations/twitter_util_operation.ex | 4 ++-- 15 files changed, 47 insertions(+), 27 deletions(-) diff --git a/lib/pleroma/web/api_spec/helpers.ex b/lib/pleroma/web/api_spec/helpers.ex index f20a9163d..7257253ba 100644 --- a/lib/pleroma/web/api_spec/helpers.ex +++ b/lib/pleroma/web/api_spec/helpers.ex @@ -62,7 +62,7 @@ defmodule Pleroma.Web.ApiSpec.Helpers do Operation.parameter( :with_relationships, :query, - BooleanLike, + BooleanLike.schema(), "Embed relationships into accounts. **If this parameter is not set account's `pleroma.relationship` is going to be `null`.**" ) end diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 5d8d16e98..357022973 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -122,22 +122,27 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do parameters: [ %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( :only_media, :query, - BooleanLike, + BooleanLike.schema(), "Include only statuses with media attached" ), Operation.parameter( :with_muted, :query, - BooleanLike, + BooleanLike.schema(), "Include statuses from muted accounts." ), - Operation.parameter(:exclude_reblogs, :query, BooleanLike, "Exclude reblogs"), - Operation.parameter(:exclude_replies, :query, BooleanLike, "Exclude replies"), + Operation.parameter(:exclude_reblogs, :query, BooleanLike.schema(), "Exclude reblogs"), + Operation.parameter(:exclude_replies, :query, BooleanLike.schema(), "Exclude replies"), Operation.parameter( :exclude_visibilities, :query, @@ -147,7 +152,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do Operation.parameter( :with_muted, :query, - BooleanLike, + BooleanLike.schema(), "Include reactions from muted accounts." ) ] ++ pagination_params(), diff --git a/lib/pleroma/web/api_spec/operations/admin/report_operation.ex b/lib/pleroma/web/api_spec/operations/admin/report_operation.ex index 3902f12f1..29b08d93c 100644 --- a/lib/pleroma/web/api_spec/operations/admin/report_operation.ex +++ b/lib/pleroma/web/api_spec/operations/admin/report_operation.ex @@ -141,7 +141,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.ReportOperation do end def id_param do - Operation.parameter(:id, :path, FlakeID, "Report ID", + Operation.parameter(:id, :path, FlakeID.schema(), "Report ID", example: "9umDrYheeY451cQnEe", required: true ) diff --git a/lib/pleroma/web/api_spec/operations/chat_operation.ex b/lib/pleroma/web/api_spec/operations/chat_operation.ex index cee39f9d3..d3b033f0b 100644 --- a/lib/pleroma/web/api_spec/operations/chat_operation.ex +++ b/lib/pleroma/web/api_spec/operations/chat_operation.ex @@ -137,7 +137,12 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do "Deprecated due to no support for pagination. Using [/api/v2/pleroma/chats](#operation/ChatController.index2) instead is recommended.", operationId: "ChatController.index", 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: %{ 200 => Operation.response("The chats of the user", "application/json", chats_response()) @@ -156,7 +161,12 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do summary: "Retrieve list of chats", operationId: "ChatController.index2", 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() ], responses: %{ diff --git a/lib/pleroma/web/api_spec/operations/directory_operation.ex b/lib/pleroma/web/api_spec/operations/directory_operation.ex index 23fa84dff..2eca17664 100644 --- a/lib/pleroma/web/api_spec/operations/directory_operation.ex +++ b/lib/pleroma/web/api_spec/operations/directory_operation.ex @@ -29,7 +29,7 @@ defmodule Pleroma.Web.ApiSpec.DirectoryOperation do "Order by recent activity or account creation", required: nil ), - Operation.parameter(:local, :query, BooleanLike, "Include local users only") + Operation.parameter(:local, :query, BooleanLike.schema(), "Include local users only") ] ++ pagination_params(), responses: %{ 200 => diff --git a/lib/pleroma/web/api_spec/operations/emoji_reaction_operation.ex b/lib/pleroma/web/api_spec/operations/emoji_reaction_operation.ex index 74341d64f..8d6be89a7 100644 --- a/lib/pleroma/web/api_spec/operations/emoji_reaction_operation.ex +++ b/lib/pleroma/web/api_spec/operations/emoji_reaction_operation.ex @@ -21,7 +21,7 @@ defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do summary: "Get an object of emoji to account mappings with accounts that reacted to the post", 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", required: nil ), @@ -45,7 +45,7 @@ defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do tags: ["Emoji reactions"], summary: "React to a post with a unicode emoji", 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", required: true ) @@ -64,7 +64,7 @@ defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do tags: ["Emoji reactions"], summary: "Remove a reaction to a post with a unicode emoji", 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", required: true ) diff --git a/lib/pleroma/web/api_spec/operations/notification_operation.ex b/lib/pleroma/web/api_spec/operations/notification_operation.ex index 56aa129d2..757429d12 100644 --- a/lib/pleroma/web/api_spec/operations/notification_operation.ex +++ b/lib/pleroma/web/api_spec/operations/notification_operation.ex @@ -62,7 +62,7 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do Operation.parameter( :with_muted, :query, - BooleanLike, + BooleanLike.schema(), "Include the notifications from muted users" ) ] ++ pagination_params(), diff --git a/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex index 5375c5b15..7340653fb 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_account_operation.ex @@ -142,7 +142,7 @@ defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do end defp id_param do - Operation.parameter(:id, :path, FlakeID, "Account ID", + Operation.parameter(:id, :path, FlakeID.schema(), "Account ID", example: "9umDrYheeY451cQnEe", required: true ) diff --git a/lib/pleroma/web/api_spec/operations/pleroma_status_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_status_operation.ex index 6e69c5269..77c604952 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_status_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_status_operation.ex @@ -37,7 +37,7 @@ defmodule Pleroma.Web.ApiSpec.PleromaStatusOperation do end def id_param do - Operation.parameter(:id, :path, FlakeID, "Status ID", + Operation.parameter(:id, :path, FlakeID.schema(), "Status ID", example: "9umDrYheeY451cQnEe", required: true ) diff --git a/lib/pleroma/web/api_spec/operations/poll_operation.ex b/lib/pleroma/web/api_spec/operations/poll_operation.ex index efd784f03..6dd251743 100644 --- a/lib/pleroma/web/api_spec/operations/poll_operation.ex +++ b/lib/pleroma/web/api_spec/operations/poll_operation.ex @@ -47,7 +47,7 @@ defmodule Pleroma.Web.ApiSpec.PollOperation do end defp id_param do - Operation.parameter(:id, :path, FlakeID, "Poll ID", + Operation.parameter(:id, :path, FlakeID.schema(), "Poll ID", example: "123", required: true ) diff --git a/lib/pleroma/web/api_spec/operations/scheduled_activity_operation.ex b/lib/pleroma/web/api_spec/operations/scheduled_activity_operation.ex index 802d3b6dd..c7ed02ff3 100644 --- a/lib/pleroma/web/api_spec/operations/scheduled_activity_operation.ex +++ b/lib/pleroma/web/api_spec/operations/scheduled_activity_operation.ex @@ -88,7 +88,7 @@ defmodule Pleroma.Web.ApiSpec.ScheduledActivityOperation do end defp id_param do - Operation.parameter(:id, :path, FlakeID, "Poll ID", + Operation.parameter(:id, :path, FlakeID.schema(), "Poll ID", example: "123", required: true ) diff --git a/lib/pleroma/web/api_spec/operations/search_operation.ex b/lib/pleroma/web/api_spec/operations/search_operation.ex index 1a7e49be4..539743ba3 100644 --- a/lib/pleroma/web/api_spec/operations/search_operation.ex +++ b/lib/pleroma/web/api_spec/operations/search_operation.ex @@ -70,7 +70,7 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do Operation.parameter( :account_id, :query, - FlakeID, + FlakeID.schema(), "If provided, statuses returned will be authored only by this account" ), Operation.parameter( @@ -116,7 +116,7 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do Operation.parameter( :account_id, :query, - FlakeID, + FlakeID.schema(), "If provided, statuses returned will be authored only by this account" ), Operation.parameter( diff --git a/lib/pleroma/web/api_spec/operations/status_operation.ex b/lib/pleroma/web/api_spec/operations/status_operation.ex index f52372c18..ef4e34044 100644 --- a/lib/pleroma/web/api_spec/operations/status_operation.ex +++ b/lib/pleroma/web/api_spec/operations/status_operation.ex @@ -39,7 +39,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do Operation.parameter( :with_muted, :query, - BooleanLike, + BooleanLike.schema(), "Include reactions from muted acccounts." ) ], @@ -82,7 +82,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do Operation.parameter( :with_muted, :query, - BooleanLike, + BooleanLike.schema(), "Include reactions from muted acccounts." ) ], @@ -685,7 +685,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do end def id_param do - Operation.parameter(:id, :path, FlakeID, "Status ID", + Operation.parameter(:id, :path, FlakeID.schema(), "Status ID", example: "9umDrYheeY451cQnEe", required: true ) diff --git a/lib/pleroma/web/api_spec/operations/timeline_operation.ex b/lib/pleroma/web/api_spec/operations/timeline_operation.ex index fbe3f763a..f55e59805 100644 --- a/lib/pleroma/web/api_spec/operations/timeline_operation.ex +++ b/lib/pleroma/web/api_spec/operations/timeline_operation.ex @@ -176,7 +176,12 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do end 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 defp exclude_visibilities_param do diff --git a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex index b536bb6c1..02b54d61a 100644 --- a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex +++ b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex @@ -146,13 +146,13 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do Operation.parameter( :block_from_strangers, :query, - BooleanLike, + BooleanLike.schema(), "blocks notifications from accounts you do not follow" ), Operation.parameter( :hide_notification_contents, :query, - BooleanLike, + BooleanLike.schema(), "removes the contents of a message from the push notification" ) ], From a2664927762f9e34146830cc83940a4db2b071d2 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 29 Jan 2024 17:37:52 -0500 Subject: [PATCH 03/27] Pleroma.User: dialyzer errors lib/pleroma/user.ex:757:no_return Function register_changeset/1 has no local return. ________________________________________________________________________________ lib/pleroma/user.ex:757:no_return Function register_changeset/2 has no local return. ________________________________________________________________________________ lib/pleroma/user.ex:757:no_return Function register_changeset/3 has no local return. ________________________________________________________________________________ lib/pleroma/user.ex:778:call The function call will not succeed. Pleroma.User.approval_changeset( %Ecto.Changeset{ :action => atom(), :changes => %{atom() => _}, :constraints => [ %{ :constraint => binary() | %Regex{ :opts => binary() | [any()], :re_pattern => _, :re_version => _, :source => binary() }, :error_message => binary(), :error_type => atom(), :field => atom(), :match => :exact | :prefix | :suffix, :type => :check | :exclusion | :foreign_key | :unique } ], :data => nil | map(), :empty_values => _, :errors => Keyword.t({binary(), Keyword.t()}), :filters => %{atom() => _}, :params => nil | %{binary() => _}, :prepare => [(_ -> any())], :repo => atom(), :repo_opts => Keyword.t(), :required => [atom()], :types => nil | %{ atom() => atom() | {:array | :assoc | :embed | :in | :map | :maybe | :param, _} | {:parameterized, atom(), _} }, :valid? => boolean(), :validations => Keyword.t() }, [{:set_approval, _}, ...] ) breaks the contract (t(), :elixir.keyword()) :: Ecto.Changeset.t() ________________________________________________________________________________ lib/pleroma/user.ex:854:unused_fun Function maybe_validate_required_birthday/1 will never be called. --- lib/pleroma/user.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 8129845b5..0773434c5 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -2559,9 +2559,9 @@ defmodule Pleroma.User do cast(user, params, [:is_confirmed, :confirmation_token]) end - @spec approval_changeset(User.t(), keyword()) :: Ecto.Changeset.t() - def approval_changeset(user, set_approval: approved?) do - cast(user, %{is_approved: approved?}, [:is_approved]) + @spec approval_changeset(Ecto.Changeset.t(), keyword()) :: Ecto.Changeset.t() + def approval_changeset(changeset, set_approval: approved?) do + cast(changeset, %{is_approved: approved?}, [:is_approved]) end @spec add_pinned_object_id(User.t(), String.t()) :: {:ok, User.t()} | {:error, term()} From 3cb2807244887847f4511d3627d3cdeab6e4876c Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 29 Jan 2024 17:42:39 -0500 Subject: [PATCH 04/27] Pleroma.Web.MastodonAPI.StatusView: dialyzer error lib/pleroma/web/mastodon_api/views/status_view.ex:799:pattern_match_cov The pattern _, _ can never match, because previous clauses completely cover the type %URI{ :authority => URI.authority(), :fragment => nil | binary(), :host => nil | binary(), :path => nil | binary(), :port => nil | char(), :query => nil | binary(), :scheme => nil | binary(), :userinfo => nil | binary() }, %URI{ :authority => URI.authority(), :fragment => nil | binary(), :host => nil | binary(), :path => nil | binary(), :port => nil | char(), :query => nil | binary(), :scheme => nil | binary(), :userinfo => nil | binary() } . --- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 0e2e604f5..6303e72ce 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -796,8 +796,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do URI.merge(page_url_data, image_url_data) |> to_string end - defp build_image_url(_, _), do: nil - defp get_source_text(%{"content" => content} = _source) do content end From 378edeaf159c0ff98780ad1b41f513992f1af305 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 29 Jan 2024 17:44:54 -0500 Subject: [PATCH 05/27] Pleroma.Web.MastodonAPI.DomainBlockController: dialyzer errors lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex:32:call The function call will not succeed. Phoenix.Controller.json( _conn :: %{ :assigns => %{:user => _, _ => _}, :body_params => %{:domain => _, _ => _}, _ => _ }, %{} ) breaks the contract (Plug.Conn.t(), term()) :: Plug.Conn.t() ________________________________________________________________________________ lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex:43:call The function call will not succeed. Phoenix.Controller.json( _conn :: %{ :assigns => %{:user => _, _ => _}, :body_params => %{:domain => _, _ => _}, _ => _ }, %{} ) breaks the contract (Plug.Conn.t(), term()) :: Plug.Conn.t() --- lib/pleroma/web/api_spec/operations/domain_block_operation.ex | 4 ++-- .../web/mastodon_api/controllers/domain_block_controller.ex | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/domain_block_operation.ex b/lib/pleroma/web/api_spec/operations/domain_block_operation.ex index 2340fd914..dac3bc883 100644 --- a/lib/pleroma/web/api_spec/operations/domain_block_operation.ex +++ b/lib/pleroma/web/api_spec/operations/domain_block_operation.ex @@ -73,10 +73,10 @@ defmodule Pleroma.Web.ApiSpec.DomainBlockOperation do %Schema{ type: :object, properties: %{ - domain: %Schema{type: :string} + "domain" => %Schema{type: :string} } }, - required: false, + required: true, example: %{ "domain" => "facebook.com" } diff --git a/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex b/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex index b2e347ed9..33dfee3ca 100644 --- a/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex @@ -27,7 +27,7 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do end @doc "POST /api/v1/domain_blocks" - def create(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do + def create(%{assigns: %{user: blocker}, body_params: %{"domain" => domain}} = conn, _params) do User.block_domain(blocker, domain) json(conn, %{}) end @@ -38,7 +38,7 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do end @doc "DELETE /api/v1/domain_blocks" - def delete(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do + def delete(%{assigns: %{user: blocker}, body_params: %{"domain" => domain}} = conn, _params) do User.unblock_domain(blocker, domain) json(conn, %{}) end From 8cd527985780f6c9e4512f2e72f3dddbbf9b33ca Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 29 Jan 2024 18:11:03 -0500 Subject: [PATCH 06/27] Pleroma.Web.MastodonAPI.MediaController: dialyzer errors lib/pleroma/web/mastodon_api/controllers/media_controller.ex:32:call The function call will not succeed. Phoenix.Controller.render( _conn :: %{ :assigns => %{:user => _, _ => _}, :body_params => %{:file => _, _ => _}, _ => _ }, <<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>, %{:attachment => map()} ) will never return since the success typing is: ( %Plug.Conn{ :adapter => {atom(), _}, :assigns => %{atom() => _}, :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :halted => boolean(), :host => binary(), :method => binary(), :owner => pid(), :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :path_info => [binary()], :path_params => %{binary() => binary() | [any()] | map()}, :port => char(), :private => %{atom() => _}, :query_params => %Plug.Conn.Unfetched{ :aspect => atom(), binary() => binary() | [any()] | map() }, :query_string => binary(), :remote_ip => {byte(), byte(), byte(), byte()} | {char(), char(), char(), char(), char(), char(), char(), char()}, :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()}, :req_headers => [{_, _}], :request_path => binary(), :resp_body => nil | binary() | maybe_improper_list( binary() | maybe_improper_list(any(), binary() | []) | byte(), binary() | [] ), :resp_cookies => %{binary() => map()}, :resp_headers => [{_, _}], :scheme => :http | :https, :script_name => [binary()], :secret_key_base => nil | binary(), :state => :chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded, :status => nil | non_neg_integer() }, atom() | binary(), atom() | binary() | [{_, _}] | map() ) :: %Plug.Conn{ :adapter => {atom(), _}, :assigns => %{atom() => _}, :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :halted => boolean(), :host => binary(), :method => binary(), :owner => pid(), :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :path_info => [binary()], :path_params => %{binary() => binary() | [any()] | map()}, :port => char(), :private => %{atom() => _}, :query_params => %Plug.Conn.Unfetched{ :aspect => atom(), binary() => binary() | [any()] | map() }, :query_string => binary(), :remote_ip => {byte(), byte(), byte(), byte()} | {char(), char(), char(), char(), char(), char(), char(), char()}, :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()}, :req_headers => [{_, _}], :request_path => binary(), :resp_body => nil | binary() | maybe_improper_list( binary() | maybe_improper_list(any(), binary() | []) | byte(), binary() | [] ), :resp_cookies => %{binary() => map()}, :resp_headers => [{_, _}], :scheme => :http | :https, :script_name => [binary()], :secret_key_base => nil | binary(), :state => :sent, :status => nil | non_neg_integer() } and the contract is (Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t() ________________________________________________________________________________ lib/pleroma/web/mastodon_api/controllers/media_controller.ex:48:call The function call will not succeed. Plug.Conn.put_status( _conn :: %{ :assigns => %{:user => _, _ => _}, :body_params => %{:file => _, _ => _}, _ => _ }, 202 ) breaks the contract (t(), status()) :: t() ________________________________________________________________________________ lib/pleroma/web/mastodon_api/controllers/media_controller.ex:63:call The function call will not succeed. Phoenix.Controller.render( _conn :: %{ :assigns => %{:user => _, _ => _}, :body_params => %{:description => _, _ => _}, _ => _ }, <<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>, %{:attachment => map()} ) will never return since the success typing is: ( %Plug.Conn{ :adapter => {atom(), _}, :assigns => %{atom() => _}, :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :halted => boolean(), :host => binary(), :method => binary(), :owner => pid(), :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :path_info => [binary()], :path_params => %{binary() => binary() | [any()] | map()}, :port => char(), :private => %{atom() => _}, :query_params => %Plug.Conn.Unfetched{ :aspect => atom(), binary() => binary() | [any()] | map() }, :query_string => binary(), :remote_ip => {byte(), byte(), byte(), byte()} | {char(), char(), char(), char(), char(), char(), char(), char()}, :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()}, :req_headers => [{_, _}], :request_path => binary(), :resp_body => nil | binary() | maybe_improper_list( binary() | maybe_improper_list(any(), binary() | []) | byte(), binary() | [] ), :resp_cookies => %{binary() => map()}, :resp_headers => [{_, _}], :scheme => :http | :https, :script_name => [binary()], :secret_key_base => nil | binary(), :state => :chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded, :status => nil | non_neg_integer() }, atom() | binary(), atom() | binary() | [{_, _}] | map() ) :: %Plug.Conn{ :adapter => {atom(), _}, :assigns => %{atom() => _}, :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :halted => boolean(), :host => binary(), :method => binary(), :owner => pid(), :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _}, :path_info => [binary()], :path_params => %{binary() => binary() | [any()] | map()}, :port => char(), :private => %{atom() => _}, :query_params => %Plug.Conn.Unfetched{ :aspect => atom(), binary() => binary() | [any()] | map() }, :query_string => binary(), :remote_ip => {byte(), byte(), byte(), byte()} | {char(), char(), char(), char(), char(), char(), char(), char()}, :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()}, :req_headers => [{_, _}], :request_path => binary(), :resp_body => nil | binary() | maybe_improper_list( binary() | maybe_improper_list(any(), binary() | []) | byte(), binary() | [] ), :resp_cookies => %{binary() => map()}, :resp_headers => [{_, _}], :scheme => :http | :https, :script_name => [binary()], :secret_key_base => nil | binary(), :state => :sent, :status => nil | non_neg_integer() } and the contract is (Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t() --- .../web/api_spec/operations/media_operation.ex | 14 +++++++------- .../mastodon_api/controllers/media_controller.ex | 12 +++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/media_operation.ex b/lib/pleroma/web/api_spec/operations/media_operation.ex index e6df21246..718cacec1 100644 --- a/lib/pleroma/web/api_spec/operations/media_operation.ex +++ b/lib/pleroma/web/api_spec/operations/media_operation.ex @@ -36,18 +36,18 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do title: "MediaCreateRequest", description: "POST body for creating an attachment", type: :object, - required: [:file], + required: ["file"], properties: %{ - file: %Schema{ + "file" => %Schema{ type: :string, format: :binary, description: "The file to be attached, using multipart form data." }, - description: %Schema{ + "description" => %Schema{ type: :string, description: "A plain-text description of the media, for accessibility purposes." }, - focus: %Schema{ + "focus" => %Schema{ type: :string, description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0." } @@ -79,16 +79,16 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do description: "POST body for updating an attachment", type: :object, properties: %{ - file: %Schema{ + "file" => %Schema{ type: :string, format: :binary, description: "The file to be attached, using multipart form data." }, - description: %Schema{ + "description" => %Schema{ type: :string, description: "A plain-text description of the media, for accessibility purposes." }, - focus: %Schema{ + "focus" => %Schema{ type: :string, description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0." } diff --git a/lib/pleroma/web/mastodon_api/controllers/media_controller.ex b/lib/pleroma/web/mastodon_api/controllers/media_controller.ex index 7d9a63cf4..b0c7a858b 100644 --- a/lib/pleroma/web/mastodon_api/controllers/media_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/media_controller.ex @@ -20,12 +20,12 @@ defmodule Pleroma.Web.MastodonAPI.MediaController do defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.MediaOperation @doc "POST /api/v1/media" - def create(%{assigns: %{user: user}, body_params: %{file: file} = data} = conn, _) do + def create(%{assigns: %{user: user}, body_params: %{"file" => file} = data} = conn, _) do with {:ok, object} <- ActivityPub.upload( file, actor: User.ap_id(user), - description: Map.get(data, :description) + description: Map.get(data, "description") ) do attachment_data = Map.put(object.data, "id", object.id) @@ -36,12 +36,12 @@ defmodule Pleroma.Web.MastodonAPI.MediaController do def create(_conn, _data), do: {:error, :bad_request} @doc "POST /api/v2/media" - def create2(%{assigns: %{user: user}, body_params: %{file: file} = data} = conn, _) do + def create2(%{assigns: %{user: user}, body_params: %{"file" => file} = data} = conn, _) do with {:ok, object} <- ActivityPub.upload( file, actor: User.ap_id(user), - description: Map.get(data, :description) + description: Map.get(data, "description") ) do attachment_data = Map.put(object.data, "id", object.id) @@ -54,7 +54,9 @@ defmodule Pleroma.Web.MastodonAPI.MediaController do def create2(_conn, _data), do: {:error, :bad_request} @doc "PUT /api/v1/media/:id" - def update(%{assigns: %{user: user}, body_params: %{description: description}} = conn, %{id: id}) do + def update(%{assigns: %{user: user}, body_params: %{"description" => description}} = conn, %{ + id: id + }) do with %Object{} = object <- Object.get_by_id(id), :ok <- Object.authorize_access(object, user), {:ok, %Object{data: data}} <- Object.update_data(object, %{"name" => description}) do From b6667105741c44d5ed102f6657b1b0ae77d4206b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 29 Jan 2024 18:47:54 -0500 Subject: [PATCH 07/27] Pleroma.Web.MediaProxy.MediaProxyController: dialyzer errors lib/pleroma/web/media_proxy/media_proxy_controller.ex:55:no_return Function handle_preview/2 has no local return. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:59:call The function call will not succeed. Pleroma.HTTP.request(<<72, 69, 65, 68>>, _media_proxy_url :: any(), [], [], [{:pool, :media}]) will never return since the success typing is: ( :delete | :get | :head | :options | :patch | :post | :put | :trace, binary(), any(), [{binary(), binary()}], Keyword.t() ) :: any() and the contract is ( method(), Pleroma.HTTP.Request.url(), String.t(), Pleroma.HTTP.Request.headers(), :elixir.keyword() ) :: {:ok, Tesla.Env.t()} | {:error, any()} ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:95:unused_fun Function handle_preview/3 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:111:unused_fun Function handle_png_preview/2 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:134:unused_fun Function handle_jpeg_preview/2 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:152:unused_fun Function handle_video_preview/2 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:164:unused_fun Function drop_static_param_and_redirect/1 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:173:unused_fun Function fallback_on_preview_error/2 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:177:unused_fun Function put_preview_response_headers/1 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:177:unused_fun Function put_preview_response_headers/2 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:187:unused_fun Function thumbnail_max_dimensions/0 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:196:unused_fun Function min_content_length_for_preview/0 will never be called. ________________________________________________________________________________ lib/pleroma/web/media_proxy/media_proxy_controller.ex:200:unused_fun Function media_preview_proxy_config/0 will never be called. --- .../web/media_proxy/media_proxy_controller.ex | 2 +- .../media_proxy_controller_test.exs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/media_proxy/media_proxy_controller.ex b/lib/pleroma/web/media_proxy/media_proxy_controller.ex index bda5b36ed..c11484ecb 100644 --- a/lib/pleroma/web/media_proxy/media_proxy_controller.ex +++ b/lib/pleroma/web/media_proxy/media_proxy_controller.ex @@ -56,7 +56,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do media_proxy_url = MediaProxy.url(url) 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_length = Tesla.get_header(head_response, "content-length") content_length = content_length && String.to_integer(content_length) diff --git a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs index 5b3f5fbdc..f0c1dd640 100644 --- a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs +++ b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs @@ -182,7 +182,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do media_proxy_url: media_proxy_url } do Tesla.Mock.mock(fn - %{method: "HEAD", url: ^media_proxy_url} -> + %{method: :head, url: ^media_proxy_url} -> %Tesla.Env{status: 500, body: ""} end) @@ -197,7 +197,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do media_proxy_url: media_proxy_url } do 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"}]} end) @@ -217,7 +217,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do clear_config([:media_preview_proxy, :min_content_length], 1_000_000_000) Tesla.Mock.mock(fn - %{method: "HEAD", url: ^media_proxy_url} -> + %{method: :head, url: ^media_proxy_url} -> %Tesla.Env{ status: 200, body: "", @@ -242,7 +242,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do media_proxy_url: media_proxy_url } do 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"}]} end) @@ -260,7 +260,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do media_proxy_url: media_proxy_url } do 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"}]} end) @@ -280,7 +280,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do clear_config([:media_preview_proxy, :min_content_length], 100_000) Tesla.Mock.mock(fn - %{method: "HEAD", url: ^media_proxy_url} -> + %{method: :head, url: ^media_proxy_url} -> %Tesla.Env{ status: 200, body: "", @@ -302,7 +302,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do assert_dependencies_installed() 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"}]} %{method: :get, url: ^media_proxy_url} -> @@ -324,7 +324,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do assert_dependencies_installed() 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"}]} %{method: :get, url: ^media_proxy_url} -> @@ -344,7 +344,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do media_proxy_url: media_proxy_url } do 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"}]} %{method: :get, url: ^media_proxy_url} -> From a3426fcaf38b5533a553e0ffe3f031c4bb27cad5 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:13:13 -0500 Subject: [PATCH 08/27] Revert "Pleroma.Web.MastodonAPI.MediaController: dialyzer errors" This reverts commit 8cd527985780f6c9e4512f2e72f3dddbbf9b33ca. --- .../web/api_spec/operations/media_operation.ex | 14 +++++++------- .../mastodon_api/controllers/media_controller.ex | 12 +++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/media_operation.ex b/lib/pleroma/web/api_spec/operations/media_operation.ex index 718cacec1..e6df21246 100644 --- a/lib/pleroma/web/api_spec/operations/media_operation.ex +++ b/lib/pleroma/web/api_spec/operations/media_operation.ex @@ -36,18 +36,18 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do title: "MediaCreateRequest", description: "POST body for creating an attachment", type: :object, - required: ["file"], + required: [:file], properties: %{ - "file" => %Schema{ + file: %Schema{ type: :string, format: :binary, description: "The file to be attached, using multipart form data." }, - "description" => %Schema{ + description: %Schema{ type: :string, description: "A plain-text description of the media, for accessibility purposes." }, - "focus" => %Schema{ + focus: %Schema{ type: :string, description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0." } @@ -79,16 +79,16 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do description: "POST body for updating an attachment", type: :object, properties: %{ - "file" => %Schema{ + file: %Schema{ type: :string, format: :binary, description: "The file to be attached, using multipart form data." }, - "description" => %Schema{ + description: %Schema{ type: :string, description: "A plain-text description of the media, for accessibility purposes." }, - "focus" => %Schema{ + focus: %Schema{ type: :string, description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0." } diff --git a/lib/pleroma/web/mastodon_api/controllers/media_controller.ex b/lib/pleroma/web/mastodon_api/controllers/media_controller.ex index b0c7a858b..7d9a63cf4 100644 --- a/lib/pleroma/web/mastodon_api/controllers/media_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/media_controller.ex @@ -20,12 +20,12 @@ defmodule Pleroma.Web.MastodonAPI.MediaController do defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.MediaOperation @doc "POST /api/v1/media" - def create(%{assigns: %{user: user}, body_params: %{"file" => file} = data} = conn, _) do + def create(%{assigns: %{user: user}, body_params: %{file: file} = data} = conn, _) do with {:ok, object} <- ActivityPub.upload( file, actor: User.ap_id(user), - description: Map.get(data, "description") + description: Map.get(data, :description) ) do attachment_data = Map.put(object.data, "id", object.id) @@ -36,12 +36,12 @@ defmodule Pleroma.Web.MastodonAPI.MediaController do def create(_conn, _data), do: {:error, :bad_request} @doc "POST /api/v2/media" - def create2(%{assigns: %{user: user}, body_params: %{"file" => file} = data} = conn, _) do + def create2(%{assigns: %{user: user}, body_params: %{file: file} = data} = conn, _) do with {:ok, object} <- ActivityPub.upload( file, actor: User.ap_id(user), - description: Map.get(data, "description") + description: Map.get(data, :description) ) do attachment_data = Map.put(object.data, "id", object.id) @@ -54,9 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaController do def create2(_conn, _data), do: {:error, :bad_request} @doc "PUT /api/v1/media/:id" - def update(%{assigns: %{user: user}, body_params: %{"description" => description}} = conn, %{ - id: id - }) do + def update(%{assigns: %{user: user}, body_params: %{description: description}} = conn, %{id: id}) do with %Object{} = object <- Object.get_by_id(id), :ok <- Object.authorize_access(object, user), {:ok, %Object{data: data}} <- Object.update_data(object, %{"name" => description}) do From 41493bd6428d42e1be4ba7294334310cb74c3e1e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:13:23 -0500 Subject: [PATCH 09/27] Revert "Pleroma.Web.MastodonAPI.DomainBlockController: dialyzer errors" This reverts commit 378edeaf159c0ff98780ad1b41f513992f1af305. --- lib/pleroma/web/api_spec/operations/domain_block_operation.ex | 4 ++-- .../web/mastodon_api/controllers/domain_block_controller.ex | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/domain_block_operation.ex b/lib/pleroma/web/api_spec/operations/domain_block_operation.ex index dac3bc883..2340fd914 100644 --- a/lib/pleroma/web/api_spec/operations/domain_block_operation.ex +++ b/lib/pleroma/web/api_spec/operations/domain_block_operation.ex @@ -73,10 +73,10 @@ defmodule Pleroma.Web.ApiSpec.DomainBlockOperation do %Schema{ type: :object, properties: %{ - "domain" => %Schema{type: :string} + domain: %Schema{type: :string} } }, - required: true, + required: false, example: %{ "domain" => "facebook.com" } diff --git a/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex b/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex index 33dfee3ca..b2e347ed9 100644 --- a/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex @@ -27,7 +27,7 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do end @doc "POST /api/v1/domain_blocks" - def create(%{assigns: %{user: blocker}, body_params: %{"domain" => domain}} = conn, _params) do + def create(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do User.block_domain(blocker, domain) json(conn, %{}) end @@ -38,7 +38,7 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do end @doc "DELETE /api/v1/domain_blocks" - def delete(%{assigns: %{user: blocker}, body_params: %{"domain" => domain}} = conn, _params) do + def delete(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do User.unblock_domain(blocker, domain) json(conn, %{}) end From 1fa1a93cd6ffefaa80a660fa48968f83b925b21a Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:13:46 -0500 Subject: [PATCH 10/27] Revert "Pleroma.Web.MastodonAPI.AccountController: dialyzer errors" This reverts commit e53c20b03c934c725726f49b2ca98b0bd9406bef. --- lib/pleroma/web/api_spec/operations/account_operation.ex | 6 +++--- .../web/mastodon_api/controllers/account_controller.ex | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 357022973..36025e47a 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -887,9 +887,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 @@ -930,7 +930,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/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index fdf9d2dfb..1b5de4b45 100644 --- 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 From 39241107d96775a7e854f777316a907ee8ddea35 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:13:56 -0500 Subject: [PATCH 11/27] Revert "Pleroma.Web.AdminAPI.InstanceDocumentController: fix dialyzer error" This reverts commit a3024dd5ac28bc23a91b12fa15ab56d15c1c341d. --- .../web/admin_api/controllers/instance_document_controller.ex | 2 +- .../api_spec/operations/admin/instance_document_operation.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/admin_api/controllers/instance_document_controller.ex b/lib/pleroma/web/admin_api/controllers/instance_document_controller.ex index a35878926..990a94313 100644 --- 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/api_spec/operations/admin/instance_document_operation.ex b/lib/pleroma/web/api_spec/operations/admin/instance_document_operation.ex index b2a1ba8ad..fc0de499b 100644 --- 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." From da5e0fca4fee099b65a76f27013032776600ac40 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:14:07 -0500 Subject: [PATCH 12/27] Revert "Pleroma.Web.AdminAPI.ReportController: dialyzer errors" This reverts commit bfe626d5787ae546e2a96b8c4c621c09fea1332a. --- lib/pleroma/web/admin_api/controllers/report_controller.ex | 4 ++-- .../web/api_spec/operations/admin/report_operation.ex | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/admin_api/controllers/report_controller.ex b/lib/pleroma/web/admin_api/controllers/report_controller.ex index f667e7003..15cbbcc3e 100644 --- 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/api_spec/operations/admin/report_operation.ex b/lib/pleroma/web/api_spec/operations/admin/report_operation.ex index 29b08d93c..fbb6896a9 100644 --- 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, From ac06a476896831ce74e87cd5d3b889d34426ad73 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:14:22 -0500 Subject: [PATCH 13/27] Revert "Pleroma.Web.AdminAPI.RelayController: dialyzer errors" This reverts commit 94838ed941494fb6132086aa2cb3b5e65a00b08c. --- .../web/admin_api/controllers/relay_controller.ex | 9 +++------ .../web/api_spec/operations/admin/relay_operation.ex | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/web/admin_api/controllers/relay_controller.ex b/lib/pleroma/web/admin_api/controllers/relay_controller.ex index 664011b06..2e83fe139 100644 --- 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,11 +44,8 @@ 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/api_spec/operations/admin/relay_operation.ex b/lib/pleroma/web/api_spec/operations/admin/relay_operation.ex index ca9080fb3..8b241bd49 100644 --- 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 From 4227db08716bf46d677009127438746bd7cd6729 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:14:39 -0500 Subject: [PATCH 14/27] Revert "Pleroma.Web.AdminAPI.UserController: dialyzer errors" This reverts commit d92c3d927d4134941dabef3e8f1b5209de115665. --- .../admin_api/controllers/user_controller.ex | 24 +++++++++---------- .../operations/admin/user_operation.ex | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/pleroma/web/admin_api/controllers/user_controller.ex b/lib/pleroma/web/admin_api/controllers/user_controller.ex index cca7d8c2f..ed93af11c 100644 --- 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) @@ -215,7 +215,7 @@ defmodule Pleroma.Web.AdminAPI.UserController do 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) @@ -228,7 +228,7 @@ defmodule Pleroma.Web.AdminAPI.UserController do 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/admin/user_operation.ex b/lib/pleroma/web/api_spec/operations/admin/user_operation.ex index 49f5a4786..a5179ac39 100644 --- 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} } From 589456f0ba6e9700a8a413618f0582e8f63cec2b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:14:56 -0500 Subject: [PATCH 15/27] Revert "Pleroma.Web.AdminAPI.InviteController: dialyzer errors" This reverts commit db87be126e707ffc84c0b6b598aa07a4b068e82a. --- .../web/admin_api/controllers/invite_controller.ex | 6 +++--- .../web/api_spec/operations/admin/invite_operation.ex | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/pleroma/web/admin_api/controllers/invite_controller.ex b/lib/pleroma/web/admin_api/controllers/invite_controller.ex index 229b39909..c5d759bb5 100644 --- 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/api_spec/operations/admin/invite_operation.ex b/lib/pleroma/web/api_spec/operations/admin/invite_operation.ex index 3b084f3b8..e4a9ffaeb 100644 --- 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 From b709fc4dfe2708a95c3fd3179f4de20051b138d7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:15:05 -0500 Subject: [PATCH 16/27] Revert "Pleroma.Web.PleromaAPI.ChatController: Dialyzer error" This reverts commit 8d64eedbecec99d1ae19d300891a9c4cd3dbdf9d. --- lib/pleroma/web/api_spec/operations/chat_operation.ex | 4 ++-- lib/pleroma/web/pleroma_api/controllers/chat_controller.ex | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/chat_operation.ex b/lib/pleroma/web/api_spec/operations/chat_operation.ex index d3b033f0b..f56e57a41 100644 --- a/lib/pleroma/web/api_spec/operations/chat_operation.ex +++ b/lib/pleroma/web/api_spec/operations/chat_operation.ex @@ -378,9 +378,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/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex index dc0f2cfe3..6158af60e 100644 --- a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex @@ -120,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), From 4a9ed4682ab292232637ceb39819bbd7d266926e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:15:17 -0500 Subject: [PATCH 17/27] Revert "Pleroma.Web.PleromaAPI.EmojiFileController: dialyzer errors" This reverts commit dc912dc5909922f4100c6a56bec72a4bb9e0d5dc. --- .../operations/pleroma_emoji_file_operation.ex | 18 +++++++++--------- .../controllers/emoji_file_controller.ex | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) 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 index ebb32f448..b05bad197 100644 --- 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/pleroma_api/controllers/emoji_file_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex index 618b924a0..f854cf9c1 100644 --- 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) - 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}} when code in 200..299 <- Pleroma.HTTP.get(url) do path = Plug.Upload.random_file!("emoji") From b1a6102a85a73f5ce0ab620660488a7d379ab2b6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:15:40 -0500 Subject: [PATCH 18/27] Revert "Pleroma.Web.PleromaAPI.EmojiPackController: dialyzer errors" This reverts commit 77bf617c4b28fce84f268ca391fa4af6dd590c82. --- .../pleroma_emoji_pack_operation.ex | 30 +++++++++++++++---- .../controllers/emoji_pack_controller.ex | 6 ++-- 2 files changed, 28 insertions(+), 8 deletions(-) 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 index 1c2b2c2b7..efa36ffdc 100644 --- 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,7 +302,27 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do defp update_request do %Schema{ 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 diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex index 64fd95759..420fea12c 100644 --- 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 From 2c8e4f32c60793aba3e048f4d1c2b30186eb22af Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:18:36 -0500 Subject: [PATCH 19/27] Revert "Pleroma.Web.PleromaAPI.MascotController: dialyzer errors" This reverts commit 9c8055d4b3eeed04e2fc27b69e1bd2b8bae11bb8. --- lib/pleroma/upload.ex | 1 - .../web/api_spec/operations/pleroma_mascot_operation.ex | 2 +- .../web/pleroma_api/controllers/mascot_controller.ex | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index e6c484548..89cd3d920 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -51,7 +51,6 @@ 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/web/api_spec/operations/pleroma_mascot_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_mascot_operation.ex index 49c50751b..775e27219 100644 --- 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/pleroma_api/controllers/mascot_controller.ex b/lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex index 0533c348c..2b6093753 100644 --- 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 {_, "image" <> _} <- {:content_type, file.content_type}, - {_, {:ok, object}} <- {:upload, ActivityPub.upload(file, actor: User.ap_id(user))} do + 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 attachment = render_attachment(object) {:ok, _user} = User.mascot_update(user, attachment) From 1e76ceacd53325fdb5a6483d3d42926d6579d3cc Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:19:13 -0500 Subject: [PATCH 20/27] Revert "Pleroma.Web.AdminAPI.ConfigController: dialyzer error" This reverts commit 60d89cb40455f9f70b683849dd95311975b0b6f7. --- lib/pleroma/web/admin_api/controllers/config_controller.ex | 2 +- lib/pleroma/web/api_spec/operations/admin/config_operation.ex | 2 +- .../web/admin_api/controllers/config_controller_test.exs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/admin_api/controllers/config_controller.ex b/lib/pleroma/web/admin_api/controllers/config_controller.ex index 989316041..a03318c0e 100644 --- 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/api_spec/operations/admin/config_operation.ex b/lib/pleroma/web/api_spec/operations/admin/config_operation.ex index c528cacf2..487dd5cda 100644 --- 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/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs index 734aca752..19ce3681c 100644 --- 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" => [ ":_", - "Plug.Cowboy.Handler", + "Phoenix.Endpoint.Cowboy2Handler", %{"tuple" => ["Pleroma.Web.Endpoint", []]} ] } @@ -937,7 +937,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do %{ "tuple" => [ ":_", - "Plug.Cowboy.Handler", + "Phoenix.Endpoint.Cowboy2Handler", %{"tuple" => ["Pleroma.Web.Endpoint", []]} ] } From 4a80a285d1c358a94a5f2401277968f457e01e2b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:19:32 -0500 Subject: [PATCH 21/27] Revert "Pleroma.Web.PleromaAPI.NotificationController: dialyzer errors" This reverts commit 26a95e57873630491066687d2a216ab6e01549b0. --- .../api_spec/operations/pleroma_notification_operation.ex | 7 ++----- .../web/pleroma_api/controllers/notification_controller.ex | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex index 79990cb78..a994345db 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex @@ -24,11 +24,8 @@ 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/pleroma_api/controllers/notification_controller.ex b/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex index 0c6ec29f5..87ea81cef 100644 --- 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) From 674ae51d6a25e9b094c72250aa9b138e6ef6ce8d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:19:41 -0500 Subject: [PATCH 22/27] Revert "Pleroma.Web.PleromaAPI.UserImportController: Dialyzer errors" This reverts commit 52e18a624922e64eb4a7fd3f0d7a9aef06ea7fad. --- .../operations/user_import_operation.ex | 4 ++-- .../controllers/user_import_controller.ex | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/user_import_operation.ex b/lib/pleroma/web/api_spec/operations/user_import_operation.ex index d12ebd968..e99e6e648 100644 --- 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/pleroma_api/controllers/user_import_controller.ex b/lib/pleroma/web/pleroma_api/controllers/user_import_controller.ex index d0ae6d6e5..90428a532 100644 --- 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 From 88a35b2865103a0147669bcfe237f8e1bc8d0ec6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:19:54 -0500 Subject: [PATCH 23/27] Revert "Pleroma.Web.TwitterAPI.UtilController: dialyzer fixes" This reverts commit 17f4251b19846401ca36ee31156294ec63de84ee. --- .../web/api_spec/operations/twitter_util_operation.ex | 6 +++--- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex index 02b54d61a..724d873c0 100644 --- 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/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index a74c806a6..c8ecf5eff 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -150,10 +150,7 @@ 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)}) From 8476eb1842dc60f440c9d928324c76f4393ba8fb Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:20:02 -0500 Subject: [PATCH 24/27] Revert "Pleroma.Web.AdminAPI.MediaProxyCacheController: dialyzer errors" This reverts commit 8b02c858102232700826214ffb5d58e5b2f90edf. --- .../controllers/media_proxy_cache_controller.ex | 4 ++-- .../operations/admin/media_proxy_cache_operation.ex | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) 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 index c615422cd..4d53f5451 100644 --- 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/api_spec/operations/admin/media_proxy_cache_operation.ex b/lib/pleroma/web/api_spec/operations/admin/media_proxy_cache_operation.ex index 79363d4cd..0b1eb3946 100644 --- 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 From 91a70ba552fa4450e1a3b1dbbafcb9f6cdc7ba21 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:48:45 -0500 Subject: [PATCH 25/27] Bump open_api_spex --- mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.lock b/mix.lock index 63a53bd96..60d0d51d9 100644 --- a/mix.lock +++ b/mix.lock @@ -88,7 +88,7 @@ "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"}, "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"}, "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"}, From 608466d0982373bfc1d3fbc37fe5ac28a6484f1b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:49:55 -0500 Subject: [PATCH 26/27] Modify our CastAndValidate plug to include the new functionality provided by the :replace_params config option This allows us to configure Open API Spex to not overwrite the params with the casted versions which violates the Plug.Conn.t() contract https://github.com/open-api-spex/open_api_spex/issues/92 https://github.com/open-api-spex/open_api_spex/pull/425 --- lib/pleroma/web/api_spec/cast_and_validate.ex | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/api_spec/cast_and_validate.ex b/lib/pleroma/web/api_spec/cast_and_validate.ex index add59eb88..f3e8e093e 100644 --- a/lib/pleroma/web/api_spec/cast_and_validate.ex +++ b/lib/pleroma/web/api_spec/cast_and_validate.ex @@ -27,10 +27,12 @@ defmodule Pleroma.Web.ApiSpec.CastAndValidate do @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) operation = operation_lookup[operation_id] + cast_opts = opts |> Map.take([:replace_params]) |> Map.to_list() + content_type = case Conn.get_req_header(conn, "content-type") do [header_value | _] -> @@ -44,7 +46,7 @@ defmodule Pleroma.Web.ApiSpec.CastAndValidate do 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} -> conn @@ -94,11 +96,11 @@ defmodule Pleroma.Web.ApiSpec.CastAndValidate do def call(conn, opts), do: OpenApiSpex.Plug.CastAndValidate.call(conn, opts) - defp cast_and_validate(spec, operation, conn, content_type, true = _strict) do - OpenApiSpex.cast_and_validate(spec, operation, conn, content_type) + defp cast_and_validate(spec, operation, conn, content_type, true = _strict, cast_opts) do + OpenApiSpex.cast_and_validate(spec, operation, conn, content_type, cast_opts) 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 {:ok, conn} -> {:ok, conn} @@ -123,7 +125,7 @@ defmodule Pleroma.Web.ApiSpec.CastAndValidate do end) 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 From cfe7438b2f953575eb0cb9e8318f0c39bcad35c6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 30 Jan 2024 14:52:15 -0500 Subject: [PATCH 27/27] Pleroma.Web.MastodonAPI.DomainBlockController: dialyzer fixes via :replace_params --- .../controllers/domain_block_controller.ex | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex b/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex index b2e347ed9..4615794a1 100644 --- a/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/domain_block_controller.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do alias Pleroma.User 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 plug( @@ -27,23 +27,31 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockController do end @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) json(conn, %{}) end - def create(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do + def create(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do User.block_domain(blocker, domain) json(conn, %{}) end @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) json(conn, %{}) end - def delete(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do + def delete(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do User.unblock_domain(blocker, domain) json(conn, %{}) end