add DELETE for frontend settings
ci/woodpecker/push/woodpecker Pipeline is pending Details
ci/woodpecker/pr/woodpecker Pipeline was successful Details

This commit is contained in:
FloatingGhost 2022-10-06 16:46:33 +01:00
parent 4940a49a50
commit d1670d7cf3
3 changed files with 46 additions and 14 deletions

View File

@ -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

View File

@ -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})
}
}

View File

@ -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