diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index e30fed610..9d93f8df0 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -55,6 +55,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do muting: User.mutes?(user, target), muting_notifications: User.muted_notifications?(user, target), subscribing: User.subscribed_to?(user, target), + whitelisting: User.whitelists?(user, target), requested: requested, domain_blocking: User.blocks_domain?(user, target), showing_reblogs: User.showing_reblogs?(user, target), diff --git a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex index bc2f1017c..cc010d35e 100644 --- a/lib/pleroma/web/pleroma_api/controllers/account_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/account_controller.ex @@ -43,7 +43,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do ) plug(RateLimiter, [name: :account_confirmation_resend] when action == :confirmation_resend) - plug(:assign_account_by_id when action in [:favourites, :subscribe, :unsubscribe]) + plug(:assign_account_by_id when action in [:favourites, :subscribe, :unsubscribe, :whitelist, :unwhitelist]) plug(:put_view, Pleroma.Web.MastodonAPI.AccountView) @doc "POST /api/v1/pleroma/accounts/confirmation_resend" @@ -159,4 +159,22 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do {:error, message} -> json_response(conn, :forbidden, %{error: message}) end end + + @doc "POST /api/v1/pleroma/accounts/:id/whitelist" + def whitelist(%{assigns: %{user: user, account: whitelist_target}} = conn, _params) do + with {:ok, user} <- User.whitelist(user, whitelist_target) do + render(conn, "relationship.json", user: user, target: whitelist_target) + else + {:error, message} -> json_response(conn, :forbidden, %{error: message}) + end + end + + @doc "POST /api/v1/pleroma/accounts/:id/unwhitelist" + def unwhitelist(%{assigns: %{user: user, account: whitelist_target}} = conn, _params) do + with {:ok, user} <- User.unwhitelist(user, whitelist_target) do + render(conn, "relationship.json", user: user, target: whitelist_target) + else + {:error, message} -> json_response(conn, :forbidden, %{error: message}) + end + end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index e6c4f6f14..8144aff8b 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -310,6 +310,8 @@ defmodule Pleroma.Web.Router do post("/accounts/:id/subscribe", AccountController, :subscribe) post("/accounts/:id/unsubscribe", AccountController, :unsubscribe) + post("/accounts/:id/whitelist", AccountController, :whitelist) + post("/accounts/:id/unwhitelist", AccountController, :unwhitelist) end post("/accounts/confirmation_resend", AccountController, :confirmation_resend)