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-05-04 10:16:18 -06:00
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
2020-04-13 12:44:52 -06:00
|
|
|
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-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
|
|
|
|
|
2020-07-23 11:59:40 -06:00
|
|
|
def create(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
|
|
|
|
User.block_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
|
|
|
|
2019-09-27 01:28:05 -06:00
|
|
|
@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
|
2020-07-21 06:06:46 -06:00
|
|
|
|
|
|
|
def delete(%{assigns: %{user: blocker}} = conn, %{domain: domain}) do
|
|
|
|
User.unblock_domain(blocker, domain)
|
|
|
|
json(conn, %{})
|
|
|
|
end
|
2019-09-27 01:28:05 -06:00
|
|
|
end
|