Allow unblocking a domain via query params
[akkoma] / lib / pleroma / web / mastodon_api / controllers / domain_block_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Plugs.OAuthScopesPlug
9 alias Pleroma.User
10
11 plug(Pleroma.Web.ApiSpec.CastAndValidate)
12 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.DomainBlockOperation
13
14 plug(
15 OAuthScopesPlug,
16 %{scopes: ["follow", "read:blocks"]} when action == :index
17 )
18
19 plug(
20 OAuthScopesPlug,
21 %{scopes: ["follow", "write:blocks"]} when action != :index
22 )
23
24 @doc "GET /api/v1/domain_blocks"
25 def index(%{assigns: %{user: user}} = conn, _) do
26 json(conn, Map.get(user, :domain_blocks, []))
27 end
28
29 @doc "POST /api/v1/domain_blocks"
30 def create(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do
31 User.block_domain(blocker, domain)
32 json(conn, %{})
33 end
34
35 @doc "DELETE /api/v1/domain_blocks"
36 def delete(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do
37 User.unblock_domain(blocker, domain)
38 json(conn, %{})
39 end
40
41 def delete(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
42 User.unblock_domain(blocker, domain)
43 json(conn, %{})
44 end
45 end