twitterapi: add profile setting for locked/unlocked accounts
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 28 May 2018 18:19:20 +0000 (18:19 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 11 Jun 2018 22:15:53 +0000 (22:15 +0000)
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_controller_test.exs

index d53dd0c44897f6adb5c794dbe61be7a4e5386d19..b078c447efbf18b5b7b65a84a4d139b2823cee77 100644 (file)
@@ -357,6 +357,20 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
         params
       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),
          {:ok, user} <- User.update_and_set_cache(changeset) do
       CommonAPI.update(user)
index 68f4331dfbda7fc6ec64ca4584bf0e58638d03f9..6a29d583c87c961d4cd43d47d210f31a3b6426ca 100644 (file)
@@ -762,6 +762,38 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
 
       assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
     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
 
   defp valid_user(_context) do