X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fcontrollers%2Fsuggestion_controller.ex;h=4ebfc737c74a0d4892e985e2d9cb6f56bd99582b;hb=aee55b9a8bc3e643377d5843a1ff5d379aecf0e3;hp=a34da98df183c0bbbda0be18a4258f1e84d62563;hpb=b17360cd7c92d8b2337fa4fd175c3e1312eb352e;p=akkoma diff --git a/lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex b/lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex index a34da98df..4ebfc737c 100644 --- a/lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex @@ -5,11 +5,13 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionController do use Pleroma.Web, :controller alias Pleroma.User + alias Pleroma.UserRelationship require Logger plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["read"]} when action in [:index, :index2]) + plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["write"]} when action in [:dismiss]) def open_api_operation(action) do operation = String.to_existing_atom("#{action}_operation") @@ -38,12 +40,32 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionController do } end + def dismiss_operation do + %OpenApiSpex.Operation{ + tags: ["Suggestions"], + summary: "Remove a suggestion", + operationId: "SuggestionController.dismiss", + parameters: [ + OpenApiSpex.Operation.parameter( + :account_id, + :path, + %OpenApiSpex.Schema{type: :string}, + "Account to dismiss", + required: true + ) + ], + responses: %{ + 200 => Pleroma.Web.ApiSpec.Helpers.empty_object_response() + } + } + end + @doc "GET /api/v1/suggestions" def index(conn, params), do: Pleroma.Web.MastodonAPI.MastodonAPIController.empty_array(conn, params) @doc "GET /api/v2/suggestions" - def index2(conn, params) do + def index2(%{assigns: %{user: user}} = conn, params) do limit = Map.get(params, :limit, 40) |> min(80) users = @@ -51,6 +73,14 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionController do |> User.Query.build() |> Pleroma.Repo.all() - render(conn, "index.json", %{users: users, source: :staff, skip_visibility_check: true}) + render(conn, "index.json", %{users: users, source: :staff, for: user}) + end + + @doc "DELETE /api/v1/suggestions/:account_id" + def dismiss(%{assigns: %{user: source}} = conn, %{account_id: user_id}) do + with %User{} = target <- User.get_cached_by_id(user_id), + {:ok, _} <- UserRelationship.create(:suggestion_dismiss, source, target) do + json(conn, %{}) + end end end