mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-19 16:16:55 +00:00
Ensure consistent behavior between pleroma.user activate/deactivate mix tasks
This commit is contained in:
parent
6e51d7264b
commit
f868dcf3ac
|
@ -162,17 +162,20 @@ defmodule Mix.Tasks.Pleroma.User do
|
||||||
def run(["deactivate", nickname]) do
|
def run(["deactivate", nickname]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||||
shell_info("Deactivating #{user.nickname}")
|
true <- user.is_active do
|
||||||
User.set_activation(user, false)
|
User.set_activation(user, false)
|
||||||
:timer.sleep(500)
|
:timer.sleep(500)
|
||||||
|
|
||||||
user = User.get_cached_by_id(user.id)
|
user = User.get_cached_by_id(user.id)
|
||||||
|
|
||||||
if Enum.empty?(Enum.filter(User.get_friends(user), & &1.local)) do
|
if Enum.empty?(Enum.filter(User.get_friends(user), & &1.local)) do
|
||||||
shell_info("Successfully unsubscribed all local followers from #{user.nickname}")
|
shell_info("Successfully deactivated #{nickname} and unsubscribed all local followers")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
false ->
|
||||||
|
shell_info("User #{nickname} already deactivated")
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
shell_error("No user #{nickname}")
|
shell_error("No user #{nickname}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -158,7 +158,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "running deactivate" do
|
describe "running deactivate" do
|
||||||
test "user is unsubscribed" do
|
test "active user is deactivated and unsubscribed" do
|
||||||
followed = insert(:user)
|
followed = insert(:user)
|
||||||
remote_followed = insert(:user, local: false)
|
remote_followed = insert(:user, local: false)
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
@ -168,18 +168,28 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
||||||
|
|
||||||
Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname])
|
Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname])
|
||||||
|
|
||||||
assert_received {:mix_shell, :info, [message]}
|
|
||||||
assert message =~ "Deactivating"
|
|
||||||
|
|
||||||
# Note that the task has delay :timer.sleep(500)
|
# Note that the task has delay :timer.sleep(500)
|
||||||
assert_received {:mix_shell, :info, [message]}
|
assert_received {:mix_shell, :info, [message]}
|
||||||
assert message =~ "Successfully unsubscribed"
|
|
||||||
|
assert message ==
|
||||||
|
"Successfully deactivated #{user.nickname} and unsubscribed all local followers"
|
||||||
|
|
||||||
user = User.get_cached_by_nickname(user.nickname)
|
user = User.get_cached_by_nickname(user.nickname)
|
||||||
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
|
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
|
||||||
refute user.is_active
|
refute user.is_active
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "user is deactivated" do
|
||||||
|
%{id: id, nickname: nickname} = insert(:user, is_active: false)
|
||||||
|
|
||||||
|
assert :ok = Mix.Tasks.Pleroma.User.run(["deactivate", nickname])
|
||||||
|
assert_received {:mix_shell, :info, [message]}
|
||||||
|
assert message == "User #{nickname} already deactivated"
|
||||||
|
|
||||||
|
user = Repo.get(User, id)
|
||||||
|
refute user.is_active
|
||||||
|
end
|
||||||
|
|
||||||
test "no user to deactivate" do
|
test "no user to deactivate" do
|
||||||
Mix.Tasks.Pleroma.User.run(["deactivate", "nonexistent"])
|
Mix.Tasks.Pleroma.User.run(["deactivate", "nonexistent"])
|
||||||
|
|
||||||
|
@ -479,7 +489,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
||||||
assert user.is_active
|
assert user.is_active
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it prints an error message when user is not exist" do
|
test "no user to activate" do
|
||||||
Mix.Tasks.Pleroma.User.run(["activate", "foo"])
|
Mix.Tasks.Pleroma.User.run(["activate", "foo"])
|
||||||
|
|
||||||
assert_received {:mix_shell, :error, [message]}
|
assert_received {:mix_shell, :error, [message]}
|
||||||
|
|
Loading…
Reference in a new issue