v2 Suggestions: don't skip visibility check
[akkoma] / lib / pleroma / web / mastodon_api / controllers / suggestion_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.SuggestionController do
6 use Pleroma.Web, :controller
7 alias Pleroma.User
8
9 require Logger
10
11 plug(Pleroma.Web.ApiSpec.CastAndValidate)
12 plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["read"]} when action in [:index, :index2])
13
14 def open_api_operation(action) do
15 operation = String.to_existing_atom("#{action}_operation")
16 apply(__MODULE__, operation, [])
17 end
18
19 def index_operation do
20 %OpenApiSpex.Operation{
21 tags: ["Suggestions"],
22 summary: "Follow suggestions (Not implemented)",
23 operationId: "SuggestionController.index",
24 responses: %{
25 200 => Pleroma.Web.ApiSpec.Helpers.empty_array_response()
26 }
27 }
28 end
29
30 def index2_operation do
31 %OpenApiSpex.Operation{
32 tags: ["Suggestions"],
33 summary: "Follow suggestions",
34 operationId: "SuggestionController.index2",
35 responses: %{
36 200 => Pleroma.Web.ApiSpec.Helpers.empty_array_response()
37 }
38 }
39 end
40
41 @doc "GET /api/v1/suggestions"
42 def index(conn, params),
43 do: Pleroma.Web.MastodonAPI.MastodonAPIController.empty_array(conn, params)
44
45 @doc "GET /api/v2/suggestions"
46 def index2(%{assigns: %{user: user}} = conn, params) do
47 limit = Map.get(params, :limit, 40) |> min(80)
48
49 users =
50 %{is_suggested: true, limit: limit}
51 |> User.Query.build()
52 |> Pleroma.Repo.all()
53
54 render(conn, "index.json", %{users: users, source: :staff, for: user})
55 end
56 end