Exclude reblogs from `GET /api/pleroma/admin/statuses` by default
[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 plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
22
23 @doc "GET /api/v1/domain_blocks"
24 def index(%{assigns: %{user: user}} = conn, _) do
25 json(conn, Map.get(user, :domain_blocks, []))
26 end
27
28 @doc "POST /api/v1/domain_blocks"
29 def create(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
30 User.block_domain(blocker, domain)
31 json(conn, %{})
32 end
33
34 @doc "DELETE /api/v1/domain_blocks"
35 def delete(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
36 User.unblock_domain(blocker, domain)
37 json(conn, %{})
38 end
39 end