From d1670d7cf369fd2766ef8cda7986db8d53471c6a Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Thu, 6 Oct 2022 16:46:33 +0100 Subject: [PATCH] add DELETE for frontend settings --- .../frontend_settings_controller.ex | 5 ++-- .../operations/frontend_settings_operation.ex | 25 ++++++++++------ .../frontend_settings_controller_test.exs | 30 +++++++++++++++++-- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/lib/pleroma/web/akkoma_api/controllers/frontend_settings_controller.ex b/lib/pleroma/web/akkoma_api/controllers/frontend_settings_controller.ex index 71f7f195d..c13ff9096 100644 --- a/lib/pleroma/web/akkoma_api/controllers/frontend_settings_controller.ex +++ b/lib/pleroma/web/akkoma_api/controllers/frontend_settings_controller.ex @@ -18,7 +18,8 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsController do OAuthScopesPlug, %{@unauthenticated_access | scopes: ["write:accounts"]} when action in [ - :update_profile, :delete_profile + :update_profile, + :delete_profile ] ) @@ -69,7 +70,7 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsController do profile_name ), {:ok, _} <- FrontendSettingsProfile.delete_profile(profile) do - json(conn, %{}) + json(conn, %{deleted: "ok"}) else nil -> {:error, :not_found} end diff --git a/lib/pleroma/web/api_spec/operations/frontend_settings_operation.ex b/lib/pleroma/web/api_spec/operations/frontend_settings_operation.ex index 8608086d5..40e81ad55 100644 --- a/lib/pleroma/web/api_spec/operations/frontend_settings_operation.ex +++ b/lib/pleroma/web/api_spec/operations/frontend_settings_operation.ex @@ -22,10 +22,13 @@ defmodule Pleroma.Web.ApiSpec.FrontendSettingsOperation do 200 => Operation.response("Profiles", "application/json", %Schema{ type: :array, - items: %Schema{type: :object, properties: %{ - name: %Schema{type: :string}, - version: %Schema{type: :integer} - }} + items: %Schema{ + type: :object, + properties: %{ + name: %Schema{type: :string}, + version: %Schema{type: :integer} + } + } }) } } @@ -41,10 +44,14 @@ defmodule Pleroma.Web.ApiSpec.FrontendSettingsOperation do security: [%{"oAuth" => ["read:accounts"]}], parameters: [frontend_name_param(), profile_name_param()], responses: %{ - 200 => Operation.response("Profile", "application/json", %Schema{type: :object, properties: %{ - "version" => %Schema{type: :integer}, - "settings" => %Schema{type: :object, additionalProperties: true} - }}), + 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}) } } @@ -60,7 +67,7 @@ defmodule Pleroma.Web.ApiSpec.FrontendSettingsOperation do security: [%{"oAuth" => ["write:accounts"]}], parameters: [frontend_name_param(), profile_name_param()], responses: %{ - 200 => Operation.response("Empty", "application/json", %Schema{type: :string}), + 200 => Operation.response("Empty", "application/json", %Schema{type: :object}), 404 => Operation.response("Not Found", "application/json", %Schema{type: :object}) } } diff --git a/test/pleroma/web/akkoma_api/frontend_settings_controller_test.exs b/test/pleroma/web/akkoma_api/frontend_settings_controller_test.exs index 0eaac9d94..4909ef3a7 100644 --- a/test/pleroma/web/akkoma_api/frontend_settings_controller_test.exs +++ b/test/pleroma/web/akkoma_api/frontend_settings_controller_test.exs @@ -17,8 +17,8 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsControllerTest do |> json_response_and_validate_schema(200) assert response == [ - "test1", - "test2" + %{"name" => "test1", "version" => 1}, + %{"name" => "test2", "version" => 1} ] end end @@ -47,7 +47,7 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsControllerTest do |> get("/api/v1/akkoma/frontend_settings/test/test1") |> json_response_and_validate_schema(200) - assert response == %{"test" => "test"} + assert response == %{"settings" => %{"test" => "test"}, "version" => 1} end end @@ -95,4 +95,28 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsControllerTest do |> json_response_and_validate_schema(422) end end + + describe "DELETE /api/v1/akkoma/frontend_settings/:frontend_name/:profile_name" do + test "deletes a config" do + %{conn: conn, user: user} = oauth_access(["write"]) + + insert(:frontend_setting_profile, + user: user, + frontend_name: "test", + profile_name: "test1", + settings: %{"test" => "test"}, + version: 2 + ) + + conn + |> delete("/api/v1/akkoma/frontend_settings/test/test1") + |> json_response_and_validate_schema(200) + + assert FrontendSettingsProfile.get_by_user_and_frontend_name_and_profile_name( + user, + "test", + "test1" + ) == nil + end + end end