From b92e38d2d4c05da19b00162d7ca35f1905b44a80 Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 29 Oct 2018 23:08:56 +0000 Subject: [PATCH] Add user reactivation task. --- lib/mix/tasks/deactivate_user.ex | 2 +- lib/mix/tasks/reactivate_user.ex | 13 +++++++++++++ lib/pleroma/user.ex | 4 ++-- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- test/user_test.exs | 4 +++- 5 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 lib/mix/tasks/reactivate_user.ex diff --git a/lib/mix/tasks/deactivate_user.ex b/lib/mix/tasks/deactivate_user.ex index 96b3db6e4..f18541787 100644 --- a/lib/mix/tasks/deactivate_user.ex +++ b/lib/mix/tasks/deactivate_user.ex @@ -2,7 +2,7 @@ defmodule Mix.Tasks.DeactivateUser do use Mix.Task alias Pleroma.User - @shortdoc "Toggle deactivation status for a user" + @shortdoc "Deactivate a user" def run([nickname]) do Mix.Task.run("app.start") diff --git a/lib/mix/tasks/reactivate_user.ex b/lib/mix/tasks/reactivate_user.ex new file mode 100644 index 000000000..40bd068ea --- /dev/null +++ b/lib/mix/tasks/reactivate_user.ex @@ -0,0 +1,13 @@ +defmodule Mix.Tasks.ReactivateUser do + use Mix.Task + alias Pleroma.User + + @shortdoc "Reactivate a user" + def run([nickname]) do + Mix.Task.run("app.start") + + with user <- User.get_by_nickname(nickname) do + User.deactivate(user, false) + end + end +end diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 0c9fa559a..bb5b91c61 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -622,8 +622,8 @@ defmodule Pleroma.User do ) end - def deactivate(%User{} = user) do - new_info = Map.put(user.info, "deactivated", true) + def deactivate(%User{} = user, status \\ true) do + new_info = Map.put(user.info, "deactivated", status) cs = User.info_changeset(user, %{info: new_info}) update_and_set_cache(cs) end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 537b99f31..5a81f6fa2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -44,7 +44,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp check_actor_is_active(actor) do if not is_nil(actor) do with user <- User.get_cached_by_ap_id(actor), - nil <- user.info["deactivated"] do + false <- !!user.info["deactivated"] do :ok else _e -> :reject diff --git a/test/user_test.exs b/test/user_test.exs index 248c26a3d..05da24f8d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -487,11 +487,13 @@ defmodule Pleroma.UserTest do assert addressed in recipients end - test ".deactivate deactivates a user" do + test ".deactivate can de-activate then re-activate a user" do user = insert(:user) assert false == !!user.info["deactivated"] {:ok, user} = User.deactivate(user) assert true == user.info["deactivated"] + {:ok, user} = User.deactivate(user, false) + assert false == !!user.info["deactivated"] end test ".delete deactivates a user, all follow relationships and all create activities" do