45c5ef8a44a70047e712adefbb0a2d3c66eb665e
[akkoma] / lib / pleroma / web / mastodon_api / controllers / domain_block_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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(
12 OAuthScopesPlug,
13 %{scopes: ["follow", "read:blocks"]} when action == :index
14 )
15
16 plug(
17 OAuthScopesPlug,
18 %{scopes: ["follow", "write:blocks"]} when action != :index
19 )
20
21 @doc "GET /api/v1/domain_blocks"
22 def index(%{assigns: %{user: %{info: info}}} = conn, _) do
23 json(conn, Map.get(info, :domain_blocks, []))
24 end
25
26 @doc "POST /api/v1/domain_blocks"
27 def create(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
28 User.block_domain(blocker, domain)
29 json(conn, %{})
30 end
31
32 @doc "DELETE /api/v1/domain_blocks"
33 def delete(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
34 User.unblock_domain(blocker, domain)
35 json(conn, %{})
36 end
37 end