1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
6 use Pleroma.Web, :controller
9 alias Pleroma.Web.Plugs.OAuthScopesPlug
11 plug(Pleroma.Web.ApiSpec.CastAndValidate)
12 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.DomainBlockOperation
16 %{scopes: ["follow", "read:blocks"]} when action == :index
21 %{scopes: ["follow", "write:blocks"]} when action != :index
24 @doc "GET /api/v1/domain_blocks"
25 def index(%{assigns: %{user: user}} = conn, _) do
26 json(conn, Map.get(user, :domain_blocks, []))
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)
35 def create(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
36 User.block_domain(blocker, domain)
40 @doc "DELETE /api/v1/domain_blocks"
41 def delete(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do
42 User.unblock_domain(blocker, domain)
46 def delete(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
47 User.unblock_domain(blocker, domain)