diff options
author | lain <lain@soykaf.club> | 2020-06-23 10:17:12 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-06-23 10:17:12 +0200 |
commit | 2c603f20098d7f342e1cbad8e6a6c86b007c5a99 (patch) | |
tree | dd9a339daed6a25e758167413d9231e22ce42ac4 /lib/pleroma/web/mastodon_api/controllers/account_controller.ex | |
parent | b05f795326b77edd881ffea2c004d7ca0ddd7df9 (diff) | |
parent | 3875a507d4b52df7edbda376d3ed31ad52241ac5 (diff) | |
download | pleroma-2c603f20098d7f342e1cbad8e6a6c86b007c5a99.tar.gz |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into update-validator
Diffstat (limited to 'lib/pleroma/web/mastodon_api/controllers/account_controller.ex')
-rw-r--r-- | lib/pleroma/web/mastodon_api/controllers/account_controller.ex | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index d4605c518..7a88a847c 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -179,6 +179,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do |> Maps.put_if_present(:pleroma_settings_store, params[:pleroma_settings_store]) |> Maps.put_if_present(:default_scope, params[:default_scope]) |> Maps.put_if_present(:default_scope, params["source"]["privacy"]) + |> Maps.put_if_present(:actor_type, params[:bot], fn bot -> + if bot, do: {:ok, "Service"}, else: {:ok, "Person"} + end) |> Maps.put_if_present(:actor_type, params[:actor_type]) # What happens here: @@ -238,17 +241,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do @doc "GET /api/v1/accounts/:id" def show(%{assigns: %{user: for_user}} = conn, %{id: nickname_or_id}) do with %User{} = user <- User.get_cached_by_nickname_or_id(nickname_or_id, for: for_user), - true <- User.visible_for?(user, for_user) do + :visible <- User.visible_for(user, for_user) do render(conn, "show.json", user: user, for: for_user) else - _e -> render_error(conn, :not_found, "Can't find user") + error -> user_visibility_error(conn, error) end end @doc "GET /api/v1/accounts/:id/statuses" def statuses(%{assigns: %{user: reading_user}} = conn, params) do with %User{} = user <- User.get_cached_by_nickname_or_id(params.id, for: reading_user), - true <- User.visible_for?(user, reading_user) do + :visible <- User.visible_for(user, reading_user) do params = params |> Map.delete(:tagged) @@ -265,7 +268,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do as: :activity ) else - _e -> render_error(conn, :not_found, "Can't find user") + error -> user_visibility_error(conn, error) + end + end + + defp user_visibility_error(conn, error) do + case error do + :restrict_unauthenticated -> + render_error(conn, :unauthorized, "This API requires an authenticated user") + + _ -> + render_error(conn, :not_found, "Can't find user") end end |