2019-09-27 09:28:05 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 23:44:49 +01:00
|
|
|
# Copyright © 2017-2020 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
|
|
|
|
|
2019-10-02 19:42:40 +02:00
|
|
|
alias Pleroma.Plugs.OAuthScopesPlug
|
2019-09-27 09:28:05 +02:00
|
|
|
alias Pleroma.User
|
|
|
|
|
2020-04-13 20:44:52 +02:00
|
|
|
plug(OpenApiSpex.Plug.CastAndValidate)
|
|
|
|
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
|
|
|
|
|
|
|
|
@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
|
|
|
|
end
|