set_admin.ex 794 Bytes
Newer Older
1
2
defmodule Mix.Tasks.SetAdmin do
  use Mix.Task
3
  import Ecto.Changeset
4
5
6
7
8
9
10
11
12
  alias Pleroma.User

  @doc """
  Sets admin status
  Usage: set_admin nickname [true|false]
  """
  def run([nickname | rest]) do
    Application.ensure_all_started(:pleroma)

13
    admin =
14
      case rest do
15
        [admin] -> admin == "true"
16
17
18
19
        _ -> true
      end

    with %User{local: true} = user <- User.get_by_nickname(nickname) do
20
      info_cng = User.Info.admin_api_update(user.info, %{is_admin: !!admin})
Rin Toshaka's avatar
Sorry    
Rin Toshaka committed
21
22
23
24
25

      user_cng =
        Ecto.Changeset.change(user)
        |> put_embed(:info, info_cng)

26
      {:ok, user} = User.update_and_set_cache(user_cng)
27

28
      IO.puts("Admin status of #{nickname}: #{user.info.is_admin}")
29
30
31
32
33
34
    else
      _ ->
        IO.puts("No local user #{nickname}")
    end
  end
end