forked from mirrors/akkoma
Ensure consistent behavior between pleroma.user activate/deactivate mix tasks
This commit is contained in:
parent
6e51d7264b
commit
f868dcf3ac
2 changed files with 22 additions and 9 deletions
|
@ -162,17 +162,20 @@ defmodule Mix.Tasks.Pleroma.User do
|
|||
def run(["deactivate", nickname]) do
|
||||
start_pleroma()
|
||||
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||
shell_info("Deactivating #{user.nickname}")
|
||||
with %User{} = user <- User.get_cached_by_nickname(nickname),
|
||||
true <- user.is_active do
|
||||
User.set_activation(user, false)
|
||||
:timer.sleep(500)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
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
|
||||
else
|
||||
false ->
|
||||
shell_info("User #{nickname} already deactivated")
|
||||
|
||||
_ ->
|
||||
shell_error("No user #{nickname}")
|
||||
end
|
||||
|
|
|
@ -158,7 +158,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
|||
end
|
||||
|
||||
describe "running deactivate" do
|
||||
test "user is unsubscribed" do
|
||||
test "active user is deactivated and unsubscribed" do
|
||||
followed = insert(:user)
|
||||
remote_followed = insert(:user, local: false)
|
||||
user = insert(:user)
|
||||
|
@ -168,18 +168,28 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
|||
|
||||
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)
|
||||
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)
|
||||
assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
|
||||
refute user.is_active
|
||||
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
|
||||
Mix.Tasks.Pleroma.User.run(["deactivate", "nonexistent"])
|
||||
|
||||
|
@ -479,7 +489,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
|||
assert user.is_active
|
||||
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"])
|
||||
|
||||
assert_received {:mix_shell, :error, [message]}
|
||||
|
|
Loading…
Reference in a new issue