forked from AkkomaGang/akkoma
Add user reactivation task.
This commit is contained in:
parent
a880e0a527
commit
b92e38d2d4
5 changed files with 20 additions and 5 deletions
|
@ -2,7 +2,7 @@ defmodule Mix.Tasks.DeactivateUser do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@shortdoc "Toggle deactivation status for a user"
|
@shortdoc "Deactivate a user"
|
||||||
def run([nickname]) do
|
def run([nickname]) do
|
||||||
Mix.Task.run("app.start")
|
Mix.Task.run("app.start")
|
||||||
|
|
||||||
|
|
13
lib/mix/tasks/reactivate_user.ex
Normal file
13
lib/mix/tasks/reactivate_user.ex
Normal file
|
@ -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
|
|
@ -622,8 +622,8 @@ def moderator_user_query() do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def deactivate(%User{} = user) do
|
def deactivate(%User{} = user, status \\ true) do
|
||||||
new_info = Map.put(user.info, "deactivated", true)
|
new_info = Map.put(user.info, "deactivated", status)
|
||||||
cs = User.info_changeset(user, %{info: new_info})
|
cs = User.info_changeset(user, %{info: new_info})
|
||||||
update_and_set_cache(cs)
|
update_and_set_cache(cs)
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ defp get_recipients(data) do
|
||||||
defp check_actor_is_active(actor) do
|
defp check_actor_is_active(actor) do
|
||||||
if not is_nil(actor) do
|
if not is_nil(actor) do
|
||||||
with user <- User.get_cached_by_ap_id(actor),
|
with user <- User.get_cached_by_ap_id(actor),
|
||||||
nil <- user.info["deactivated"] do
|
false <- !!user.info["deactivated"] do
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
_e -> :reject
|
_e -> :reject
|
||||||
|
|
|
@ -487,11 +487,13 @@ test "get recipients from activity" do
|
||||||
assert addressed in recipients
|
assert addressed in recipients
|
||||||
end
|
end
|
||||||
|
|
||||||
test ".deactivate deactivates a user" do
|
test ".deactivate can de-activate then re-activate a user" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
assert false == !!user.info["deactivated"]
|
assert false == !!user.info["deactivated"]
|
||||||
{:ok, user} = User.deactivate(user)
|
{:ok, user} = User.deactivate(user)
|
||||||
assert true == user.info["deactivated"]
|
assert true == user.info["deactivated"]
|
||||||
|
{:ok, user} = User.deactivate(user, false)
|
||||||
|
assert false == !!user.info["deactivated"]
|
||||||
end
|
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
|
||||||
|
|
Loading…
Reference in a new issue