2019-09-27 09:28:05 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 07:49:20 +01:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-09-27 09:28:05 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
alias Pleroma.User
|
2020-06-24 12:07:47 +02:00
|
|
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
2019-09-27 09:28:05 +02:00
|
|
|
|
2020-05-04 18:16:18 +02:00
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
2020-04-13 20:44:52 +02:00
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.DomainBlockOperation
|
|
|
|
|
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-09-27 09:28:05 +02:00
|
|
|
@doc "GET /api/v1/domain_blocks"
|
2019-10-20 12:42:42 +02:00
|
|
|
def index(%{assigns: %{user: user}} = conn, _) do
|
|
|
|
json(conn, Map.get(user, :domain_blocks, []))
|
2019-09-27 09:28:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc "POST /api/v1/domain_blocks"
|
2020-04-13 20:44:52 +02:00
|
|
|
def create(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do
|
2019-09-27 09:28:05 +02:00
|
|
|
User.block_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
|
|
|
|
2020-07-23 19:59:40 +02:00
|
|
|
def create(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
|
|
|
|
User.block_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
|
|
|
|
2019-09-27 09:28:05 +02:00
|
|
|
@doc "DELETE /api/v1/domain_blocks"
|
2020-04-13 20:44:52 +02:00
|
|
|
def delete(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do
|
2019-09-27 09:28:05 +02:00
|
|
|
User.unblock_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
2020-07-21 14:06:46 +02:00
|
|
|
|
|
|
|
def delete(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
|
|
|
|
User.unblock_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
2019-09-27 09:28:05 +02:00
|
|
|
end
|