2019-09-27 09:28:05 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
alias Pleroma.Plugs.OAuthScopesPlug
|
2019-09-27 09:28:05 +02:00
|
|
|
alias Pleroma.User
|
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["follow", "read:blocks"]} when action == :index
|
|
|
|
)
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["follow", "write:blocks"]} when action != :index
|
|
|
|
)
|
|
|
|
|
2019-10-06 16:12:17 +02:00
|
|
|
plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
|
|
|
|
|
2019-09-27 09:28:05 +02:00
|
|
|
@doc "GET /api/v1/domain_blocks"
|
|
|
|
def index(%{assigns: %{user: %{info: info}}} = conn, _) do
|
|
|
|
json(conn, Map.get(info, :domain_blocks, []))
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "POST /api/v1/domain_blocks"
|
|
|
|
def create(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
|
|
|
|
User.block_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "DELETE /api/v1/domain_blocks"
|
|
|
|
def delete(%{assigns: %{user: blocker}} = conn, %{"domain" => domain}) do
|
|
|
|
User.unblock_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
|
|
|
end
|