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