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