add user delete_activities
mix task
This commit is contained in:
parent
a1869f5272
commit
a14742f495
4 changed files with 43 additions and 18 deletions
|
@ -33,6 +33,10 @@ defmodule Mix.Tasks.Pleroma.User do
|
||||||
|
|
||||||
mix pleroma.user rm NICKNAME
|
mix pleroma.user rm NICKNAME
|
||||||
|
|
||||||
|
## Delete the user's activities.
|
||||||
|
|
||||||
|
mix pleroma.user delete_activities NICKNAME
|
||||||
|
|
||||||
## Deactivate or activate the user's account.
|
## Deactivate or activate the user's account.
|
||||||
|
|
||||||
mix pleroma.user toggle_activated NICKNAME
|
mix pleroma.user toggle_activated NICKNAME
|
||||||
|
@ -309,7 +313,7 @@ def run(["delete_activities", nickname]) do
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||||
User.delete_user_activities(user)
|
User.delete_user_activities(user)
|
||||||
Mix.shell().info("User #{nickname} statuses deleted..")
|
Mix.shell().info("User #{nickname} statuses deleted.")
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
Mix.shell().error("No local user #{nickname}")
|
Mix.shell().error("No local user #{nickname}")
|
||||||
|
|
|
@ -1088,29 +1088,30 @@ def delete(%User{} = user) do
|
||||||
# Remove all relationships
|
# Remove all relationships
|
||||||
{:ok, followers} = User.get_followers(user)
|
{:ok, followers} = User.get_followers(user)
|
||||||
|
|
||||||
followers
|
Enum.each(followers, fn follower -> User.unfollow(follower, user) end)
|
||||||
|> Enum.each(fn follower -> User.unfollow(follower, user) end)
|
|
||||||
|
|
||||||
{:ok, friends} = User.get_friends(user)
|
{:ok, friends} = User.get_friends(user)
|
||||||
|
|
||||||
friends
|
Enum.each(friends, fn followed -> User.unfollow(user, followed) end)
|
||||||
|> Enum.each(fn followed -> User.unfollow(user, followed) end)
|
|
||||||
|
|
||||||
query =
|
delete_user_activities(user)
|
||||||
from(a in Activity, where: a.actor == ^user.ap_id)
|
end
|
||||||
|
|
||||||
|
def delete_user_activities(%User{ap_id: ap_id} = user) do
|
||||||
|
Activity
|
||||||
|
|> where(actor: ^ap_id)
|
||||||
|> Activity.with_preloaded_object()
|
|> Activity.with_preloaded_object()
|
||||||
|
|> Repo.all()
|
||||||
Repo.all(query)
|
|> Enum.each(fn
|
||||||
|> Enum.each(fn activity ->
|
%{data: %{"type" => "Create"}} = activity ->
|
||||||
case activity.data["type"] do
|
activity |> Object.normalize() |> ActivityPub.delete()
|
||||||
"Create" ->
|
|
||||||
ActivityPub.delete(Object.normalize(activity))
|
|
||||||
|
|
||||||
# TODO: Do something with likes, follows, repeats.
|
# TODO: Do something with likes, follows, repeats.
|
||||||
_ ->
|
_ ->
|
||||||
"Doing nothing"
|
"Doing nothing"
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
{:ok, user}
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_filter_policy(%User{info: %{no_rich_text: true}}) do
|
def html_filter_policy(%User{info: %{no_rich_text: true}}) do
|
||||||
|
|
|
@ -248,4 +248,14 @@ test "invite token is generated" do
|
||||||
assert message =~ "Generated"
|
assert message =~ "Generated"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "running delete_activities" do
|
||||||
|
test "activities are deleted" do
|
||||||
|
%{nickname: nickname} = insert(:user)
|
||||||
|
|
||||||
|
assert :ok == Mix.Tasks.Pleroma.User.run(["delete_activities", nickname])
|
||||||
|
assert_received {:mix_shell, :info, [message]}
|
||||||
|
assert message == "User #{nickname} statuses deleted."
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -792,6 +792,16 @@ test ".deactivate can de-activate then re-activate a user" do
|
||||||
assert false == user.info.deactivated
|
assert false == user.info.deactivated
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test ".delete_user_activities deletes all create activities" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
||||||
|
{:ok, _} = User.delete_user_activities(user)
|
||||||
|
|
||||||
|
# TODO: Remove favorites, repeats, delete activities.
|
||||||
|
refute Activity.get_by_id(activity.id)
|
||||||
|
end
|
||||||
|
|
||||||
test ".delete deactivates a user, all follow relationships and all create activities" do
|
test ".delete deactivates a user, all follow relationships and all create activities" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
followed = insert(:user)
|
followed = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue