From d013b58e84f2c8213a5d26b1c3daf36e2f4807e5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 12 Mar 2019 22:04:08 +0700 Subject: [PATCH] add `mix pleroma.user delete_activities NICKNAME` task --- lib/mix/tasks/pleroma/user.ex | 12 ++++++++++++ lib/pleroma/user.ex | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 037e44716..e232df14f 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -304,6 +304,18 @@ defmodule Mix.Tasks.Pleroma.User do end end + def run(["delete_activities", nickname]) do + Common.start_pleroma() + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + User.delete_user_activities(user) + Mix.shell().info("User #{nickname} deleted.") + else + _ -> + Mix.shell().error("No local user #{nickname}") + end + end + defp set_moderator(user, value) do info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 50e7e7ccd..2d0a8cde4 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1083,6 +1083,12 @@ defmodule Pleroma.User do friends |> Enum.each(fn followed -> User.unfollow(user, followed) end) + delete_user_activities(user) + + {:ok, user} + end + + def delete_user_activities(user) do query = from(a in Activity, where: a.actor == ^user.ap_id) Repo.all(query) @@ -1096,8 +1102,6 @@ defmodule Pleroma.User do "Doing nothing" end end) - - {:ok, user} end def html_filter_policy(%User{info: %{no_rich_text: true}}) do -- 2.45.2