2018-10-12 05:12:09 +02:00
|
|
|
defmodule Mix.Tasks.SetAdmin do
|
|
|
|
use Mix.Task
|
2018-12-05 16:41:50 +01:00
|
|
|
import Ecto.Changeset
|
2018-10-12 05:12:09 +02: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 16:41:50 +01:00
|
|
|
admin =
|
2018-10-12 05:12:09 +02:00
|
|
|
case rest do
|
2018-12-05 16:41:50 +01:00
|
|
|
[admin] -> admin == "true"
|
2018-10-12 05:12:09 +02:00
|
|
|
_ -> 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.admin_api_update(user.info, %{is_admin: !!admin})
|
|
|
|
user_cng = Ecto.Changeset.change(user)
|
|
|
|
|> put_embed(:info, info_cng)
|
|
|
|
{:ok, user} = User.update_and_set_cache(user_cng)
|
2018-10-12 05:12:09 +02:00
|
|
|
|
2018-12-05 16:41:50 +01:00
|
|
|
IO.puts("Admin status of #{nickname}: #{user.info.is_admin}")
|
2018-10-12 05:12:09 +02:00
|
|
|
else
|
|
|
|
_ ->
|
|
|
|
IO.puts("No local user #{nickname}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|