2018-02-21 12:33:36 -05:00
|
|
|
defmodule Mix.Tasks.SetModerator do
|
2018-07-12 19:02:18 -04:00
|
|
|
@moduledoc """
|
|
|
|
Set moderator to a local user
|
|
|
|
|
|
|
|
Usage: ``mix set_moderator <username>``
|
|
|
|
|
|
|
|
Example: ``mix set_moderator lain``
|
|
|
|
"""
|
|
|
|
|
2018-02-21 12:33:36 -05:00
|
|
|
use Mix.Task
|
|
|
|
import Mix.Ecto
|
|
|
|
alias Pleroma.{Repo, User}
|
|
|
|
|
|
|
|
def run([nickname | rest]) do
|
2018-06-12 08:42:40 -04:00
|
|
|
Application.ensure_all_started(:pleroma)
|
2018-02-21 12:33:36 -05:00
|
|
|
|
2018-03-30 09:01:53 -04:00
|
|
|
moderator =
|
|
|
|
case rest do
|
|
|
|
[moderator] -> moderator == "true"
|
|
|
|
_ -> true
|
|
|
|
end
|
2018-02-21 12:33:36 -05:00
|
|
|
|
|
|
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
2018-03-30 09:01:53 -04:00
|
|
|
info =
|
|
|
|
user.info
|
|
|
|
|> Map.put("is_moderator", !!moderator)
|
|
|
|
|
2018-02-21 12:33:36 -05:00
|
|
|
cng = User.info_changeset(user, %{info: info})
|
2018-06-11 15:53:38 -04:00
|
|
|
{:ok, user} = User.update_and_set_cache(cng)
|
2018-02-21 12:33:36 -05:00
|
|
|
|
2018-03-30 09:01:53 -04:00
|
|
|
IO.puts("Moderator status of #{nickname}: #{user.info["is_moderator"]}")
|
2018-02-21 12:33:36 -05:00
|
|
|
else
|
|
|
|
_ ->
|
2018-03-30 09:01:53 -04:00
|
|
|
IO.puts("No local user #{nickname}")
|
2018-02-21 12:33:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|