removing saving settings in mastofe
This commit is contained in:
parent
5361e40162
commit
af6725121f
@ -53,21 +53,7 @@ defmodule Pleroma.Web.MastoFEController do
|
|||||||
|
|
||||||
@doc "PUT /api/web/settings: Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere"
|
@doc "PUT /api/web/settings: Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere"
|
||||||
def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
|
def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
|
||||||
with {:ok, user} <- User.mastodon_settings_update(user, settings) do
|
with {:ok, _} <- User.mastodon_settings_update(user, settings) do
|
||||||
if settings = get_in(user.settings, ["notifications", "shows"]) do
|
|
||||||
notify_settings =
|
|
||||||
settings
|
|
||||||
|> Enum.map(fn {k, v} -> if v == false, do: k end)
|
|
||||||
|> Enum.reject(&is_nil/1)
|
|
||||||
|
|
||||||
notification_settings =
|
|
||||||
user.notification_settings
|
|
||||||
|> Map.from_struct()
|
|
||||||
|> Map.put(:exclude_types, notify_settings)
|
|
||||||
|
|
||||||
User.update_notification_settings(user, notification_settings)
|
|
||||||
end
|
|
||||||
|
|
||||||
json(conn, %{})
|
json(conn, %{})
|
||||||
else
|
else
|
||||||
e ->
|
e ->
|
||||||
|
@ -11,95 +11,20 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
|
|||||||
|
|
||||||
setup do: clear_config([:instance, :public])
|
setup do: clear_config([:instance, :public])
|
||||||
|
|
||||||
describe "put_settings/2" do
|
test "put settings", %{conn: conn} do
|
||||||
setup do
|
user = insert(:user)
|
||||||
%{conn: conn, user: user} = oauth_access(["write:accounts"])
|
|
||||||
[conn: conn, user: user]
|
|
||||||
end
|
|
||||||
|
|
||||||
test "common", %{conn: conn, user: user} do
|
conn =
|
||||||
assert conn
|
conn
|
||||||
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
|
|> assign(:user, user)
|
||||||
|> json_response(200)
|
|> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"]))
|
||||||
|
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
|
||||||
|
|
||||||
|
assert _result = json_response(conn, 200)
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(user.ap_id)
|
user = User.get_cached_by_ap_id(user.ap_id)
|
||||||
assert user.mastofe_settings == %{"programming" => "socks"}
|
assert user.mastofe_settings == %{"programming" => "socks"}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "saves notification settings", %{conn: conn, user: user} do
|
|
||||||
assert conn
|
|
||||||
|> put("/api/web/settings", %{
|
|
||||||
"data" => %{
|
|
||||||
"notifications" => %{
|
|
||||||
"alerts" => %{
|
|
||||||
"favourite" => true,
|
|
||||||
"follow" => true,
|
|
||||||
"follow_request" => true,
|
|
||||||
"mention" => true,
|
|
||||||
"poll" => true,
|
|
||||||
"reblog" => true
|
|
||||||
},
|
|
||||||
"quickFilter" => %{"active" => "all", "advanced" => true, "show" => true},
|
|
||||||
"shows" => %{
|
|
||||||
"favourite" => false,
|
|
||||||
"follow" => false,
|
|
||||||
"follow_request" => false,
|
|
||||||
"mention" => false,
|
|
||||||
"poll" => false,
|
|
||||||
"reblog" => true
|
|
||||||
},
|
|
||||||
"sounds" => %{
|
|
||||||
"favourite" => true,
|
|
||||||
"follow" => true,
|
|
||||||
"follow_request" => true,
|
|
||||||
"mention" => true,
|
|
||||||
"poll" => true,
|
|
||||||
"reblog" => true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(user.ap_id)
|
|
||||||
|
|
||||||
assert user.settings == %{
|
|
||||||
"notifications" => %{
|
|
||||||
"alerts" => %{
|
|
||||||
"favourite" => true,
|
|
||||||
"follow" => true,
|
|
||||||
"follow_request" => true,
|
|
||||||
"mention" => true,
|
|
||||||
"poll" => true,
|
|
||||||
"reblog" => true
|
|
||||||
},
|
|
||||||
"quickFilter" => %{"active" => "all", "advanced" => true, "show" => true},
|
|
||||||
"shows" => %{
|
|
||||||
"favourite" => false,
|
|
||||||
"follow" => false,
|
|
||||||
"follow_request" => false,
|
|
||||||
"mention" => false,
|
|
||||||
"poll" => false,
|
|
||||||
"reblog" => true
|
|
||||||
},
|
|
||||||
"sounds" => %{
|
|
||||||
"favourite" => true,
|
|
||||||
"follow" => true,
|
|
||||||
"follow_request" => true,
|
|
||||||
"mention" => true,
|
|
||||||
"poll" => true,
|
|
||||||
"reblog" => true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert user.notification_settings.exclude_types == [
|
|
||||||
"favourite",
|
|
||||||
"follow",
|
|
||||||
"follow_request",
|
|
||||||
"mention",
|
|
||||||
"poll"
|
|
||||||
]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "index/2 redirections" do
|
describe "index/2 redirections" do
|
||||||
|
Loading…
Reference in New Issue
Block a user