Merge branch 'issue/1667' into 'develop'
[#1667] fix api/v1/accounts/update_credentials See merge request pleroma/pleroma!2556
This commit is contained in:
commit
7e3814390e
2 changed files with 10 additions and 1 deletions
|
@ -177,6 +177,7 @@ def update_credentials(%{assigns: %{user: original_user}, body_params: params} =
|
||||||
)
|
)
|
||||||
|> add_if_present(params, :pleroma_settings_store, :pleroma_settings_store)
|
|> add_if_present(params, :pleroma_settings_store, :pleroma_settings_store)
|
||||||
|> add_if_present(params, :default_scope, :default_scope)
|
|> add_if_present(params, :default_scope, :default_scope)
|
||||||
|
|> add_if_present(params["source"], "privacy", :default_scope)
|
||||||
|> add_if_present(params, :actor_type, :actor_type)
|
|> add_if_present(params, :actor_type, :actor_type)
|
||||||
|
|
||||||
changeset = User.update_changeset(user, user_params)
|
changeset = User.update_changeset(user, user_params)
|
||||||
|
@ -189,7 +190,8 @@ def update_credentials(%{assigns: %{user: original_user}, body_params: params} =
|
||||||
end
|
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 <- Map.has_key?(params, params_field),
|
with true <- is_map(params),
|
||||||
|
true <- Map.has_key?(params, params_field),
|
||||||
{:ok, new_value} <- value_function.(Map.get(params, params_field)) do
|
{:ok, new_value} <- value_function.(Map.get(params, params_field)) do
|
||||||
Map.put(map, map_field, new_value)
|
Map.put(map, map_field, new_value)
|
||||||
else
|
else
|
||||||
|
|
|
@ -112,6 +112,13 @@ test "updates the user's default scope", %{conn: conn} do
|
||||||
assert user_data["source"]["privacy"] == "unlisted"
|
assert user_data["source"]["privacy"] == "unlisted"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "updates the user's privacy", %{conn: conn} do
|
||||||
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{source: %{privacy: "unlisted"}})
|
||||||
|
|
||||||
|
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||||
|
assert user_data["source"]["privacy"] == "unlisted"
|
||||||
|
end
|
||||||
|
|
||||||
test "updates the user's hide_followers status", %{conn: conn} do
|
test "updates the user's hide_followers status", %{conn: conn} do
|
||||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_followers: "true"})
|
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_followers: "true"})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue