Move GET /api/v1/apps to GET /api/v1/pleroma/apps
This commit is contained in:
parent
eab6291094
commit
a14e1c0003
7 changed files with 66 additions and 33 deletions
|
@ -14,19 +14,6 @@ def open_api_operation(action) do
|
|||
apply(__MODULE__, operation, [])
|
||||
end
|
||||
|
||||
@spec index_operation() :: Operation.t()
|
||||
def index_operation do
|
||||
%Operation{
|
||||
tags: ["Applications"],
|
||||
summary: "List applications",
|
||||
description: "List the OAuth applications for the current user",
|
||||
operationId: "AppController.index",
|
||||
responses: %{
|
||||
200 => Operation.response("Array of App", "application/json", array_of_apps())
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@spec create_operation() :: Operation.t()
|
||||
def create_operation do
|
||||
%Operation{
|
||||
|
@ -137,8 +124,4 @@ defp create_request do
|
|||
defp create_response do
|
||||
Operation.response("App", "application/json", App)
|
||||
end
|
||||
|
||||
defp array_of_apps do
|
||||
%Schema{type: :array, items: App, example: [App.schema().example]}
|
||||
end
|
||||
end
|
||||
|
|
31
lib/pleroma/web/api_spec/operations/pleroma_app_operation.ex
Normal file
31
lib/pleroma/web/api_spec/operations/pleroma_app_operation.ex
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ApiSpec.PleromaAppOperation do
|
||||
alias OpenApiSpex.Operation
|
||||
alias OpenApiSpex.Schema
|
||||
alias Pleroma.Web.ApiSpec.Schemas.App
|
||||
|
||||
def open_api_operation(action) do
|
||||
operation = String.to_existing_atom("#{action}_operation")
|
||||
apply(__MODULE__, operation, [])
|
||||
end
|
||||
|
||||
@spec index_operation() :: Operation.t()
|
||||
def index_operation do
|
||||
%Operation{
|
||||
tags: ["Applications"],
|
||||
summary: "List applications",
|
||||
description: "List the OAuth applications for the current user",
|
||||
operationId: "AppController.index",
|
||||
responses: %{
|
||||
200 => Operation.response("Array of App", "application/json", array_of_apps())
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp array_of_apps do
|
||||
%Schema{type: :array, items: App, example: [App.schema().example]}
|
||||
end
|
||||
end
|
|
@ -14,27 +14,17 @@ defmodule Pleroma.Web.MastodonAPI.AppController do
|
|||
alias Pleroma.Web.OAuth.App
|
||||
alias Pleroma.Web.OAuth.Scopes
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||
|
||||
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
||||
|
||||
plug(:skip_auth when action in [:create, :verify_credentials])
|
||||
|
||||
plug(OAuthScopesPlug, %{scopes: ["follow", "read"]} when action in [:index])
|
||||
|
||||
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||
|
||||
@local_mastodon_name "Mastodon-Local"
|
||||
|
||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.AppOperation
|
||||
|
||||
@doc "GET /api/v1/apps"
|
||||
def index(%{assigns: %{user: user}} = conn, _params) do
|
||||
with apps <- App.get_user_apps(user) do
|
||||
render(conn, "index.json", %{apps: apps})
|
||||
end
|
||||
end
|
||||
|
||||
@doc "POST /api/v1/apps"
|
||||
def create(%{body_params: params} = conn, _params) do
|
||||
scopes = Scopes.fetch_scopes(params, ["read"])
|
||||
|
|
|
@ -15,10 +15,6 @@ def render("index.json", %{apps: apps, count: count, page_size: page_size, admin
|
|||
}
|
||||
end
|
||||
|
||||
def render("index.json", %{apps: apps}) do
|
||||
render_many(apps, Pleroma.Web.MastodonAPI.AppView, "show.json")
|
||||
end
|
||||
|
||||
def render("show.json", %{admin: true, app: %App{} = app} = assigns) do
|
||||
"show.json"
|
||||
|> render(Map.delete(assigns, :admin))
|
||||
|
|
23
lib/pleroma/web/pleroma_api/controllers/app_controller.ex
Normal file
23
lib/pleroma/web/pleroma_api/controllers/app_controller.ex
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.AppController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
alias Pleroma.Web.OAuth.App
|
||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||
|
||||
plug(OAuthScopesPlug, %{scopes: ["follow", "read"]} when action in [:index])
|
||||
|
||||
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||
|
||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaAppOperation
|
||||
|
||||
@doc "GET /api/v1/pleroma/apps"
|
||||
def index(%{assigns: %{user: user}} = conn, _params) do
|
||||
with apps <- App.get_user_apps(user) do
|
||||
render(conn, "index.json", %{apps: apps})
|
||||
end
|
||||
end
|
||||
end
|
11
lib/pleroma/web/pleroma_api/views/app_view.ex
Normal file
11
lib/pleroma/web/pleroma_api/views/app_view.ex
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.AppView do
|
||||
use Pleroma.Web, :view
|
||||
|
||||
def render("index.json", %{apps: apps}) do
|
||||
render_many(apps, Pleroma.Web.MastodonAPI.AppView, "show.json")
|
||||
end
|
||||
end
|
|
@ -372,6 +372,7 @@ defmodule Pleroma.Web.Router do
|
|||
scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
|
||||
pipe_through(:api)
|
||||
|
||||
get("/apps", AppController, :index)
|
||||
get("/statuses/:id/reactions/:emoji", EmojiReactionController, :index)
|
||||
get("/statuses/:id/reactions", EmojiReactionController, :index)
|
||||
end
|
||||
|
@ -444,8 +445,6 @@ defmodule Pleroma.Web.Router do
|
|||
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
||||
pipe_through(:authenticated_api)
|
||||
|
||||
get("/apps", AppController, :index)
|
||||
|
||||
get("/accounts/verify_credentials", AccountController, :verify_credentials)
|
||||
patch("/accounts/update_credentials", AccountController, :update_credentials)
|
||||
|
||||
|
|
Loading…
Reference in a new issue