Fix User deactivation.

This commit is contained in:
lain 2018-11-18 18:06:02 +01:00
parent 50585d051b
commit 47d883d3ab
3 changed files with 15 additions and 12 deletions

View File

@ -19,11 +19,11 @@ defmodule Pleroma.User do
field(:ap_id, :string) field(:ap_id, :string)
field(:avatar, :map) field(:avatar, :map)
field(:local, :boolean, default: true) field(:local, :boolean, default: true)
field(:info, :map, default: %{})
field(:follower_address, :string) field(:follower_address, :string)
field(:search_distance, :float, virtual: true) field(:search_distance, :float, virtual: true)
field(:last_refreshed_at, :naive_datetime) field(:last_refreshed_at, :naive_datetime)
has_many(:notifications, Notification) has_many(:notifications, Notification)
embeds_one :info, Pleroma.User.Info
timestamps() timestamps()
end end
@ -71,10 +71,10 @@ def user_info(%User{} = user) do
%{ %{
following_count: length(user.following) - oneself, following_count: length(user.following) - oneself,
note_count: user.info["note_count"] || 0, note_count: user.info.note_count,
follower_count: user.info["follower_count"] || 0, follower_count: user.info.follower_count,
locked: user.info["locked"] || false, locked: user.info.locked,
default_scope: user.info["default_scope"] || "public" default_scope: user.info.default_scope
} }
end end
@ -613,9 +613,11 @@ def moderator_user_query() do
end end
def deactivate(%User{} = user, status \\ true) do def deactivate(%User{} = user, status \\ true) do
new_info = Map.put(user.info, "deactivated", status) info_cng = User.Info.set_activation_status(user.info, status)
cs = User.info_changeset(user, %{info: new_info}) cng = change(user)
update_and_set_cache(cs) |> put_embed(:info, info_cng)
update_and_set_cache(cng)
end end
def delete(%User{} = user) do def delete(%User{} = user) do

View File

@ -7,7 +7,8 @@ def user_factory do
email: sequence(:email, &"user#{&1}@example.com"), email: sequence(:email, &"user#{&1}@example.com"),
nickname: sequence(:nickname, &"nick#{&1}"), nickname: sequence(:nickname, &"nick#{&1}"),
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"), password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
bio: sequence(:bio, &"Tester Number #{&1}") bio: sequence(:bio, &"Tester Number #{&1}"),
info: %{}
} }
%{ %{

View File

@ -489,11 +489,11 @@ test "get recipients from activity" do
test ".deactivate can de-activate then re-activate a user" do test ".deactivate can de-activate then re-activate a user" do
user = insert(:user) user = insert(:user)
assert false == !!user.info["deactivated"] assert false == user.info.deactivated
{:ok, user} = User.deactivate(user) {:ok, user} = User.deactivate(user)
assert true == user.info["deactivated"] assert true == user.info.deactivated
{:ok, user} = User.deactivate(user, false) {:ok, user} = User.deactivate(user, false)
assert false == !!user.info["deactivated"] assert false == user.info.deactivated
end end
test ".delete deactivates a user, all follow relationships and all create activities" do test ".delete deactivates a user, all follow relationships and all create activities" do