add DELETE for frontend settings
This commit is contained in:
parent
4940a49a50
commit
d1670d7cf3
3 changed files with 46 additions and 14 deletions
|
@ -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 @@ def delete_profile(conn, %{frontend_name: frontend_name, profile_name: profile_n
|
|||
profile_name
|
||||
),
|
||||
{:ok, _} <- FrontendSettingsProfile.delete_profile(profile) do
|
||||
json(conn, %{})
|
||||
json(conn, %{deleted: "ok"})
|
||||
else
|
||||
nil -> {:error, :not_found}
|
||||
end
|
||||
|
|
|
@ -22,10 +22,13 @@ def list_profiles_operation() 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 @@ def get_profile_operation() 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 @@ def delete_profile_operation() 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})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ test "it returns a list of profiles" 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 @@ test "it returns 200 if found" 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 @@ test "refuses to overwrite a newer config" 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
|
||||
|
|
Loading…
Reference in a new issue