distraction.party/lib/mix/tasks/set_admin.ex

35 lines
794 B
Elixir
Raw Normal View History

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