X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fmix%2Ftasks%2Fpleroma%2Fuser.ex;h=3635c02bc4d21aaf0b29c5f25434e3d83e624ebf;hb=283fb1e05bcd34294ea7bdedab62b0cc6f88d742;hp=4e3b80db3040ace90fd6c5a39a9f011220390ab5;hpb=4c1dd55c48f80f3ebdb26d1a0c1a75b7922f578c;p=akkoma
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex
index 4e3b80db3..3635c02bc 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-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.User do
@@ -8,7 +8,8 @@ defmodule Mix.Tasks.Pleroma.User do
alias Ecto.Changeset
alias Pleroma.User
alias Pleroma.UserInviteToken
- alias Pleroma.Web.OAuth
+ alias Pleroma.Web.ActivityPub.Builder
+ alias Pleroma.Web.ActivityPub.Pipeline
@shortdoc "Manages Pleroma users"
@moduledoc File.read!("docs/administration/CLI_tasks/user.md")
@@ -97,12 +98,12 @@ defmodule Mix.Tasks.Pleroma.User do
def run(["rm", nickname]) do
start_pleroma()
- with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
- User.perform(:delete, user)
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
+ {:ok, delete_data, _} <- Builder.delete(user, user.ap_id),
+ {:ok, _delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do
shell_info("User #{nickname} deleted.")
else
- _ ->
- shell_error("No local user #{nickname}")
+ _ -> shell_error("No local user #{nickname}")
end
end
@@ -143,28 +144,18 @@ defmodule Mix.Tasks.Pleroma.User do
end
end
- def run(["unsubscribe", nickname]) do
+ 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)
-
- user
- |> User.get_friends()
- |> Enum.each(fn friend ->
- user = User.get_cached_by_id(user.id)
-
- shell_info("Unsubscribing #{friend.nickname} from #{user.nickname}")
- User.unfollow(user, friend)
- end)
-
:timer.sleep(500)
user = User.get_cached_by_id(user.id)
- if Enum.empty?(User.get_friends(user)) do
- shell_info("Successfully unsubscribed all followers from #{user.nickname}")
+ if Enum.empty?(Enum.filter(User.get_friends(user), & &1.local)) do
+ shell_info("Successfully unsubscribed all local followers from #{user.nickname}")
end
else
_ ->
@@ -172,7 +163,7 @@ defmodule Mix.Tasks.Pleroma.User do
end
end
- def run(["unsubscribe_all_from_instance", instance]) do
+ def run(["deactivate_all_from_instance", instance]) do
start_pleroma()
Pleroma.User.Query.build(%{nickname: "@#{instance}"})
@@ -180,7 +171,7 @@ defmodule Mix.Tasks.Pleroma.User do
|> Stream.each(fn users ->
users
|> Enum.each(fn user ->
- run(["unsubscribe", user.nickname])
+ run(["deactivate", user.nickname])
end)
end)
|> Stream.run()
@@ -354,8 +345,7 @@ defmodule Mix.Tasks.Pleroma.User do
start_pleroma()
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
- OAuth.Token.delete_user_tokens(user)
- OAuth.Authorization.delete_user_authorizations(user)
+ User.global_sign_out(user)
shell_info("#{nickname} signed out from all apps.")
else
@@ -364,6 +354,24 @@ defmodule Mix.Tasks.Pleroma.User do
end
end
+ def run(["list"]) do
+ start_pleroma()
+
+ Pleroma.User.Query.build(%{local: true})
+ |> Pleroma.RepoStreamer.chunk_stream(500)
+ |> Stream.each(fn users ->
+ users
+ |> Enum.each(fn user ->
+ shell_info(
+ "#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{
+ user.locked
+ }, deactivated: #{user.deactivated}"
+ )
+ end)
+ end)
+ |> Stream.run()
+ end
+
defp set_moderator(user, value) do
{:ok, user} =
user
@@ -375,10 +383,7 @@ defmodule Mix.Tasks.Pleroma.User do
end
defp set_admin(user, value) do
- {:ok, user} =
- user
- |> Changeset.change(%{is_admin: value})
- |> User.update_and_set_cache()
+ {:ok, user} = User.admin_api_update(user, %{is_admin: value})
shell_info("Admin status of #{user.nickname}: #{user.is_admin}")
user