X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fmix%2Ftasks%2Fpleroma%2Fuser.ex;h=53d5fc6d927799253ee85a98d66e14cbd7a4d610;hb=ea5469961a537d12ca799bf7470e53cb636b1439;hp=ca9c8579f932d26406213abf3ed25d0a449563db;hpb=a010c5b16a395d823a98cd088c83acd098930ade;p=akkoma
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex
index ca9c8579f..53d5fc6d9 100644
--- a/lib/mix/tasks/pleroma/user.ex
+++ b/lib/mix/tasks/pleroma/user.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.User do
@@ -74,7 +74,7 @@ defmodule Mix.Tasks.Pleroma.User do
bio: bio
}
- changeset = User.register_changeset(%User{}, params, need_confirmation: false)
+ changeset = User.register_changeset(%User{}, params, is_confirmed: true)
{:ok, _user} = User.register(changeset)
shell_info("User #{nickname} created")
@@ -107,21 +107,6 @@ defmodule Mix.Tasks.Pleroma.User do
end
end
- def run(["toggle_activated", nickname]) do
- start_pleroma()
-
- with %User{} = user <- User.get_cached_by_nickname(nickname) do
- {:ok, user} = User.deactivate(user, !user.deactivated)
-
- shell_info(
- "Activation status of #{nickname}: #{if(user.deactivated, do: "de", else: "")}activated"
- )
- else
- _ ->
- shell_error("No user #{nickname}")
- end
- end
-
def run(["reset_password", nickname]) do
start_pleroma()
@@ -156,20 +141,41 @@ 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()
- with %User{} = user <- User.get_cached_by_nickname(nickname) do
- shell_info("Deactivating #{user.nickname}")
- User.deactivate(user)
+ 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
@@ -213,7 +219,7 @@ defmodule Mix.Tasks.Pleroma.User do
user =
case Keyword.get(options, :confirmed) do
nil -> user
- value -> set_confirmed(user, value)
+ value -> set_confirmation(user, value)
end
user =
@@ -345,13 +351,13 @@ defmodule Mix.Tasks.Pleroma.User do
end
end
- def run(["toggle_confirmed", nickname]) do
+ def run(["confirm", nickname]) do
start_pleroma()
with %User{} = user <- User.get_cached_by_nickname(nickname) do
- {:ok, user} = User.toggle_confirmation(user)
+ {:ok, user} = User.confirm(user)
- message = if user.confirmation_pending, do: "needs", else: "doesn't need"
+ message = if !user.is_confirmed, do: "needs", else: "doesn't need"
shell_info("#{nickname} #{message} confirmation.")
else
@@ -365,7 +371,7 @@ defmodule Mix.Tasks.Pleroma.User do
Pleroma.User.Query.build(%{
local: true,
- deactivated: false,
+ is_active: true,
is_moderator: false,
is_admin: false,
invisible: false
@@ -373,7 +379,7 @@ defmodule Mix.Tasks.Pleroma.User do
|> Pleroma.Repo.chunk_stream(500, :batches)
|> Stream.each(fn users ->
users
- |> Enum.each(fn user -> User.need_confirmation(user, false) end)
+ |> Enum.each(fn user -> User.set_confirmation(user, true) end)
end)
|> Stream.run()
end
@@ -383,7 +389,7 @@ defmodule Mix.Tasks.Pleroma.User do
Pleroma.User.Query.build(%{
local: true,
- deactivated: false,
+ is_active: true,
is_moderator: false,
is_admin: false,
invisible: false
@@ -391,7 +397,7 @@ defmodule Mix.Tasks.Pleroma.User do
|> Pleroma.Repo.chunk_stream(500, :batches)
|> Stream.each(fn users ->
users
- |> Enum.each(fn user -> User.need_confirmation(user, true) end)
+ |> Enum.each(fn user -> User.set_confirmation(user, false) end)
end)
|> Stream.run()
end
@@ -420,7 +426,7 @@ defmodule Mix.Tasks.Pleroma.User do
shell_info(
"#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{
user.is_locked
- }, deactivated: #{user.deactivated}"
+ }, is_active: #{user.is_active}"
)
end)
end)
@@ -454,10 +460,10 @@ defmodule Mix.Tasks.Pleroma.User do
user
end
- defp set_confirmed(user, value) do
- {:ok, user} = User.need_confirmation(user, !value)
+ defp set_confirmation(user, value) do
+ {:ok, user} = User.set_confirmation(user, value)
- shell_info("Confirmation pending status of #{user.nickname}: #{user.confirmation_pending}")
+ shell_info("Confirmation status of #{user.nickname}: #{user.is_confirmed}")
user
end
end