with %User{} = user <- User.get_cached_by_nickname(nickname) do
shell_info("Deactivating #{user.nickname}")
- User.deactivate(user)
+ User.set_activation(user, false)
:timer.sleep(500)
user = User.get_cached_by_id(user.id)
defp maybe_filter_on_ap_id(query, _ap_ids), do: query
- def deactivate_async(user, status \\ true) do
- BackgroundWorker.enqueue("deactivate_user", %{"user_id" => user.id, "status" => status})
+ def set_activation_async(user, status \\ true) do
+ BackgroundWorker.enqueue("user_activation", %{"user_id" => user.id, "status" => status})
end
- def deactivate(user, status \\ true)
-
- def deactivate(users, status) when is_list(users) do
+ @spec set_activation([User.t()], boolean()) :: {:ok, User.t()} | {:error, Changeset.t()}
+ def set_activation(users, status) when is_list(users) do
Repo.transaction(fn ->
- for user <- users, do: deactivate(user, status)
+ for user <- users, do: set_activation(user, status)
end)
end
- def deactivate(%User{} = user, status) do
- with {:ok, user} <- set_activation_status(user, !status) do
+ @spec set_activation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()}
+ def set_activation(%User{} = user, status) do
+ with {:ok, user} <- set_activation_status(user, status) do
user
|> get_followers()
|> Enum.filter(& &1.local)
delete_or_deactivate(user)
end
- def perform(:deactivate_async, user, status), do: deactivate(user, status)
+ def perform(:set_activation_async, user, status), do: set_activation(user, status)
@spec external_users_query() :: Ecto.Query.t()
def external_users_query do
def toggle_activation(%{assigns: %{user: admin}} = conn, %{"nickname" => nickname}) do
user = User.get_cached_by_nickname(nickname)
- {:ok, updated_user} = User.deactivate(user, !user.is_active)
+ {:ok, updated_user} = User.set_activation(user, !user.is_active)
action = if !user.is_active, do: "activate", else: "deactivate"
def activate(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
- {:ok, updated_users} = User.deactivate(users, false)
+ {:ok, updated_users} = User.set_activation(users, true)
ModerationLog.insert_log(%{
actor: admin,
def deactivate(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
- {:ok, updated_users} = User.deactivate(users, true)
+ {:ok, updated_users} = User.set_activation(users, false)
ModerationLog.insert_log(%{
actor: admin,
def disable_account(%{assigns: %{user: user}} = conn, params) do
case CommonAPI.Utils.confirm_current_password(user, params["password"]) do
{:ok, user} ->
- User.deactivate_async(user)
+ User.set_activation_async(user, false)
json(conn, %{status: "success"})
{:error, msg} ->
@impl Oban.Worker
- def perform(%Job{args: %{"op" => "deactivate_user", "user_id" => user_id, "status" => status}}) do
+ def perform(%Job{args: %{"op" => "user_activation", "user_id" => user_id, "status" => status}}) do
user = User.get_cached_by_id(user_id)
- User.perform(:deactivate_async, user, status)
+ User.perform(:set_activation_async, user, status)
end
def perform(%Job{args: %{"op" => "delete_user", "user_id" => user_id}}) do
end
end
- describe ".deactivate" do
+ describe ".set_activation" do
test "can de-activate then re-activate a user" do
user = insert(:user)
assert user.is_active
- {:ok, user} = User.deactivate(user)
+ {:ok, user} = User.set_activation(user, false)
refute user.is_active
- {:ok, user} = User.deactivate(user, false)
+ {:ok, user} = User.set_activation(user, true)
assert user.is_active
end
user2 = insert(:user)
{:ok, user, user2} = User.follow(user, user2)
- {:ok, _user} = User.deactivate(user)
+ {:ok, _user} = User.set_activation(user, false)
user2 = User.get_cached_by_id(user2.id)
assert user2.following_count == 1
assert User.following_count(user2) == 1
- {:ok, _user} = User.deactivate(user)
+ {:ok, _user} = User.set_activation(user, false)
user2 = User.get_cached_by_id(user2.id)
user: user2
})
- {:ok, _user} = User.deactivate(user)
+ {:ok, _user} = User.set_activation(user, false)
assert [] == ActivityPub.fetch_public_activities(%{})
assert [] == Pleroma.Notification.for_user(user2)
assert json_response(conn, 200) ==
user_response(
user,
- %{"is_active" => user.is_active}
+ %{"is_active" => !user.is_active}
)
log_entry = Repo.one(ModerationLog)
user = insert(:user, %{local: true})
user2 = insert(:user, %{local: true})
- {:ok, _user2} = User.deactivate(user2, user2.is_active)
+ {:ok, _user2} = User.set_activation(user2, false)
insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})