2018-05-26 08:45:41 -06:00
|
|
|
defmodule Mix.Tasks.SetLocked do
|
2018-07-12 17:02:18 -06: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 08:44:15 -07:00
|
|
|
|
2018-05-26 08:45:41 -06:00
|
|
|
use Mix.Task
|
2018-12-05 08:41:50 -07:00
|
|
|
import Ecto.Changeset
|
2018-05-26 08:45:41 -06:00
|
|
|
alias Pleroma.{Repo, User}
|
|
|
|
|
|
|
|
def run([nickname | rest]) do
|
2018-12-05 08:41:50 -07:00
|
|
|
Application.ensure_all_started(:pleroma)
|
2018-05-26 08:45:41 -06:00
|
|
|
|
|
|
|
locked =
|
|
|
|
case rest do
|
|
|
|
[locked] -> locked == "true"
|
|
|
|
_ -> true
|
|
|
|
end
|
|
|
|
|
|
|
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
2018-12-05 08:41:50 -07:00
|
|
|
info_cng = User.Info.profile_update(user.info, %{locked: !!locked})
|
2018-12-05 08:44:15 -07:00
|
|
|
|
|
|
|
user_cng =
|
|
|
|
Ecto.Changeset.change(user)
|
|
|
|
|> put_embed(:info, info_cng)
|
|
|
|
|
2018-12-05 08:41:50 -07:00
|
|
|
{:ok, user} = User.update_and_set_cache(user_cng)
|
2018-05-26 08:45:41 -06:00
|
|
|
|
2018-12-05 08:41:50 -07:00
|
|
|
IO.puts("Locked status of #{nickname}: #{user.info.locked}")
|
2018-05-26 08:45:41 -06:00
|
|
|
else
|
|
|
|
_ ->
|
|
|
|
IO.puts("No local user #{nickname}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|