add DELETE for frontend settings
This commit is contained in:
parent
4940a49a50
commit
d1670d7cf3
|
@ -18,7 +18,8 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsController do
|
||||||
OAuthScopesPlug,
|
OAuthScopesPlug,
|
||||||
%{@unauthenticated_access | scopes: ["write:accounts"]}
|
%{@unauthenticated_access | scopes: ["write:accounts"]}
|
||||||
when action in [
|
when action in [
|
||||||
:update_profile, :delete_profile
|
:update_profile,
|
||||||
|
:delete_profile
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsController do
|
||||||
profile_name
|
profile_name
|
||||||
),
|
),
|
||||||
{:ok, _} <- FrontendSettingsProfile.delete_profile(profile) do
|
{:ok, _} <- FrontendSettingsProfile.delete_profile(profile) do
|
||||||
json(conn, %{})
|
json(conn, %{deleted: "ok"})
|
||||||
else
|
else
|
||||||
nil -> {:error, :not_found}
|
nil -> {:error, :not_found}
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,10 +22,13 @@ defmodule Pleroma.Web.ApiSpec.FrontendSettingsOperation do
|
||||||
200 =>
|
200 =>
|
||||||
Operation.response("Profiles", "application/json", %Schema{
|
Operation.response("Profiles", "application/json", %Schema{
|
||||||
type: :array,
|
type: :array,
|
||||||
items: %Schema{type: :object, properties: %{
|
items: %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
name: %Schema{type: :string},
|
name: %Schema{type: :string},
|
||||||
version: %Schema{type: :integer}
|
version: %Schema{type: :integer}
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,10 +44,14 @@ defmodule Pleroma.Web.ApiSpec.FrontendSettingsOperation do
|
||||||
security: [%{"oAuth" => ["read:accounts"]}],
|
security: [%{"oAuth" => ["read:accounts"]}],
|
||||||
parameters: [frontend_name_param(), profile_name_param()],
|
parameters: [frontend_name_param(), profile_name_param()],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Profile", "application/json", %Schema{type: :object, properties: %{
|
200 =>
|
||||||
|
Operation.response("Profile", "application/json", %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
"version" => %Schema{type: :integer},
|
"version" => %Schema{type: :integer},
|
||||||
"settings" => %Schema{type: :object, additionalProperties: true}
|
"settings" => %Schema{type: :object, additionalProperties: true}
|
||||||
}}),
|
}
|
||||||
|
}),
|
||||||
404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
|
404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +67,7 @@ defmodule Pleroma.Web.ApiSpec.FrontendSettingsOperation do
|
||||||
security: [%{"oAuth" => ["write:accounts"]}],
|
security: [%{"oAuth" => ["write:accounts"]}],
|
||||||
parameters: [frontend_name_param(), profile_name_param()],
|
parameters: [frontend_name_param(), profile_name_param()],
|
||||||
responses: %{
|
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})
|
404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsControllerTest do
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert response == [
|
assert response == [
|
||||||
"test1",
|
%{"name" => "test1", "version" => 1},
|
||||||
"test2"
|
%{"name" => "test2", "version" => 1}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,7 +47,7 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsControllerTest do
|
||||||
|> get("/api/v1/akkoma/frontend_settings/test/test1")
|
|> get("/api/v1/akkoma/frontend_settings/test/test1")
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert response == %{"test" => "test"}
|
assert response == %{"settings" => %{"test" => "test"}, "version" => 1}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -95,4 +95,28 @@ defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsControllerTest do
|
||||||
|> json_response_and_validate_schema(422)
|
|> json_response_and_validate_schema(422)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue