twitterapi: add profile setting for locked/unlocked accounts
This commit is contained in:
parent
a0c5b42e29
commit
993312cdb3
2 changed files with 46 additions and 0 deletions
|
@ -357,6 +357,20 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
params
|
params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
user =
|
||||||
|
if locked = params["locked"] do
|
||||||
|
with locked <- locked == "true",
|
||||||
|
new_info <- Map.put(user.info, "locked", locked),
|
||||||
|
change <- User.info_changeset(user, %{info: new_info}),
|
||||||
|
{:ok, user} <- User.update_and_set_cache(change) do
|
||||||
|
user
|
||||||
|
else
|
||||||
|
_e -> user
|
||||||
|
end
|
||||||
|
else
|
||||||
|
user
|
||||||
|
end
|
||||||
|
|
||||||
with changeset <- User.update_changeset(user, params),
|
with changeset <- User.update_changeset(user, params),
|
||||||
{:ok, user} <- User.update_and_set_cache(changeset) do
|
{:ok, user} <- User.update_and_set_cache(changeset) do
|
||||||
CommonAPI.update(user)
|
CommonAPI.update(user)
|
||||||
|
|
|
@ -762,6 +762,38 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
||||||
|
|
||||||
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it locks an account", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> post("/api/account/update_profile.json", %{
|
||||||
|
"locked" => "true"
|
||||||
|
})
|
||||||
|
|
||||||
|
user = Repo.get!(User, user.id)
|
||||||
|
assert user.info["locked"] == true
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it unlocks an account", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> post("/api/account/update_profile.json", %{
|
||||||
|
"locked" => "false"
|
||||||
|
})
|
||||||
|
|
||||||
|
user = Repo.get!(User, user.id)
|
||||||
|
assert user.info["locked"] == false
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp valid_user(_context) do
|
defp valid_user(_context) do
|
||||||
|
|
Loading…
Reference in a new issue