Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85595426
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
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 867a751b3..ede66709c 100644
--- a/lib/pleroma/web/api_spec/operations/frontend_settings_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/frontend_settings_operation.ex
@@ -1,184 +1,186 @@
defmodule Pleroma.Web.ApiSpec.FrontendSettingsOperation do
alias OpenApiSpex.Operation
alias OpenApiSpex.Schema
import Pleroma.Web.ApiSpec.Helpers
@spec open_api_operation(atom) :: Operation.t()
def open_api_operation(action) do
operation = String.to_existing_atom("#{action}_operation")
apply(__MODULE__, operation, [])
end
@spec list_profiles_operation() :: Operation.t()
def list_profiles_operation() do
%Operation{
tags: ["Frontends"],
summary: "Frontend Settings Profiles",
description: "List frontend setting profiles",
operationId: "AkkomaAPI.FrontendSettingsController.list_profiles",
parameters: [frontend_name_param()],
security: [%{"oAuth" => ["read:accounts"]}],
responses: %{
200 =>
Operation.response("Profiles", "application/json", %Schema{
type: :array,
items: %Schema{
type: :object,
properties: %{
name: %Schema{type: :string},
version: %Schema{type: :integer}
}
}
})
}
}
end
@spec get_profile_operation() :: Operation.t()
def get_profile_operation() do
%Operation{
tags: ["Frontends"],
summary: "Frontend Settings Profile",
description: "Get frontend setting profile",
operationId: "AkkomaAPI.FrontendSettingsController.get_profile",
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}
}
}),
404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
}
}
end
@spec delete_profile_operation() :: Operation.t()
def delete_profile_operation() do
%Operation{
tags: ["Frontends"],
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: :object}),
404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
}
}
end
@spec update_profile_operation() :: Operation.t()
def update_profile_operation() do
%Operation{
tags: ["Frontends"],
summary: "Frontend Settings Profile",
description: "Update frontend setting profile",
operationId: "AkkomaAPI.FrontendSettingsController.update_profile_operation",
security: [%{"oAuth" => ["write:accounts"]}],
parameters: [frontend_name_param(), profile_name_param()],
requestBody: profile_body_param(),
responses: %{
200 => Operation.response("Settings", "application/json", %Schema{type: :object}),
422 => Operation.response("Invalid", "application/json", %Schema{type: :object})
}
}
end
def available_frontends_operation() do
%Operation{
tags: ["Frontends"],
summary: "Frontend Settings Profiles",
description: "List frontend setting profiles",
operationId: "AkkomaAPI.FrontendSettingsController.available_frontends",
responses: %{
200 =>
Operation.response("Frontends", "application/json", %Schema{
type: :array,
items: %Schema{
type: :string
}
})
}
}
end
def update_preferred_frontend_operation() do
%Operation{
tags: ["Frontends"],
- summary: "Frontend Settings Profiles",
- description: "List frontend setting profiles",
- operationId: "AkkomaAPI.FrontendSettingsController.available_frontends",
+ summary: "Update preferred frontend setting",
+ description: "Store preferred frontend in cookies",
+ operationId: "AkkomaAPI.FrontendSettingsController.update_preferred_frontend",
requestBody:
request_body(
"Frontend",
%Schema{
type: :object,
required: [:frontend_name],
properties: %{
frontend_name: %Schema{
type: :string,
description: "Frontend name"
}
}
},
required: true
),
responses: %{
200 =>
Operation.response("Frontends", "application/json", %Schema{
- type: :array,
- items: %Schema{
- type: :string
+ type: :object,
+ properties: %{
+ frontend_name: %Schema{
+ type: :string
+ }
}
})
}
}
end
def frontend_name_param do
Operation.parameter(:frontend_name, :path, :string, "Frontend name",
example: "pleroma-fe",
required: true
)
end
def profile_name_param do
Operation.parameter(:profile_name, :path, :string, "Profile name",
example: "mobile",
required: true
)
end
def profile_body_param do
request_body(
"Settings",
%Schema{
title: "Frontend Setting Profile",
type: :object,
required: [:version, :settings],
properties: %{
version: %Schema{
type: :integer,
description: "Version of the profile, must increment by 1 each time",
example: 1
},
settings: %Schema{
type: :object,
description: "Settings of the profile",
example: %{
theme: "dark",
locale: "en"
}
}
}
},
required: true
)
end
end
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 07e45d9b9..7b1329593 100644
--- a/test/pleroma/web/akkoma_api/frontend_settings_controller_test.exs
+++ b/test/pleroma/web/akkoma_api/frontend_settings_controller_test.exs
@@ -1,122 +1,136 @@
defmodule Pleroma.Web.AkkomaAPI.FrontendSettingsControllerTest do
use Pleroma.Web.ConnCase, async: false
import Pleroma.Factory
alias Pleroma.Akkoma.FrontendSettingsProfile
describe "GET /api/v1/akkoma/frontend_settings/:frontend_name" do
test "it returns a list of profiles" do
%{conn: conn, user: user} = oauth_access(["read"])
insert(:frontend_setting_profile, user: user, frontend_name: "test", profile_name: "test1")
insert(:frontend_setting_profile, user: user, frontend_name: "test", profile_name: "test2")
response =
conn
|> get("/api/v1/akkoma/frontend_settings/test")
|> json_response_and_validate_schema(200)
assert response == [
%{"name" => "test1", "version" => 1},
%{"name" => "test2", "version" => 1}
]
end
end
describe "GET /api/v1/akkoma/frontend_settings/:frontend_name/:profile_name" do
test "it returns 404 if not found" do
%{conn: conn} = oauth_access(["read"])
conn
|> get("/api/v1/akkoma/frontend_settings/unknown_frontend/unknown_profile")
|> json_response_and_validate_schema(404)
end
test "it returns 200 if found" do
%{conn: conn, user: user} = oauth_access(["read"])
insert(:frontend_setting_profile,
user: user,
frontend_name: "test",
profile_name: "test1",
settings: %{"test" => "test"}
)
response =
conn
|> get("/api/v1/akkoma/frontend_settings/test/test1")
|> json_response_and_validate_schema(200)
assert response == %{"settings" => %{"test" => "test"}, "version" => 1}
end
end
describe "PUT /api/v1/akkoma/frontend_settings/:frontend_name/:profile_name" do
test "puts a config" do
%{conn: conn, user: user} = oauth_access(["write"])
settings = %{"test" => "test2"}
response =
conn
|> put_req_header("content-type", "application/json")
|> put("/api/v1/akkoma/frontend_settings/test/test1", %{
"settings" => settings,
"version" => 1
})
|> json_response_and_validate_schema(200)
assert response == settings
assert %FrontendSettingsProfile{settings: ^settings} =
FrontendSettingsProfile.get_by_user_and_frontend_name_and_profile_name(
user,
"test",
"test1"
)
end
test "refuses to overwrite a newer 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
|> put_req_header("content-type", "application/json")
|> put("/api/v1/akkoma/frontend_settings/test/test1", %{
"settings" => %{"test" => "test2"},
"version" => 1
})
|> 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
+
+ describe "PUT /api/v1/akkoma/preferred_frontend" do
+ test "sets a cookie with selected frontend" do
+ %{conn: conn} = oauth_access(["read"])
+
+ response =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> put("/api/v1/akkoma/preferred_frontend", %{"frontend_name" => "pleroma-fe/stable"})
+
+ json_response_and_validate_schema(response, 200)
+ assert %{"preferred_frontend" => %{value: "pleroma-fe/stable"}} = response.resp_cookies
+ end
+ end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jul 19, 1:46 AM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1695177
Default Alt Text
(10 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment