2018-05-26 16:45:41 +02:00
|
|
|
defmodule Mix.Tasks.SetLocked do
|
2018-07-13 01:02:18 +02:00
|
|
|
@moduledoc """
|
|
|
|
Lock a local user
|
|
|
|
|
|
|
|
The local user will then have to manually accept/reject followers. This can also be done by the user into their settings.
|
|
|
|
|
|
|
|
Usage: ``mix set_locked <username>``
|
|
|
|
|
|
|
|
Example: ``mix set_locked lain``
|
|
|
|
"""
|
2018-12-05 16:44:15 +01:00
|
|
|
|
2018-05-26 16:45:41 +02:00
|
|
|
use Mix.Task
|
2018-12-05 16:41:50 +01:00
|
|
|
import Ecto.Changeset
|
2018-05-26 16:45:41 +02:00
|
|
|
alias Pleroma.{Repo, User}
|
|
|
|
|
|
|
|
def run([nickname | rest]) do
|
2018-12-05 16:41:50 +01:00
|
|
|
Application.ensure_all_started(:pleroma)
|
2018-05-26 16:45:41 +02:00
|
|
|
|
|
|
|
locked =
|
|
|
|
case rest do
|
|
|
|
[locked] -> locked == "true"
|
|
|
|
_ -> true
|
|
|
|
end
|
|
|
|
|
|
|
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
2018-12-05 16:41:50 +01:00
|
|
|
info_cng = User.Info.profile_update(user.info, %{locked: !!locked})
|
2018-12-05 16:44:15 +01:00
|
|
|
|
|
|
|
user_cng =
|
|
|
|
Ecto.Changeset.change(user)
|
|
|
|
|> put_embed(:info, info_cng)
|
|
|
|
|
2018-12-05 16:41:50 +01:00
|
|
|
{:ok, user} = User.update_and_set_cache(user_cng)
|
2018-05-26 16:45:41 +02:00
|
|
|
|
2018-12-05 16:41:50 +01:00
|
|
|
IO.puts("Locked status of #{nickname}: #{user.info.locked}")
|
2018-05-26 16:45:41 +02:00
|
|
|
else
|
|
|
|
_ ->
|
|
|
|
IO.puts("No local user #{nickname}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|