allow deleting profiles
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending

This commit is contained in:
FloatingGhost 2022-10-02 17:00:26 +01:00
parent 8a3b7a3757
commit 4940a49a50
4 changed files with 50 additions and 3 deletions

View file

@ -69,6 +69,10 @@ def get_by_user_and_frontend_name_and_profile_name(
)
end
def delete_profile(profile) do
Repo.delete(profile)
end
defp validate_settings_length(
%Ecto.Changeset{changes: %{settings: settings}} = changeset,
max_length

View file

@ -18,7 +18,7 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsController do
OAuthScopesPlug,
%{@unauthenticated_access | scopes: ["write:accounts"]}
when action in [
:update_profile
:update_profile, :delete_profile
]
)
@ -60,6 +60,21 @@ def list_profiles(conn, %{frontend_name: frontend_name}) do
end
end
@doc "DELETE /api/v1/akkoma/frontend_settings/:frontend_name/:profile_name"
def delete_profile(conn, %{frontend_name: frontend_name, profile_name: profile_name}) do
with %FrontendSettingsProfile{} = profile <-
FrontendSettingsProfile.get_by_user_and_frontend_name_and_profile_name(
conn.assigns.user,
frontend_name,
profile_name
),
{:ok, _} <- FrontendSettingsProfile.delete_profile(profile) do
json(conn, %{})
else
nil -> {:error, :not_found}
end
end
@doc "PUT /api/v1/akkoma/frontend_settings/:frontend_name/:profile_name"
def update_profile(%{body_params: %{settings: settings, version: version}} = conn, %{
frontend_name: frontend_name,

View file

@ -22,7 +22,10 @@ def list_profiles_operation() do
200 =>
Operation.response("Profiles", "application/json", %Schema{
type: :array,
items: %Schema{type: :string}
items: %Schema{type: :object, properties: %{
name: %Schema{type: :string},
version: %Schema{type: :integer}
}}
})
}
}
@ -38,7 +41,26 @@ def get_profile_operation() do
security: [%{"oAuth" => ["read:accounts"]}],
parameters: [frontend_name_param(), profile_name_param()],
responses: %{
200 => Operation.response("Translation", "application/json", %Schema{type: :object}),
200 => Operation.response("Profile", "application/json", %Schema{type: :object, properties: %{
"version" => %Schema{type: :integer},
"settings" => %Schema{type: :object, additionalProperties: true}
}}),
404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
}
}
end
@spec delete_profile_operation() :: Operation.t()
def delete_profile_operation() do
%Operation{
tags: ["Delete frontend setting profile"],
summary: "Delete frontend Settings Profile",
description: "Delete frontend setting profile",
operationId: "AkkomaAPI.FrontendSettingsController.delete_profile",
security: [%{"oAuth" => ["write:accounts"]}],
parameters: [frontend_name_param(), profile_name_param()],
responses: %{
200 => Operation.response("Empty", "application/json", %Schema{type: :string}),
404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
}
}

View file

@ -480,6 +480,12 @@ defmodule Pleroma.Web.Router do
FrontendSettingsController,
:update_profile
)
delete(
"/frontend_settings/:frontend_name/:profile_name",
FrontendSettingsController,
:delete_profile
)
end
scope "/api/v1", Pleroma.Web.MastodonAPI do