2018-10-11 20:12:09 -07:00
|
|
|
defmodule Mix.Tasks.SetAdmin do
|
|
|
|
use Mix.Task
|
2018-12-05 07:41:50 -08:00
|
|
|
import Ecto.Changeset
|
2018-10-11 20:12:09 -07:00
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Sets admin status
|
|
|
|
Usage: set_admin nickname [true|false]
|
|
|
|
"""
|
|
|
|
def run([nickname | rest]) do
|
|
|
|
Application.ensure_all_started(:pleroma)
|
|
|
|
|
2018-12-05 07:41:50 -08:00
|
|
|
admin =
|
2018-10-11 20:12:09 -07:00
|
|
|
case rest do
|
2018-12-05 07:41:50 -08:00
|
|
|
[admin] -> admin == "true"
|
2018-10-11 20:12:09 -07:00
|
|
|
_ -> true
|
|
|
|
end
|
|
|
|
|
|
|
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
2018-12-05 07:41:50 -08:00
|
|
|
info_cng = User.Info.admin_api_update(user.info, %{is_admin: !!admin})
|
2018-12-05 07:44:15 -08:00
|
|
|
|
|
|
|
user_cng =
|
|
|
|
Ecto.Changeset.change(user)
|
|
|
|
|> put_embed(:info, info_cng)
|
|
|
|
|
2018-12-05 07:41:50 -08:00
|
|
|
{:ok, user} = User.update_and_set_cache(user_cng)
|
2018-10-11 20:12:09 -07:00
|
|
|
|
2018-12-05 07:41:50 -08:00
|
|
|
IO.puts("Admin status of #{nickname}: #{user.info.is_admin}")
|
2018-10-11 20:12:09 -07:00
|
|
|
else
|
|
|
|
_ ->
|
|
|
|
IO.puts("No local user #{nickname}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|