projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request 'Correct og:description tag in static-fe' (#373) from sfr/akkoma...
[akkoma]
/
lib
/
pleroma
/
web
/
mastodon_api
/
controllers
/
app_controller.ex
diff --git
a/lib/pleroma/web/mastodon_api/controllers/app_controller.ex
b/lib/pleroma/web/mastodon_api/controllers/app_controller.ex
index dd3b39c7789db7bc8fb3be29f046568edb4ad7a9..499ccf056d0470e8b39eb561e857c0b92d48374d 100644
(file)
--- a/
lib/pleroma/web/mastodon_api/controllers/app_controller.ex
+++ b/
lib/pleroma/web/mastodon_api/controllers/app_controller.ex
@@
-10,20
+10,16
@@
defmodule Pleroma.Web.MastodonAPI.AppController do
use Pleroma.Web, :controller
use Pleroma.Web, :controller
+ alias Pleroma.Maps
alias Pleroma.Repo
alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Scopes
alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Scopes
alias Pleroma.Web.OAuth.Token
- alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
- alias Pleroma.Web.Plugs.OAuthScopesPlug
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
- plug(
- :skip_plug,
- [OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug]
- when action in [:create, :verify_credentials]
- )
+ plug(:skip_auth when action in [:create, :verify_credentials])
plug(Pleroma.Web.ApiSpec.CastAndValidate)
plug(Pleroma.Web.ApiSpec.CastAndValidate)
@@
-34,11
+30,13
@@
defmodule Pleroma.Web.MastodonAPI.AppController do
@doc "POST /api/v1/apps"
def create(%{body_params: params} = conn, _params) do
scopes = Scopes.fetch_scopes(params, ["read"])
@doc "POST /api/v1/apps"
def create(%{body_params: params} = conn, _params) do
scopes = Scopes.fetch_scopes(params, ["read"])
+ user_id = get_user_id(conn)
app_attrs =
params
|> Map.take([:client_name, :redirect_uris, :website])
|> Map.put(:scopes, scopes)
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,
with cs <- App.register_changeset(%App{}, app_attrs),
false <- cs.changes[:client_name] == @local_mastodon_name,
@@
-47,6
+45,9
@@
defmodule Pleroma.Web.MastodonAPI.AppController do
end
end
end
end
+ defp get_user_id(%{assigns: %{user: %User{id: user_id}}}), do: user_id
+ defp get_user_id(_conn), do: nil
+
@doc """
GET /api/v1/apps/verify_credentials
Gets compact non-secret representation of the app. Supports app tokens and user tokens.
@doc """
GET /api/v1/apps/verify_credentials
Gets compact non-secret representation of the app. Supports app tokens and user tokens.