Fix User deactivation.
authorlain <lain@soykaf.club>
Sun, 18 Nov 2018 17:06:02 +0000 (18:06 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Nov 2018 17:06:02 +0000 (18:06 +0100)
lib/pleroma/user.ex
test/support/factory.ex
test/user_test.exs

index 6e1d5559d359f6aab26e08731747a36a5d007ac9..7336e85408ba568fe21d3ddc76c96d930cb5cef0 100644 (file)
@@ -19,11 +19,11 @@ defmodule Pleroma.User do
     field(:ap_id, :string)
     field(:avatar, :map)
     field(:local, :boolean, default: true)
-    field(:info, :map, default: %{})
     field(:follower_address, :string)
     field(:search_distance, :float, virtual: true)
     field(:last_refreshed_at, :naive_datetime)
     has_many(:notifications, Notification)
+    embeds_one :info, Pleroma.User.Info
 
     timestamps()
   end
@@ -71,10 +71,10 @@ defmodule Pleroma.User do
 
     %{
       following_count: length(user.following) - oneself,
-      note_count: user.info["note_count"] || 0,
-      follower_count: user.info["follower_count"] || 0,
-      locked: user.info["locked"] || false,
-      default_scope: user.info["default_scope"] || "public"
+      note_count: user.info.note_count,
+      follower_count: user.info.follower_count,
+      locked: user.info.locked,
+      default_scope: user.info.default_scope
     }
   end
 
@@ -613,9 +613,11 @@ defmodule Pleroma.User do
   end
 
   def deactivate(%User{} = user, status \\ true) do
-    new_info = Map.put(user.info, "deactivated", status)
-    cs = User.info_changeset(user, %{info: new_info})
-    update_and_set_cache(cs)
+    info_cng = User.Info.set_activation_status(user.info, status)
+    cng = change(user)
+    |> put_embed(:info, info_cng)
+
+    update_and_set_cache(cng)
   end
 
   def delete(%User{} = user) do
index 4f5060abf698a50a1a3bd421180f12aff55ce185..2889d8977fb803e1e9448b92dd95dc9ba11fdc09 100644 (file)
@@ -7,7 +7,8 @@ defmodule Pleroma.Factory do
       email: sequence(:email, &"user#{&1}@example.com"),
       nickname: sequence(:nickname, &"nick#{&1}"),
       password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
-      bio: sequence(:bio, &"Tester Number #{&1}")
+      bio: sequence(:bio, &"Tester Number #{&1}"),
+      info: %{}
     }
 
     %{
index 231f1d94d9c61a220929f23616f0035fff61f5a5..d6a3c99795de9d999e9db354e31819634defbe09 100644 (file)
@@ -489,11 +489,11 @@ defmodule Pleroma.UserTest do
 
   test ".deactivate can de-activate then re-activate a user" do
     user = insert(:user)
-    assert false == !!user.info["deactivated"]
+    assert false == user.info.deactivated
     {:ok, user} = User.deactivate(user)
-    assert true == user.info["deactivated"]
+    assert true == user.info.deactivated
     {:ok, user} = User.deactivate(user, false)
-    assert false == !!user.info["deactivated"]
+    assert false == user.info.deactivated
   end
 
   test ".delete deactivates a user, all follow relationships and all create activities" do