From 59b6d5f2aa57f78ecfe7066671bb12d223214c18 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 13 May 2020 15:08:07 +0300 Subject: [PATCH] [#2456] Changed `embed_relationships` param to `with_relationships`. --- lib/pleroma/web/api_spec/helpers.ex | 10 +- .../api_spec/operations/account_operation.ex | 14 ++- .../api_spec/operations/search_operation.ex | 118 +++++++++--------- .../api_spec/operations/timeline_operation.ex | 4 - lib/pleroma/web/controller_helper.ex | 6 +- .../controllers/account_controller.ex | 6 +- .../controllers/search_controller.ex | 4 +- 7 files changed, 77 insertions(+), 85 deletions(-) diff --git a/lib/pleroma/web/api_spec/helpers.ex b/lib/pleroma/web/api_spec/helpers.ex index ee077a3f9..859e45b57 100644 --- a/lib/pleroma/web/api_spec/helpers.ex +++ b/lib/pleroma/web/api_spec/helpers.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Web.ApiSpec.Helpers do alias OpenApiSpex.Operation alias OpenApiSpex.Schema + alias Pleroma.Web.ApiSpec.Schemas.BooleanLike def request_body(description, schema_ref, opts \\ []) do media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"] @@ -47,13 +48,8 @@ def pagination_params do ] end - def embed_relationships_param do - Operation.parameter( - :embed_relationships, - :query, - :boolean, - "Embed relationships into accounts (Pleroma extension)" - ) + def with_relationships_param do + Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships") end def empty_object_response do diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index c2a56b786..7056f739b 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -155,9 +155,10 @@ def followers_operation do security: [%{"oAuth" => ["read:accounts"]}], description: "Accounts which follow the given account, if network is not hidden by the account owner.", - parameters: - [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ - pagination_params() ++ [embed_relationships_param()], + parameters: [ + %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}, + with_relationships_param() | pagination_params() + ], responses: %{ 200 => Operation.response("Accounts", "application/json", array_of_accounts()) } @@ -172,9 +173,10 @@ def following_operation do security: [%{"oAuth" => ["read:accounts"]}], description: "Accounts which the given account is following, if network is not hidden by the account owner.", - parameters: - [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ - pagination_params() ++ [embed_relationships_param()], + parameters: [ + %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}, + with_relationships_param() | pagination_params() + ], responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())} } end diff --git a/lib/pleroma/web/api_spec/operations/search_operation.ex b/lib/pleroma/web/api_spec/operations/search_operation.ex index 0dd908d7f..475848ff5 100644 --- a/lib/pleroma/web/api_spec/operations/search_operation.ex +++ b/lib/pleroma/web/api_spec/operations/search_operation.ex @@ -24,30 +24,30 @@ def account_search_operation do tags: ["Search"], summary: "Search for matching accounts by username or display name", operationId: "SearchController.account_search", - parameters: - [ - Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for", - required: true - ), - Operation.parameter( - :limit, - :query, - %Schema{type: :integer, default: 40}, - "Maximum number of results" - ), - Operation.parameter( - :resolve, - :query, - %Schema{allOf: [BooleanLike], default: false}, - "Attempt WebFinger lookup. Use this when `q` is an exact address." - ), - Operation.parameter( - :following, - :query, - %Schema{allOf: [BooleanLike], default: false}, - "Only include accounts that the user is following" - ) - ] ++ [embed_relationships_param()], + parameters: [ + Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for", + required: true + ), + Operation.parameter( + :limit, + :query, + %Schema{type: :integer, default: 40}, + "Maximum number of results" + ), + Operation.parameter( + :resolve, + :query, + %Schema{allOf: [BooleanLike], default: false}, + "Attempt WebFinger lookup. Use this when `q` is an exact address." + ), + Operation.parameter( + :following, + :query, + %Schema{allOf: [BooleanLike], default: false}, + "Only include accounts that the user is following" + ), + with_relationships_param() + ], responses: %{ 200 => Operation.response( @@ -66,42 +66,40 @@ def search_operation do security: [%{"oAuth" => ["read:search"]}], operationId: "SearchController.search", deprecated: true, - parameters: - [ - Operation.parameter( - :account_id, - :query, - FlakeID, - "If provided, statuses returned will be authored only by this account" - ), - Operation.parameter( - :type, - :query, - %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]}, - "Search type" - ), - Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", - required: true - ), - Operation.parameter( - :resolve, - :query, - %Schema{allOf: [BooleanLike], default: false}, - "Attempt WebFinger lookup" - ), - Operation.parameter( - :following, - :query, - %Schema{allOf: [BooleanLike], default: false}, - "Only include accounts that the user is following" - ), - Operation.parameter( - :offset, - :query, - %Schema{type: :integer}, - "Offset" - ) - ] ++ pagination_params() ++ [embed_relationships_param()], + parameters: [ + Operation.parameter( + :account_id, + :query, + FlakeID, + "If provided, statuses returned will be authored only by this account" + ), + Operation.parameter( + :type, + :query, + %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]}, + "Search type" + ), + Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", required: true), + Operation.parameter( + :resolve, + :query, + %Schema{allOf: [BooleanLike], default: false}, + "Attempt WebFinger lookup" + ), + Operation.parameter( + :following, + :query, + %Schema{allOf: [BooleanLike], default: false}, + "Only include accounts that the user is following" + ), + Operation.parameter( + :offset, + :query, + %Schema{type: :integer}, + "Offset" + ), + with_relationships_param() | pagination_params() + ], responses: %{ 200 => Operation.response("Results", "application/json", results()) } diff --git a/lib/pleroma/web/api_spec/operations/timeline_operation.ex b/lib/pleroma/web/api_spec/operations/timeline_operation.ex index 1b89035d4..6cbc7f747 100644 --- a/lib/pleroma/web/api_spec/operations/timeline_operation.ex +++ b/lib/pleroma/web/api_spec/operations/timeline_operation.ex @@ -153,10 +153,6 @@ defp array_of_statuses do } end - defp with_relationships_param do - Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships") - end - defp local_param do Operation.parameter( :local, diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index ae9b265b1..ff94c6be0 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -104,8 +104,8 @@ def put_if_exist(map, _key, nil), do: map def put_if_exist(map, key, value), do: Map.put(map, key, value) - def embed_relationships?(params) do - # To do: change to `truthy_param?(params["embed_relationships"])` once PleromaFE supports it - not explicitly_falsy_param?(params["embed_relationships"]) + def with_relationships?(params) do + # To do: change to `truthy_param?(params["with_relationships"])` once PleromaFE supports it + not explicitly_falsy_param?(params["with_relationships"]) end end diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index ef41f9e96..2dd0252cc 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -10,7 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do add_link_headers: 2, truthy_param?: 1, assign_account_by_id: 2, - embed_relationships?: 1, + with_relationships?: 1, json_response: 3 ] @@ -275,7 +275,7 @@ def followers(%{assigns: %{user: for_user, account: user}} = conn, params) do for: for_user, users: followers, as: :user, - embed_relationships: embed_relationships?(params) + embed_relationships: with_relationships?(params) ) end @@ -300,7 +300,7 @@ def following(%{assigns: %{user: for_user, account: user}} = conn, params) do for: for_user, users: followers, as: :user, - embed_relationships: embed_relationships?(params) + embed_relationships: with_relationships?(params) ) end diff --git a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex index 632c4590f..1c2860cc7 100644 --- a/lib/pleroma/web/mastodon_api/controllers/search_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/search_controller.ex @@ -38,7 +38,7 @@ def account_search(%{assigns: %{user: user}} = conn, %{q: query} = params) do users: accounts, for: user, as: :user, - embed_relationships: ControllerHelper.embed_relationships?(params) + embed_relationships: ControllerHelper.with_relationships?(params) ) end @@ -82,7 +82,7 @@ defp search_options(params, user) do offset: params[:offset], type: params[:type], author: get_author(params), - embed_relationships: ControllerHelper.embed_relationships?(params), + embed_relationships: ControllerHelper.with_relationships?(params), for_user: user ] |> Enum.filter(&elem(&1, 1))