1
0
mirror of https://git.pleroma.social/sjw/pleroma.git synced 2024-12-28 14:55:04 +01:00

Merge branch 'reactivate' into 'develop'

Add user reactivation task.

Closes #338

See merge request pleroma/pleroma!404
This commit is contained in:
kaniini 2018-10-30 20:30:01 +00:00
commit c5948996f6
5 changed files with 20 additions and 5 deletions

View File

@ -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")

View 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

View File

@ -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

View File

@ -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

View File

@ -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