Add spec for AccountController.follow
This commit is contained in:
parent
1b680a98ae
commit
854780c72b
@ -39,7 +39,7 @@ def spec do
|
|||||||
password: %OpenApiSpex.OAuthFlow{
|
password: %OpenApiSpex.OAuthFlow{
|
||||||
authorizationUrl: "/oauth/authorize",
|
authorizationUrl: "/oauth/authorize",
|
||||||
tokenUrl: "/oauth/token",
|
tokenUrl: "/oauth/token",
|
||||||
scopes: %{"read" => "read", "write" => "write"}
|
scopes: %{"read" => "read", "write" => "write", "follow" => "follow"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||||||
alias Pleroma.Web.ApiSpec.Schemas.Account
|
alias Pleroma.Web.ApiSpec.Schemas.Account
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
|
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
|
alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
|
||||||
|
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
|
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
|
alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
|
alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
|
||||||
@ -186,9 +187,7 @@ def following_operation do
|
|||||||
"Limit"
|
"Limit"
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{200 => Operation.response("Accounts", "application/json", AccountsResponse)}
|
||||||
200 => Operation.response("Accounts", "application/json", AccountsResponse)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -199,16 +198,33 @@ def lists_operation do
|
|||||||
operationId: "AccountController.lists",
|
operationId: "AccountController.lists",
|
||||||
security: [%{"oAuth" => ["read:lists"]}],
|
security: [%{"oAuth" => ["read:lists"]}],
|
||||||
description: "User lists that you have added this account to.",
|
description: "User lists that you have added this account to.",
|
||||||
|
parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
|
||||||
|
responses: %{200 => Operation.response("Lists", "application/json", ListsResponse)}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def follow_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["accounts"],
|
||||||
|
summary: "Follow",
|
||||||
|
operationId: "AccountController.follow",
|
||||||
|
security: [%{"oAuth" => ["follow", "write:follows"]}],
|
||||||
|
description: "Follow the given account",
|
||||||
parameters: [
|
parameters: [
|
||||||
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}
|
%Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
|
||||||
|
Operation.parameter(
|
||||||
|
:reblogs,
|
||||||
|
:query,
|
||||||
|
BooleanLike,
|
||||||
|
"Receive this account's reblogs in home timeline? Defaults to true."
|
||||||
|
)
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Lists", "application/json", ListsResponse)
|
200 => Operation.response("Relationship", "application/json", AccountRelationship)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow_operation, do: :ok
|
|
||||||
def unfollow_operation, do: :ok
|
def unfollow_operation, do: :ok
|
||||||
def mute_operation, do: :ok
|
def mute_operation, do: :ok
|
||||||
def unmute_operation, do: :ok
|
def unmute_operation, do: :ok
|
||||||
|
@ -2,41 +2,43 @@
|
|||||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipResponse do
|
defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
|
|
||||||
require OpenApiSpex
|
require OpenApiSpex
|
||||||
|
|
||||||
OpenApiSpex.schema(%{
|
OpenApiSpex.schema(%{
|
||||||
title: "AccountRelationshipResponse",
|
title: "AccountRelationship",
|
||||||
description: "Response schema for an account relationship",
|
description: "Response schema for relationship",
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
id: %Schema{type: :string},
|
|
||||||
following: %Schema{type: :boolean},
|
|
||||||
showing_reblogs: %Schema{type: :boolean},
|
|
||||||
followed_by: %Schema{type: :boolean},
|
|
||||||
blocking: %Schema{type: :boolean},
|
|
||||||
blocked_by: %Schema{type: :boolean},
|
blocked_by: %Schema{type: :boolean},
|
||||||
|
blocking: %Schema{type: :boolean},
|
||||||
|
domain_blocking: %Schema{type: :boolean},
|
||||||
|
endorsed: %Schema{type: :boolean},
|
||||||
|
followed_by: %Schema{type: :boolean},
|
||||||
|
following: %Schema{type: :boolean},
|
||||||
|
id: %Schema{type: :string},
|
||||||
muting: %Schema{type: :boolean},
|
muting: %Schema{type: :boolean},
|
||||||
muting_notifications: %Schema{type: :boolean},
|
muting_notifications: %Schema{type: :boolean},
|
||||||
requested: %Schema{type: :boolean},
|
requested: %Schema{type: :boolean},
|
||||||
domain_blocking: %Schema{type: :boolean},
|
showing_reblogs: %Schema{type: :boolean},
|
||||||
endorsed: %Schema{type: :boolean}
|
subscribing: %Schema{type: :boolean}
|
||||||
},
|
},
|
||||||
example: %{
|
example: %{
|
||||||
"JSON" => %{
|
"JSON" => %{
|
||||||
"id" => "1",
|
|
||||||
"following" => true,
|
|
||||||
"showing_reblogs" => true,
|
|
||||||
"followed_by" => true,
|
|
||||||
"blocking" => false,
|
|
||||||
"blocked_by" => false,
|
"blocked_by" => false,
|
||||||
|
"blocking" => false,
|
||||||
|
"domain_blocking" => false,
|
||||||
|
"endorsed" => false,
|
||||||
|
"followed_by" => false,
|
||||||
|
"following" => false,
|
||||||
|
"id" => "9tKi3esbG7OQgZ2920",
|
||||||
"muting" => false,
|
"muting" => false,
|
||||||
"muting_notifications" => false,
|
"muting_notifications" => false,
|
||||||
"requested" => false,
|
"requested" => false,
|
||||||
"domain_blocking" => false,
|
"showing_reblogs" => true,
|
||||||
"endorsed" => false
|
"subscribing" => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
@ -9,7 +9,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
|
|||||||
title: "AccountRelationshipsResponse",
|
title: "AccountRelationshipsResponse",
|
||||||
description: "Response schema for account relationships",
|
description: "Response schema for account relationships",
|
||||||
type: :array,
|
type: :array,
|
||||||
items: Pleroma.Web.ApiSpec.Schemas.AccountRelationshipResponse,
|
items: Pleroma.Web.ApiSpec.Schemas.AccountRelationship,
|
||||||
example: [
|
example: [
|
||||||
%{
|
%{
|
||||||
"id" => "1",
|
"id" => "1",
|
||||||
@ -22,6 +22,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
|
|||||||
"muting_notifications" => false,
|
"muting_notifications" => false,
|
||||||
"requested" => false,
|
"requested" => false,
|
||||||
"domain_blocking" => false,
|
"domain_blocking" => false,
|
||||||
|
"subscribing" => false,
|
||||||
"endorsed" => true
|
"endorsed" => true
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
@ -35,6 +36,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
|
|||||||
"muting_notifications" => false,
|
"muting_notifications" => false,
|
||||||
"requested" => true,
|
"requested" => true,
|
||||||
"domain_blocking" => false,
|
"domain_blocking" => false,
|
||||||
|
"subscribing" => false,
|
||||||
"endorsed" => false
|
"endorsed" => false
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
@ -48,6 +50,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
|
|||||||
"muting_notifications" => false,
|
"muting_notifications" => false,
|
||||||
"requested" => false,
|
"requested" => false,
|
||||||
"domain_blocking" => true,
|
"domain_blocking" => true,
|
||||||
|
"subscribing" => true,
|
||||||
"endorsed" => false
|
"endorsed" => false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -92,7 +92,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||||||
:statuses,
|
:statuses,
|
||||||
:followers,
|
:followers,
|
||||||
:following,
|
:following,
|
||||||
:lists
|
:lists,
|
||||||
|
:follow
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -337,8 +338,8 @@ def follow(%{assigns: %{user: %{id: id}, account: %{id: id}}}, _params) do
|
|||||||
{:error, :not_found}
|
{:error, :not_found}
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow(%{assigns: %{user: follower, account: followed}} = conn, _params) do
|
def follow(%{assigns: %{user: follower, account: followed}} = conn, params) do
|
||||||
with {:ok, follower} <- MastodonAPI.follow(follower, followed, conn.params) do
|
with {:ok, follower} <- MastodonAPI.follow(follower, followed, params) do
|
||||||
render(conn, "relationship.json", user: follower, target: followed)
|
render(conn, "relationship.json", user: follower, target: followed)
|
||||||
else
|
else
|
||||||
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
||||||
|
@ -669,6 +669,7 @@ test "following / unfollowing a user", %{conn: conn} do
|
|||||||
|
|
||||||
assert %{"id" => id} = json_response(conn, 200)
|
assert %{"id" => id} = json_response(conn, 200)
|
||||||
assert id == to_string(other_user.id)
|
assert id == to_string(other_user.id)
|
||||||
|
assert_schema(json_response(conn, 200), "AccountRelationship", ApiSpec.spec())
|
||||||
end
|
end
|
||||||
|
|
||||||
test "cancelling follow request", %{conn: conn} do
|
test "cancelling follow request", %{conn: conn} do
|
||||||
|
Loading…
Reference in New Issue
Block a user