2019-09-27 07:28:05 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 22:44:49 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-09-27 07:28:05 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.DomainBlockController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
2019-10-02 17:42:40 +00:00
|
|
|
alias Pleroma.Plugs.OAuthScopesPlug
|
2019-09-27 07:28:05 +00:00
|
|
|
alias Pleroma.User
|
|
|
|
|
2020-04-13 18:44:52 +00:00
|
|
|
plug(OpenApiSpex.Plug.CastAndValidate)
|
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.DomainBlockOperation
|
|
|
|
|
2019-10-02 17:42:40 +00:00
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["follow", "read:blocks"]} when action == :index
|
|
|
|
)
|
|
|
|
|
|
|
|
plug(
|
|
|
|
OAuthScopesPlug,
|
|
|
|
%{scopes: ["follow", "write:blocks"]} when action != :index
|
|
|
|
)
|
|
|
|
|
2019-09-27 07:28:05 +00:00
|
|
|
@doc "GET /api/v1/domain_blocks"
|
2019-10-20 10:42:42 +00:00
|
|
|
def index(%{assigns: %{user: user}} = conn, _) do
|
|
|
|
json(conn, Map.get(user, :domain_blocks, []))
|
2019-09-27 07:28:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc "POST /api/v1/domain_blocks"
|
2020-04-13 18:44:52 +00:00
|
|
|
def create(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do
|
2019-09-27 07:28:05 +00:00
|
|
|
User.block_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc "DELETE /api/v1/domain_blocks"
|
2020-04-13 18:44:52 +00:00
|
|
|
def delete(%{assigns: %{user: blocker}, body_params: %{domain: domain}} = conn, _params) do
|
2019-09-27 07:28:05 +00:00
|
|
|
User.unblock_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
|
|
|
end
|