Provide pleroma.user mix task for both activate and deactivate

This commit is contained in:
Mark Felder 2021-01-25 10:36:51 -06:00
parent fe63b48c8f
commit 5e8da27e14
3 changed files with 50 additions and 1 deletions

View File

@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- **Breaking**: Changed `mix pleroma.user toggle_confirmed` to `mix pleroma.user confirm`
- **Breaking**: Changed `mix pleroma.user toggle_activated` to `mix pleroma.user activate`
- **Breaking**: Changed `mix pleroma.user toggle_activated` to `mix pleroma.user activate/deactivate`
- **Breaking**: AdminAPI changed User field `confirmation_pending` to `is_confirmed`
- **Breaking**: AdminAPI changed User field `approval_pending` to `is_approved`
- **Breaking**: AdminAPI changed User field `deactivated` to `is_active`

View File

@ -141,6 +141,24 @@ defmodule Mix.Tasks.Pleroma.User do
end
end
def run(["activate", nickname]) do
start_pleroma()
with %User{} = user <- User.get_cached_by_nickname(nickname),
false <- user.is_active do
User.set_activation(user, true)
:timer.sleep(500)
shell_info("Successfully activated #{nickname}")
else
true ->
shell_info("User #{nickname} already activated")
_ ->
shell_error("No user #{nickname}")
end
end
def run(["deactivate", nickname]) do
start_pleroma()

View File

@ -456,6 +456,37 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
describe "running activate" do
test "user is activated" do
%{id: id, nickname: nickname} = insert(:user, is_active: true)
assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
assert_received {:mix_shell, :info, [message]}
assert message == "User #{nickname} already activated"
user = Repo.get(User, id)
assert user.is_active
end
test "user is not activated" do
%{id: id, nickname: nickname} = insert(:user, is_active: false)
assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
assert_received {:mix_shell, :info, [message]}
assert message == "Successfully activated #{nickname}"
user = Repo.get(User, id)
assert user.is_active
end
test "it prints an error message when user is not exist" do
Mix.Tasks.Pleroma.User.run(["activate", "foo"])
assert_received {:mix_shell, :error, [message]}
assert message =~ "No user"
end
end
describe "search" do
test "it returns users matching" do
user = insert(:user)