1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
8 alias Pleroma.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 @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)
41 def delete(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
42 User.unblock_domain(blocker, domain)