AccountController: Federate user account changes.
Hotfixy commit, will be moved to the pipeline.
This commit is contained in:
parent
e96765df6b
commit
9460983032
2 changed files with 43 additions and 18 deletions
|
@ -139,9 +139,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "PATCH /api/v1/accounts/update_credentials"
|
@doc "PATCH /api/v1/accounts/update_credentials"
|
||||||
def update_credentials(%{assigns: %{user: original_user}, body_params: params} = conn, _params) do
|
def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _params) do
|
||||||
user = original_user
|
|
||||||
|
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|> Enum.filter(fn {_, value} -> not is_nil(value) end)
|
|> Enum.filter(fn {_, value} -> not is_nil(value) end)
|
||||||
|
@ -183,12 +181,31 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
||||||
changeset = User.update_changeset(user, user_params)
|
changeset = User.update_changeset(user, user_params)
|
||||||
|
|
||||||
with {:ok, user} <- User.update_and_set_cache(changeset) do
|
with {:ok, user} <- User.update_and_set_cache(changeset) do
|
||||||
|
user
|
||||||
|
|> build_update_activity_params()
|
||||||
|
|> ActivityPub.update()
|
||||||
|
|
||||||
render(conn, "show.json", user: user, for: user, with_pleroma_settings: true)
|
render(conn, "show.json", user: user, for: user, with_pleroma_settings: true)
|
||||||
else
|
else
|
||||||
_e -> render_error(conn, :forbidden, "Invalid request")
|
_e -> render_error(conn, :forbidden, "Invalid request")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Hotfix, handling will be redone with the pipeline
|
||||||
|
defp build_update_activity_params(user) do
|
||||||
|
object =
|
||||||
|
Pleroma.Web.ActivityPub.UserView.render("user.json", user: user)
|
||||||
|
|> Map.delete("@context")
|
||||||
|
|
||||||
|
%{
|
||||||
|
local: true,
|
||||||
|
to: [user.follower_address],
|
||||||
|
cc: [],
|
||||||
|
object: object,
|
||||||
|
actor: user.ap_id
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
defp add_if_present(map, params, params_field, map_field, value_function \\ &{:ok, &1}) do
|
defp add_if_present(map, params, params_field, map_field, value_function \\ &{:ok, &1}) do
|
||||||
with true <- is_map(params),
|
with true <- is_map(params),
|
||||||
true <- Map.has_key?(params, params_field),
|
true <- Map.has_key?(params, params_field),
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
||||||
|
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
|
|
||||||
|
import Mock
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup do: clear_config([:instance, :max_account_fields])
|
setup do: clear_config([:instance, :max_account_fields])
|
||||||
|
@ -52,24 +53,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
||||||
|
|
||||||
user = Repo.get(User, user_data["id"])
|
user = Repo.get(User, user_data["id"])
|
||||||
|
|
||||||
res_conn =
|
clear_config([:instance, :federating], true)
|
||||||
conn
|
|
||||||
|> assign(:user, user)
|
with_mock Pleroma.Web.Federator,
|
||||||
|> patch("/api/v1/accounts/update_credentials", %{
|
publish: fn _activity -> :ok end do
|
||||||
"pleroma_settings_store" => %{
|
res_conn =
|
||||||
masto_fe: %{
|
conn
|
||||||
theme: "blub"
|
|> assign(:user, user)
|
||||||
|
|> patch("/api/v1/accounts/update_credentials", %{
|
||||||
|
"pleroma_settings_store" => %{
|
||||||
|
masto_fe: %{
|
||||||
|
theme: "blub"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
|
||||||
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
||||||
|
|
||||||
assert user_data["pleroma"]["settings_store"] ==
|
assert user_data["pleroma"]["settings_store"] ==
|
||||||
%{
|
%{
|
||||||
"pleroma_fe" => %{"theme" => "bla"},
|
"pleroma_fe" => %{"theme" => "bla"},
|
||||||
"masto_fe" => %{"theme" => "blub"}
|
"masto_fe" => %{"theme" => "blub"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_called(Pleroma.Web.Federator.publish(:_))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "updates the user's bio", %{conn: conn} do
|
test "updates the user's bio", %{conn: conn} do
|
||||||
|
|
Loading…
Reference in a new issue