aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/mastodon_api
diff options
context:
space:
mode:
authorSean King <seanking2919@protonmail.com>2021-08-28 23:18:12 -0600
committerSean King <seanking2919@protonmail.com>2021-08-28 23:18:12 -0600
commit33f063204edb63344628bdfa72ff11f81ded62a9 (patch)
tree790078abe47ee5a6f2fd9ebb35aac38d0868eb84 /lib/pleroma/web/mastodon_api
parentd02cf7b0cd550bc182e7307b90f077e159b5637f (diff)
downloadpleroma-33f063204edb63344628bdfa72ff11f81ded62a9.tar.gz
Add unit test for Pleroma API app controller
Diffstat (limited to 'lib/pleroma/web/mastodon_api')
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/app_controller.ex14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/pleroma/web/mastodon_api/controllers/app_controller.ex b/lib/pleroma/web/mastodon_api/controllers/app_controller.ex
index a95cc52fd..466508137 100644
--- a/lib/pleroma/web/mastodon_api/controllers/app_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/app_controller.ex
@@ -10,11 +10,15 @@ defmodule Pleroma.Web.MastodonAPI.AppController do
use Pleroma.Web, :controller
+ alias Pleroma.Maps
+ alias Pleroma.User
alias Pleroma.Repo
alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Scopes
alias Pleroma.Web.OAuth.Token
+ require Logger
+
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
plug(:skip_auth when action in [:create, :verify_credentials])
@@ -26,13 +30,21 @@ defmodule Pleroma.Web.MastodonAPI.AppController do
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.AppOperation
@doc "POST /api/v1/apps"
- def create(%{body_params: params} = conn, _params) do
+ def create(%{assigns: %{user: user}, body_params: params} = conn, _params) do
scopes = Scopes.fetch_scopes(params, ["read"])
+ user_id =
+ with %User{id: id} <- user do
+ id
+ else
+ _ -> nil
+ end
+
app_attrs =
params
|> Map.take([:client_name, :redirect_uris, :website])
|> Map.put(:scopes, scopes)
+ |> Maps.put_if_present(:user_id, user_id)
with cs <- App.register_changeset(%App{}, app_attrs),
false <- cs.changes[:client_name] == @local_mastodon_name,