diff options
| author | Egor Kislitsyn <egor@kislitsyn.com> | 2020-04-09 18:28:14 +0400 | 
|---|---|---|
| committer | Egor Kislitsyn <egor@kislitsyn.com> | 2020-04-13 18:17:08 +0400 | 
| commit | e4195d4a684908d58482f9c865375a080e7b78bc (patch) | |
| tree | 63a27c7ff4ae1964f0994091a09b4ac803626a9b | |
| parent | aa958a6dda7cdcf12e9cd9232e7c6be421610317 (diff) | |
| download | pleroma-e4195d4a684908d58482f9c865375a080e7b78bc.tar.gz pleroma-e4195d4a684908d58482f9c865375a080e7b78bc.zip | |
Add specs for AccountController.mute and AccountController.unmute
4 files changed, 79 insertions, 9 deletions
| diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 8925ebefd..62ae2eead 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -10,6 +10,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do    alias Pleroma.Web.ApiSpec.Schemas.Account    alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest    alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse +  alias Pleroma.Web.ApiSpec.Schemas.AccountMuteRequest    alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship    alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse    alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse @@ -239,8 +240,44 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do      }    end -  def mute_operation, do: :ok -  def unmute_operation, do: :ok +  def mute_operation do +    %Operation{ +      tags: ["accounts"], +      summary: "Mute", +      operationId: "AccountController.mute", +      security: [%{"oAuth" => ["follow", "write:mutes"]}], +      requestBody: Helpers.request_body("Parameters", AccountMuteRequest), +      description: +        "Mute the given account. Clients should filter statuses and notifications from this account, if received (e.g. due to a boost in the Home timeline).", +      parameters: [ +        %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}, +        Operation.parameter( +          :notifications, +          :query, +          %Schema{allOf: [BooleanLike], default: true}, +          "Mute notifications in addition to statuses? Defaults to `true`." +        ) +      ], +      responses: %{ +        200 => Operation.response("Relationship", "application/json", AccountRelationship) +      } +    } +  end + +  def unmute_operation do +    %Operation{ +      tags: ["accounts"], +      summary: "Unmute", +      operationId: "AccountController.unmute", +      security: [%{"oAuth" => ["follow", "write:mutes"]}], +      description: "Unmute the given account.", +      parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}], +      responses: %{ +        200 => Operation.response("Relationship", "application/json", AccountRelationship) +      } +    } +  end +    def block_operation, do: :ok    def unblock_operation, do: :ok    def follows_operation, do: :ok diff --git a/lib/pleroma/web/api_spec/schemas/account_mute_request.ex b/lib/pleroma/web/api_spec/schemas/account_mute_request.ex new file mode 100644 index 000000000..a61f6d04c --- /dev/null +++ b/lib/pleroma/web/api_spec/schemas/account_mute_request.ex @@ -0,0 +1,24 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ApiSpec.Schemas.AccountMuteRequest do +  alias OpenApiSpex.Schema +  require OpenApiSpex + +  OpenApiSpex.schema(%{ +    title: "AccountMuteRequest", +    description: "POST body for muting an account", +    type: :object, +    properties: %{ +      notifications: %Schema{ +        type: :boolean, +        description: "Mute notifications in addition to statuses? Defaults to true.", +        default: true +      } +    }, +    example: %{ +      "notifications" => true +    } +  }) +end diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 1ecce2928..9aba2e094 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -94,7 +94,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do             :following,             :lists,             :follow, -           :unfollow +           :unfollow, +           :mute, +           :unmute           ]    ) @@ -359,10 +361,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do    end    @doc "POST /api/v1/accounts/:id/mute" -  def mute(%{assigns: %{user: muter, account: muted}} = conn, params) do -    notifications? = params |> Map.get("notifications", true) |> truthy_param?() - -    with {:ok, _user_relationships} <- User.mute(muter, muted, notifications?) do +  def mute(%{assigns: %{user: muter, account: muted}, body_params: params} = conn, _params) do +    with {:ok, _user_relationships} <- User.mute(muter, muted, params.notifications) do        render(conn, "relationship.json", user: muter, target: muted)      else        {:error, message} -> json_response(conn, :forbidden, %{error: message}) diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index d56e7fb4a..91d4685cb 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -751,32 +751,41 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do      test "with notifications", %{conn: conn} do        other_user = insert(:user) -      ret_conn = post(conn, "/api/v1/accounts/#{other_user.id}/mute") +      ret_conn = +        conn +        |> put_req_header("content-type", "application/json") +        |> post("/api/v1/accounts/#{other_user.id}/mute")        response = json_response(ret_conn, 200)        assert %{"id" => _id, "muting" => true, "muting_notifications" => true} = response +      assert_schema(response, "AccountRelationship", ApiSpec.spec())        conn = post(conn, "/api/v1/accounts/#{other_user.id}/unmute")        response = json_response(conn, 200)        assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response +      assert_schema(response, "AccountRelationship", ApiSpec.spec())      end      test "without notifications", %{conn: conn} do        other_user = insert(:user)        ret_conn = -        post(conn, "/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"}) +        conn +        |> put_req_header("content-type", "multipart/form-data") +        |> post("/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"})        response = json_response(ret_conn, 200)        assert %{"id" => _id, "muting" => true, "muting_notifications" => false} = response +      assert_schema(response, "AccountRelationship", ApiSpec.spec())        conn = post(conn, "/api/v1/accounts/#{other_user.id}/unmute")        response = json_response(conn, 200)        assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response +      assert_schema(response, "AccountRelationship", ApiSpec.spec())      end    end | 
