forked from AkkomaGang/akkoma
MastodonAPI: Add extension to set and get pleroma_settings_store.
This commit is contained in:
parent
aaad85c4d9
commit
7861974ab2
3 changed files with 72 additions and 3 deletions
|
@ -210,7 +210,8 @@ def profile_update(info, params) do
|
||||||
:hide_followers,
|
:hide_followers,
|
||||||
:hide_favorites,
|
:hide_favorites,
|
||||||
:background,
|
:background,
|
||||||
:show_role
|
:show_role,
|
||||||
|
:pleroma_settings_store
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,9 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) do
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|> add_if_present(params, "default_scope", :default_scope)
|
|> add_if_present(params, "default_scope", :default_scope)
|
||||||
|
|> add_if_present(params, "pleroma_settings_store", :pleroma_settings_store, fn value ->
|
||||||
|
{:ok, Map.merge(user.info.pleroma_settings_store, value)}
|
||||||
|
end)
|
||||||
|> add_if_present(params, "header", :banner, fn value ->
|
|> add_if_present(params, "header", :banner, fn value ->
|
||||||
with %Plug.Upload{} <- value,
|
with %Plug.Upload{} <- value,
|
||||||
{:ok, object} <- ActivityPub.upload(value, type: :banner) do
|
{:ok, object} <- ActivityPub.upload(value, type: :banner) do
|
||||||
|
@ -143,7 +146,10 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) do
|
||||||
CommonAPI.update(user)
|
CommonAPI.update(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
json(conn, AccountView.render("account.json", %{user: user, for: user}))
|
json(
|
||||||
|
conn,
|
||||||
|
AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
|
||||||
|
)
|
||||||
else
|
else
|
||||||
_e ->
|
_e ->
|
||||||
conn
|
conn
|
||||||
|
@ -153,7 +159,9 @@ def update_credentials(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_credentials(%{assigns: %{user: user}} = conn, _) do
|
def verify_credentials(%{assigns: %{user: user}} = conn, _) do
|
||||||
account = AccountView.render("account.json", %{user: user, for: user})
|
account =
|
||||||
|
AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
|
||||||
|
|
||||||
json(conn, account)
|
json(conn, account)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2322,6 +2322,66 @@ test "hides favorites for new users by default", %{conn: conn, current_user: cur
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "updating credentials" do
|
describe "updating credentials" do
|
||||||
|
test "sets user settings in a generic way", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
res_conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{
|
||||||
|
"pleroma_settings_store" => %{
|
||||||
|
pleroma_fe: %{
|
||||||
|
theme: "bla"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
assert user = json_response(res_conn, 200)
|
||||||
|
assert user["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
|
||||||
|
|
||||||
|
user = Repo.get(User, user["id"])
|
||||||
|
|
||||||
|
res_conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{
|
||||||
|
"pleroma_settings_store" => %{
|
||||||
|
masto_fe: %{
|
||||||
|
theme: "bla"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
assert user = json_response(res_conn, 200)
|
||||||
|
|
||||||
|
assert user["pleroma"]["settings_store"] ==
|
||||||
|
%{
|
||||||
|
"pleroma_fe" => %{"theme" => "bla"},
|
||||||
|
"masto_fe" => %{"theme" => "bla"}
|
||||||
|
}
|
||||||
|
|
||||||
|
user = Repo.get(User, user["id"])
|
||||||
|
|
||||||
|
res_conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{
|
||||||
|
"pleroma_settings_store" => %{
|
||||||
|
masto_fe: %{
|
||||||
|
theme: "blub"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
assert user = json_response(res_conn, 200)
|
||||||
|
|
||||||
|
assert user["pleroma"]["settings_store"] ==
|
||||||
|
%{
|
||||||
|
"pleroma_fe" => %{"theme" => "bla"},
|
||||||
|
"masto_fe" => %{"theme" => "blub"}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
test "updates the user's bio", %{conn: conn} do
|
test "updates the user's bio", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
user2 = insert(:user)
|
user2 = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue